From: Côme Chilliet Date: Mon, 28 Nov 2016 12:43:59 +0000 (+0700) Subject: Cleaned up handling of envsounds array through a function X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=7d89354018ef03ca4256ae63db3a8c89df5f277d;p=lugaru.git Cleaned up handling of envsounds array through a function --- diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 592d0e3..fda1df5 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -2932,12 +2932,8 @@ void doAerialAcrobatics() Person::players[k]->animTarget = Person::players[k]->getLanding(); emit_sound_at(landsound, Person::players[k]->coords, 128.); if (k == 0) { - envsound[numenvsounds] = Person::players[k]->coords; - envsoundvol[numenvsounds] = 16; - envsoundlife[numenvsounds] = .4; - numenvsounds++; + addEnvSound(Person::players[k]->coords); } - } } } diff --git a/Source/Person.cpp b/Source/Person.cpp index 8a3579e..a957945 100644 --- a/Source/Person.cpp +++ b/Source/Person.cpp @@ -57,10 +57,6 @@ extern float flashamount, flashr, flashg, flashb; extern int flashdelay; extern bool showpoints; extern bool immediate; -extern XYZ envsound[30]; -extern float envsoundvol[30]; -extern float envsoundlife[30]; -extern int numenvsounds; extern int tutoriallevel; extern float smoketex; extern int tutorialstage; @@ -625,17 +621,12 @@ void Person::DoBloodBig(float howmuch, int which) // play pain sounds int whichsound = -1; - // FIXME: seems to be spawning sounds by manipulating attributes... MESSY! if (creature == wolftype) { int i = abs(Random() % 2); if (i == 0) whichsound = snarlsound; if (i == 1) whichsound = snarl2sound; - envsound[numenvsounds] = coords; - envsoundvol[numenvsounds] = 16; - envsoundlife[numenvsounds] = .4; - numenvsounds++; } if (creature == rabbittype) { int i = abs(Random() % 2); @@ -643,14 +634,12 @@ void Person::DoBloodBig(float howmuch, int which) whichsound = rabbitpainsound; if (i == 1 && howmuch >= 2) whichsound = rabbitpain1sound; - envsound[numenvsounds] = coords; - envsoundvol[numenvsounds] = 16; - envsoundlife[numenvsounds] = .4; - numenvsounds++; } - if (whichsound != -1) + if (whichsound != -1) { emit_sound_at(whichsound, coords); + addEnvSound(coords); + } } if (id == 0 && howmuch > 0) { @@ -1441,10 +1430,6 @@ void Person::DoDamage(float howmuch) whichsound = snarlsound; if (i == 1) whichsound = snarl2sound; - envsound[numenvsounds] = coords; - envsoundvol[numenvsounds] = 16; - envsoundlife[numenvsounds] = .4; - numenvsounds++; } if (creature == rabbittype) { int i = abs(Random() % 2); @@ -1452,14 +1437,11 @@ void Person::DoDamage(float howmuch) whichsound = rabbitpainsound; if (i == 1 && damage > damagetolerance) whichsound = rabbitpain1sound; - envsound[numenvsounds] = coords; - envsoundvol[numenvsounds] = 16; - envsoundlife[numenvsounds] = .4; - numenvsounds++; } if (whichsound != -1) { emit_sound_at(whichsound, coords); + addEnvSound(coords); } } speechdelay = .3; @@ -1987,13 +1969,11 @@ void Person::DoAnimations() if (id == 0) if (whichsound == footstepsound || whichsound == footstepsound2 || whichsound == footstepsound3 || whichsound == footstepsound4) { - envsound[numenvsounds] = coords; - if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim) - envsoundvol[numenvsounds] = 15; - else - envsoundvol[numenvsounds] = 6; - envsoundlife[numenvsounds] = .4; - numenvsounds++; + if (animTarget == wolfrunninganim || animTarget == rabbitrunninganim) { + addEnvSound(coords, 15); + } else { + addEnvSound(coords, 6); + } } if (animation[animTarget].label[frameTarget] == 3) { @@ -5229,10 +5209,7 @@ void Person::DoStuff() emit_sound_at(bushrustle, coords, 40 * findLength(&velocity)); if (id == 0) { - envsound[numenvsounds] = coords; - envsoundvol[numenvsounds] = 4 * findLength(&velocity); - envsoundlife[numenvsounds] = .4; - numenvsounds++; + addEnvSound(coords, 4 * findLength(&velocity)); } int howmany; @@ -5292,10 +5269,7 @@ void Person::DoStuff() emit_sound_at(bushrustle, coords, 40 * findLength(&velocity)); if (id == 0) { - envsound[numenvsounds] = coords; - envsoundvol[numenvsounds] = 4 * findLength(&velocity); - envsoundlife[numenvsounds] = .4; - numenvsounds++; + addEnvSound(coords, 4 * findLength(&velocity)); } int howmany; @@ -5784,10 +5758,7 @@ void Person::DoStuff() emit_sound_at(landsound, coords, 128.); if (id == 0) { - envsound[numenvsounds] = coords; - envsoundvol[numenvsounds] = 16; - envsoundlife[numenvsounds] = .4; - numenvsounds++; + addEnvSound(coords); } } } @@ -6684,10 +6655,7 @@ int Person::SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, emit_sound_at(landsound, coords, 128.); if (id == 0) { - envsound[numenvsounds] = coords; - envsoundvol[numenvsounds] = 16; - envsoundlife[numenvsounds] = .4; - numenvsounds++; + addEnvSound(coords); } } } diff --git a/Source/Skeleton.cpp b/Source/Skeleton.cpp index 1abc959..af343d6 100644 --- a/Source/Skeleton.cpp +++ b/Source/Skeleton.cpp @@ -32,10 +32,6 @@ extern int environment; extern float camerashake; extern bool freeze; extern int detail; -extern XYZ envsound[30]; -extern float envsoundvol[30]; -extern int numenvsounds; -extern float envsoundlife[30]; extern int tutoriallevel; extern int whichjointstartarray[26]; @@ -350,10 +346,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords); - envsound[numenvsounds] = *coords; - envsoundvol[numenvsounds] = 64; - envsoundlife[numenvsounds] = .4; - numenvsounds++; + addEnvSound(*coords, 64); } if (findLengthfast(&bounceness) > 2500) { @@ -438,10 +431,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords); - envsound[numenvsounds] = *coords; - envsoundvol[numenvsounds] = 64; - envsoundlife[numenvsounds] = .4; - numenvsounds++; + addEnvSound(*coords, 64); } if (objects.type[k] == treetrunktype) { objects.rotx[k] += joints[i].velocity.x * multiplier * .4; diff --git a/Source/Sounds.cpp b/Source/Sounds.cpp index 6bb6970..c2d4eb7 100644 --- a/Source/Sounds.cpp +++ b/Source/Sounds.cpp @@ -23,6 +23,11 @@ along with Lugaru. If not, see . struct OPENAL_SAMPLE *samp[sounds_count]; +extern XYZ envsound[30]; +extern float envsoundvol[30]; +extern int numenvsounds; +extern float envsoundlife[30]; + int footstepsound, footstepsound2, footstepsound3, footstepsound4; int channels[100]; @@ -69,8 +74,15 @@ void loadAllSounds() OPENAL_Stream_SetMode(samp[i], OPENAL_LOOP_NORMAL); } -void -emit_sound_at(int soundid, const XYZ &pos, float vol) +void addEnvSound(XYZ coords, float vol, float life) +{ + envsound[numenvsounds] = coords; + envsoundvol[numenvsounds] = vol; + envsoundlife[numenvsounds] = life; + numenvsounds++; +} + +void emit_sound_at(int soundid, const XYZ &pos, float vol) { PlaySoundEx (soundid, samp[soundid], NULL, true); OPENAL_3D_SetAttributes_ (channels[soundid], pos, NULL); @@ -78,16 +90,14 @@ emit_sound_at(int soundid, const XYZ &pos, float vol) OPENAL_SetPaused (channels[soundid], false); } -void -emit_sound_np(int soundid, float vol) +void emit_sound_np(int soundid, float vol) { PlaySoundEx (soundid, samp[soundid], NULL, true); OPENAL_SetVolume (channels[soundid], vol); OPENAL_SetPaused (channels[soundid], false); } -void -emit_stream_at(int soundid, const XYZ &pos, float vol) +void emit_stream_at(int soundid, const XYZ &pos, float vol) { PlayStreamEx (soundid, samp[soundid], NULL, true); OPENAL_3D_SetAttributes_ (channels[soundid], pos, NULL); @@ -95,23 +105,19 @@ emit_stream_at(int soundid, const XYZ &pos, float vol) OPENAL_SetPaused (channels[soundid], false); } -void -emit_stream_np(int soundid, float vol) +void emit_stream_np(int soundid, float vol) { PlayStreamEx (soundid, samp[soundid], NULL, true); OPENAL_SetVolume (channels[soundid], vol); OPENAL_SetPaused (channels[soundid], false); } -void -resume_stream(int soundid) +void resume_stream(int soundid) { OPENAL_SetPaused (channels[soundid], false); } -void -pause_sound(int soundid) +void pause_sound(int soundid) { OPENAL_SetPaused (channels[soundid], true); } - diff --git a/Source/Sounds.h b/Source/Sounds.h index 0ef5f3e..7557993 100644 --- a/Source/Sounds.h +++ b/Source/Sounds.h @@ -32,6 +32,8 @@ extern int channels[]; extern void loadAllSounds(); +extern void addEnvSound(XYZ coords, float vol = 16, float life = .4); + extern void emit_sound_at(int soundid, const XYZ &pos = XYZ(), float vol = 256.f); extern void emit_sound_np(int soundid, float vol = 256.f); extern void emit_stream_at(int soundid, const XYZ &pos = XYZ(), float vol = 256.f);