Fix "random" behaviour of sound, music and fullscreen options.
The state of these options was not only stored in the global config file, but also in each saved game. When loading a game or clicking on "continue game" from the title screen, the state of these options would also be loaded from the save game file. If this changed the state of sound and music, this would only take effect when starting a mission or going back to the title screen. If it changed the state of the fullscreen option, it would never toggle the state, but would desynchronise the actual state of the window and the fullscreen option. This is now fixed by moving these options from the currentGame variable to the engine variable, where they are not in danger of being overwritten.
This commit is contained in:
parent
6ea4744832
commit
931d110692
|
@ -24,7 +24,7 @@ Mix_Chunk *sound[MAX_SOUNDS];
|
||||||
|
|
||||||
void playSound(int sid)
|
void playSound(int sid)
|
||||||
{
|
{
|
||||||
if ((!currentGame.useSound) || (!engine.useAudio))
|
if ((!engine.useSound) || (!engine.useAudio))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch(sid)
|
switch(sid)
|
||||||
|
@ -95,7 +95,7 @@ void loadMusic(const char *filename)
|
||||||
|
|
||||||
void playRandomTrack()
|
void playRandomTrack()
|
||||||
{
|
{
|
||||||
if ((!currentGame.useMusic) || (!engine.useAudio))
|
if ((!engine.useMusic) || (!engine.useAudio))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int tracks = 0;
|
int tracks = 0;
|
||||||
|
|
|
@ -31,8 +31,8 @@ void newGame()
|
||||||
|
|
||||||
if (!engine.useAudio)
|
if (!engine.useAudio)
|
||||||
{
|
{
|
||||||
currentGame.useSound = false;
|
engine.useSound = false;
|
||||||
currentGame.useMusic = false;
|
engine.useMusic = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentGame.autoSaveSlot = -1;
|
currentGame.autoSaveSlot = -1;
|
||||||
|
|
|
@ -179,14 +179,14 @@ void initSystem()
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentGame.fullScreen = fullScreen;
|
engine.fullScreen = fullScreen;
|
||||||
currentGame.useSound = useSound;
|
engine.useSound = useSound;
|
||||||
currentGame.useMusic = useMusic;
|
engine.useMusic = useMusic;
|
||||||
|
|
||||||
SDL_WM_SetCaption("Project: Starfighter", "starfighter");
|
SDL_WM_SetCaption("Project: Starfighter", "starfighter");
|
||||||
SDL_WM_SetIcon(loadImage("gfx/alienDevice.png"), NULL);
|
SDL_WM_SetIcon(loadImage("gfx/alienDevice.png"), NULL);
|
||||||
|
|
||||||
if (currentGame.fullScreen)
|
if (engine.fullScreen)
|
||||||
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
|
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
|
||||||
else
|
else
|
||||||
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
|
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
|
||||||
|
@ -260,7 +260,7 @@ void cleanUp()
|
||||||
fp = fopen(filename, "wb");
|
fp = fopen(filename, "wb");
|
||||||
if (fp != NULL)
|
if (fp != NULL)
|
||||||
{
|
{
|
||||||
fprintf(fp, "%d %d %d\n", currentGame.fullScreen, currentGame.useSound, currentGame.useMusic);
|
fprintf(fp, "%d %d %d\n", engine.fullScreen, engine.useSound, engine.useMusic);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -345,7 +345,7 @@ static void createOptions(SDL_Surface *optionsSurface)
|
||||||
graphics.blevelRect(optionsSurface, 190, 45, 50, 22, 0x00, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 190, 45, 50, 22, 0x00, 0x00, 0x00);
|
||||||
graphics.blevelRect(optionsSurface, 250, 45, 50, 22, 0x00, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 250, 45, 50, 22, 0x00, 0x00, 0x00);
|
||||||
graphics.blevelRect(optionsSurface, 20, 45, 150, 22, 0x00, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 20, 45, 150, 22, 0x00, 0x00, 0x00);
|
||||||
if (currentGame.useSound)
|
if (engine.useSound)
|
||||||
graphics.blevelRect(optionsSurface, 190, 45, 50, 22, 0xff, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 190, 45, 50, 22, 0xff, 0x00, 0x00);
|
||||||
else
|
else
|
||||||
graphics.blevelRect(optionsSurface, 250, 45, 50, 22, 0xff, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 250, 45, 50, 22, 0xff, 0x00, 0x00);
|
||||||
|
@ -356,7 +356,7 @@ static void createOptions(SDL_Surface *optionsSurface)
|
||||||
graphics.blevelRect(optionsSurface, 190, 95, 50, 22, 0x00, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 190, 95, 50, 22, 0x00, 0x00, 0x00);
|
||||||
graphics.blevelRect(optionsSurface, 250, 95, 50, 22, 0x00, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 250, 95, 50, 22, 0x00, 0x00, 0x00);
|
||||||
graphics.blevelRect(optionsSurface, 20, 95, 150, 22, 0x00, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 20, 95, 150, 22, 0x00, 0x00, 0x00);
|
||||||
if (currentGame.useMusic)
|
if (engine.useMusic)
|
||||||
graphics.blevelRect(optionsSurface, 190, 95, 50, 22, 0xff, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 190, 95, 50, 22, 0xff, 0x00, 0x00);
|
||||||
else
|
else
|
||||||
graphics.blevelRect(optionsSurface, 250, 95, 50, 22, 0xff, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 250, 95, 50, 22, 0xff, 0x00, 0x00);
|
||||||
|
@ -367,7 +367,7 @@ static void createOptions(SDL_Surface *optionsSurface)
|
||||||
graphics.blevelRect(optionsSurface, 190, 145, 50, 22, 0x00, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 190, 145, 50, 22, 0x00, 0x00, 0x00);
|
||||||
graphics.blevelRect(optionsSurface, 250, 145, 50, 22, 0x00, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 250, 145, 50, 22, 0x00, 0x00, 0x00);
|
||||||
graphics.blevelRect(optionsSurface, 20, 145, 150, 22, 0x00, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 20, 145, 150, 22, 0x00, 0x00, 0x00);
|
||||||
if (currentGame.fullScreen)
|
if (engine.fullScreen)
|
||||||
graphics.blevelRect(optionsSurface, 190, 145, 50, 22, 0xff, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 190, 145, 50, 22, 0xff, 0x00, 0x00);
|
||||||
else
|
else
|
||||||
graphics.blevelRect(optionsSurface, 250, 145, 50, 22, 0xff, 0x00, 0x00);
|
graphics.blevelRect(optionsSurface, 250, 145, 50, 22, 0xff, 0x00, 0x00);
|
||||||
|
@ -396,15 +396,15 @@ static void showOptions(SDL_Surface *optionsSurface)
|
||||||
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
|
if ((engine.keyState[SDLK_LCTRL]) || (engine.keyState[SDLK_RCTRL]))
|
||||||
{
|
{
|
||||||
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 172, 45, 22))
|
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 172, 45, 22))
|
||||||
currentGame.useSound = true;
|
engine.useSound = true;
|
||||||
|
|
||||||
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 172, 45, 22))
|
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 172, 45, 22))
|
||||||
currentGame.useSound = false;
|
engine.useSound = false;
|
||||||
|
|
||||||
|
|
||||||
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 222, 45, 22))
|
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 222, 45, 22))
|
||||||
{
|
{
|
||||||
currentGame.useMusic = true;
|
engine.useMusic = true;
|
||||||
if (engine.useAudio)
|
if (engine.useAudio)
|
||||||
{
|
{
|
||||||
if (Mix_PausedMusic() == 1)
|
if (Mix_PausedMusic() == 1)
|
||||||
|
@ -416,14 +416,14 @@ static void showOptions(SDL_Surface *optionsSurface)
|
||||||
|
|
||||||
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 222, 45, 22))
|
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 222, 45, 22))
|
||||||
{
|
{
|
||||||
currentGame.useMusic = false;
|
engine.useMusic = false;
|
||||||
if (engine.useAudio)
|
if (engine.useAudio)
|
||||||
Mix_PauseMusic();
|
Mix_PauseMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 272, 45, 22))
|
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 417, 272, 45, 22))
|
||||||
{
|
{
|
||||||
if (!currentGame.fullScreen)
|
if (!engine.fullScreen)
|
||||||
{
|
{
|
||||||
#if LINUX
|
#if LINUX
|
||||||
SDL_WM_ToggleFullScreen(graphics.screen);
|
SDL_WM_ToggleFullScreen(graphics.screen);
|
||||||
|
@ -432,13 +432,13 @@ static void showOptions(SDL_Surface *optionsSurface)
|
||||||
graphics.drawBackground();
|
graphics.drawBackground();
|
||||||
flushBuffer();
|
flushBuffer();
|
||||||
#endif
|
#endif
|
||||||
currentGame.fullScreen = true;
|
engine.fullScreen = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 272, 45, 22))
|
if (Collision::collision(engine.cursor_x + 13, engine.cursor_y + 13, 6, 6, 478, 272, 45, 22))
|
||||||
{
|
{
|
||||||
if (currentGame.fullScreen)
|
if (engine.fullScreen)
|
||||||
{
|
{
|
||||||
#if LINUX
|
#if LINUX
|
||||||
SDL_WM_ToggleFullScreen(graphics.screen);
|
SDL_WM_ToggleFullScreen(graphics.screen);
|
||||||
|
@ -447,7 +447,7 @@ static void showOptions(SDL_Surface *optionsSurface)
|
||||||
graphics.drawBackground();
|
graphics.drawBackground();
|
||||||
flushBuffer();
|
flushBuffer();
|
||||||
#endif
|
#endif
|
||||||
currentGame.fullScreen = false;
|
engine.fullScreen = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,7 +556,7 @@ int galaxyMap()
|
||||||
|
|
||||||
int rtn = 0;
|
int rtn = 0;
|
||||||
|
|
||||||
if ((engine.useAudio) && (currentGame.useMusic))
|
if ((engine.useAudio) && (engine.useMusic))
|
||||||
Mix_PlayMusic(engine.music, -1);
|
Mix_PlayMusic(engine.music, -1);
|
||||||
|
|
||||||
textObject iconInfo[12];
|
textObject iconInfo[12];
|
||||||
|
|
|
@ -130,9 +130,12 @@ struct Game {
|
||||||
unsigned char musicVolume;
|
unsigned char musicVolume;
|
||||||
unsigned char sfxVolume;
|
unsigned char sfxVolume;
|
||||||
|
|
||||||
bool fullScreen;
|
// First three variable below are here for save game compatibility only.
|
||||||
bool useMusic;
|
|
||||||
bool useSound;
|
signed char fullScreen; // Do not use!
|
||||||
|
signed char useMusic; // Do not use!
|
||||||
|
signed char useSound; // Do not use!
|
||||||
|
|
||||||
signed char autoSaveSlot;
|
signed char autoSaveSlot;
|
||||||
|
|
||||||
unsigned int cash;
|
unsigned int cash;
|
||||||
|
@ -265,6 +268,9 @@ struct globalEngineVariables {
|
||||||
signed char gameSection;
|
signed char gameSection;
|
||||||
|
|
||||||
bool useAudio;
|
bool useAudio;
|
||||||
|
bool useSound;
|
||||||
|
bool useMusic;
|
||||||
|
bool fullScreen;
|
||||||
|
|
||||||
// This really only applies to Linux users.
|
// This really only applies to Linux users.
|
||||||
char userHomeDirectory[1024];
|
char userHomeDirectory[1024];
|
||||||
|
|
|
@ -66,17 +66,17 @@ static signed char showLoadMenu()
|
||||||
|
|
||||||
static void createOptionsMenu()
|
static void createOptionsMenu()
|
||||||
{
|
{
|
||||||
if (currentGame.useSound)
|
if (engine.useSound)
|
||||||
graphics.textSurface(8, "SOUND - ON", -1, 350, FONT_WHITE);
|
graphics.textSurface(8, "SOUND - ON", -1, 350, FONT_WHITE);
|
||||||
else
|
else
|
||||||
graphics.textSurface(8, "SOUND - OFF", -1, 350, FONT_WHITE);
|
graphics.textSurface(8, "SOUND - OFF", -1, 350, FONT_WHITE);
|
||||||
|
|
||||||
if (currentGame.useMusic)
|
if (engine.useMusic)
|
||||||
graphics.textSurface(9, "MUSIC - ON", -1, 370, FONT_WHITE);
|
graphics.textSurface(9, "MUSIC - ON", -1, 370, FONT_WHITE);
|
||||||
else
|
else
|
||||||
graphics.textSurface(9, "MUSIC - OFF", -1, 370, FONT_WHITE);
|
graphics.textSurface(9, "MUSIC - OFF", -1, 370, FONT_WHITE);
|
||||||
|
|
||||||
if (currentGame.fullScreen)
|
if (engine.fullScreen)
|
||||||
graphics.textSurface(10, "FULLSCREEN - ON", -1, 390, FONT_WHITE);
|
graphics.textSurface(10, "FULLSCREEN - ON", -1, 390, FONT_WHITE);
|
||||||
else
|
else
|
||||||
graphics.textSurface(10, "FULLSCREEN - OFF", -1, 390, FONT_WHITE);
|
graphics.textSurface(10, "FULLSCREEN - OFF", -1, 390, FONT_WHITE);
|
||||||
|
@ -237,7 +237,7 @@ int doTitle()
|
||||||
flushInput();
|
flushInput();
|
||||||
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
|
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
|
||||||
|
|
||||||
if ((currentGame.useMusic) && (engine.useAudio))
|
if ((engine.useMusic) && (engine.useAudio))
|
||||||
Mix_PlayMusic(engine.music, 1);
|
Mix_PlayMusic(engine.music, 1);
|
||||||
|
|
||||||
while (!engine.done)
|
while (!engine.done)
|
||||||
|
@ -388,12 +388,12 @@ int doTitle()
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
if ((selectedOption == 1) && (engine.useAudio))
|
if ((selectedOption == 1) && (engine.useAudio))
|
||||||
currentGame.useSound = !currentGame.useSound;
|
engine.useSound = !engine.useSound;
|
||||||
else if ((selectedOption == 2) && (engine.useAudio))
|
else if ((selectedOption == 2) && (engine.useAudio))
|
||||||
{
|
{
|
||||||
currentGame.useMusic = !currentGame.useMusic;
|
engine.useMusic = !engine.useMusic;
|
||||||
|
|
||||||
if (currentGame.useMusic)
|
if (engine.useMusic)
|
||||||
{
|
{
|
||||||
if (Mix_PausedMusic() == 1)
|
if (Mix_PausedMusic() == 1)
|
||||||
Mix_ResumeMusic();
|
Mix_ResumeMusic();
|
||||||
|
@ -407,11 +407,11 @@ int doTitle()
|
||||||
}
|
}
|
||||||
else if (selectedOption == 3)
|
else if (selectedOption == 3)
|
||||||
{
|
{
|
||||||
currentGame.fullScreen = !currentGame.fullScreen;
|
engine.fullScreen = !engine.fullScreen;
|
||||||
#if LINUX
|
#if LINUX
|
||||||
SDL_WM_ToggleFullScreen(graphics.screen);
|
SDL_WM_ToggleFullScreen(graphics.screen);
|
||||||
#else
|
#else
|
||||||
if (currentGame.fullScreen)
|
if (engine.fullScreen)
|
||||||
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
|
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
|
||||||
else
|
else
|
||||||
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
|
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
|
||||||
|
@ -577,7 +577,7 @@ void gameover()
|
||||||
graphics.clearScreen(graphics.black);
|
graphics.clearScreen(graphics.black);
|
||||||
SDL_Delay(1000);
|
SDL_Delay(1000);
|
||||||
|
|
||||||
if ((currentGame.useMusic) && (engine.useAudio))
|
if ((engine.useMusic) && (engine.useAudio))
|
||||||
{
|
{
|
||||||
Mix_VolumeMusic(100);
|
Mix_VolumeMusic(100);
|
||||||
Mix_PlayMusic(engine.music, 1);
|
Mix_PlayMusic(engine.music, 1);
|
||||||
|
@ -610,7 +610,7 @@ void gameover()
|
||||||
|
|
||||||
SDL_FreeSurface(gameover);
|
SDL_FreeSurface(gameover);
|
||||||
|
|
||||||
if ((currentGame.useMusic) && (engine.useAudio))
|
if ((engine.useMusic) && (engine.useAudio))
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
|
|
||||||
graphics.flushBuffer();
|
graphics.flushBuffer();
|
||||||
|
@ -622,7 +622,7 @@ void doCredits()
|
||||||
graphics.flushBuffer();
|
graphics.flushBuffer();
|
||||||
graphics.freeGraphics();
|
graphics.freeGraphics();
|
||||||
|
|
||||||
if ((currentGame.useMusic) && (engine.useAudio))
|
if ((engine.useMusic) && (engine.useAudio))
|
||||||
loadMusic("music/Solace.s3m");
|
loadMusic("music/Solace.s3m");
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
@ -670,7 +670,7 @@ void doCredits()
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if ((currentGame.useMusic) && (engine.useAudio))
|
if ((engine.useMusic) && (engine.useAudio))
|
||||||
{
|
{
|
||||||
Mix_VolumeMusic(100);
|
Mix_VolumeMusic(100);
|
||||||
Mix_PlayMusic(engine.music, 1);
|
Mix_PlayMusic(engine.music, 1);
|
||||||
|
|
Loading…
Reference in New Issue