From: Freddy Date: Fri, 16 Mar 2018 02:13:56 +0000 (+0100) Subject: minor cleanup for trigger_music and target_music X-Git-Tag: xonotic-v0.8.5~2176^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b970f20f7c6249ecbf6839b70947d9d2639acd1b;p=xonotic%2Fxonotic-data.pk3dir.git minor cleanup for trigger_music and target_music This commit does not fix trigger_music. --- diff --git a/qcsrc/common/triggers/func/breakable.qc b/qcsrc/common/triggers/func/breakable.qc index 4f488fc92..d09ccd5e0 100644 --- a/qcsrc/common/triggers/func/breakable.qc +++ b/qcsrc/common/triggers/func/breakable.qc @@ -34,7 +34,7 @@ // target = targets to trigger when broken // health = amount of damage it can take // spawnflags: -// BREAKABLE_START_DISABLED: needs to be triggered to activate +// START_DISABLED: needs to be triggered to activate // BREAKABLE_INDICATE_DAMAGE: indicate damage // BREAKABLE_NODAMAGE: don't take direct damage (needs to be triggered to 'explode', then triggered again to restore) // NOSPLASH: don't take splash damage @@ -291,7 +291,7 @@ void func_breakable_reset(entity this) { this.team = this.team_saved; func_breakable_look_restore(this); - if(this.spawnflags & BREAKABLE_START_DISABLED) + if(this.spawnflags & START_DISABLED) func_breakable_behave_destroyed(this); else func_breakable_behave_restore(this); diff --git a/qcsrc/common/triggers/spawnflags.qh b/qcsrc/common/triggers/spawnflags.qh index 02f80d6f0..75464b076 100644 --- a/qcsrc/common/triggers/spawnflags.qh +++ b/qcsrc/common/triggers/spawnflags.qh @@ -2,6 +2,7 @@ // generic usage const int START_ENABLED = BIT(0); +const int START_DISABLED = BIT(0); const int ALL_ENTITIES = BIT(1); const int ON_MAPLOAD = BIT(1); const int INVERT_TEAMS = BIT(2); @@ -17,7 +18,6 @@ const int BOBBING_XAXIS = BIT(0); const int BOBBING_YAXIS = BIT(1); // breakable -const int BREAKABLE_START_DISABLED = BIT(0); const int BREAKABLE_INDICATE_DAMAGE = BIT(1); const int BREAKABLE_NODAMAGE = BIT(2); @@ -161,3 +161,6 @@ const int SF_LASER_NOTRACE = BIT(4); const int SF_LASER_SCALE = BIT(5); const int SF_LASER_ALPHA = BIT(6); const int SF_LASER_FINITE = BIT(7); + +// music +const int SF_MUSIC_ORIGIN = BIT(2); diff --git a/qcsrc/common/triggers/target/music.qc b/qcsrc/common/triggers/target/music.qc index 7ec335138..3b09f16a7 100644 --- a/qcsrc/common/triggers/target/music.qc +++ b/qcsrc/common/triggers/target/music.qc @@ -14,7 +14,10 @@ REGISTER_NET_LINKED(ENT_CLIENT_TRIGGER_MUSIC) #ifdef SVQC IntrusiveList g_targetmusic_list; -STATIC_INIT(g_targetmusic_list) { g_targetmusic_list = IL_NEW(); } +STATIC_INIT(g_targetmusic_list) +{ + g_targetmusic_list = IL_NEW(); +} // values: // volume @@ -37,7 +40,10 @@ void target_music_sendto(entity this, int to, bool is) } void target_music_reset(entity this) { - if (this.targetname == "") target_music_sendto(this, MSG_ALL, 1); + if (this.targetname == "") + { + target_music_sendto(this, MSG_ALL, true); + } } void target_music_kill() { @@ -45,9 +51,9 @@ void target_music_kill() { it.volume = 0; if (it.targetname == "") - target_music_sendto(it, MSG_ALL, 1); + target_music_sendto(it, MSG_ALL, true); else - target_music_sendto(it, MSG_ALL, 0); + target_music_sendto(it, MSG_ALL, false); }); } void target_music_use(entity this, entity actor, entity trigger) @@ -57,11 +63,11 @@ void target_music_use(entity this, entity actor, entity trigger) if(IS_REAL_CLIENT(actor)) { msg_entity = actor; - target_music_sendto(this, MSG_ONE, 1); + target_music_sendto(this, MSG_ONE, true); } FOREACH_CLIENT(IS_SPEC(it) && it.enemy == actor, { msg_entity = it; - target_music_sendto(this, MSG_ONE, 1); + target_music_sendto(this, MSG_ONE, true); }); } spawnfunc(target_music) @@ -72,18 +78,18 @@ spawnfunc(target_music) this.volume = 1; IL_PUSH(g_targetmusic_list, this); if(this.targetname == "") - target_music_sendto(this, MSG_INIT, 1); + target_music_sendto(this, MSG_INIT, true); else - target_music_sendto(this, MSG_INIT, 0); + target_music_sendto(this, MSG_INIT, false); } void TargetMusic_RestoreGame() { IL_EACH(g_targetmusic_list, true, { if(it.targetname == "") - target_music_sendto(it, MSG_INIT, 1); + target_music_sendto(it, MSG_INIT, true); else - target_music_sendto(it, MSG_INIT, 0); + target_music_sendto(it, MSG_INIT, false); }); } // values: @@ -92,20 +98,20 @@ void TargetMusic_RestoreGame() // targetname // fade_time // spawnflags: -// 1 = START_OFF +// START_DISABLED // when triggered, it is disabled/enabled for everyone -bool trigger_music_SendEntity(entity this, entity to, float sf) +bool trigger_music_SendEntity(entity this, entity to, int sendflags) { WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC); - sf &= ~0x80; + sendflags &= ~0x80; if(this.cnt) - sf |= 0x80; - WriteByte(MSG_ENTITY, sf); - if(sf & 4) + sendflags |= 0x80; + WriteByte(MSG_ENTITY, sendflags); + if(sendflags & SF_MUSIC_ORIGIN) { WriteVector(MSG_ENTITY, this.origin); } - if(sf & 1) + if(sendflags & SF_TRIGGER_INIT) { if(this.model != "null") { @@ -123,11 +129,11 @@ bool trigger_music_SendEntity(entity this, entity to, float sf) WriteByte(MSG_ENTITY, this.fade_rate * 16.0); WriteString(MSG_ENTITY, this.noise); } - return 1; + return true; } void trigger_music_reset(entity this) { - this.cnt = !(this.spawnflags & 1); + this.cnt = !(this.spawnflags & START_DISABLED); this.SendFlags |= 0x80; } void trigger_music_use(entity this, entity actor, entity trigger) @@ -137,8 +143,14 @@ void trigger_music_use(entity this, entity actor, entity trigger) } spawnfunc(trigger_music) { - if(this.model != "") _setmodel(this, this.model); - if(!this.volume) this.volume = 1; + if(this.model != "") + { + _setmodel(this, this.model); + } + if(!this.volume) + { + this.volume = 1; + } if(!this.modelindex) { setorigin(this, this.origin + this.mins); @@ -163,8 +175,14 @@ void TargetMusic_Advance() { // run AFTER all the thinks! entity best = music_default; - if (music_target && time < music_target.lifetime) best = music_target; - if (music_trigger) best = music_trigger; + if (music_target && time < music_target.lifetime) + { + best = music_target; + } + if (music_trigger) + { + best = music_trigger; + } LL_EACH(TargetMusic_list, it.noise, { const float vol0 = (getsoundtime(it, CH_BGM_SINGLE) >= 0) ? it.lastvol : -1; if (it == best) @@ -269,12 +287,12 @@ void Ent_TriggerMusic_Remove(entity this) NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew) { - int f = ReadByte(); - if(f & 4) + int sendflags = ReadByte(); + if(sendflags & SF_MUSIC_ORIGIN) { this.origin = ReadVector(); } - if(f & 1) + if(sendflags & SF_TRIGGER_INIT) { this.modelindex = ReadShort(); if(this.modelindex) @@ -301,7 +319,7 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_MUSIC, bool isnew) _sound(this, CH_BGM_SINGLE, this.noise, 0, ATTEN_NONE); if(getsoundtime(this, CH_BGM_SINGLE) < 0) { - LOG_TRACEF("Cannot initialize sound %s", this.noise); + LOG_WARNF("Cannot initialize sound %s", this.noise); strunzone(this.noise); this.noise = string_null; }