Merge pull request #38 from executionunit/master

VS2010 build and Fix for Negative Scale in X
This commit is contained in:
Nathan Sweet 2013-04-25 13:49:26 -07:00
commit 7f78b25312
14 changed files with 455 additions and 105 deletions

20
spine-c/Spine-C.sln Normal file
View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Spine-C", "Spine-C.vcxproj", "{5D74934A-7512-45EE-8402-7B95D3642E85}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5D74934A-7512-45EE-8402-7B95D3642E85}.Debug|Win32.ActiveCfg = Debug|Win32
{5D74934A-7512-45EE-8402-7B95D3642E85}.Debug|Win32.Build.0 = Debug|Win32
{5D74934A-7512-45EE-8402-7B95D3642E85}.Release|Win32.ActiveCfg = Release|Win32
{5D74934A-7512-45EE-8402-7B95D3642E85}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

120
spine-c/Spine-C.vcxproj Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5D74934A-7512-45EE-8402-7B95D3642E85}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>SpineC</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\spine\Animation.h" />
<ClInclude Include="include\spine\AnimationState.h" />
<ClInclude Include="include\spine\AnimationStateData.h" />
<ClInclude Include="include\spine\Atlas.h" />
<ClInclude Include="include\spine\AtlasAttachmentLoader.h" />
<ClInclude Include="include\spine\Attachment.h" />
<ClInclude Include="include\spine\AttachmentLoader.h" />
<ClInclude Include="include\spine\Bone.h" />
<ClInclude Include="include\spine\BoneData.h" />
<ClInclude Include="include\spine\extension.h" />
<ClInclude Include="include\spine\RegionAttachment.h" />
<ClInclude Include="include\spine\Skeleton.h" />
<ClInclude Include="include\spine\SkeletonData.h" />
<ClInclude Include="include\spine\SkeletonJson.h" />
<ClInclude Include="include\spine\Skin.h" />
<ClInclude Include="include\spine\Slot.h" />
<ClInclude Include="include\spine\SlotData.h" />
<ClInclude Include="include\spine\spine.h" />
<ClInclude Include="src\spine\Json.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\spine\Animation.c" />
<ClCompile Include="src\spine\AnimationState.c" />
<ClCompile Include="src\spine\AnimationStateData.c" />
<ClCompile Include="src\spine\Atlas.c" />
<ClCompile Include="src\spine\AtlasAttachmentLoader.c" />
<ClCompile Include="src\spine\Attachment.c" />
<ClCompile Include="src\spine\AttachmentLoader.c" />
<ClCompile Include="src\spine\Bone.c" />
<ClCompile Include="src\spine\BoneData.c" />
<ClCompile Include="src\spine\extension.c" />
<ClCompile Include="src\spine\Json.c" />
<ClCompile Include="src\spine\RegionAttachment.c" />
<ClCompile Include="src\spine\Skeleton.c" />
<ClCompile Include="src\spine\SkeletonData.c" />
<ClCompile Include="src\spine\SkeletonJson.c" />
<ClCompile Include="src\spine\Skin.c" />
<ClCompile Include="src\spine\Slot.c" />
<ClCompile Include="src\spine\SlotData.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\spine\Animation.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\AnimationState.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\AnimationStateData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\Atlas.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\AtlasAttachmentLoader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\Attachment.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\AttachmentLoader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\Bone.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\BoneData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\extension.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\RegionAttachment.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\Skeleton.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\SkeletonData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\SkeletonJson.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\Skin.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\Slot.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\SlotData.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\spine\spine.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\spine\Json.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\spine\Animation.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\AnimationState.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\AnimationStateData.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\Atlas.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\AtlasAttachmentLoader.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\Attachment.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\AttachmentLoader.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\Bone.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\BoneData.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\extension.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\Json.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\RegionAttachment.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\Skeleton.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\SkeletonData.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\SkeletonJson.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\Skin.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\Slot.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\spine\SlotData.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -49,17 +49,19 @@ void Animation_dispose (Animation* self) {
}
void Animation_apply (const Animation* self, Skeleton* skeleton, float time, int/*bool*/loop) {
int i, n = self->timelineCount;
if (loop && self->duration) time = fmodf(time, self->duration);
int i, n = self->timelineCount;
for (i = 0; i < n; ++i)
Timeline_apply(self->timelines[i], skeleton, time, 1);
}
void Animation_mix (const Animation* self, Skeleton* skeleton, float time, int/*bool*/loop, float alpha) {
int i, n = self->timelineCount;
if (loop && self->duration) time = fmodf(time, self->duration);
int i, n = self->timelineCount;
for (i = 0; i < n; ++i)
Timeline_apply(self->timelines[i], skeleton, time, alpha);
}
@ -139,17 +141,24 @@ void CurveTimeline_setCurve (CurveTimeline* self, int frameIndex, float cx1, flo
}
float CurveTimeline_getCurvePercent (const CurveTimeline* self, int frameIndex, float percent) {
float dfy;
float ddfx;
float ddfy;
float dddfx;
float dddfy;
float x, y;
int i;
int curveIndex = frameIndex * 6;
float dfx = self->curves[curveIndex];
if (dfx == CURVE_LINEAR) return percent;
if (dfx == CURVE_STEPPED) return 0;
float dfy = self->curves[curveIndex + 1];
float ddfx = self->curves[curveIndex + 2];
float ddfy = self->curves[curveIndex + 3];
float dddfx = self->curves[curveIndex + 4];
float dddfy = self->curves[curveIndex + 5];
float x = dfx, y = dfy;
int i = CURVE_SEGMENTS - 2;
dfy = self->curves[curveIndex + 1];
ddfx = self->curves[curveIndex + 2];
ddfy = self->curves[curveIndex + 3];
dddfx = self->curves[curveIndex + 4];
dddfy = self->curves[curveIndex + 5];
x = dfx, y = dfy;
i = CURVE_SEGMENTS - 2;
while (1) {
if (x >= percent) {
float lastX = x - dfx;
@ -170,10 +179,10 @@ float CurveTimeline_getCurvePercent (const CurveTimeline* self, int frameIndex,
/* @param target After the first and before the last entry. */
static int binarySearch (float *values, int valuesLength, float target, int step) {
int low = 0;
int low = 0, current;
int high = valuesLength / step - 2;
if (high == 0) return step;
int current = high >> 1;
current = high >> 1;
while (1) {
if (values[(current + 1) * step] <= target)
low = current + 1;
@ -222,11 +231,15 @@ static const int ROTATE_LAST_FRAME_TIME = -2;
static const int ROTATE_FRAME_VALUE = 1;
void _RotateTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float time, float alpha) {
Bone *bone;
int frameIndex;
float lastFrameValue, frameTime, percent, amount;
RotateTimeline* self = SUB_CAST(RotateTimeline, timeline);
if (time < self->frames[0]) return; /* Time is before first frame. */
Bone *bone = skeleton->bones[self->boneIndex];
bone = skeleton->bones[self->boneIndex];
if (time >= self->frames[self->framesLength - 2]) { /* Time is after last frame. */
float amount = bone->data->rotation + self->frames[self->framesLength - 1] - bone->rotation;
@ -239,13 +252,13 @@ void _RotateTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float
}
/* Interpolate between the last frame and the current frame. */
int frameIndex = binarySearch(self->frames, self->framesLength, time, 2);
float lastFrameValue = self->frames[frameIndex - 1];
float frameTime = self->frames[frameIndex];
float percent = 1 - (time - frameTime) / (self->frames[frameIndex + ROTATE_LAST_FRAME_TIME] - frameTime);
frameIndex = binarySearch(self->frames, self->framesLength, time, 2);
lastFrameValue = self->frames[frameIndex - 1];
frameTime = self->frames[frameIndex];
percent = 1 - (time - frameTime) / (self->frames[frameIndex + ROTATE_LAST_FRAME_TIME] - frameTime);
percent = CurveTimeline_getCurvePercent(SUPER(self), frameIndex / 2 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent));
float amount = self->frames[frameIndex + ROTATE_FRAME_VALUE] - lastFrameValue;
amount = self->frames[frameIndex + ROTATE_FRAME_VALUE] - lastFrameValue;
while (amount > 180)
amount -= 360;
while (amount < -180)
@ -275,11 +288,15 @@ static const int TRANSLATE_FRAME_X = 1;
static const int TRANSLATE_FRAME_Y = 2;
void _TranslateTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float time, float alpha) {
Bone *bone;
int frameIndex;
float lastFrameX, lastFrameY, frameTime, percent;
TranslateTimeline* self = SUB_CAST(TranslateTimeline, timeline);
if (time < self->frames[0]) return; /* Time is before first frame. */
Bone *bone = skeleton->bones[self->boneIndex];
bone = skeleton->bones[self->boneIndex];
if (time >= self->frames[self->framesLength - 3]) { /* Time is after last frame. */
bone->x += (bone->data->x + self->frames[self->framesLength - 2] - bone->x) * alpha;
@ -288,11 +305,11 @@ void _TranslateTimeline_apply (const Timeline* timeline, Skeleton* skeleton, flo
}
/* Interpolate between the last frame and the current frame. */
int frameIndex = binarySearch(self->frames, self->framesLength, time, 3);
float lastFrameX = self->frames[frameIndex - 2];
float lastFrameY = self->frames[frameIndex - 1];
float frameTime = self->frames[frameIndex];
float percent = 1 - (time - frameTime) / (self->frames[frameIndex + TRANSLATE_LAST_FRAME_TIME] - frameTime);
frameIndex = binarySearch(self->frames, self->framesLength, time, 3);
lastFrameX = self->frames[frameIndex - 2];
lastFrameY = self->frames[frameIndex - 1];
frameTime = self->frames[frameIndex];
percent = 1 - (time - frameTime) / (self->frames[frameIndex + TRANSLATE_LAST_FRAME_TIME] - frameTime);
percent = CurveTimeline_getCurvePercent(SUPER(self), frameIndex / 3 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent));
bone->x += (bone->data->x + lastFrameX + (self->frames[frameIndex + TRANSLATE_FRAME_X] - lastFrameX) * percent - bone->x)
@ -315,11 +332,15 @@ void TranslateTimeline_setFrame (TranslateTimeline* self, int frameIndex, float
/**/
void _ScaleTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float time, float alpha) {
Bone *bone;
int frameIndex;
float lastFrameX, lastFrameY, frameTime, percent;
ScaleTimeline* self = SUB_CAST(ScaleTimeline, timeline);
if (time < self->frames[0]) return; /* Time is before first frame. */
Bone *bone = skeleton->bones[self->boneIndex];
bone = skeleton->bones[self->boneIndex];
if (time >= self->frames[self->framesLength - 3]) { /* Time is after last frame. */
bone->scaleX += (bone->data->scaleX - 1 + self->frames[self->framesLength - 2] - bone->scaleX) * alpha;
bone->scaleY += (bone->data->scaleY - 1 + self->frames[self->framesLength - 1] - bone->scaleY) * alpha;
@ -327,11 +348,11 @@ void _ScaleTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float t
}
/* Interpolate between the last frame and the current frame. */
int frameIndex = binarySearch(self->frames, self->framesLength, time, 3);
float lastFrameX = self->frames[frameIndex - 2];
float lastFrameY = self->frames[frameIndex - 1];
float frameTime = self->frames[frameIndex];
float percent = 1 - (time - frameTime) / (self->frames[frameIndex + TRANSLATE_LAST_FRAME_TIME] - frameTime);
frameIndex = binarySearch(self->frames, self->framesLength, time, 3);
lastFrameX = self->frames[frameIndex - 2];
lastFrameY = self->frames[frameIndex - 1];
frameTime = self->frames[frameIndex];
percent = 1 - (time - frameTime) / (self->frames[frameIndex + TRANSLATE_LAST_FRAME_TIME] - frameTime);
percent = CurveTimeline_getCurvePercent(SUPER(self), frameIndex / 3 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent));
bone->scaleX += (bone->data->scaleX - 1 + lastFrameX + (self->frames[frameIndex + TRANSLATE_FRAME_X] - lastFrameX) * percent
@ -357,11 +378,15 @@ static const int COLOR_FRAME_B = 3;
static const int COLOR_FRAME_A = 4;
void _ColorTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float time, float alpha) {
Slot *slot;
int frameIndex;
float lastFrameR, lastFrameG, lastFrameB, lastFrameA, percent, frameTime;
float r, g, b, a;
ColorTimeline* self = (ColorTimeline*)timeline;
if (time < self->frames[0]) return; /* Time is before first frame. */
Slot *slot = skeleton->slots[self->slotIndex];
slot = skeleton->slots[self->slotIndex];
if (time >= self->frames[self->framesLength - 5]) { /* Time is after last frame. */
int i = self->framesLength - 1;
@ -373,19 +398,19 @@ void _ColorTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float t
}
/* Interpolate between the last frame and the current frame. */
int frameIndex = binarySearch(self->frames, self->framesLength, time, 5);
float lastFrameR = self->frames[frameIndex - 4];
float lastFrameG = self->frames[frameIndex - 3];
float lastFrameB = self->frames[frameIndex - 2];
float lastFrameA = self->frames[frameIndex - 1];
float frameTime = self->frames[frameIndex];
float percent = 1 - (time - frameTime) / (self->frames[frameIndex + COLOR_LAST_FRAME_TIME] - frameTime);
frameIndex = binarySearch(self->frames, self->framesLength, time, 5);
lastFrameR = self->frames[frameIndex - 4];
lastFrameG = self->frames[frameIndex - 3];
lastFrameB = self->frames[frameIndex - 2];
lastFrameA = self->frames[frameIndex - 1];
frameTime = self->frames[frameIndex];
percent = 1 - (time - frameTime) / (self->frames[frameIndex + COLOR_LAST_FRAME_TIME] - frameTime);
percent = CurveTimeline_getCurvePercent(SUPER(self), frameIndex / 5 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent));
float r = lastFrameR + (self->frames[frameIndex + COLOR_FRAME_R] - lastFrameR) * percent;
float g = lastFrameG + (self->frames[frameIndex + COLOR_FRAME_G] - lastFrameG) * percent;
float b = lastFrameB + (self->frames[frameIndex + COLOR_FRAME_B] - lastFrameB) * percent;
float a = lastFrameA + (self->frames[frameIndex + COLOR_FRAME_A] - lastFrameA) * percent;
r = lastFrameR + (self->frames[frameIndex + COLOR_FRAME_R] - lastFrameR) * percent;
g = lastFrameG + (self->frames[frameIndex + COLOR_FRAME_G] - lastFrameG) * percent;
b = lastFrameB + (self->frames[frameIndex + COLOR_FRAME_B] - lastFrameB) * percent;
a = lastFrameA + (self->frames[frameIndex + COLOR_FRAME_A] - lastFrameA) * percent;
if (alpha < 1) {
slot->r += (r - slot->r) * alpha;
slot->g += (g - slot->g) * alpha;
@ -415,26 +440,30 @@ void ColorTimeline_setFrame (ColorTimeline* self, int frameIndex, float time, fl
/**/
void _AttachmentTimeline_apply (const Timeline* timeline, Skeleton* skeleton, float time, float alpha) {
int frameIndex;
const char* attachmentName;
AttachmentTimeline* self = (AttachmentTimeline*)timeline;
if (time < self->frames[0]) return; /* Time is before first frame. */
int frameIndex;
frameIndex;
if (time >= self->frames[self->framesLength - 1]) /* Time is after last frame. */
frameIndex = self->framesLength - 1;
else
frameIndex = binarySearch(self->frames, self->framesLength, time, 1) - 1;
const char* attachmentName = self->attachmentNames[frameIndex];
attachmentName = self->attachmentNames[frameIndex];
Slot_setAttachment(skeleton->slots[self->slotIndex],
attachmentName ? Skeleton_getAttachmentForSlotIndex(skeleton, self->slotIndex, attachmentName) : 0);
}
void _AttachmentTimeline_dispose (Timeline* timeline) {
_Timeline_deinit(timeline);
AttachmentTimeline* self = (AttachmentTimeline*)timeline;
AttachmentTimeline* self;
int i;
_Timeline_deinit(timeline);
self = (AttachmentTimeline*)timeline;
for (i = 0; i < self->framesLength; ++i)
FREE(self->attachmentNames[i]);
FREE(self->attachmentNames);

View File

@ -56,11 +56,14 @@ void AnimationState_update (AnimationState* self, float delta) {
}
void AnimationState_apply (AnimationState* self, Skeleton* skeleton) {
_Internal* internal;
float alpha;
if (!self->animation) return;
_Internal* internal = SUB_CAST(_Internal, self);
internal = SUB_CAST(_Internal, self);
if (internal->previous) {
Animation_apply(internal->previous, skeleton, internal->previousTime, internal->previousLoop);
float alpha = internal->mixTime / internal->mixDuration;
alpha = internal->mixTime / internal->mixDuration;
if (alpha >= 1) {
alpha = 1;
internal->previous = 0;

View File

@ -76,37 +76,43 @@ AnimationStateData* AnimationStateData_create (SkeletonData* skeletonData) {
}
void AnimationStateData_dispose (AnimationStateData* self) {
_ToEntry* toEntry;
_ToEntry* nextToEntry;
_FromEntry* nextFromEntry;
_FromEntry* fromEntry = (_FromEntry*)self->entries;
while (fromEntry) {
_ToEntry* toEntry = fromEntry->toEntries;
toEntry = fromEntry->toEntries;
while (toEntry) {
_ToEntry* next = toEntry->next;
nextToEntry = toEntry->next;
_ToEntry_dispose(toEntry);
toEntry = next;
toEntry = nextToEntry;
}
_FromEntry* next = fromEntry->next;
nextFromEntry = fromEntry->next;
_FromEntry_dispose(fromEntry);
fromEntry = next;
fromEntry = nextFromEntry;
}
FREE(self);
}
void AnimationStateData_setMixByName (AnimationStateData* self, const char* fromName, const char* toName, float duration) {
Animation* to;
Animation* from = SkeletonData_findAnimation(self->skeletonData, fromName);
if (!from) return;
Animation* to = SkeletonData_findAnimation(self->skeletonData, toName);
to = SkeletonData_findAnimation(self->skeletonData, toName);
if (!to) return;
AnimationStateData_setMix(self, from, to, duration);
}
void AnimationStateData_setMix (AnimationStateData* self, Animation* from, Animation* to, float duration) {
/* Find existing FromEntry. */
_ToEntry* toEntry;
_FromEntry* fromEntry = (_FromEntry*)self->entries;
while (fromEntry) {
if (fromEntry->animation == from) {
/* Find existing ToEntry. */
_ToEntry* toEntry = fromEntry->toEntries;
toEntry = fromEntry->toEntries;
while (toEntry) {
if (toEntry->animation == to) {
toEntry->duration = duration;
@ -123,7 +129,7 @@ void AnimationStateData_setMix (AnimationStateData* self, Animation* from, Anima
fromEntry->next = (_FromEntry*)self->entries;
CONST_CAST(_FromEntry*, self->entries) = fromEntry;
}
_ToEntry* toEntry = _ToEntry_create(to, duration);
toEntry = _ToEntry_create(to, duration);
toEntry->next = fromEntry->toEntries;
fromEntry->toEntries = toEntry;
}

View File

@ -116,10 +116,11 @@ static int readValue (const char* end, Str* str) {
/* Returns the number of tuple values read (2, 4, or 0 for failure). */
static int readTuple (const char* end, Str tuple[]) {
int i;
Str str;
readLine(0, end, &str);
if (!beginPast(&str, ':')) return 0;
int i = 0;
for (i = 0; i < 3; ++i) {
tuple[i].begin = str.begin;
if (!beginPast(&str, ',')) {
@ -169,6 +170,7 @@ static const char* textureFilterNames[] = {"Nearest", "Linear", "MipMap", "MipMa
"MipMapNearestLinear", "MipMapLinearLinear"};
Atlas* Atlas_readAtlas (const char* begin, int length, const char* dir) {
int count;
const char* end = begin + length;
int dirLength = strlen(dir);
int needsSlash = dirLength > 0 && dir[dirLength - 1] != '/' && dir[dirLength - 1] != '\\';
@ -246,7 +248,6 @@ Atlas* Atlas_readAtlas (const char* begin, int length, const char* dir) {
region->v2 = (region->y + region->height) / (float)page->height;
}
int count;
if (!(count = readTuple(end, tuple))) return abortAtlas(self);
if (count == 4) { /* split is optional */
region->splits = MALLOC(int, 4);
@ -283,6 +284,11 @@ Atlas* Atlas_readAtlas (const char* begin, int length, const char* dir) {
}
Atlas* Atlas_readAtlasFile (const char* path) {
int dirLength;
char *dir;
int length;
const char* data;
Atlas* atlas = 0;
/* Get directory from atlas path. */
@ -290,13 +296,12 @@ Atlas* Atlas_readAtlasFile (const char* path) {
const char* lastBackwardSlash = strrchr(path, '\\');
const char* lastSlash = lastForwardSlash > lastBackwardSlash ? lastForwardSlash : lastBackwardSlash;
if (lastSlash == path) lastSlash++; /* Never drop starting slash. */
int dirLength = lastSlash ? lastSlash - path : 0;
char* dir = MALLOC(char, dirLength + 1);
dirLength = lastSlash ? lastSlash - path : 0;
dir = MALLOC(char, dirLength + 1);
memcpy(dir, path, dirLength);
dir[dirLength] = '\0';
int length;
const char* data = _Util_readFile(path, &length);
data = _Util_readFile(path, &length);
if (data) atlas = Atlas_readAtlas(data, length, dir);
FREE(data);
@ -305,6 +310,7 @@ Atlas* Atlas_readAtlasFile (const char* path) {
}
void Atlas_dispose (Atlas* self) {
AtlasRegion* region, *nextRegion;
AtlasPage* page = self->pages;
while (page) {
AtlasPage* nextPage = page->next;
@ -312,9 +318,9 @@ void Atlas_dispose (Atlas* self) {
page = nextPage;
}
AtlasRegion* region = self->regions;
region = self->regions;
while (region) {
AtlasRegion* nextRegion = region->next;
nextRegion = region->next;
AtlasRegion_dispose(region);
region = nextRegion;
}

View File

@ -34,12 +34,13 @@ Attachment* _AtlasAttachmentLoader_newAttachment (AttachmentLoader* loader, Skin
AtlasAttachmentLoader* self = SUB_CAST(AtlasAttachmentLoader, loader);
switch (type) {
case ATTACHMENT_REGION: {
RegionAttachment* attachment;
AtlasRegion* region = Atlas_findRegion(self->atlas, name);
if (!region) {
_AttachmentLoader_setError(loader, "Region not found: ", name);
return 0;
}
RegionAttachment* attachment = RegionAttachment_create(name);
attachment = RegionAttachment_create(name);
attachment->texture = region->page->texture;
RegionAttachment_setUVs(attachment, region->u, region->v, region->u2, region->v2, region->rotate);
attachment->regionOffsetX = region->offsetX;

View File

@ -58,6 +58,7 @@ void Bone_setToBindPose (Bone* self) {
}
void Bone_updateWorldTransform (Bone* self, int flipX, int flipY) {
float radians, cosine, sine;
if (self->parent) {
CONST_CAST(float, self->worldX) = self->x * self->parent->m00 + self->y * self->parent->m01 + self->parent->worldX;
CONST_CAST(float, self->worldY) = self->x * self->parent->m10 + self->y * self->parent->m11 + self->parent->worldY;
@ -71,9 +72,9 @@ void Bone_updateWorldTransform (Bone* self, int flipX, int flipY) {
CONST_CAST(float, self->worldScaleY) = self->scaleY;
CONST_CAST(float, self->worldRotation) = self->rotation;
}
float radians = (float)(self->worldRotation * 3.1415926535897932385 / 180);
float cosine = cosf(radians);
float sine = sinf(radians);
radians = (float)(self->worldRotation * 3.1415926535897932385 / 180);
cosine = cosf(radians);
sine = sinf(radians);
CONST_CAST(float, self->m00) = cosine * self->worldScaleX;
CONST_CAST(float, self->m10) = sine * self->worldScaleX;
CONST_CAST(float, self->m01) = -sine * self->worldScaleY;

View File

@ -63,9 +63,9 @@ void RegionAttachment_setUVs (RegionAttachment* self, float u, float v, float u2
void RegionAttachment_updateOffset (RegionAttachment* self) {
float regionScaleX = self->width / self->regionOriginalWidth * self->scaleX;
float regionScaleY = self->height / self->regionOriginalHeight * self->scaleX;
float regionScaleY = self->height / self->regionOriginalHeight * self->scaleY;
float localX = -self->width / 2 * self->scaleX + self->regionOffsetX * regionScaleX;
float localY = -self->height / 2 * self->scaleX + self->regionOffsetY * regionScaleY;
float localY = -self->height / 2 * self->scaleY + self->regionOffsetY * regionScaleY;
float localX2 = localX + self->regionWidth * regionScaleX;
float localY2 = localY + self->regionHeight * regionScaleY;
float radians = (float)(self->rotation * 3.1415926535897932385 / 180);

View File

@ -32,12 +32,14 @@ namespace spine {
#endif
Skeleton* Skeleton_create (SkeletonData* data) {
int i, ii;
Skeleton* self = NEW(Skeleton);
CONST_CAST(SkeletonData*, self->data) = data;
self->boneCount = self->data->boneCount;
self->bones = MALLOC(Bone*, self->boneCount);
int i, ii;
for (i = 0; i < self->boneCount; ++i) {
BoneData* boneData = self->data->bones[i];
Bone* parent = 0;
@ -147,11 +149,12 @@ int Skeleton_findSlotIndex (const Skeleton* self, const char* slotName) {
}
int Skeleton_setSkinByName (Skeleton* self, const char* skinName) {
Skin *skin;
if (!skinName) {
Skeleton_setSkin(self, 0);
return 1;
}
Skin *skin = SkeletonData_findSkin(self->data, skinName);
skin = SkeletonData_findSkin(self->data, skinName);
if (!skin) return 0;
Skeleton_setSkin(self, skin);
return 1;

View File

@ -62,24 +62,28 @@ void SkeletonJson_dispose (SkeletonJson* self) {
}
void _SkeletonJson_setError (SkeletonJson* self, Json* root, const char* value1, const char* value2) {
FREE(self->error);
char message[256];
int length;
FREE(self->error);
strcpy(message, value1);
int length = strlen(value1);
length = strlen(value1);
if (value2) strncat(message + length, value2, 256 - length);
MALLOC_STR(self->error, message);
if (root) Json_dispose(root);
}
static float toColor (const char* value, int index) {
char digits[3];
char *error;
int color;
if (strlen(value) != 8) return -1;
value += index * 2;
char digits[3];
digits[0] = *value;
digits[1] = *(value + 1);
digits[2] = '\0';
char* error;
int color = strtoul(digits, &error, 16);
color = strtoul(digits, &error, 16);
if (*error != 0) return -1;
return color / (float)255;
}
@ -96,6 +100,8 @@ static void readCurve (CurveTimeline* timeline, int frameIndex, Json* frame) {
}
static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, SkeletonData *skeletonData) {
Animation* animation;
Json* bones = Json_getItem(root, "bones");
int boneCount = bones ? Json_getSize(bones) : 0;
@ -108,12 +114,13 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
timelineCount += Json_getSize(Json_getItemAt(bones, i));
for (i = 0; i < slotCount; ++i)
timelineCount += Json_getSize(Json_getItemAt(slots, i));
Animation* animation = Animation_create(root->name, timelineCount);
animation = Animation_create(root->name, timelineCount);
animation->timelineCount = 0;
skeletonData->animations[skeletonData->animationCount] = animation;
skeletonData->animationCount++;
for (i = 0; i < boneCount; ++i) {
int timelineCount;
Json* boneMap = Json_getItemAt(bones, i);
const char* boneName = boneMap->name;
@ -125,13 +132,15 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
return 0;
}
int timelineCount = Json_getSize(boneMap);
timelineCount = Json_getSize(boneMap);
for (ii = 0; ii < timelineCount; ++ii) {
float duration;
Json* timelineArray = Json_getItemAt(boneMap, ii);
int frameCount = Json_getSize(timelineArray);
const char* timelineType = timelineArray->name;
if (strcmp(timelineType, "rotate") == 0) {
RotateTimeline *timeline = RotateTimeline_create(frameCount);
timeline->boneIndex = boneIndex;
for (iii = 0; iii < frameCount; ++iii) {
@ -140,14 +149,14 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
readCurve(SUPER(timeline), iii, frame);
}
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
float duration = timeline->frames[frameCount * 2 - 2];
duration = timeline->frames[frameCount * 2 - 2];
if (duration > animation->duration) animation->duration = duration;
} else {
int isScale = strcmp(timelineType, "scale") == 0;
if (isScale || strcmp(timelineType, "translate") == 0) {
TranslateTimeline *timeline = isScale ? ScaleTimeline_create(frameCount) : TranslateTimeline_create(frameCount);
float scale = isScale ? 1 : self->scale;
TranslateTimeline *timeline = isScale ? ScaleTimeline_create(frameCount) : TranslateTimeline_create(frameCount);
timeline->boneIndex = boneIndex;
for (iii = 0; iii < frameCount; ++iii) {
Json* frame = Json_getItemAt(timelineArray, iii);
@ -156,7 +165,7 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
readCurve(SUPER(timeline), iii, frame);
}
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
float duration = timeline->frames[frameCount * 3 - 3];
duration = timeline->frames[frameCount * 3 - 3];
if (duration > animation->duration) animation->duration = duration;
} else {
Animation_dispose(animation);
@ -168,6 +177,7 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
}
for (i = 0; i < slotCount; ++i) {
int timelineCount;
Json* slotMap = Json_getItemAt(slots, i);
const char* slotName = slotMap->name;
@ -178,8 +188,9 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
return 0;
}
int timelineCount = Json_getSize(slotMap);
timelineCount = Json_getSize(slotMap);
for (ii = 0; ii < timelineCount; ++ii) {
float duration;
Json* timelineArray = Json_getItemAt(slotMap, ii);
int frameCount = Json_getSize(timelineArray);
const char* timelineType = timelineArray->name;
@ -195,7 +206,7 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
readCurve(SUPER(timeline), iii, frame);
}
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
float duration = timeline->frames[frameCount * 5 - 5];
duration = timeline->frames[frameCount * 5 - 5];
if (duration > animation->duration) animation->duration = duration;
} else if (strcmp(timelineType, "attachment") == 0) {
@ -208,7 +219,7 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
name->type == Json_NULL ? 0 : name->valuestring);
}
animation->timelines[animation->timelineCount++] = (Timeline*)timeline;
float duration = timeline->frames[frameCount - 1];
duration = timeline->frames[frameCount - 1];
if (duration > animation->duration) animation->duration = duration;
} else {
@ -224,34 +235,42 @@ static Animation* _SkeletonJson_readAnimation (SkeletonJson* self, Json* root, S
SkeletonData* SkeletonJson_readSkeletonDataFile (SkeletonJson* self, const char* path) {
int length;
SkeletonData* skeletonData;
const char* json = _Util_readFile(path, &length);
if (!json) {
_SkeletonJson_setError(self, 0, "Unable to read skeleton file: ", path);
return 0;
}
SkeletonData* skeletonData = SkeletonJson_readSkeletonData(self, json);
skeletonData = SkeletonJson_readSkeletonData(self, json);
FREE(json);
return skeletonData;
}
SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* json) {
SkeletonData* skeletonData;
Json *root, *bones;
int i, ii, iii, boneCount;
Json* slots;
Json* skinsMap;
Json* animations;
FREE(self->error);
CONST_CAST(char*, self->error) = 0;
Json* root = Json_create(json);
root = Json_create(json);
if (!root) {
_SkeletonJson_setError(self, 0, "Invalid skeleton JSON: ", Json_getError());
return 0;
}
SkeletonData* skeletonData = SkeletonData_create();
int i, ii, iii;
skeletonData = SkeletonData_create();
Json* bones = Json_getItem(root, "bones");
int boneCount = Json_getSize(bones);
bones = Json_getItem(root, "bones");
boneCount = Json_getSize(bones);
skeletonData->bones = MALLOC(BoneData*, boneCount);
for (i = 0; i < boneCount; ++i) {
Json* boneMap = Json_getItemAt(bones, i);
BoneData* boneData;
const char* boneName = Json_getString(boneMap, "name", 0);
@ -266,7 +285,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
}
}
BoneData* boneData = BoneData_create(boneName, parent);
boneData = BoneData_create(boneName, parent);
boneData->length = Json_getFloat(boneMap, "length", 0) * self->scale;
boneData->x = Json_getFloat(boneMap, "x", 0) * self->scale;
boneData->y = Json_getFloat(boneMap, "y", 0) * self->scale;
@ -278,11 +297,14 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
skeletonData->boneCount++;
}
Json* slots = Json_getItem(root, "slots");
slots = Json_getItem(root, "slots");
if (slots) {
int slotCount = Json_getSize(slots);
skeletonData->slots = MALLOC(SlotData*, slotCount);
for (i = 0; i < slotCount; ++i) {
SlotData* slotData;
const char* color;
Json *attachmentItem;
Json* slotMap = Json_getItemAt(slots, i);
const char* slotName = Json_getString(slotMap, "name", 0);
@ -295,9 +317,9 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
return 0;
}
SlotData* slotData = SlotData_create(slotName, boneData);
slotData = SlotData_create(slotName, boneData);
const char* color = Json_getString(slotMap, "color", 0);
color = Json_getString(slotMap, "color", 0);
if (color) {
slotData->r = toColor(color, 0);
slotData->g = toColor(color, 1);
@ -305,7 +327,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
slotData->a = toColor(color, 3);
}
Json *attachmentItem = Json_getItem(slotMap, "attachment");
attachmentItem = Json_getItem(slotMap, "attachment");
if (attachmentItem) SlotData_setAttachmentName(slotData, attachmentItem->valuestring);
skeletonData->slots[i] = slotData;
@ -313,7 +335,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
}
}
Json* skinsMap = Json_getItem(root, "skins");
skinsMap = Json_getItem(root, "skins");
if (skinsMap) {
int skinCount = Json_getSize(skinsMap);
skeletonData->skins = MALLOC(Skin*, skinCount);
@ -321,11 +343,13 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
Json* slotMap = Json_getItemAt(skinsMap, i);
const char* skinName = slotMap->name;
Skin *skin = Skin_create(skinName);
int slotNameCount;
skeletonData->skins[i] = skin;
skeletonData->skinCount++;
if (strcmp(skinName, "default") == 0) skeletonData->defaultSkin = skin;
int slotNameCount = Json_getSize(slotMap);
slotNameCount = Json_getSize(slotMap);
for (ii = 0; ii < slotNameCount; ++ii) {
Json* attachmentsMap = Json_getItemAt(slotMap, ii);
const char* slotName = attachmentsMap->name;
@ -333,6 +357,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
int attachmentCount = Json_getSize(attachmentsMap);
for (iii = 0; iii < attachmentCount; ++iii) {
Attachment* attachment;
Json* attachmentMap = Json_getItemAt(attachmentsMap, iii);
const char* skinAttachmentName = attachmentMap->name;
const char* attachmentName = Json_getString(attachmentMap, "name", skinAttachmentName);
@ -349,7 +374,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
return 0;
}
Attachment* attachment = AttachmentLoader_newAttachment(self->attachmentLoader, skin, type, attachmentName);
attachment = AttachmentLoader_newAttachment(self->attachmentLoader, skin, type, attachmentName);
if (!attachment) {
if (self->attachmentLoader->error1) {
SkeletonData_dispose(skeletonData);
@ -377,7 +402,7 @@ SkeletonData* SkeletonJson_readSkeletonData (SkeletonJson* self, const char* jso
}
}
Json* animations = Json_getItem(root, "animations");
animations = Json_getItem(root, "animations");
if (animations) {
int animationCount = Json_getSize(animations);
skeletonData->animations = MALLOC(Animation*, animationCount);

View File

@ -63,12 +63,12 @@ float Slot_getAttachmentTime (const Slot* self) {
}
void Slot_setToBindPose (Slot* self) {
Attachment* attachment = 0;
self->r = self->data->r;
self->g = self->data->g;
self->b = self->data->b;
self->a = self->data->a;
Attachment* attachment = 0;
if (self->data->attachmentName) {
/* Find slot index. */
int i;

View File

@ -53,6 +53,7 @@ void _setFree (void (*free) (void* ptr)) {
}
char* _readFile (const char* path, int* length) {
char *data;
FILE *file = fopen(path, "rb");
if (!file) return 0;
@ -60,7 +61,7 @@ char* _readFile (const char* path, int* length) {
*length = ftell(file);
fseek(file, 0, SEEK_SET);
char* data = MALLOC(char, *length);
data = MALLOC(char, *length);
fread(data, 1, *length, file);
fclose(file);