X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fclient%2Ftarget_music.qc;h=b1957038eb4eb9b7c1a97574713ceed3e42bf2e4;hb=da1e17b0c055f095795b17f4784e175f5f0e2d23;hp=69c42ee101751f3dde4bb9048b53595649e6942b;hpb=37b903eeaeee1fc1662556a56cdcf19881abbeeb;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/client/target_music.qc b/qcsrc/client/target_music.qc index 69c42ee10..b1957038e 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 Net_AdvanceMusic() +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, CHAN_VOICE) < 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,14 +35,26 @@ void Net_AdvanceMusic() { // decrease volume if(e.fade_rate > 0) - e.state = max(1, 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) - sound(e, CHAN_PROJECTILE, "", e.volume * e.state, ATTN_NONE); + vol = e.state * e.volume * cvar("bgmvolume"); + if(vol != vol0) + { + if(vol0 < 0) + sound(e, CHAN_VOICE, e.noise, vol, ATTN_NONE); // restart + else + sound(e, CHAN_VOICE, "", vol, ATTN_NONE); + e.lastvol = vol; + } } music_trigger = world; + + if(best) + bgmtime = getsoundtime(best, CHAN_VOICE); + else + bgmtime = gettime(GETTIME_CDTRACK); } void Net_TargetMusic() @@ -61,10 +79,21 @@ void Net_TargetMusic() { e = spawn(); e.enttype = ENT_CLIENT_TRIGGER_MUSIC; + e.count = id; + } + if(e.noise != noi) + { if(e.noise) strunzone(e.noise); e.noise = strzone(noi); - sound(e, CHAN_PROJECTILE, self.noise, 0, ATTN_NONE); + precache_sound(e.noise); + sound(e, CHAN_VOICE, e.noise, 0, ATTN_NONE); + if(getsoundtime(e, CHAN_VOICE) < 0) + { + print("Cannot initialize sound ", e.noise, "\n"); + strunzone(e.noise); + e.noise = string_null; + } } e.volume = vol; e.fade_time = fai; @@ -74,6 +103,12 @@ void Net_TargetMusic() if(tim == 0) { music_default = e; + if(!music_disabled) + { + e.state = 2; + localcmd("cd stop\n"); // just in case + music_disabled = 1; + } } else { @@ -85,8 +120,10 @@ void Net_TargetMusic() void Ent_TriggerMusic_Think() { - if(WarpZoneLib_BoxTouchesBrush(pmove_org + pmove_mins, pmove_org + pmove_maxs, self, world)) + if(WarpZoneLib_BoxTouchesBrush(view_origin, view_origin, self, world)) + { music_trigger = self; + } self.nextthink = time; } @@ -100,6 +137,7 @@ void Ent_TriggerMusic_Remove() void Ent_ReadTriggerMusic() { float f; + string s; f = ReadByte(); if(f & 4) { @@ -130,11 +168,25 @@ void Ent_ReadTriggerMusic() self.volume = ReadByte() / 255.0; self.fade_time = ReadByte() / 16.0; self.fade_rate = ReadByte() / 16.0; + s = self.noise; if(self.noise) strunzone(self.noise); self.noise = strzone(ReadString()); + if(self.noise != s) + { + precache_sound(self.noise); + sound(self, CHAN_VOICE, self.noise, 0, ATTN_NONE); + if(getsoundtime(self, CHAN_VOICE) < 0) + { + print("Cannot initialize sound ", self.noise, "\n"); + strunzone(self.noise); + self.noise = string_null; + } + } } + setorigin(self, self.origin); + setsize(self, self.mins, self.maxs); self.cnt = 1; self.think = Ent_TriggerMusic_Think; self.nextthink = time;