Allow in-game volume adjustment
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8380 30fe4595-0a0c-4342-8851-515496e4dcbd
This commit is contained in:
parent
88186d8fbc
commit
a2d923114e
|
@ -30,6 +30,8 @@ public:
|
|||
virtual void shutdown() = 0;
|
||||
virtual void refresh(struct Situation *s, Camera *camera) = 0;
|
||||
virtual void mute(bool bOn = true) = 0;
|
||||
virtual float getVolume() const = 0;
|
||||
virtual void setVolume(float g) = 0;
|
||||
};
|
||||
|
||||
#endif // __ISOUNDENGINE__H__
|
||||
|
|
|
@ -1260,3 +1260,51 @@ GfuiSwapBuffers(void)
|
|||
{
|
||||
SDL_GL_SwapWindow(GfuiWindow);
|
||||
}
|
||||
|
||||
void
|
||||
GfuiToggleMenuSound(void*)
|
||||
{
|
||||
static bool muteToggle = true;
|
||||
|
||||
static float musicVol = 0.0f;
|
||||
static float sfxVol = 0.0f;
|
||||
|
||||
if(muteToggle)
|
||||
{
|
||||
musicVol = getMusicVolume();
|
||||
setMusicVolume(0.0f);
|
||||
|
||||
sfxVol = getMenuSfxVolume();
|
||||
setMenuSfxVolume(0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
setMusicVolume(musicVol);
|
||||
setMenuSfxVolume(sfxVol);
|
||||
}
|
||||
muteToggle = !muteToggle;
|
||||
}
|
||||
|
||||
void
|
||||
GfuiMenuVolumeUp(void*)
|
||||
{
|
||||
float musicVol = getMusicVolume();
|
||||
musicVol += 10.0f;
|
||||
setMusicVolume(musicVol);
|
||||
|
||||
float sfxVol = getMenuSfxVolume();
|
||||
sfxVol += 10.0f;
|
||||
setMenuSfxVolume(sfxVol);
|
||||
}
|
||||
|
||||
void
|
||||
GfuiMenuVolumeDown(void*)
|
||||
{
|
||||
float musicVol = getMusicVolume();
|
||||
musicVol -= 10.0f;
|
||||
setMusicVolume(musicVol);
|
||||
|
||||
float sfxVol = getMenuSfxVolume();
|
||||
sfxVol -= 10.0f;
|
||||
setMenuSfxVolume(sfxVol);
|
||||
}
|
||||
|
|
|
@ -84,8 +84,13 @@ GfuiMenuDefaultKeysAdd(void* scr)
|
|||
GfuiAddKey(scr, GFUIK_PAGEDOWN, "Select Next Entry", NULL, gfuiSelectNext, NULL);
|
||||
GfuiAddKey(scr, GFUIK_F1, "Help", scr, GfuiHelpScreen, NULL);
|
||||
GfuiAddKey(scr, GFUIK_F12, "Screen-Shot", NULL, GfuiScreenShot, NULL);
|
||||
GfuiAddKey(scr, '>', "Menu Volume Up", NULL, GfuiMenuVolumeUp, NULL);
|
||||
GfuiAddKey(scr, '<', "Menu Volume Down", NULL, GfuiMenuVolumeDown, NULL);
|
||||
//GfuiAddKey(scr, '?', "Toggle Menu Sounds", NULL, GfuiToggleMenuSound, NULL);
|
||||
if(GfScrUsingResizableWindow())
|
||||
{
|
||||
GfuiAddKey(scr, GFUIK_RETURN, GFUIM_ALT, "Toggle Full-screen", (void*)0, GfScrToggleFullScreen, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
// Font size map : Gives the integer size from the size name.
|
||||
|
|
|
@ -165,6 +165,12 @@ void setMenuSfxVolume(float vol /* 100.0f */)
|
|||
GfLogInfo("Menu SFX volume set to %.2f\n", vol);
|
||||
}
|
||||
|
||||
float getMenuSfxVolume()
|
||||
{
|
||||
float divisor = MIX_MAX_VOLUME/100.0f;
|
||||
return (sfxVolume / divisor);
|
||||
}
|
||||
|
||||
void enableMenuSfx(bool enable /* true */)
|
||||
{
|
||||
if (isSfxEnabled())
|
||||
|
|
|
@ -36,6 +36,7 @@ TGFCLIENT_API void gfuiInitMenuSfx();
|
|||
TGFCLIENT_API void gfuiShutdownMenuSfx();
|
||||
TGFCLIENT_API void enableMenuSfx(bool enable = true);
|
||||
TGFCLIENT_API void setMenuSfxVolume(float volume = 100.0f);
|
||||
TGFCLIENT_API float getMenuSfxVolume();
|
||||
TGFCLIENT_API void playMenuSfx(int sfxIndex);
|
||||
|
||||
#define SFX_CLICK 0
|
||||
|
|
|
@ -236,6 +236,11 @@ void setMusicVolume(float vol /* 100.0f */)
|
|||
GfLogInfo("Music volume set to %.2f\n", maxMusicVolume);
|
||||
}
|
||||
|
||||
float getMusicVolume()
|
||||
{
|
||||
return (maxMusicVolume * 100.0f);
|
||||
}
|
||||
|
||||
void enableMusic(bool enable /* true */)
|
||||
{
|
||||
if (isEnabled())
|
||||
|
|
|
@ -41,6 +41,7 @@ TGFCLIENT_API void initMusic();
|
|||
TGFCLIENT_API void shutdownMusic();
|
||||
TGFCLIENT_API void enableMusic(bool enable = true);
|
||||
TGFCLIENT_API void setMusicVolume(float volume = 100.0f);
|
||||
TGFCLIENT_API float getMusicVolume();
|
||||
TGFCLIENT_API void playMusic(char* filename);
|
||||
|
||||
#endif //__musicplayer_h__
|
|
@ -99,6 +99,14 @@ TGFCLIENT_API tScreenSize GfScrGetCurrentDisplaySize(int nDisplayIndex);
|
|||
TGFCLIENT_API bool GfScrUsingResizableWindow();
|
||||
TGFCLIENT_API void GfScrToggleFullScreen(void* unused);
|
||||
|
||||
/********************
|
||||
* Music Interface *
|
||||
********************/
|
||||
|
||||
TGFCLIENT_API void GfuiToggleMenuSound(void*);
|
||||
TGFCLIENT_API void GfuiMenuVolumeUp(void*);
|
||||
TGFCLIENT_API void GfuiMenuVolumeDown(void*);
|
||||
|
||||
/*****************************
|
||||
* GUI interface (low-level) *
|
||||
*****************************/
|
||||
|
|
|
@ -265,8 +265,8 @@ int initView(int x, int y, int width, int height, int /* flag */, void *screen)
|
|||
GfuiAddKey(screen, '+', GFUIM_CTRL, "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
|
||||
GfuiAddKey(screen, '=', GFUIM_CTRL, "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
|
||||
GfuiAddKey(screen, '-', GFUIM_CTRL, "Zoom Out", (void*)GR_ZOOM_OUT, SDSetZoom, NULL);
|
||||
GfuiAddKey(screen, '>', "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
|
||||
GfuiAddKey(screen, '<', "Zoom Out", (void*)GR_ZOOM_OUT, SDSetZoom, NULL);
|
||||
//GfuiAddKey(screen, '>', "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
|
||||
//GfuiAddKey(screen, '<', "Zoom Out", (void*)GR_ZOOM_OUT, SDSetZoom, NULL);
|
||||
//GfuiAddKey(screen, '(', "Split Screen", (void*)SD_SPLIT_ADD, SDSplitScreen, NULL);
|
||||
//GfuiAddKey(screen, ')', "UnSplit Screen", (void*)SD_SPLIT_REM, SDSplitScreen, NULL);
|
||||
//GfuiAddKey(screen, '_', "Split Screen Arrangement", (void*)SD_SPLIT_ARR, SDSplitScreen, NULL);
|
||||
|
|
|
@ -562,8 +562,8 @@ initView(int x, int y, int width, int height, int /* flag */, void *screen)
|
|||
GfuiAddKey(screen, '+', GFUIM_CTRL, "Zoom In", (void*)GR_ZOOM_IN, grSetZoom, NULL);
|
||||
GfuiAddKey(screen, '=', GFUIM_CTRL, "Zoom In", (void*)GR_ZOOM_IN, grSetZoom, NULL);
|
||||
GfuiAddKey(screen, '-', GFUIM_CTRL, "Zoom Out", (void*)GR_ZOOM_OUT, grSetZoom, NULL);
|
||||
GfuiAddKey(screen, '>', "Zoom In", (void*)GR_ZOOM_IN, grSetZoom, NULL);
|
||||
GfuiAddKey(screen, '<', "Zoom Out", (void*)GR_ZOOM_OUT, grSetZoom, NULL);
|
||||
//GfuiAddKey(screen, '>', "Zoom In", (void*)GR_ZOOM_IN, grSetZoom, NULL);
|
||||
//GfuiAddKey(screen, '<', "Zoom Out", (void*)GR_ZOOM_OUT, grSetZoom, NULL);
|
||||
GfuiAddKey(screen, '(', "Split Screen", (void*)GR_SPLIT_ADD, grSplitScreen, NULL);
|
||||
GfuiAddKey(screen, ')', "UnSplit Screen", (void*)GR_SPLIT_REM, grSplitScreen, NULL);
|
||||
GfuiAddKey(screen, '_', "Split Screen Arrangement", (void*)GR_SPLIT_ARR, grSplitScreen, NULL);
|
||||
|
|
|
@ -226,6 +226,16 @@ void SoundInterface::setGlobalGain(float g)
|
|||
GfLogInfo("Sound global gain set to %.2f\n", global_gain);
|
||||
}
|
||||
|
||||
float SoundInterface::getVolume() const
|
||||
{
|
||||
return getGlobalGain();
|
||||
}
|
||||
|
||||
void SoundInterface::setVolume(float g)
|
||||
{
|
||||
setGlobalGain(g);
|
||||
}
|
||||
|
||||
void SoundInterface::mute(bool bOn)
|
||||
{
|
||||
silent = bOn;
|
||||
|
|
|
@ -146,6 +146,10 @@ class SoundInterface {
|
|||
|
||||
virtual void setGlobalGain(float g);
|
||||
|
||||
virtual float getVolume() const;
|
||||
|
||||
virtual void setVolume(float vol);
|
||||
|
||||
virtual void mute(bool bOn = true);
|
||||
};
|
||||
|
||||
|
|
|
@ -218,6 +218,30 @@ grRefreshSound(tSituation *s, Camera* camera)
|
|||
|
||||
}
|
||||
|
||||
float grGetVolume()
|
||||
{
|
||||
if (sound_mode == DISABLED) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
if (!soundInitialized) {
|
||||
return 0.0f;
|
||||
}
|
||||
return sound_interface->getVolume();
|
||||
}
|
||||
|
||||
void grSetVolume(float vol)
|
||||
{
|
||||
if (sound_mode == DISABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!soundInitialized) {
|
||||
return;
|
||||
}
|
||||
sound_interface->setVolume(vol);
|
||||
}
|
||||
|
||||
void grMuteSound(bool bOn)
|
||||
{
|
||||
if (sound_mode == DISABLED) {
|
||||
|
|
|
@ -28,5 +28,7 @@ extern void grInitSound(tSituation* s, int ncars);
|
|||
extern void grShutdownSound();
|
||||
extern void grRefreshSound(tSituation *s, Camera *camera);
|
||||
extern void grMuteSound(bool bOn = true);
|
||||
extern float grGetVolume();
|
||||
extern void grSetVolume(float vol);
|
||||
|
||||
#endif /* _GRSOUND_H_ */
|
||||
|
|
|
@ -83,3 +83,11 @@ void SndDefault::mute(bool bOn)
|
|||
{
|
||||
::grMuteSound(bOn);
|
||||
}
|
||||
float SndDefault::getVolume() const
|
||||
{
|
||||
return grGetVolume();
|
||||
}
|
||||
void SndDefault::setVolume(float vol)
|
||||
{
|
||||
::grSetVolume(vol);
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ class SNDDEFAULT_API SndDefault : public GfModule, public ISoundEngine
|
|||
virtual void shutdown();
|
||||
virtual void refresh(Situation* s, Camera* camera);
|
||||
virtual void mute(bool bOn = true);
|
||||
virtual float getVolume() const;
|
||||
virtual void setVolume(float vol);
|
||||
|
||||
// Accessor to the singleton.
|
||||
static SndDefault& self();
|
||||
|
|
|
@ -463,6 +463,40 @@ rmSkipPreStart(void * /* dummy */)
|
|||
reInfo->_reLastRobTime = -1.0;
|
||||
}
|
||||
}
|
||||
static void
|
||||
rmToggleSound(void * /* dummy */)
|
||||
{
|
||||
static bool muteToggle = true;
|
||||
if (LegacyMenu::self().soundEngine())
|
||||
{
|
||||
LegacyMenu::self().soundEngine()->mute(muteToggle);
|
||||
muteToggle = !muteToggle;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rmVolumeMod (void *pvCmd)
|
||||
{
|
||||
// If not paused ...
|
||||
if ((!rmRacePaused)&&(!rmPreRacePause))
|
||||
{
|
||||
if (LegacyMenu::self().soundEngine())
|
||||
{
|
||||
float curr = LegacyMenu::self().soundEngine()->getVolume();
|
||||
|
||||
if ((long)pvCmd > 0)
|
||||
{
|
||||
curr += 0.1f;
|
||||
LegacyMenu::self().soundEngine()->setVolume(curr);
|
||||
}
|
||||
else if ((long)pvCmd < 0)
|
||||
{
|
||||
curr -= 0.1f;
|
||||
LegacyMenu::self().soundEngine()->setVolume(curr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rmTimeMod (void *pvCmd)
|
||||
|
@ -560,6 +594,10 @@ rmAddKeys()
|
|||
GfuiAddKey(rmScreenHandle, GFUIK_ESCAPE, "Stop current race", (void*)RE_STATE_RACE_STOP, rmApplyState, NULL);
|
||||
GfuiAddKey(rmScreenHandle, 'q', GFUIM_ALT, "Quit (without saving)", (void*)RE_STATE_EXIT, rmApplyState, NULL);
|
||||
GfuiAddKey(rmScreenHandle, ' ', "Skip pre-start", (void*)0, rmSkipPreStart, NULL);
|
||||
|
||||
GfuiAddKey(rmScreenHandle, '>', "SFX volume up", (void*)+1, rmVolumeMod, NULL);
|
||||
GfuiAddKey(rmScreenHandle, '<', "SFX volume down", (void*)-1, rmVolumeMod, NULL);
|
||||
//GfuiAddKey(rmScreenHandle, '?', "Toggle Sound FX", (void*)0, rmToggleSound, NULL);
|
||||
|
||||
// WARNING: Sure this won't work with multi-threading On/Auto ...
|
||||
//GfuiAddKey(rmScreenHandle, '0', "One step simulation", (void*)1, rmOneStep, NULL);
|
||||
|
|
Loading…
Reference in New Issue