Skip to content

Commit

Permalink
tts for players is queued (#149)
Browse files Browse the repository at this point in the history
## About The Pull Request
Теперь в рацию не говорят все одновременно
Теперь, когда кукла игрока говорит, она должна закончить предыдущее свое
сообщение перед новым

## Changelog
:cl:
sound: Теперь в рацию не говорят все одновременно
sound: Теперь, когда кукла игрока говорит, она должна закончить
предыдущее свое сообщение перед новым
/:cl:
  • Loading branch information
larentoun authored Apr 20, 2024
1 parent fa2005b commit f4b94a4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion code/__DEFINES/sound.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#define CHANNEL_TRAITOR 1016
#define CHANNEL_CHARGED_SPELL 1015
#define CHANNEL_ELEVATOR 1014
// BANDASTATION ADDITION START
#define CHANNEL_TTS_RADIO 1013
// BANDASTATION EDIT END

///Default range of a sound.
#define SOUND_RANGE 17
Expand All @@ -26,7 +29,7 @@
//THIS SHOULD ALWAYS BE THE LOWEST ONE!
//KEEP IT UPDATED

#define CHANNEL_HIGHEST_AVAILABLE 1015
#define CHANNEL_HIGHEST_AVAILABLE 1012 // BANDASTATION EDIT

#define MAX_INSTRUMENT_CHANNELS (128 * 6)

Expand Down
4 changes: 2 additions & 2 deletions code/game/sound.dm
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@
listening_mob.playsound_local(turf_source, soundin, vol, vary, frequency, falloff_exponent, channel, pressure_affected, S, maxdistance, falloff_distance, 1, use_reverb)
. += listening_mob

/mob/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff_exponent = SOUND_FALLOFF_EXPONENT, channel = 0, pressure_affected = TRUE, sound/sound_to_use, max_distance, falloff_distance = SOUND_DEFAULT_FALLOFF_DISTANCE, distance_multiplier = 1, use_reverb = TRUE)
/mob/proc/playsound_local(turf/turf_source, soundin, vol as num, vary, frequency, falloff_exponent = SOUND_FALLOFF_EXPONENT, channel = 0, pressure_affected = TRUE, sound/sound_to_use, max_distance, falloff_distance = SOUND_DEFAULT_FALLOFF_DISTANCE, distance_multiplier = 1, use_reverb = TRUE, wait = FALSE) // BANDASTATION EDIT: Add wait arg
if(!client || !can_hear())
return

if(!sound_to_use)
sound_to_use = sound(get_sfx(soundin))

sound_to_use.wait = 0 //No queue
sound_to_use.wait = wait // BANDASTATION EDIT - Original: 0
sound_to_use.channel = channel || SSsounds.random_available_channel()
sound_to_use.volume = vol

Expand Down
18 changes: 16 additions & 2 deletions modular_bandastation/tts/code/tts_subsystem.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ SUBSYSTEM_DEF(tts220)
/// Lazy list of request that need to performed to TTS provider API
VAR_PRIVATE/list/tts_requests_queue

/// List of currently existing binding of atom and sound channel: `atom` => `sound_channel`. SS220 TODO: free channel when atom is detroyed and may be on some other circumstances
/// List of currently existing binding of atom and sound channel: `atom` => `sound_channel`.
VAR_PRIVATE/list/tts_local_channels_by_owner = list()

/// Mapping of BYOND gender to TTS gender
Expand Down Expand Up @@ -365,6 +365,7 @@ SUBSYSTEM_DEF(tts220)
output.wait = TRUE
output.volume = volume
output.environment = SOUND_ENVIRONMENT_NONE
output.channel = CHANNEL_TTS_RADIO

if(output.volume <= 0)
return
Expand All @@ -377,7 +378,13 @@ SUBSYSTEM_DEF(tts220)

play_sfx_if_exists(listener, preSFX, output)

output = listener.playsound_local(turf_source, output, volume)
// Reserve channel only for players
if(ismob(speaker))
var/mob/speaking_mob = speaker
if(speaking_mob.client)
output.channel = get_local_channel_by_owner(speaker)
output.wait = TRUE
output = listener.playsound_local(turf_source, output, volume, wait = TRUE)

if(!output || output.volume <= 0)
return
Expand All @@ -396,6 +403,13 @@ SUBSYSTEM_DEF(tts220)
output.environment = environment
SEND_SOUND(listener, output)

/datum/controller/subsystem/tts220/proc/get_local_channel_by_owner(owner)
var/channel = tts_local_channels_by_owner[owner]
if(isnull(channel))
channel = SSsounds.reserve_sound_channel()
tts_local_channels_by_owner[owner] = channel
return channel

/datum/controller/subsystem/tts220/proc/cleanup_tts_file(filename)
fdel(filename)

Expand Down

0 comments on commit f4b94a4

Please sign in to comment.