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

index 28097bdd2744308a257f52c8cc15adf21091ee06..c96eb28c06990fabcf7d0fe831bf5777dc9262ce 100644 (file)
@@ -97,8 +97,6 @@ extern float accountcampaigntime[10];
 extern int accountcampaignchoicesmade[10];
 extern int accountcampaignchoices[10][5000];
 
-extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
-
 void LOG(const std::string &fmt, ...)
 {
     // !!! FIXME: write me.
@@ -872,11 +870,8 @@ void Game::InitGame()
        OPENAL_SetSFXMasterVolume((int)(volume*255));
        loadAllSounds();
 
-       if(musictoggle){
-               PlayStreamEx(stream_music3, samp[stream_music3], 0, true);
-               OPENAL_SetPaused(channels[stream_music3], false);
-               OPENAL_SetVolume(channels[stream_music3], 256);
-       }
+       if(musictoggle)
+         emit_stream_np(stream_music3);
 
        LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
 
index 8984c42df84b92a41c861a7677bac07e2d76e08c..b74cb5e9331e43761ae81e111ed56282b41d3ef5 100644 (file)
@@ -214,9 +214,6 @@ static bool stripfx(const char *str, const char *pfx)
   return !strncasecmp(str, pfx, strlen(pfx));
 }
 
-extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
-
-
 static const char *cmd_names[] = {
 #define DECLARE_COMMAND(cmd) #cmd " ",
 #include "ConsoleCmds.h"
@@ -1335,12 +1332,8 @@ void     Game::Setenvironment(int which)
        if(environment==snowyenvironment){
                windvector=0;
                windvector.z=3;
-               if(ambientsound){
-                       //PlaySoundEx( wind, samp[wind], NULL, true);
-                       PlayStreamEx(stream_wind, samp[stream_wind], 0, true);
-                       OPENAL_SetPaused(channels[stream_wind], false);
-                       OPENAL_SetVolume(channels[stream_wind], 256);
-               }
+               if(ambientsound)
+                 emit_stream_np(stream_wind);
 
                LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
                LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
@@ -1386,12 +1379,8 @@ void     Game::Setenvironment(int which)
                LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
 
 
-               if(ambientsound){
-                       //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
-                       PlayStreamEx( stream_desertambient, samp[stream_desertambient], NULL, true);
-                       OPENAL_SetPaused(channels[stream_desertambient], false);
-                       OPENAL_SetVolume(channels[stream_desertambient], 256);
-               }
+               if(ambientsound)
+                 emit_stream_np(stream_desertambient);
 
                footstepsound = footstepsn1;
                footstepsound2 = footstepsn2;
@@ -1430,11 +1419,8 @@ void     Game::Setenvironment(int which)
                LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
                LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
 
-               if(ambientsound){
-                       PlayStreamEx( stream_wind, samp[stream_wind], NULL, true);
-                       OPENAL_SetPaused(channels[stream_wind], false);
-                       OPENAL_SetVolume(channels[stream_wind], 100);
-               }
+               if(ambientsound)
+                 emit_stream_np(stream_wind, 100.);
 
                footstepsound = footstepgr1;
                footstepsound2 = footstepgr2;
@@ -2217,33 +2203,17 @@ void    Game::Loadlevel(char *name){
                if(environment==snowyenvironment)
                {
                        if(ambientsound)
-                       {
-                               PlayStreamEx(stream_wind, samp[stream_wind], NULL, true);
-                               OPENAL_SetPaused(channels[stream_wind], false);
-                               OPENAL_SetVolume(channels[stream_wind], 256);
-                       }
+                         emit_stream_np(stream_wind);
                }
                else if(environment==desertenvironment)
                {
                        if(ambientsound)
-                       {
-                               //PlaySoundEx(desertambient,
-                               //      samp[desertambient], NULL, true);
-                               PlayStreamEx(stream_desertambient,
-                                       samp[stream_desertambient], NULL, true);
-                               OPENAL_SetPaused(channels[stream_desertambient], false);
-                               OPENAL_SetVolume(channels[stream_desertambient], 256);
-                       }
+                         emit_stream_np(stream_desertambient);
                }
                else if(environment==grassyenvironment)
                {
                        if(ambientsound)
-                       {
-                               //PlaySoundEx(wind, samp[wind], NULL, true);
-                               PlayStreamEx(stream_wind, samp[stream_wind], NULL, true);
-                               OPENAL_SetPaused(channels[stream_wind], false);
-                               OPENAL_SetVolume(channels[stream_wind], 100);
-                       }
+                         emit_stream_np(stream_wind, 100.);
                }
                oldmusicvolume[0]=0;
                oldmusicvolume[1]=0;
@@ -2338,9 +2308,7 @@ void      Game::Tick()
                                if(mainmenu&&musictoggle){
                                        if(mainmenu==1||mainmenu==2||mainmenu==100){
                                                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
-                                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
-                                               OPENAL_SetPaused(channels[stream_music3], false);
-                                               OPENAL_SetVolume(channels[stream_music3], 256);
+                                               emit_stream_np(stream_music3);
                                                OPENAL_SetPaused(channels[music1], true);
                                        }
                                }
@@ -2542,11 +2510,8 @@ void     Game::Tick()
                                        }
                                }
 
-                               if(musictoggle){
-                                       PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
-                                       OPENAL_SetPaused(channels[stream_music3], false);
-                                       OPENAL_SetVolume(channels[stream_music3], 256);
-                               }
+                               if(musictoggle)
+                                 emit_stream_np(stream_music3);
                        }
                        if(Input::Button()&&!oldbutton&&selected==9){
                                invertmouse=1-invertmouse;
@@ -7332,9 +7297,7 @@ void      Game::Tick()
                                                                                OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
                                                                                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
 
-                                                                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
-                                                                               OPENAL_SetPaused(channels[stream_music3], false);
-                                                                               OPENAL_SetVolume(channels[stream_music3], 256);
+                                                                               emit_stream_np(stream_music3);
 
                                                                                gameon=0;
                                                                                mainmenu=5;
@@ -7513,18 +7476,12 @@ void    Game::TickOnceAfter(){
                if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
 
                if(musictoggle){
-                       if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
-                               PlayStreamEx( music1, samp[music1], NULL, true);
-                               OPENAL_SetPaused(channels[music1], false);
-                       }
-                       if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
-                               PlayStreamEx( stream_music2, samp[stream_music2], NULL, true);
-                               OPENAL_SetPaused(channels[stream_music2], false);
-                       }
-                       if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
-                               PlayStreamEx( stream_music3, samp[stream_music3], NULL, true);
-                               OPENAL_SetPaused(channels[stream_music3], false);
-                       }
+                       if(musicvolume[0]>0&&oldmusicvolume[0]<=0)
+                         emit_stream_np(music1, musicvolume[0]);
+                       if(musicvolume[1]>0&&oldmusicvolume[1]<=0)
+                         emit_stream_np(stream_music2, musicvolume[1]);
+                       if(musicvolume[2]>0&&oldmusicvolume[2]<=0)
+                         emit_stream_np(stream_music3, musicvolume[2]);
                        if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
                                OPENAL_SetPaused(channels[music1], true);
                        }
index d0fa7f49fcebba93611289a854d886918b0295d9..96e18fd03157752e700489a6df1b984cf9a43b91 100644 (file)
@@ -99,3 +99,11 @@ emit_stream_at(int soundid, const XYZ &pos, float vol)
   OPENAL_SetPaused (channels[soundid], false);
 }
 
+void
+emit_stream_np(int soundid, float vol)
+{
+  PlayStreamEx (soundid, samp[soundid], NULL, true);
+  OPENAL_SetVolume (channels[soundid], vol);
+  OPENAL_SetPaused (channels[soundid], false);
+}
+
index 24fdeb83ac0239185285c673e160506a1bf7f327..cdf7d18a1c14c928de9b988c11e050daf65bb4bc 100644 (file)
@@ -36,6 +36,7 @@ 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 void emit_stream_np(int soundid, float vol = 256.f);
 
 extern int footstepsound, footstepsound2, footstepsound3, footstepsound4;
 #endif