]> git.jsancho.org Git - lugaru.git/commitdiff
More PlaySoundEx eradication
authorAlexander Monakov <amonakov@gmail.com>
Mon, 3 Jan 2011 16:23:10 +0000 (19:23 +0300)
committerAlexander Monakov <amonakov@gmail.com>
Mon, 3 Jan 2011 16:23:10 +0000 (19:23 +0300)
Source/Game.cpp
Source/GameDraw.cpp
Source/GameInitDispose.cpp
Source/GameTick.cpp
Source/Skeleton.cpp
Source/Sounds.cpp
Source/Sounds.h
Source/Weapons.cpp

index 0751da011ff12a886863ecb6c0aec0dd0dea8f36..357427fd3a8ee1f342fbd0dc5a55dd2517adb447 100644 (file)
@@ -4,7 +4,6 @@
 
 extern int mainmenu;
 extern int channels[100];
-extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 
 
 
index 068fb87838af026b2c6e084ea86aa1b20b0b4d5b..eb905545834c49e26ebd9a974479bde209f98d06 100644 (file)
@@ -133,7 +133,6 @@ extern bool gamestarted;
 extern bool showdamagebar;
 
 extern int channels[100];
-extern "C"     void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 
 void Game::flash() { // shouldn't be that way, these should be attributes and Person class should not change rendering.
        flashr=1;
index a2f93b98502158c19c4f536631f8192c48d22f9e..28097bdd2744308a257f52c8cc15adf21091ee06 100644 (file)
@@ -97,7 +97,6 @@ extern float accountcampaigntime[10];
 extern int accountcampaignchoicesmade[10];
 extern int accountcampaignchoices[10][5000];
 
-extern "C"     void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 
 void LOG(const std::string &fmt, ...)
index 6deec4030fe73405b37c88a878b3a8e20896b5f6..8984c42df84b92a41c861a7677bac07e2d76e08c 100644 (file)
@@ -214,7 +214,6 @@ static bool stripfx(const char *str, const char *pfx)
   return !strncasecmp(str, pfx, strlen(pfx));
 }
 
-extern "C"     void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 
 
@@ -1104,18 +1103,7 @@ static void cmd_dispatch(Game *game, const char *cmd)
        cmd_handlers[i](game, cmd + strlen(cmd_names[i]));
        break;
       }
-  if (i < n_cmds)
-    {
-      PlaySoundEx(consolesuccesssound, samp[consolesuccesssound], NULL, true);
-      OPENAL_SetVolume(channels[consolesuccesssound], 256);
-      OPENAL_SetPaused(channels[consolesuccesssound], false);
-    }
-  else
-    {
-      PlaySoundEx(consolefailsound, samp[consolefailsound], NULL, true);
-      OPENAL_SetVolume(channels[consolefailsound], 256);
-      OPENAL_SetPaused(channels[consolefailsound], false);
-    }
+  emit_sound_np(i < n_cmds ? consolesuccesssound : consolefailsound);
 }
 
 /********************> Tick() <*****/
