Преглед на файлове

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

badlogic преди 7 години
родител
ревизия
454ecf0c2c

+ 10 - 0
spine-cpp/spine-cpp/include/spine/Event.h

@@ -65,12 +65,22 @@ public:
 
 	void setStringValue(const String &inValue);
 
+	float getVolume();
+
+	void setVolume(float inValue);
+
+	float getBalance();
+
+	void setBalance(float inValue);
+
 private:
 	const EventData &_data;
 	const float _time;
 	int _intValue;
 	float _floatValue;
 	String _stringValue;
+	float _volume;
+	float _balance;
 };
 }
 

+ 15 - 0
spine-cpp/spine-cpp/include/spine/EventData.h

@@ -61,11 +61,26 @@ public:
 
 	void setStringValue(const String &inValue);
 
+	const String &getAudioPath();
+
+	void setAudioPath(const String &inValue);
+
+	float getVolume();
+
+	void setVolume(float inValue);
+
+	float getBalance();
+
+	void setBalance(float inValue);
+
 private:
 	const String _name;
 	int _intValue;
 	float _floatValue;
 	String _stringValue;
+	String _audioPath;
+	float _volume;
+	float _balance;
 };
 }
 

+ 20 - 1
spine-cpp/spine-cpp/src/spine/Event.cpp

@@ -39,7 +39,9 @@ Event::Event(float time, const EventData &data) :
 		_time(time),
 		_intValue(0),
 		_floatValue(0),
-		_stringValue() {
+		_stringValue(),
+		_volume(1),
+		_balance(0) {
 }
 
 const EventData &Event::getData() {
@@ -73,3 +75,20 @@ const String &Event::getStringValue() {
 void Event::setStringValue(const String &inValue) {
 	_stringValue = inValue;
 }
+
+
+float Event::getVolume() {
+	return _volume;
+}
+
+void Event::setVolume(float inValue) {
+	_volume = inValue;
+}
+
+float Event::getBalance() {
+	return _balance;
+}
+
+void Event::setBalance(float inValue) {
+	_balance = inValue;
+}

+ 29 - 1
spine-cpp/spine-cpp/src/spine/EventData.cpp

@@ -38,7 +38,10 @@ EventData::EventData(const String &name) :
 		_name(name),
 		_intValue(0),
 		_floatValue(0),
-		_stringValue() {
+		_stringValue(),
+		_audioPath(),
+		_volume(1),
+		_balance(0) {
 	assert(_name.length() > 0);
 }
 
@@ -70,3 +73,28 @@ const String &EventData::getStringValue() {
 void EventData::setStringValue(const String &inValue) {
 	_stringValue = inValue;
 }
+
+const String &EventData::getAudioPath() {
+	return _audioPath;
+}
+
+void EventData::setAudioPath(const String &inValue) {
+	_audioPath = inValue;
+}
+
+
+float EventData::getVolume() {
+	return _volume;
+}
+
+void EventData::setVolume(float inValue) {
+	_volume = inValue;
+}
+
+float EventData::getBalance() {
+	return _balance;
+}
+
+void EventData::setBalance(float inValue) {
+	_balance = inValue;
+}

+ 10 - 1
spine-cpp/spine-cpp/src/spine/SkeletonBinary.cpp

@@ -310,7 +310,11 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons
 		eventData->_intValue = readVarint(input, false);
 		eventData->_floatValue = readFloat(input);
 		eventData->_stringValue.own(readString(input));
-		String(readString(input), true); // skip audio path
+		eventData->_audioPath.own(readString(input)); // skip audio path
+		if (!eventData->_audioPath.isEmpty()) {
+			eventData->_volume = readFloat(input);
+			eventData->_balance = readFloat(input);
+		}
 		skeletonData->_events[i] = eventData;
 	}
 
@@ -1006,6 +1010,11 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
 			if (freeString) {
 				SpineExtension::free(event_stringValue, __FILE__, __LINE__);
 			}
+
+			if (!eventData->_audioPath.isEmpty()) {
+				event->_volume = readFloat(input);
+				event->_balance = readFloat(input);
+			}
 			timeline->setFrame(i, event);
 		}
 

+ 10 - 0
spine-cpp/spine-cpp/src/spine/SkeletonJson.cpp

@@ -662,6 +662,12 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
 			eventData->_floatValue = Json::getFloat(eventMap, "float", 0);
 			const char *stringValue = Json::getString(eventMap, "string", 0);
 			eventData->_stringValue = stringValue;
+			const char *audioPath = Json::getString(eventMap, "audio", 0);
+			eventData->_audioPath = audioPath;
+			if (audioPath) {
+				eventData->_volume = Json::getFloat(eventMap, "volume", 1);
+				eventData->_balance = Json::getFloat(eventMap, "balance", 0);
+			}
 			skeletonData->_events[i] = eventData;
 		}
 	}
@@ -1159,6 +1165,10 @@ Animation *SkeletonJson::readAnimation(Json *root, SkeletonData *skeletonData) {
 			event->_intValue = Json::getInt(valueMap, "int", eventData->_intValue);
 			event->_floatValue = Json::getFloat(valueMap, "float", eventData->_floatValue);
 			event->_stringValue = Json::getString(valueMap, "string", eventData->_stringValue.buffer());
+			if (!eventData->_audioPath.isEmpty()) {
+				event->_volume = Json::getFloat(valueMap, "volume", 1);
+				event->_balance = Json::getFloat(valueMap, "balance", 0);
+			}
 			timeline->setFrame(frameIndex, event);
 		}
 		timelines.add(timeline);

+ 3 - 3
spine-sfml/cpp/example/main.cpp

@@ -58,8 +58,8 @@ void callback (AnimationState* state, EventType type, TrackEntry* entry, Event*
 		printf("%d dispose: %s\n", entry->getTrackIndex(), animationName.buffer());
 		break;
 	case EventType_Event:
-		printf("%d event: %s, %s: %d, %f, %s\n", entry->getTrackIndex(), animationName.buffer(), event->getData().getName().buffer(), event->getIntValue(), event->getFloatValue(),
-				event->getStringValue().buffer());
+		printf("%d event: %s, %s: %d, %f, %s %f %f\n", entry->getTrackIndex(), animationName.buffer(), event->getData().getName().buffer(), event->getIntValue(), event->getFloatValue(),
+				event->getStringValue().buffer(), event->getVolume(), event->getBalance());
 		break;
 	}
 	fflush(stdout);
@@ -481,7 +481,7 @@ int main () {
 	DebugExtension dbgExtension;
 	SpineExtension::setInstance(&dbgExtension);
 
-	testcase(spineboy, "data/spineboy-ess.json", "data/spineboy-ess.skel", "data/spineboy.atlas", 0.6f);
+	testcase(spineboy, "data/spineboy-pro.json", "data/spineboy-pro.skel", "data/spineboy.atlas", 0.6f);
 	testcase(stretchymanStrechyIk, "data/stretchyman-stretchy-ik.json", "data/stretchyman-stretchy-ik.skel", "data/stretchyman.atlas", 0.6f);
 	testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor.atlas", 0.5f);
 	testcase(test, "data/tank-pro.json", "data/tank-pro.skel", "data/tank.atlas", 1.0f);