X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fclient%2Ftarget_music.qc;h=77cb2536eccad2d9e800b2f58695f049b0f5c81b;hb=bee48f230db466e0b858ea3c0d2113808e33ed2c;hp=97faf67900d73b77b54cc69b99949c656cbdb133;hpb=1e41ea628a3ae09c4c2341b2ba72924c1ff01bde;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/client/target_music.qc b/qcsrc/client/target_music.qc index 97faf6790..77cb2536e 100644 --- a/qcsrc/client/target_music.qc +++ b/qcsrc/client/target_music.qc @@ -1,27 +1,33 @@ +float music_disabled; entity music_default; entity music_target; entity music_trigger; .float state; +.float lastvol; void TargetMusic_Advance() { // run AFTER all the thinks! entity best, e; - float s0; + float vol, vol0; best = music_default; if(music_target && time < music_target.lifetime) best = music_target; if(music_trigger) best = music_trigger; - for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) + for(e = world; (e = findfloat(e, enttype, ENT_CLIENT_TRIGGER_MUSIC)); ) if(e.noise) { - s0 = e.state; + vol0 = e.lastvol; + if(getsoundtime(e, CH_BGM_SINGLE) < 0) + { + vol0 = -1; + } if(e == best) { // increase volume if(e.fade_time > 0) - e.state = min(1, e.state + frametime / e.fade_time); + e.state = bound(0, e.state + frametime / e.fade_time, 1); else e.state = 1; } @@ -29,22 +35,32 @@ void TargetMusic_Advance() { // decrease volume if(e.fade_rate > 0) - e.state = max(0, e.state - frametime / e.fade_rate); + e.state = bound(0, e.state - frametime / e.fade_rate, 1); else e.state = 0; } - if(e.state != s0) + vol = e.state * e.volume * autocvar_bgmvolume; + if(vol != vol0) { - sound(e, CHAN_VOICE, "", e.volume * e.state * cvar("bgmvolume"), ATTN_NONE); + if(vol0 < 0) + sound(e, CH_BGM_SINGLE, e.noise, vol, ATTN_NONE); // restart + else + sound(e, CH_BGM_SINGLE, "", vol, ATTN_NONE); + e.lastvol = vol; } } music_trigger = world; + + if(best) + bgmtime = getsoundtime(best, CH_BGM_SINGLE); + else + bgmtime = gettime(GETTIME_CDTRACK); } void Net_TargetMusic() { float vol, fai, fao, tim, id; - string noi, s; + string noi; entity e; id = ReadShort(); @@ -63,15 +79,21 @@ void Net_TargetMusic() { e = spawn(); e.enttype = ENT_CLIENT_TRIGGER_MUSIC; + e.count = id; } - s = e.noise; - if(e.noise) - strunzone(e.noise); - e.noise = strzone(noi); - if(e.noise != s) + if(e.noise != noi) { + if(e.noise) + strunzone(e.noise); + e.noise = strzone(noi); precache_sound(e.noise); - sound(e, CHAN_VOICE, e.noise, 0, ATTN_NONE); + sound(e, CH_BGM_SINGLE, e.noise, 0, ATTN_NONE); + if(getsoundtime(e, CH_BGM_SINGLE) < 0) + { + print(sprintf(_("Cannot initialize sound %s\n"), e.noise)); + strunzone(e.noise); + e.noise = string_null; + } } e.volume = vol; e.fade_time = fai; @@ -81,6 +103,13 @@ void Net_TargetMusic() if(tim == 0) { music_default = e; + if(!music_disabled) + { + e.state = 2; + cvar_settemp("music_playlist_index", "-1"); // don't use playlists + localcmd("cd stop\n"); // just in case + music_disabled = 1; + } } else { @@ -147,7 +176,13 @@ void Ent_ReadTriggerMusic() if(self.noise != s) { precache_sound(self.noise); - sound(self, CHAN_VOICE, self.noise, 0, ATTN_NONE); + sound(self, CH_BGM_SINGLE, self.noise, 0, ATTN_NONE); + if(getsoundtime(self, CH_BGM_SINGLE) < 0) + { + print(sprintf(_("Cannot initialize sound %s\n"), self.noise)); + strunzone(self.noise); + self.noise = string_null; + } } }