Skip to content

Instantly share code, notes, and snippets.

@Cheeseness
Created October 31, 2013 05:44
Show Gist options
  • Select an option

  • Save Cheeseness/7244801 to your computer and use it in GitHub Desktop.

Select an option

Save Cheeseness/7244801 to your computer and use it in GitHub Desktop.
An attachment to NeverTrac ticket #85 ( [Neverball GitHub issue #15](https://github.com/Neverball/neverball/issues/15) ) by @mehdiym
Index: share/config.c
===================================================================
--- share/config.c (revision 902)
+++ share/config.c (working copy)
@@ -83,6 +83,7 @@
config_set_d(CONFIG_FPS, DEFAULT_FPS);
config_set_d(CONFIG_SOUND_VOLUME, DEFAULT_SOUND_VOLUME);
config_set_d(CONFIG_MUSIC_VOLUME, DEFAULT_MUSIC_VOLUME);
+ config_set_d(CONFIG_VOICE, DEFAULT_VOICE);
config_set_d(CONFIG_JOYSTICK, DEFAULT_JOYSTICK);
config_set_d(CONFIG_JOYSTICK_DEVICE, DEFAULT_JOYSTICK_DEVICE);
config_set_d(CONFIG_JOYSTICK_AXIS_X, DEFAULT_JOYSTICK_AXIS_X);
@@ -165,6 +166,8 @@
config_set_d(CONFIG_SOUND_VOLUME, atoi(val));
else if (strcmp(key, "music_volume") == 0)
config_set_d(CONFIG_MUSIC_VOLUME, atoi(val));
+ else if (strcmp(key, "voice") == 0)
+ config_set_d(CONFIG_VOICE, atoi(val));
else if (strcmp(key, "joystick") == 0)
config_set_d(CONFIG_JOYSTICK, atoi(val));
else if (strcmp(key, "joystick_device") == 0)
@@ -277,6 +280,8 @@
option_d[CONFIG_SOUND_VOLUME]);
fprintf(fp, "music_volume %d\n",
option_d[CONFIG_MUSIC_VOLUME]);
+ fprintf(fp, "voice %d\n",
+ option_d[CONFIG_VOICE]);
fprintf(fp, "joystick %d\n",
option_d[CONFIG_JOYSTICK]);
fprintf(fp, "joystick_device %d\n",
Index: share/config.h
===================================================================
--- share/config.h (revision 902)
+++ share/config.h (working copy)
@@ -48,6 +48,7 @@
CONFIG_FPS,
CONFIG_SOUND_VOLUME,
CONFIG_MUSIC_VOLUME,
+ CONFIG_VOICE,
CONFIG_JOYSTICK,
CONFIG_JOYSTICK_DEVICE,
CONFIG_JOYSTICK_AXIS_X,
@@ -107,6 +108,7 @@
#define DEFAULT_FPS 0
#define DEFAULT_SOUND_VOLUME 10
#define DEFAULT_MUSIC_VOLUME 6
+#define DEFAULT_VOICE 1
#define DEFAULT_JOYSTICK 0
#define DEFAULT_JOYSTICK_DEVICE 0
#define DEFAULT_JOYSTICK_AXIS_X 0
Index: share/audio.c
===================================================================
--- share/audio.c (revision 902)
+++ share/audio.c (working copy)
@@ -101,6 +101,14 @@
}
}
+void audio_mute_channel(int c, int m)
+{
+ int v = config_get_d(CONFIG_SOUND_VOLUME) * MIX_MAX_VOLUME / 10;
+
+ if (audio_state)
+ Mix_Volume(c, m ? 0 : v);
+}
+
/*---------------------------------------------------------------------------*/
void audio_music_play(const char *filename)
Index: share/audio.h
===================================================================
--- share/audio.h (revision 902)
+++ share/audio.h (working copy)
@@ -10,6 +10,8 @@
void audio_bind(int, int, const char *);
void audio_play(int, float);
+void audio_mute_channel(int, int);
+
void audio_music_queue(const char *);
void audio_music_play(const char *);
void audio_music_stop(void);
Index: ball/st_conf.c
===================================================================
--- ball/st_conf.c (revision 902)
+++ ball/st_conf.c (working copy)
@@ -32,25 +32,29 @@
#define CONF_FULL 1
#define CONF_WIN 2
-#define CONF_TEXHI 8
-#define CONF_TEXLO 9
-#define CONF_GEOHI 10
-#define CONF_GEOLO 11
-#define CONF_REFON 12
-#define CONF_REFOF 13
-#define CONF_BACON 14
-#define CONF_BACOF 15
-#define CONF_SHDON 16
-#define CONF_SHDOF 17
-#define CONF_AUDHI 18
-#define CONF_AUDLO 19
-#define CONF_BACK 20
-#define CONF_LANG 21
-#define CONF_RES 22
-#define CONF_PLAYER 23
+#define CONF_TEXHI 3
+#define CONF_TEXLO 4
+#define CONF_GEOHI 5
+#define CONF_GEOLO 6
+#define CONF_REFON 7
+#define CONF_REFOF 8
+#define CONF_BACON 9
+#define CONF_BACOF 10
+#define CONF_SHDON 11
+#define CONF_SHDOF 12
+#define CONF_AUDHI 13
+#define CONF_AUDLO 14
+#define CONF_VOION 15
+#define CONF_VOIOF 16
+#define CONF_BACK 17
+#define CONF_LANG 18
+#define CONF_RES 19
+#define CONF_PLAYER 20
static int audlo_id;
static int audhi_id;
+static int voion_id;
+static int voiof_id;
static int music_id[11];
static int sound_id[11];
@@ -138,6 +142,28 @@
goto_state(&st_conf);
break;
+ case CONF_VOION:
+ if (config_get_d(CONFIG_VOICE) == 0)
+ {
+ config_set_d(CONFIG_VOICE, 1);
+ audio_mute_channel(1, 0);
+
+ gui_toggle(voion_id);
+ gui_toggle(voiof_id);
+ }
+ break;
+
+ case CONF_VOIOF:
+ if (config_get_d(CONFIG_VOICE) == 1)
+ {
+ config_set_d(CONFIG_VOICE, 0);
+ audio_mute_channel(1, 1);
+
+ gui_toggle(voion_id);
+ gui_toggle(voiof_id);
+ }
+ break;
+
case CONF_AUDHI:
audio_free();
config_set_d(CONFIG_AUDIO_RATE, 44100);
@@ -183,6 +209,11 @@
gui_toggle(sound_id[n]);
gui_toggle(sound_id[s]);
+
+ /* FIXME audio_volume resets volume for all channels. */
+
+ if (config_get_d(CONFIG_VOICE) == 0)
+ audio_mute_channel(1, 1);
}
if (200 <= i && i <= 210)
{
@@ -194,6 +225,11 @@
gui_toggle(music_id[n]);
gui_toggle(music_id[m]);
+
+ /* FIXME audio_volume resets volume for all channels. */
+
+ if (config_get_d(CONFIG_VOICE) == 0)
+ audio_mute_channel(1, 1);
}
}
@@ -222,6 +258,7 @@
int a = config_get_d(CONFIG_AUDIO_RATE);
int s = config_get_d(CONFIG_SOUND_VOLUME);
int m = config_get_d(CONFIG_MUSIC_VOLUME);
+ int v = config_get_d(CONFIG_VOICE);
char res[20];
@@ -264,6 +301,11 @@
}
if ((kd = gui_harray(jd)))
{
+ voiof_id = gui_state(kd, _("Off"), GUI_SML, CONF_VOIOF, !v);
+ voion_id = gui_state(kd, _("On"), GUI_SML, CONF_VOION, v);
+ }
+ if ((kd = gui_harray(jd)))
+ {
int lo = (a == 22050);
int hi = (a == 44100);
@@ -325,6 +367,7 @@
gui_label(jd, _("Reflection"), GUI_SML, GUI_ALL, 0, 0);
gui_label(jd, _("Background"), GUI_SML, GUI_ALL, 0, 0);
gui_label(jd, _("Shadow"), GUI_SML, GUI_ALL, 0, 0);
+ gui_label(jd, _("Voice"), GUI_SML, GUI_ALL, 0, 0);
gui_label(jd, _("Audio"), GUI_SML, GUI_ALL, 0, 0);
gui_label(jd, _("Sound Volume"), GUI_SML, GUI_ALL, 0, 0);
gui_label(jd, _("Music Volume"), GUI_SML, GUI_ALL, 0, 0);
Index: ball/main.c
===================================================================
--- ball/main.c (revision 902)
+++ ball/main.c (working copy)
@@ -382,6 +382,9 @@
audio_init();
+ if (config_get_d(CONFIG_VOICE) == 0)
+ audio_mute_channel(1, 1);
+
/* Require 16-bit double buffer with 16-bit depth buffer. */
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment