[c] Added event volume and balance, see #1171.

This commit is contained in:
badlogic 2018-09-06 15:05:13 +02:00
parent c408b7bae0
commit 7e1a0c172d
14 changed files with 38 additions and 11 deletions

View File

@ -161,8 +161,8 @@ cp -f ../raptor/export/raptor-pro.skel ../../spine-sfml/c/data/
cp -f ../raptor/export/raptor.atlas ../../spine-sfml/c/data/
cp -f ../raptor/export/raptor.png ../../spine-sfml/c/data/
cp -f ../spineboy/export/spineboy-ess.json ../../spine-sfml/c/data/
cp -f ../spineboy/export/spineboy-ess.skel ../../spine-sfml/c/data/
cp -f ../spineboy/export/spineboy-pro.json ../../spine-sfml/c/data/
cp -f ../spineboy/export/spineboy-pro.skel ../../spine-sfml/c/data/
cp -f ../spineboy/export/spineboy.atlas ../../spine-sfml/c/data/
cp -f ../spineboy/export/spineboy.png ../../spine-sfml/c/data/
@ -206,8 +206,8 @@ cp -f ../raptor/export/raptor-pro.skel ../../spine-sfml/cpp/data/
cp -f ../raptor/export/raptor.atlas ../../spine-sfml/cpp/data/
cp -f ../raptor/export/raptor.png ../../spine-sfml/cpp/data/
cp -f ../spineboy/export/spineboy-ess.json ../../spine-sfml/cpp/data/
cp -f ../spineboy/export/spineboy-ess.skel ../../spine-sfml/cpp/data/
cp -f ../spineboy/export/spineboy-pro.json ../../spine-sfml/cpp/data/
cp -f ../spineboy/export/spineboy-pro.skel ../../spine-sfml/cpp/data/
cp -f ../spineboy/export/spineboy.atlas ../../spine-sfml/cpp/data/
cp -f ../spineboy/export/spineboy.png ../../spine-sfml/cpp/data/

View File

@ -44,6 +44,8 @@ typedef struct spEvent {
int intValue;
float floatValue;
const char* stringValue;
float volume;
float balance;
#ifdef __cplusplus
spEvent() :
@ -51,7 +53,9 @@ typedef struct spEvent {
time(0),
intValue(0),
floatValue(0),
stringValue(0) {
stringValue(0),
volume(0),
balance(0) {
}
#endif
} spEvent;

View File

@ -43,6 +43,8 @@ typedef struct spEventData {
float floatValue;
const char* stringValue;
const char* audioPath;
float volume;
float balance;
#ifdef __cplusplus
spEventData() :
@ -50,7 +52,9 @@ typedef struct spEventData {
intValue(0),
floatValue(0),
stringValue(0),
audioPath(0) {
audioPath(0),
volume(0),
balance(0) {
}
#endif
} spEventData;

View File

@ -592,6 +592,10 @@ static spAnimation* _spSkeletonBinary_readAnimation (spSkeletonBinary* self, con
event->stringValue = readString(input);
else
MALLOC_STR(event->stringValue, eventData->stringValue);
if (eventData->audioPath) {
event->volume = readFloat(input);
event->balance = readFloat(input);
}
spEventTimeline_setFrame(timeline, i, event);
}
spTimelineArray_add(timelines, (spTimeline*)timeline);
@ -1075,6 +1079,10 @@ spSkeletonData* spSkeletonBinary_readSkeletonData (spSkeletonBinary* self, const
eventData->floatValue = readFloat(input);
eventData->stringValue = readString(input);
eventData->audioPath = readString(input);
if (eventData->audioPath) {
eventData->volume = readFloat(input);
eventData->balance = readFloat(input);
}
skeletonData->events[i] = eventData;
}

View File

@ -502,6 +502,10 @@ static spAnimation* _spSkeletonJson_readAnimation (spSkeletonJson* self, Json* r
event->floatValue = Json_getFloat(valueMap, "float", eventData->floatValue);
stringValue = Json_getString(valueMap, "string", eventData->stringValue);
if (stringValue) MALLOC_STR(event->stringValue, stringValue);
if (eventData->audioPath) {
event->volume = Json_getFloat(valueMap, "volume", 1);
event->balance = Json_getFloat(valueMap, "volume", 0);
}
spEventTimeline_setFrame(timeline, frameIndex, event);
}
animation->timelines[animation->timelinesCount++] = SUPER_CAST(spTimeline, timeline);
@ -1081,6 +1085,7 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
if (events) {
Json *eventMap;
const char* stringValue;
const char* audioPath;
skeletonData->eventsCount = events->size;
skeletonData->events = MALLOC(spEventData*, events->size);
for (eventMap = events->child, i = 0; eventMap; eventMap = eventMap->next, ++i) {
@ -1089,6 +1094,12 @@ spSkeletonData* spSkeletonJson_readSkeletonData (spSkeletonJson* self, const cha
eventData->floatValue = Json_getFloat(eventMap, "float", 0);
stringValue = Json_getString(eventMap, "string", 0);
if (stringValue) MALLOC_STR(eventData->stringValue, stringValue);
audioPath = Json_getString(eventMap, "audio", 0);
if (audioPath) {
MALLOC_STR(eventData->audioPath, audioPath);
eventData->volume = Json_getFloat(eventMap, "volume", 1);
eventData->balance = Json_getFloat(eventMap, "balance", 0);
}
skeletonData->events[i] = eventData;
}
}

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -60,8 +60,8 @@ void callback (AnimationState* state, EventType type, TrackEntry* entry, Event*
printf("%d dispose: %s\n", entry->trackIndex, animationName);
break;
case ANIMATION_EVENT:
printf("%d event: %s, %s: %d, %f, %s\n", entry->trackIndex, animationName, event->data->name, event->intValue, event->floatValue,
event->stringValue);
printf("%d event: %s, %s: %d, %f, %s %f %f\n", entry->trackIndex, animationName, event->data->name, event->intValue, event->floatValue,
event->stringValue, event->volume, event->balance);
break;
}
fflush(stdout);
@ -442,13 +442,13 @@ void test (SkeletonData* skeletonData, Atlas* atlas) {
int main () {
testcase(test, "data/tank-pro.json", "data/tank-pro.skel", "data/tank.atlas", 1.0f);
testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy.atlas", 0.6f);
testcase(stretchyman, "data/stretchyman-stretchy-ik.json", "data/stretchyman-stretchy-ik.skel", "data/stretchyman.atlas", 0.6f);
testcase(owl, "data/owl-pro.json", "data/owl-pro.skel", "data/owl.atlas", 0.5f);
testcase(coin, "data/coin-pro.json", "data/coin-pro.skel", "data/coin.atlas", 0.5f);
testcase(vine, "data/vine-pro.json", "data/vine-pro.skel", "data/vine.atlas", 0.5f);
testcase(tank, "data/tank-pro.json", "data/tank-pro.skel", "data/tank.atlas", 0.2f);
testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor.atlas", 0.5f);
testcase(spineboy, "data/spineboy-ess.json", "data/spineboy-ess.skel", "data/spineboy.atlas", 0.6f);
testcase(goblins, "data/goblins-pro.json", "data/goblins-pro.skel", "data/goblins.atlas", 1.4f);
testcase(stretchyman, "data/stretchyman-pro.json", "data/stretchyman-pro.skel", "data/stretchyman.atlas", 0.6f);
return 0;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.