]> git.mxchange.org Git - quix0rs-blobwars.git/blobdiff - src/CAudio.cpp
Added .gitignore to ignore certain files + fixed access rights on Makefile* as
[quix0rs-blobwars.git] / src / CAudio.cpp
index c985f5e3c92de3e95827f68fcbe4b3d682f94d26..c713aaa396d25d921cec4be4210e5842c43ba254 100644 (file)
@@ -1,5 +1,6 @@
 /*
-Copyright (C) 2004 Parallel Realities
+Copyright (C) 2004-2011 Parallel Realities
+Copyright (C) 2011-2015 Perpendicular Dimensions
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
@@ -35,6 +36,10 @@ Audio::Audio()
        quickSound = NULL;
        
        levelMusicName[0] = 0;
+       songtitle[0] = 0;
+       songalbum[0] = 0;
+       songartist[0] = 0;
+       songlicense = -1;
 }
 
 void Audio::setSoundVolume(int soundVolume)
@@ -106,8 +111,6 @@ bool Audio::loadMusic(const char *filename)
 
        remove(tempPath);
        
-       SDL_Delay(250); // wait a bit, just to be sure!
-
        if (music != NULL)
        {
                Mix_HaltMusic();
@@ -123,18 +126,59 @@ bool Audio::loadMusic(const char *filename)
                music = Mix_LoadMUS(filename);
        #endif
 
+       songtitle[0] = 0;
+       songalbum[0] = 0;
+       songartist[0] = 0;
+       songlicense = -1;
+
        if (!music)
        {
                debug(("WARNING - Failed to load %s\n", filename));
                return false;
        }
-               
-       strncpy(levelMusicName, filename, sizeof levelMusicName);
+
+       #if USEPAK
+               snprintf(tempPath, sizeof tempPath, "%smusic.tags", engine->userHomeDirectory);
+               remove(tempPath);
+               char tagfilename[PATH_MAX];
+               snprintf(tagfilename, sizeof tagfilename, "%s.tags", filename);
+               engine->unpack(tagfilename, PAK_TAGS);
+       #else
+               snprintf(tempPath, sizeof tempPath, "%s.tags", filename);
+       #endif
+       FILE *fp = fopen(tempPath, "r");
+       char line[1024];
+       
+       while(fp && fgets(line, sizeof line, fp))
+       {
+               int l = strlen(line);
+               if(line[l - 1] == '\n')
+                       line[l - 1] = 0;
+
+               if(!strncasecmp(line, "title=", 6))
+                        strlcpy(songtitle, line + 6, sizeof songtitle);
+               else if(!strncasecmp(line, "album=", 6))
+                        strlcpy(songalbum, line + 6, sizeof songalbum);
+               else if(!strncasecmp(line, "artist=", 7))
+                        strlcpy(songartist, line + 7, sizeof songartist);
+               else if(!strncasecmp(line, "license=", 8))
+               {
+                       if(!strncasecmp(line + 8, "CC-BY ", 6))
+                               songlicense = 0;
+                       else if(!strncasecmp(line + 8, "CC-BY-SA ", 9))
+                               songlicense = 1;
+               }
+       }
+
+       if(fp)
+               fclose(fp);
+       
+       strlcpy(levelMusicName, filename, sizeof levelMusicName);
 
        return true;
 }
 
-void Audio::playSound(int snd, int channel)
+void Audio::playSoundRelative(int snd, int channel, float x)
 {
        if ((!engine->useAudio) || (soundVolume == 0))
                return;
@@ -144,9 +188,29 @@ void Audio::playSound(int snd, int channel)
                return;
        }
 
-       Mix_Volume(channel, soundVolume);
+       int angle = atanf(x / 480) * 180 / M_PI;
+       int attenuation = fabsf(x) / 40;
+
+       if (angle < 0)
+               angle += 360;
 
+       if (attenuation > 255)
+               attenuation = 255;
+
+       Mix_Volume(channel, soundVolume);
        Mix_PlayChannel(channel, sound[snd], 0);
+       Mix_SetPosition(channel, angle, attenuation);
+}
+
+void Audio::playSound(int snd, int channel, float x)
+{
+       x -= (engine->playerPosX + 320);
+       playSoundRelative(snd, channel, x);
+}
+
+void Audio::playSound(int snd, int channel)
+{
+       playSoundRelative(snd, channel, 0);
 }
 
 void Audio::playMusic()
@@ -202,10 +266,10 @@ bool Audio::loadGameOverMusic()
        }
 
        #if USEPAK
-               engine->unpack("music/friendDied.mod", PAK_MUSIC);
+               engine->unpack("music/gameover", PAK_MUSIC);
                music = Mix_LoadMUS(tempPath);
        #else
-               music = Mix_LoadMUS("music/friendDied.mod");
+               music = Mix_LoadMUS("music/gameover");
        #endif
 
        if (!music)