Selaa lähdekoodia

Merge pull request #17367 from ShyRed/audio_playing_

Use fake audio playing property in editor
Hein-Pieter van Braam 7 vuotta sitten
vanhempi
commit
24dbe5e310

+ 10 - 1
scene/2d/audio_stream_player_2d.cpp

@@ -233,7 +233,6 @@ void AudioStreamPlayer2D::_notification(int p_what) {
 		//stop playing if no longer active
 		//stop playing if no longer active
 		if (!active) {
 		if (!active) {
 			set_physics_process_internal(false);
 			set_physics_process_internal(false);
-			//do not update, this makes it easier to animate (will shut off otherwise)
 			//_change_notify("playing"); //update property in editor
 			//_change_notify("playing"); //update property in editor
 			emit_signal("finished");
 			emit_signal("finished");
 		}
 		}
@@ -313,6 +312,11 @@ void AudioStreamPlayer2D::stop() {
 
 
 bool AudioStreamPlayer2D::is_playing() const {
 bool AudioStreamPlayer2D::is_playing() const {
 
 
+#ifdef TOOLS_ENABLED
+	if (Engine::get_singleton()->is_editor_hint())
+		return fake_active;
+#endif
+
 	if (stream_playback.is_valid()) {
 	if (stream_playback.is_valid()) {
 		return active; // && stream_playback->is_playing();
 		return active; // && stream_playback->is_playing();
 	}
 	}
@@ -357,11 +361,16 @@ bool AudioStreamPlayer2D::is_autoplay_enabled() {
 
 
 void AudioStreamPlayer2D::_set_playing(bool p_enable) {
 void AudioStreamPlayer2D::_set_playing(bool p_enable) {
 
 
+#ifdef TOOLS_ENABLED
+	fake_active = p_enable;
+#endif
+
 	if (p_enable)
 	if (p_enable)
 		play();
 		play();
 	else
 	else
 		stop();
 		stop();
 }
 }
+
 bool AudioStreamPlayer2D::_is_active() const {
 bool AudioStreamPlayer2D::_is_active() const {
 
 
 	return active;
 	return active;

+ 4 - 0
scene/2d/audio_stream_player_2d.h

@@ -69,6 +69,10 @@ private:
 	volatile bool active;
 	volatile bool active;
 	volatile float setplay;
 	volatile float setplay;
 
 
+#ifdef TOOLS_ENABLED
+	volatile bool fake_active;
+#endif
+
 	float volume_db;
 	float volume_db;
 	float pitch_scale;
 	float pitch_scale;
 	bool autoplay;
 	bool autoplay;

+ 10 - 1
scene/3d/audio_stream_player_3d.cpp

@@ -543,7 +543,6 @@ void AudioStreamPlayer3D::_notification(int p_what) {
 		//stop playing if no longer active
 		//stop playing if no longer active
 		if (!active) {
 		if (!active) {
 			set_physics_process_internal(false);
 			set_physics_process_internal(false);
-			//do not update, this makes it easier to animate (will shut off otherwise)
 			//_change_notify("playing"); //update property in editor
 			//_change_notify("playing"); //update property in editor
 			emit_signal("finished");
 			emit_signal("finished");
 		}
 		}
@@ -641,6 +640,11 @@ void AudioStreamPlayer3D::stop() {
 
 
 bool AudioStreamPlayer3D::is_playing() const {
 bool AudioStreamPlayer3D::is_playing() const {
 
 
+#ifdef TOOLS_ENABLED
+	if (Engine::get_singleton()->is_editor_hint())
+		return fake_active;
+#endif
+
 	if (stream_playback.is_valid()) {
 	if (stream_playback.is_valid()) {
 		return active; // && stream_playback->is_playing();
 		return active; // && stream_playback->is_playing();
 	}
 	}
@@ -685,11 +689,16 @@ bool AudioStreamPlayer3D::is_autoplay_enabled() {
 
 
 void AudioStreamPlayer3D::_set_playing(bool p_enable) {
 void AudioStreamPlayer3D::_set_playing(bool p_enable) {
 
 
+#ifdef TOOLS_ENABLED
+	fake_active = p_enable;
+#endif
+
 	if (p_enable)
 	if (p_enable)
 		play();
 		play();
 	else
 	else
 		stop();
 		stop();
 }
 }
+
 bool AudioStreamPlayer3D::_is_active() const {
 bool AudioStreamPlayer3D::_is_active() const {
 
 
 	return active;
 	return active;

+ 4 - 0
scene/3d/audio_stream_player_3d.h

@@ -102,6 +102,10 @@ private:
 	volatile bool active;
 	volatile bool active;
 	volatile float setplay;
 	volatile float setplay;
 
 
+#ifdef TOOLS_ENABLED
+	volatile bool fake_active;
+#endif
+
 	AttenuationModel attenuation_model;
 	AttenuationModel attenuation_model;
 	float unit_db;
 	float unit_db;
 	float unit_size;
 	float unit_size;

+ 12 - 1
scene/audio/audio_player.cpp

@@ -127,6 +127,7 @@ void AudioStreamPlayer::_notification(int p_what) {
 		if (!active || (setseek < 0 && !stream_playback->is_playing())) {
 		if (!active || (setseek < 0 && !stream_playback->is_playing())) {
 			active = false;
 			active = false;
 			set_process_internal(false);
 			set_process_internal(false);
+			//_change_notify("playing"); //update property in editor
 			emit_signal("finished");
 			emit_signal("finished");
 		}
 		}
 	}
 	}
@@ -211,8 +212,13 @@ void AudioStreamPlayer::stop() {
 
 
 bool AudioStreamPlayer::is_playing() const {
 bool AudioStreamPlayer::is_playing() const {
 
 
+#ifdef TOOLS_ENABLED
+	if (Engine::get_singleton()->is_editor_hint())
+		return fake_active;
+#endif
+
 	if (stream_playback.is_valid()) {
 	if (stream_playback.is_valid()) {
-		return active; //&& stream_playback->is_playing();
+		return active; // && stream_playback->is_playing();
 	}
 	}
 
 
 	return false;
 	return false;
@@ -265,11 +271,16 @@ AudioStreamPlayer::MixTarget AudioStreamPlayer::get_mix_target() const {
 
 
 void AudioStreamPlayer::_set_playing(bool p_enable) {
 void AudioStreamPlayer::_set_playing(bool p_enable) {
 
 
+#ifdef TOOLS_ENABLED
+	fake_active = p_enable;
+#endif
+
 	if (p_enable)
 	if (p_enable)
 		play();
 		play();
 	else
 	else
 		stop();
 		stop();
 }
 }
+
 bool AudioStreamPlayer::_is_active() const {
 bool AudioStreamPlayer::_is_active() const {
 
 
 	return active;
 	return active;

+ 4 - 0
scene/audio/audio_player.h

@@ -53,6 +53,10 @@ private:
 	volatile float setseek;
 	volatile float setseek;
 	volatile bool active;
 	volatile bool active;
 
 
+#ifdef TOOLS_ENABLED
+	volatile bool fake_active;
+#endif
+
 	float mix_volume_db;
 	float mix_volume_db;
 	float pitch_scale;
 	float pitch_scale;
 	float volume_db;
 	float volume_db;