@@ -1625,9 +1613,7 @@ void      Game::Loadlevel(char *name){
                changedelay=0;
                if(console)
                {
-                       PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
-                       OPENAL_SetVolume(channels[consolesuccesssound], 256);
-                       OPENAL_SetPaused(channels[consolesuccesssound], false);
+                       emit_sound_np(consolesuccesssound);
                        freeze=0;
                        console=0;
                }
@@ -2405,9 +2391,7 @@ void      Game::Tick()
        if(Input::isKeyDown(SDLK_TAB)&&!minimaptogglekeydown&&tutoriallevel){
                if(tutorialstage!=51)
                        tutorialstagetime=tutorialmaxtime;
-               PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
-               OPENAL_SetVolume(channels[consolefailsound], 128);
-               OPENAL_SetPaused(channels[consolefailsound], false);
+               emit_sound_np(consolefailsound, 128.);
                minimaptogglekeydown=1;
        }
        if(!Input::isKeyDown(SDLK_TAB)){
@@ -3029,9 +3013,7 @@ void      Game::Tick()
                static int oldwinfreeze;
                if(winfreeze&&!oldwinfreeze){
                        OPENAL_SetFrequency(OPENAL_ALL, 0.001);
-                       PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
-                       OPENAL_SetVolume(channels[consolesuccesssound], 256);
-                       OPENAL_SetPaused(channels[consolesuccesssound], false);
+                       emit_sound_np(consolesuccesssound);
                }
                if(winfreeze==0)oldwinfreeze=winfreeze;
                else oldwinfreeze++;
@@ -3602,9 +3584,7 @@ void      Game::Tick()
 
 
                                                if(tutorialstagetime==tutorialmaxtime-3){
-                                                       PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
-                                                       OPENAL_SetVolume(channels[consolesuccesssound], 256);
-                                                       OPENAL_SetPaused(channels[consolesuccesssound], false);
+                                                       emit_sound_np(consolesuccesssound);
                                                }
 
                                                if(tutorialsuccess>=1){
@@ -3622,16 +3602,12 @@ void    Game::Tick()
 
                                        if(tutoriallevel!=1){
                                                if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
-                                                       PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
-                                                       OPENAL_SetVolume(channels[consolesuccesssound], 256);
-                                                       OPENAL_SetPaused(channels[consolesuccesssound], false);
+                                                       emit_sound_np(consolesuccesssound);
                                                }
                                        }
                                        else
                                                if(bonustime==0){
-                                                       PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                       OPENAL_SetVolume(channels[fireendsound], 256);
-                                                       OPENAL_SetPaused(channels[fireendsound], false);
+                                                       emit_sound_np(fireendsound);
                                                }
                                                if(bonustime==0){
                                                        if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
@@ -7516,17 +7492,7 @@ void     Game::TickOnceAfter(){
 
                if(musictoggle){
                        if(musictype!=oldmusictype&&musictype==stream_music2){
-                               static float gLoc[3];
-                               static float vel[3];
-                               gLoc[0]=cameraloc.x;
-                               gLoc[1]=cameraloc.y;
-                               gLoc[2]=cameraloc.z;
-                               vel[0]=0;
-                               vel[1]=0;
-                               vel[2]=0;
-                               PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
-                               OPENAL_SetVolume(channels[alarmsound], 512);
-                               OPENAL_SetPaused(channels[alarmsound], false);
+                               emit_sound_np(alarmsound);
 
                        }
                }
index aba644e2f86c14a1c6637782a8868c51a45a1a5b..dfc4f786fd91ad9050d9448f4a733587927b135f 100644 (file)
@@ -47,7 +47,6 @@ extern int whichjointendarray[26];
 
 extern Game * pgame;
 extern bool visibleloading;
-extern "C"     void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 
 void dealloc2(void* param){
        free(param);
index 38080a67f572280525641c2c96e5f50d6643656c..d0fa7f49fcebba93611289a854d886918b0295d9 100644 (file)
@@ -82,6 +82,14 @@ emit_sound_at(int soundid, const XYZ &pos, float vol)
   OPENAL_SetPaused (channels[soundid], false);
 }
 
+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)
 {
index 49eb2d36782b3879768865289b5bf60e0a95416e..24fdeb83ac0239185285c673e160506a1bf7f327 100644 (file)
@@ -34,6 +34,7 @@ extern struct OPENAL_SAMPLE *samp[sounds_count];
 extern void loadAllSounds();
 
 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);
 
 extern int footstepsound, footstepsound2, footstepsound3, footstepsound4;
index d72534862a4c95cb96f71a97c90eb1eba5d0af59..48fbbf6d5a9fc926e0d0dc875d5c448542f464ce 100644 (file)
@@ -54,7 +54,6 @@ extern int difficulty;
 extern bool freeze;
 extern int tutoriallevel;
 extern int numthrowkill;
-extern "C"     void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
 
 void   Weapons::DoStuff(){
        static int i,whichpatchx,whichpatchz,j,k,whichhit,m;
@@ -576,25 +575,17 @@ void      Weapons::DoStuff(){
                                                else velocity[i]+=bounceness*elasticity;
 //if (type[i]==knife) printf("velocity of knife %d now %f,%f,%f.\n", i, velocity[i].x, velocity[i].y, velocity[i].z);
                                                if(findLengthfast(&bounceness)>1){
-                                                       float gLoc[3];
-                                                       float vel[3];
                                                        int whichsound;
                                                        if(terrain.getOpacity(position[i].x,position[i].z)>.2){
                                                                if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
                                                                if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
                                                        }
                                                        else whichsound=footstepsound+abs(Random()%2);
-                                                       gLoc[0]=position[i].x;
-                                                       gLoc[1]=position[i].y;
-                                                       gLoc[2]=position[i].z;
-                                                       vel[0]=0;
-                                                       vel[1]=0;
-                                                       vel[2]=0;
-                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
-                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                                       OPENAL_SetPaused(channels[whichsound], false);
+                                                       emit_sound_at(whichsound, position[i],
+                                                                     findLengthfast(&bounceness)
+                                                                     * (terrain.getOpacity(position[i].x,position[i].z) > .2
+                                                                        ? 128.
+                                                                        : 32.));
 
                                                        if(terrain.getOpacity(position[i].x,position[i].z)<.2){
                                                                XYZ terrainlight;
@@ -630,25 +621,17 @@ void      Weapons::DoStuff(){
 //if (type[i]==knife) printf("tipvelocity of knife %d now %f,%f,%f.\n", i, tipvelocity[i].x, tipvelocity[i].y, tipvelocity[i].z);
 
                                                if(findLengthfast(&bounceness)>1){
-                                                       float gLoc[3];
-                                                       float vel[3];
                                                        int whichsound;
                                                        if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2){
                                                                if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
                                                                if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
                                                        }
                                                        else whichsound=footstepsound+abs(Random()%2);
-                                                       gLoc[0]=tippoint[i].x;
-                                                       gLoc[1]=tippoint[i].y;
-                                                       gLoc[2]=tippoint[i].z;
-                                                       vel[0]=0;
-                                                       vel[1]=0;
-                                                       vel[2]=0;
-                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
-                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                       if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                                       OPENAL_SetPaused(channels[whichsound], false);
+                                                       emit_sound_at(whichsound, tippoint[i],
+                                                                     findLengthfast(&bounceness)
+                                                                     * (terrain.getOpacity(tippoint[i].x,tippoint[i].z) > .2
+                                                                        ? 128.
+                                                                        : 32.));
 
                                                        if(terrain.getOpacity(tippoint[i].x,tippoint[i].z)<.2){
                                                                XYZ terrainlight;
@@ -688,25 +671,17 @@ void      Weapons::DoStuff(){
                                                else velocity[i]+=bounceness*elasticity;
 
                                                if(findLengthfast(&bounceness)>1){
-                                                       float gLoc[3];
-                                                       float vel[3];
                                                        int whichsound;
                                                        if(terrain.getOpacity(mid.x,mid.z)>.2){
                                                                if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
                                                                if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
                                                        }
                                                        else whichsound=footstepsound+abs(Random()%2);
-                                                       gLoc[0]=mid.x;
-                                                       gLoc[1]=mid.y;
-                                                       gLoc[2]=mid.z;
-                                                       vel[0]=0;
-                                                       vel[1]=0;
-                                                       vel[2]=0;
-                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
-                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                                       OPENAL_SetPaused(channels[whichsound], false);
+                                                       emit_sound_at(whichsound, mid,
+                                                                     findLengthfast(&bounceness)
+                                                                     * (terrain.getOpacity(position[i].x,position[i].z) > .2
+                                                                        ? 128.
+                                                                        : 32.));
                                                }
                                                position[i]+=(mid-oldmid)*20;
                                        }
@@ -732,25 +707,17 @@ void      Weapons::DoStuff(){
                                                else tipvelocity[i]+=bounceness*elasticity;
 
                                                if(findLengthfast(&bounceness)>1){
-                                                       float gLoc[3];
-                                                       float vel[3];
                                                        int whichsound;
                                                        if(terrain.getOpacity(mid.x,mid.z)>.2){
                                                                if(type[i]==staff)whichsound=footstepsound3+abs(Random()%2);
                                                                if(type[i]!=staff)whichsound=clank1sound+abs(Random()%4);
                                                        }
                                                        else whichsound=footstepsound+abs(Random()%2);
-                                                       gLoc[0]=mid.x;
-                                                       gLoc[1]=mid.y;
-                                                       gLoc[2]=mid.z;
-                                                       vel[0]=0;
-                                                       vel[1]=0;
-                                                       vel[2]=0;
-                                                       PlaySoundEx( whichsound, samp[whichsound], NULL, true);
-                                                       OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
-                                                       if(terrain.getOpacity(position[i].x,position[i].z)>.2)OPENAL_SetVolume(channels[whichsound], 128*findLengthfast(&bounceness));
-                                                       else OPENAL_SetVolume(channels[whichsound], 32*findLengthfast(&bounceness));
-                                                       OPENAL_SetPaused(channels[whichsound], false);
+                                                       emit_sound_at(whichsound, mid,
+                                                                     findLengthfast(&bounceness)
+                                                                     * (terrain.getOpacity(position[i].x,position[i].z) > .2
+                                                                        ? 128.
+                                                                        : 32.));
                                                }
                                                tippoint[i]+=(mid-oldmid)*20;
                                        }