From 1a514560da04d512bfcdd31a81e72aaaa17b795a Mon Sep 17 00:00:00 2001 From: bibendovsky Date: Sun, 3 Aug 2014 19:32:56 +0300 Subject: [PATCH 1/3] Fix underwater sfx in demos --- src/common/pmove.c | 110 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 85 insertions(+), 25 deletions(-) diff --git a/src/common/pmove.c b/src/common/pmove.c index 20d4f6c9..4c0f490d 100644 --- a/src/common/pmove.c +++ b/src/common/pmove.c @@ -27,6 +27,7 @@ #include "header/common.h" #include "../client/sound/header/local.h" +#include "../client/header/client.h" #if !defined(DEDICATED_ONLY) && defined(USE_OPENAL) void AL_Underwater(); @@ -1265,16 +1266,89 @@ PM_ClampAngles(void) AngleVectors(pm->viewangles, pml.forward, pml.right, pml.up); } +void PM_CalculateViewHeightForDemo() +{ + if (pm->s.pm_type == PM_GIB) + pm->viewheight = 8; + else { + if ((pm->s.pm_flags & PMF_DUCKED) != 0) + pm->viewheight = -2; + else + pm->viewheight = 22; + } +} + +void PM_CalculateWaterLevelForDemo() +{ + vec3_t point; + int cont; + float sample1; + float sample2; + + point[0] = pml.origin[0]; + point[1] = pml.origin[1]; + + pm->waterlevel = 0; + pm->watertype = 0; + + sample2 = pm->viewheight - pm->mins[2]; + sample1 = sample2 / 2; + + point[2] = pml.origin[2] + pm->mins[2] + 1; + cont = pm->pointcontents(point); + + if ((cont & MASK_WATER) != 0) { + pm->watertype = cont; + pm->waterlevel = 1; + point[2] = pml.origin[2] + pm->mins[2] + sample1; + cont = pm->pointcontents(point); + + if ((cont & MASK_WATER) != 0) { + pm->waterlevel = 2; + point[2] = pml.origin[2] + pm->mins[2] + sample2; + cont = pm->pointcontents(point); + + if ((cont & MASK_WATER) != 0) + pm->waterlevel = 3; + } + } +} + +void PM_UpdateUnderwaterSfx() +{ +#if !defined(DEDICATED_ONLY) + static int underwater; +#endif + +#if !defined(DEDICATED_ONLY) + if ((pm->waterlevel == 3) && !underwater) { + underwater = 1; + snd_is_underwater = 1; + +#ifdef USE_OPENAL + if (snd_is_underwater_enabled) + AL_Underwater(); +#endif + } + + if ((pm->waterlevel < 3) && underwater) { + underwater = 0; + snd_is_underwater = 0; + +#ifdef USE_OPENAL + if (snd_is_underwater_enabled) + AL_Overwater(); +#endif + } +#endif +} + /* * Can be called by either the server or the client */ void Pmove(pmove_t *pmove) { -#if !defined(DEDICATED_ONLY) - static int underwater; -#endif - pm = pmove; /* clear results */ @@ -1320,6 +1394,12 @@ Pmove(pmove_t *pmove) if (pm->s.pm_type == PM_FREEZE) { + if (cl.attractloop) { + PM_CalculateViewHeightForDemo(); + PM_CalculateWaterLevelForDemo(); + PM_UpdateUnderwaterSfx(); + } + return; /* no movement at all */ } @@ -1415,27 +1495,7 @@ Pmove(pmove_t *pmove) /* set groundentity, watertype, and waterlevel for final spot */ PM_CatagorizePosition(); -#if !defined(DEDICATED_ONLY) - if ((pm->waterlevel == 3) && !underwater) - { - underwater = 1; - snd_is_underwater = 1; -#ifdef USE_OPENAL - if (snd_is_underwater_enabled) - AL_Underwater(); -#endif - } - - if (((pm->waterlevel < 3) && underwater)) - { - underwater = 0; - snd_is_underwater = 0; -#ifdef USE_OPENAL - if (snd_is_underwater_enabled) - AL_Overwater(); -#endif - } -#endif + PM_UpdateUnderwaterSfx(); PM_SnapPosition(); } From 74c8c60e38890f8aef19eea38c049d7ab0164903 Mon Sep 17 00:00:00 2001 From: bibendovsky Date: Sun, 17 Aug 2014 18:58:26 +0300 Subject: [PATCH 2/3] Turn off underwater sfx on disconnect --- src/client/cl_network.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client/cl_network.c b/src/client/cl_network.c index 16986855..0f06693a 100644 --- a/src/client/cl_network.c +++ b/src/client/cl_network.c @@ -25,6 +25,7 @@ */ #include "header/client.h" +#include "../client/sound/header/local.h" void CL_ParseStatusMessage(void); @@ -354,6 +355,8 @@ CL_Disconnect(void) } cls.state = ca_disconnected; + + snd_is_underwater = false; } void From 120bb864580777ecc0c94ccc92807bb0a2ecd535 Mon Sep 17 00:00:00 2001 From: bibendovsky Date: Mon, 18 Aug 2014 19:21:45 +0300 Subject: [PATCH 3/3] Simplify PM_CalculateWaterLevelForDemo --- src/common/pmove.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/common/pmove.c b/src/common/pmove.c index 4c0f490d..b40c5ff2 100644 --- a/src/common/pmove.c +++ b/src/common/pmove.c @@ -1282,35 +1282,19 @@ void PM_CalculateWaterLevelForDemo() { vec3_t point; int cont; - float sample1; - float sample2; point[0] = pml.origin[0]; point[1] = pml.origin[1]; + point[2] = pml.origin[2] + pm->viewheight; pm->waterlevel = 0; pm->watertype = 0; - sample2 = pm->viewheight - pm->mins[2]; - sample1 = sample2 / 2; - - point[2] = pml.origin[2] + pm->mins[2] + 1; cont = pm->pointcontents(point); if ((cont & MASK_WATER) != 0) { + pm->waterlevel = 3; pm->watertype = cont; - pm->waterlevel = 1; - point[2] = pml.origin[2] + pm->mins[2] + sample1; - cont = pm->pointcontents(point); - - if ((cont & MASK_WATER) != 0) { - pm->waterlevel = 2; - point[2] = pml.origin[2] + pm->mins[2] + sample2; - cont = pm->pointcontents(point); - - if ((cont & MASK_WATER) != 0) - pm->waterlevel = 3; - } } }