summaryrefslogtreecommitdiffstats
path: root/src/game/init_sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/init_sdl.c')
-rw-r--r--src/game/init_sdl.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/game/init_sdl.c b/src/game/init_sdl.c
new file mode 100644
index 0000000..bb787e5
--- /dev/null
+++ b/src/game/init_sdl.c
@@ -0,0 +1,47 @@
+#include "game/init.h"
+
+#include "SDL.h"
+#include <stdlib.h>
+
+int video_initialized = 0;
+
+void audioInit(void) {
+ if(SDL_Init(SDL_INIT_AUDIO) < 0 ){
+ fprintf(stderr, "Couldn't initialize SDL audio: %s\n", SDL_GetError());
+ /* FIXME: disable sound system */
+ }
+}
+
+void videoInit(void) {
+ if(SDL_Init(SDL_INIT_VIDEO) < 0 ) {
+ fprintf(stderr, "Couldn't initialize SDL video: %s\n", SDL_GetError());
+ exit(1); /* OK: critical, no visual */
+ }
+ else video_initialized = 1;
+}
+
+void inputInit(void) {
+ /* keyboard */
+ SDL_EnableKeyRepeat(0, 0); /* turn keyrepeat off */
+
+ /* joystick */
+ if(SDL_Init(SDL_INIT_JOYSTICK) >= 0) {
+ int i;
+ SDL_Joystick *joy;
+ int joysticks = SDL_NumJoysticks();
+
+ /* FIXME: why only two joysticks? */
+ /* joystick, currently at most 2 */
+ if(joysticks > 2)
+ joysticks = 2;
+
+ for(i = 0; i < joysticks; i++) {
+ joy = SDL_JoystickOpen(i);
+ }
+ if(i)
+ SDL_JoystickEventState(SDL_ENABLE);
+ } else {
+ const char *s = SDL_GetError();
+ fprintf(stderr, "[init] couldn't initialize joysticks: %s\n", s);
+ }
+}