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:
Guus Sliepen 2011-08-26 22:48:52 +02:00
parent 6ea4744832
commit 931d110692
6 changed files with 43 additions and 37 deletions

View File

@ -24,7 +24,7 @@ Mix_Chunk *sound[MAX_SOUNDS];
void playSound(int sid)
{
if ((!currentGame.useSound) || (!engine.useAudio))
if ((!engine.useSound) || (!engine.useAudio))
return;
switch(sid)
@ -95,7 +95,7 @@ void loadMusic(const char *filename)
void playRandomTrack()
{
if ((!currentGame.useMusic) || (!engine.useAudio))
if ((!engine.useMusic) || (!engine.useAudio))
return;
int tracks = 0;

View File

@ -31,8 +31,8 @@ void newGame()
if (!engine.useAudio)
{
currentGame.useSound = false;
currentGame.useMusic = false;
engine.useSound = false;
engine.useMusic = false;
}
currentGame.autoSaveSlot = -1;

View File

@ -179,14 +179,14 @@ void initSystem()
fclose(fp);
}
currentGame.fullScreen = fullScreen;
currentGame.useSound = useSound;
currentGame.useMusic = useMusic;
engine.fullScreen = fullScreen;
engine.useSound = useSound;
engine.useMusic = useMusic;
SDL_WM_SetCaption("Project: Starfighter", "starfighter");
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);
else
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
@ -260,7 +260,7 @@ void cleanUp()
fp = fopen(filename, "wb");
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);
}
else

View File

@ -345,7 +345,7 @@ static void createOptions(SDL_Surface *optionsSurface)
graphics.blevelRect(optionsSurface, 190, 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);
if (currentGame.useSound)
if (engine.useSound)
graphics.blevelRect(optionsSurface, 190, 45, 50, 22, 0xff, 0x00, 0x00);
else
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, 250, 95, 50, 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);
else
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, 250, 145, 50, 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);
else
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 (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))
currentGame.useSound = false;
engine.useSound = false;
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 (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))
{
currentGame.useMusic = false;
engine.useMusic = false;
if (engine.useAudio)
Mix_PauseMusic();
}
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
SDL_WM_ToggleFullScreen(graphics.screen);
@ -432,13 +432,13 @@ static void showOptions(SDL_Surface *optionsSurface)
graphics.drawBackground();
flushBuffer();
#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 (currentGame.fullScreen)
if (engine.fullScreen)
{
#if LINUX
SDL_WM_ToggleFullScreen(graphics.screen);
@ -447,7 +447,7 @@ static void showOptions(SDL_Surface *optionsSurface)
graphics.drawBackground();
flushBuffer();
#endif
currentGame.fullScreen = false;
engine.fullScreen = false;
}
}
@ -556,7 +556,7 @@ int galaxyMap()
int rtn = 0;
if ((engine.useAudio) && (currentGame.useMusic))
if ((engine.useAudio) && (engine.useMusic))
Mix_PlayMusic(engine.music, -1);
textObject iconInfo[12];

View File

@ -130,9 +130,12 @@ struct Game {
unsigned char musicVolume;
unsigned char sfxVolume;
bool fullScreen;
bool useMusic;
bool useSound;
// First three variable below are here for save game compatibility only.
signed char fullScreen; // Do not use!
signed char useMusic; // Do not use!
signed char useSound; // Do not use!
signed char autoSaveSlot;
unsigned int cash;
@ -265,6 +268,9 @@ struct globalEngineVariables {
signed char gameSection;
bool useAudio;
bool useSound;
bool useMusic;
bool fullScreen;
// This really only applies to Linux users.
char userHomeDirectory[1024];

View File

@ -66,17 +66,17 @@ static signed char showLoadMenu()
static void createOptionsMenu()
{
if (currentGame.useSound)
if (engine.useSound)
graphics.textSurface(8, "SOUND - ON", -1, 350, FONT_WHITE);
else
graphics.textSurface(8, "SOUND - OFF", -1, 350, FONT_WHITE);
if (currentGame.useMusic)
if (engine.useMusic)
graphics.textSurface(9, "MUSIC - ON", -1, 370, FONT_WHITE);
else
graphics.textSurface(9, "MUSIC - OFF", -1, 370, FONT_WHITE);
if (currentGame.fullScreen)
if (engine.fullScreen)
graphics.textSurface(10, "FULLSCREEN - ON", -1, 390, FONT_WHITE);
else
graphics.textSurface(10, "FULLSCREEN - OFF", -1, 390, FONT_WHITE);
@ -237,7 +237,7 @@ int doTitle()
flushInput();
engine.keyState[SDLK_LCTRL] = engine.keyState[SDLK_RCTRL] = 0;
if ((currentGame.useMusic) && (engine.useAudio))
if ((engine.useMusic) && (engine.useAudio))
Mix_PlayMusic(engine.music, 1);
while (!engine.done)
@ -388,12 +388,12 @@ int doTitle()
case 2:
if ((selectedOption == 1) && (engine.useAudio))
currentGame.useSound = !currentGame.useSound;
engine.useSound = !engine.useSound;
else if ((selectedOption == 2) && (engine.useAudio))
{
currentGame.useMusic = !currentGame.useMusic;
engine.useMusic = !engine.useMusic;
if (currentGame.useMusic)
if (engine.useMusic)
{
if (Mix_PausedMusic() == 1)
Mix_ResumeMusic();
@ -407,11 +407,11 @@ int doTitle()
}
else if (selectedOption == 3)
{
currentGame.fullScreen = !currentGame.fullScreen;
engine.fullScreen = !engine.fullScreen;
#if LINUX
SDL_WM_ToggleFullScreen(graphics.screen);
#else
if (currentGame.fullScreen)
if (engine.fullScreen)
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE|SDL_FULLSCREEN);
else
graphics.screen = SDL_SetVideoMode(800, 600, 0, SDL_DOUBLEBUF|SDL_HWPALETTE);
@ -577,7 +577,7 @@ void gameover()
graphics.clearScreen(graphics.black);
SDL_Delay(1000);
if ((currentGame.useMusic) && (engine.useAudio))
if ((engine.useMusic) && (engine.useAudio))
{
Mix_VolumeMusic(100);
Mix_PlayMusic(engine.music, 1);
@ -610,7 +610,7 @@ void gameover()
SDL_FreeSurface(gameover);
if ((currentGame.useMusic) && (engine.useAudio))
if ((engine.useMusic) && (engine.useAudio))
Mix_HaltMusic();
graphics.flushBuffer();
@ -622,7 +622,7 @@ void doCredits()
graphics.flushBuffer();
graphics.freeGraphics();
if ((currentGame.useMusic) && (engine.useAudio))
if ((engine.useMusic) && (engine.useAudio))
loadMusic("music/Solace.s3m");
FILE *fp;
@ -670,7 +670,7 @@ void doCredits()
fclose(fp);
if ((currentGame.useMusic) && (engine.useAudio))
if ((engine.useMusic) && (engine.useAudio))
{
Mix_VolumeMusic(100);
Mix_PlayMusic(engine.music, 1);