conditional compiling for sound support!
Derek Stevens nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAlvrQpQACgkQO3+8IhRO Y5ihVQ/8CRhb9cbR8e+q/5G8+iAAwk/zDgdqdBCnpn4arg6a4g9FtIMdOloebWvW lDOQHDX9oYi2PeChNLS90ldiYZsNXO4BVbVs/3WcVFtq2lxL4Q1Qn4bCOxGPAMir wUJptX+4BprFamwwPoEJvy9N0oT1uNrAlCsGlT2ctFE2VsuWjXNseSrLE7IKEYqX PuNXVSjk4SqteUPMpIuw8JLFfa4P/EgL6CHBx1mc+ttsXNtQKh0Mb6BOa7S0f9pp UrSnDmiQfKVVJfEEh7REtnnOd8WIy4xi988rvTbWDQoAhy/iaZVThqgH5rR0GV9n 6BfAhKSgTSpScXiXW5X7z7BHBYO2dgEeNouYFLm+tMGWLwIwOb/br1eAvNaAj4yY DTGllzOVs4m7Vq0SXrwmy/2ZzCr+qjey6ecDzPFrZrP+B+tIlRvSO0rx1Hq1/Uou JTOzvychQkVU0ihVhOZWMNDu0pb6Q/zxV7JLjTkv5EBQ0T/xN8OBF8Wt415Ps9K4 tHNk8q4JTVTip/5/T60vivjHslujYrigzgvUpmemt/c8620pXIlRa5yD9UOK8cki 78XKNQw/7IWmRT6mxhBVWiSqqIIm3t5L/ykn1C/xLHKPur6lRYt9j3nr21WkTWMT hO8vh4Z/x1shifKhucjU28TR1Fo3V8U0eAqfSyGztNwtdZZYOfM= =JbrP -----END PGP SIGNATURE-----
M
Engine.c
→
Engine.c
@@ -1,12 +1,16 @@
#include <stdio.h> #include <string.h> +#include "config.h" + #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include "SDL/SDL_ttf.h" + +#ifdef SOUND_ON #include "SDL/SDL_mixer.h" +#endif -#include "config.h" #include "enum.h" #include "Engine.h"@@ -53,6 +57,8 @@ //
// sound // +#ifdef SOUND_ON + Mix_Music* loadBGM(char* filename) { Mix_Music* bgmTrack = Mix_LoadMUS(filename);@@ -65,6 +71,8 @@ {
Mix_Chunk* sfxClip = Mix_LoadWAV(filename); return sfxClip; } + +#endif // // world@@ -183,10 +191,20 @@
int init(int argc, char* args[]) { printf("Initializing SDL\n"); + +#ifdef SOUND_ON if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO) == -1) return 0; printf("Initialized\nOpening soundsystem\n"); if (Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT, 2, 4096) == -1) return 0; printf("Soundsystem open\nCreating window\n"); + +#else + + if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) == -1) return 0; + printf("Initialized\nCreating window\n"); + +#endif + if (argc >= 2) { if (strcmp(args[1], "-w"))@@ -226,8 +244,12 @@
mapData = malloc(64*sizeof(Room*)); mapBuffer= malloc(64*sizeof(Room*)); dialogueData = malloc(124*sizeof(Room*)); + +#ifdef SOUND_ON bgmData = malloc(8*sizeof(Mix_Music*)); sfxData = malloc(24*sizeof(Mix_Chunk*)); +#endif + kaosData = malloc(124*sizeof(Kaos*)); theatre = malloc(8*sizeof(Scene*));@@ -296,8 +318,11 @@ free(mapData);
free(kaosData); free(dialogueData); + +#ifdef SOUND_ON free(bgmData); free(sfxData); +#endif free(theatre);@@ -311,7 +336,11 @@ SDL_FreeSurface(loadingTxt);
SDL_FreeSurface(screen); printf("Closing SDL\n"); + +#ifdef SOUND_ON Mix_CloseAudio(); +#endif + TTF_CloseFont(font); TTF_Quit(); SDL_Quit();@@ -360,10 +389,12 @@ int yPos = 90;
long long int eventState = 2; warpto(menuBG); +#ifdef SOUND_ON if (menuBGM == NULL) Mix_HaltMusic(); else Mix_PlayMusic(menuBGM, -1); +#endif while (!select) {@@ -469,7 +500,11 @@ int i;
FILE* saveData; hero->bearing.x = 0; hero->bearing.y = 0; + +#ifdef SOUND_ON Mix_VolumeMusic(MIX_MAX_VOLUME/3); +#endif + for (i = 0; i < 64; i++) { if (rightHere == mapData[i])@@ -557,6 +592,9 @@ }
SDL_Flip(screen); timeDilation(); } + +#ifdef SOUND_ON Mix_VolumeMusic(MIX_MAX_VOLUME); +#endif }
M
Kaos.c
→
Kaos.c
@@ -1,9 +1,9 @@
+#include "config.h" + #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include "SDL/SDL_ttf.h" #include "SDL/SDL_mixer.h" - -#include "config.h" #include "enum.h" #include "Engine.h"@@ -310,6 +310,7 @@ free(target->kType);
free(target); } +#ifdef SOUND_ON Kaos* newPlaySound(int i) { Kaos* core = rawKaos();@@ -335,6 +336,7 @@ {
free(target->kType); free(target); } +#endif Kaos* newErase(char t, int i) {
M
Kaos.h
→
Kaos.h
@@ -46,11 +46,13 @@ Player* p1;
Player* p2; } FaceEachother; +#ifdef SOUND_ON typedef struct kaos_PlaySound { Kaos* core; int i; } PlaySound; +#endif typedef struct kaos_Teleport {@@ -107,9 +109,11 @@ Kaos* newFaceEachother(Player* p1, Player* p2);
void runFaceEachother(Kaos* self); void deleteFaceEachother(Kaos* target); +#ifdef SOUND_ON Kaos* newPlaySound(int i); void runPlaySound(Kaos* self); void deletePlaySound(Kaos* target); +#endif Kaos* newErase(char t, int i); void runErase(Kaos* self);
M
WorldData.c
→
WorldData.c
@@ -1,10 +1,12 @@
#include <stdio.h> + +#include "config.h" + #include "SDL/SDL.h" #include "SDL/SDL_image.h" #include "SDL/SDL_ttf.h" #include "SDL/SDL_mixer.h" -#include "config.h" #include "enum.h" #include "Engine.h"@@ -27,7 +29,10 @@ SDL_Flip(screen);
printf("Loading map chunk\n"); switch (chunk){ case LEVEL1: + +#ifdef SOUND_ON bgmData[0] = loadBGM("assets/snd/bgm/artificial sun stage (mamon machine mix).mp3"); +#endif mapBuffer[0] = newRoom("assets/img/backgrounds/blueroom.gif", 10); mapBuffer[1] = newRoom("assets/img/backgrounds/redroom.gif", 4);@@ -184,10 +189,14 @@ for (i = 0; i < b; i++)
deleteTextBox(dialogueData[i]); for (i = 0; i < c; i++) kaosData[i]->destroy(kaosData[i]); + +#ifdef SOUND_ON for (i = 0; i < d; i++) Mix_FreeMusic(bgmData[i]); for (i = 0; i < e; i++) Mix_FreeChunk(sfxData[i]); +#endif + } void unloadData(enum dataChunks chunk)@@ -212,8 +221,12 @@ {
printf("Pushing map buffer\n"); mapData = mapBuffer; mapBuffer = (Room**)malloc(64*sizeof(Room*)); + +#ifdef SOUND_ON if (hasMusic) Mix_PlayMusic(bgmData[0], -1); +#endif + printf("Map buffer clean\n"); }@@ -221,10 +234,14 @@ void pager()
{ if (thisChunk != nextChunk) { + +#ifdef SOUND_ON if (Mix_PlayingMusic()) { Mix_HaltMusic(); } +#endif + unloadData(thisChunk); pushBufferData(); thisChunk=nextChunk;
M
extern.h
→
extern.h
@@ -28,7 +28,9 @@ extern SDL_Surface* nextArrow;
extern SDL_Surface* selectArrow; extern SDL_Surface* loadingTxt; +#ifdef SOUND_ON extern Mix_Music* menuBGM; +#endif extern TTF_Font* font; extern SDL_Color textColor;@@ -39,7 +41,11 @@
extern Room** mapData; extern Room** mapBuffer; extern TextBox** dialogueData; + +#ifdef SOUND_ON extern Mix_Music** bgmData; extern Mix_Chunk** sfxData; +#endif + extern Kaos** kaosData; extern Scene** theatre;