From 1715b7631f9986c044baf515ee1c5944f96f44ac Mon Sep 17 00:00:00 2001 From: helixhorned Date: Tue, 28 May 2013 19:52:51 +0000 Subject: [PATCH] Make deletion of an ambient sound MUSICANDSFX sprite stop its sound again. Add a test case source/lunatic/test/delmusicsfx.lua. git-svn-id: https://svn.eduke32.com/eduke32@3822 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/actors.c | 13 ++++++ .../source/lunatic/test/delmusicsfx.lua | 44 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 polymer/eduke32/source/lunatic/test/delmusicsfx.lua diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index f08cabf2a..3665623e4 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -596,6 +596,12 @@ void A_DeleteSprite(int32_t s) A_DeleteLight(s); #endif + if (sprite[s].picnum == MUSICANDSFX && actor[s].t_data[8]==1) + { + // AMBIENT_SFX_PLAYING + S_StopEnvSound(sprite[s].lotag, s); + } + // NetAlloc if (Net_IsRelevantSprite(s)) { @@ -1328,6 +1334,7 @@ ACTOR_STATIC void G_MoveFX(void) if (T2 != ud.config.SoundToggle) { + // If sound playback was toggled, restart. T2 = ud.config.SoundToggle; T1 = 0; } @@ -1371,6 +1378,8 @@ ACTOR_STATIC void G_MoveFX(void) if (x < ht && T1 == 0 && FX_VoiceAvailable(g_sounds[s->lotag].pr-1)) { + // Start playing an ambience sound. + char om = g_sounds[s->lotag].m; if (g_numEnvSoundsPlaying == ud.config.NumVoices) { @@ -1392,10 +1401,14 @@ ACTOR_STATIC void G_MoveFX(void) A_PlaySound(s->lotag,i); g_sounds[s->lotag].m = om; T1 = 1; + T9 = 1; // AMBIENT_SFX_PLAYING } else if (x >= ht && T1 == 1) { + // Stop playing ambience sound because we're out of its range. + // T1 = 0; + T9 = 0; S_StopEnvSound(s->lotag,i); } } diff --git a/polymer/eduke32/source/lunatic/test/delmusicsfx.lua b/polymer/eduke32/source/lunatic/test/delmusicsfx.lua new file mode 100644 index 000000000..dcf6dd2ee --- /dev/null +++ b/polymer/eduke32/source/lunatic/test/delmusicsfx.lua @@ -0,0 +1,44 @@ + +local con = require "con" + +local spritesofstat = spritesofstat + +local Inf = 0/1 + +-- Insert MUSICANDSFX? (Delete it otherwise.) +-- XXX: should be a per-player gamevar, but this is testing code. +local insp = false +local hitag, lotag = 0, 0 + +gameevent("JUMP", +function(aci, pli) + local ps = player[pli] + + if (insp) then + -- Insert MUSICANDSFX sprite with same lo-/hitag as last deleted one. + + local spr = sprite[con.spawn(aci, 5)] + spr.lotag, spr.hitag = lotag, hitag + else + -- Delete nearest MUSICANDSFX sprite. + + local nearestdst = Inf + local nearesti = -1 + + for i in spritesofstat(gv.STAT_FX) do + local dst = (sprite[i]-ps.pos):len2() + if (nearesti == -1 or dst < nearestdst) then + nearesti = i + nearestdst = dst + end + end + + if (nearesti >= 0) then + local spr = sprite[nearesti] + lotag, hitag = spr.lotag, spr.hitag + actor.delete(nearesti) + end + end + + insp = not insp +end)