Added tilt sensor abstraction.
authorrlk <rlk@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Wed, 2 Jan 2008 01:40:11 +0000 (01:40 +0000)
committerrlk <rlk@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Wed, 2 Jan 2008 01:40:11 +0000 (01:40 +0000)
Added Wiimote tilt sensor mode for Linux.

git-svn-id: https://s.snth.net/svn/neverball/trunk@1360 78b8d119-cf0a-0410-b17c-f493084dd1d7

31 files changed:
Makefile
ball/game.c
ball/game.h
ball/main.c
ball/st_conf.c
ball/st_demo.c
ball/st_done.c
ball/st_fall_out.c
ball/st_goal.c
ball/st_help.c
ball/st_level.c
ball/st_name.c
ball/st_over.c
ball/st_pause.c
ball/st_play.c
ball/st_save.c
ball/st_set.c
ball/st_shared.c
ball/st_shared.h
ball/st_start.c
ball/st_time_out.c
ball/st_title.c
data/sets.txt
share/config.c
share/config.h
share/geom.c
share/st_resol.c
share/state.c
share/state.h
share/tilt.c [new file with mode: 0644]
share/tilt.h [new file with mode: 0644]

index ff99150..506e114 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+
 #-------------------------------------------------------------------------------
 
 VERSION := $(shell sh scripts/version.sh)
@@ -38,6 +39,11 @@ else
     ALL_CPPFLAGS += -DENABLE_NLS=1
 endif
 
+ifeq ($(ENABLE_WII),1)
+    ALL_CFLAGS    = -O2  # libwiimote is NOT ANSI compliant
+    ALL_CPPFLAGS += -DENABLE_WII=1
+endif
+
 ifdef DARWIN
     ALL_CPPFLAGS += -I/opt/local/include
 endif
@@ -63,6 +69,10 @@ else ifdef DARWIN
 
     OGL_LIBS := -framework OpenGL
 else
+    ifneq ($(ENABLE_WII),0)
+        TILT_LIBS := -lcwiimote -lbluetooth
+    endif
+
     OGL_LIBS := -lGL -lm
 endif
 
@@ -72,7 +82,7 @@ ifdef DARWIN
     BASE_LIBS += -L/opt/local/lib
 endif
 
-ALL_LIBS := $(SDL_LIBS) $(BASE_LIBS) $(INTL_LIBS) -lSDL_ttf \
+ALL_LIBS := $(SDL_LIBS) $(BASE_LIBS) $(TILT_LIBS) $(INTL_LIBS) -lSDL_ttf \
     -lvorbisfile $(OGL_LIBS)
 
 #------------------------------------------------------------------------------
@@ -120,6 +130,7 @@ BALL_OBJS := \
        share/audio.o       \
        share/text.o        \
        share/sync.o        \
+       share/tilt.o        \
        ball/hud.o          \
        ball/mode.o         \
        ball/game.o         \
index 57c9a42..785d16e 100644 (file)
@@ -1104,6 +1104,12 @@ void game_set_z(int k)
     input_set_z(+ANGLE_BOUND * k / JOY_MAX);
 }
 
+void game_set_ang(int x, int z)
+{
+    input_set_x(x);
+    input_set_z(z);
+}
+
 void game_set_pos(int x, int y)
 {
     input_set_x(input_get_x() + 40.0f * y / config_get_d(CONFIG_MOUSE_SENSE));
index 73013fa..4a4727c 100644 (file)
@@ -49,6 +49,7 @@ int   curr_goal(void);
 void  game_draw(int, float);
 int   game_step(const float[3], float, int);
 
+void  game_set_ang(int, int);
 void  game_set_pos(int, int);
 void  game_set_x  (int);
 void  game_set_z  (int);
index 67cadff..bfd0a17 100644 (file)
@@ -29,6 +29,7 @@
 #include "gui.h"
 #include "set.h"
 #include "text.h"
+#include "tilt.h"
 
 #include "st_conf.h"
 #include "st_title.h"
@@ -79,6 +80,8 @@ static int loop(void)
     SDL_Event e;
     int d = 1;
     int c;
+    int x;
+    int y;
 
     while (d && SDL_PollEvent(&e))
     {
@@ -150,7 +153,7 @@ static int loop(void)
 
             c = e.key.keysym.sym;
 
-            if (config_tst_d(CONFIG_KEY_FORWARD, c))
+            if      (config_tst_d(CONFIG_KEY_FORWARD, c))
                 st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1);
 
             else if (config_tst_d(CONFIG_KEY_BACKWARD, c))
@@ -194,6 +197,21 @@ static int loop(void)
             break;
         }
     }
+
+    if (tilt_stat())
+    {
+        tilt_get_direct(&x, &y);
+
+        st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), x);
+        st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), y);
+
+        st_angle((int) tilt_get_x(),
+                 (int) tilt_get_z());
+
+        if (tilt_get_button(&x, &y))
+            d = st_buttn(x, y);
+    }
+
     return d;
 }
 
@@ -353,6 +371,7 @@ int main(int argc, char *argv[])
     /* Initialize the audio. */
 
     audio_init();
+    tilt_init();
 
     /* Require 16-bit double buffer with 16-bit depth buffer. */
 
@@ -425,6 +444,7 @@ int main(int argc, char *argv[])
     if (SDL_JoystickOpened(0))
         SDL_JoystickClose(joy);
 
+    tilt_free();
     SDL_Quit();
 
     config_save();
index 100e088..8524675 100644 (file)
@@ -404,6 +404,7 @@ struct state st_conf = {
     shared_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     NULL,
     conf_buttn,
@@ -420,5 +421,6 @@ struct state st_null = {
     NULL,
     NULL,
     NULL,
+    NULL,
     1, 0
 };
index 88a9e41..79ef104 100644 (file)
@@ -560,6 +560,7 @@ struct state st_demo = {
     demo_timer,
     demo_point,
     demo_stick,
+    shared_stick,
     shared_click,
     NULL,
     demo_buttn,
@@ -574,6 +575,7 @@ struct state st_demo_play = {
     NULL,
     NULL,
     NULL,
+    NULL,
     demo_play_keybd,
     demo_play_buttn,
     1, 0
@@ -586,6 +588,7 @@ struct state st_demo_end = {
     shared_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     demo_end_keybd,
     demo_end_buttn,
@@ -599,6 +602,7 @@ struct state st_demo_del = {
     shared_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     NULL,
     demo_del_buttn,
index 2ac3231..5672fe5 100644 (file)
@@ -128,6 +128,7 @@ struct state st_done = {
     shared_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     NULL,
     done_buttn,
index 866b145..d68f110 100644 (file)
@@ -166,6 +166,7 @@ struct state st_fall_out = {
     fall_out_timer,
     shared_point,
     shared_stick,
+    NULL,
     shared_click,
     NULL,
     fall_out_buttn,
index 2572771..96f5f98 100644 (file)
@@ -307,6 +307,7 @@ struct state st_goal = {
     goal_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     NULL,
     goal_buttn,
index 10d0edd..4fa23bf 100644 (file)
@@ -417,6 +417,7 @@ struct state st_help = {
     shared_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     NULL,
     help_buttn,
@@ -432,6 +433,7 @@ struct state st_help_demo = {
     NULL,
     NULL,
     NULL,
+    NULL,
     help_demo_buttn,
     1, 0
 };
index b49a301..f523fb1 100644 (file)
@@ -149,6 +149,7 @@ struct state st_level = {
     level_timer,
     NULL,
     NULL,
+    NULL,
     level_click,
     level_keybd,
     level_buttn,
@@ -164,6 +165,7 @@ struct state st_poser = {
     NULL,
     NULL,
     NULL,
+    NULL,
     poser_buttn,
     1, 0
 };
index 91656a6..4debe4b 100644 (file)
@@ -191,6 +191,7 @@ struct state st_name = {
     shared_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     name_keybd,
     name_buttn,
index 84b6230..c455042 100644 (file)
@@ -80,6 +80,7 @@ struct state st_over = {
     over_timer,
     NULL,
     NULL,
+    NULL,
     over_click,
     NULL,
     over_buttn,
index ea4c53d..e46333b 100644 (file)
@@ -177,6 +177,7 @@ struct state st_pause = {
     pause_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     pause_keybd,
     pause_buttn,
index 2c3bd7d..902260e 100644 (file)
@@ -263,6 +263,12 @@ static void play_loop_stick(int id, int a, int k)
         game_set_x(k);
 }
 
+static void play_loop_angle(int id, int x, int z)
+{
+    game_set_x(x);
+    game_set_z(z);
+}
+
 static int play_loop_click(int b, int d)
 {
     view_rotate = d ? b : 0;
@@ -422,6 +428,7 @@ struct state st_play_ready = {
     play_ready_timer,
     NULL,
     NULL,
+    NULL,
     play_ready_click,
     play_ready_keybd,
     play_ready_buttn,
@@ -435,6 +442,7 @@ struct state st_play_set = {
     play_set_timer,
     NULL,
     NULL,
+    NULL,
     play_set_click,
     play_set_keybd,
     play_set_buttn,
@@ -448,6 +456,7 @@ struct state st_play_loop = {
     play_loop_timer,
     play_loop_point,
     play_loop_stick,
+    shared_angle,
     play_loop_click,
     play_loop_keybd,
     play_loop_buttn,
@@ -462,6 +471,7 @@ struct state st_look = {
     look_point,
     NULL,
     NULL,
+    NULL,
     look_keybd,
     look_buttn,
     0, 0
index 9ea2efd..ea4abe3 100644 (file)
@@ -223,6 +223,7 @@ struct state st_save = {
     shared_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     save_keybd,
     save_buttn,
@@ -236,6 +237,7 @@ struct state st_clobber = {
     shared_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     NULL,
     clobber_buttn,
index ac10cc6..2402a1b 100644 (file)
@@ -180,6 +180,7 @@ struct state st_set = {
     shared_timer,
     set_point,
     set_stick,
+    shared_angle,
     shared_click,
     NULL,
     set_buttn,
index af878bc..2870101 100644 (file)
@@ -37,13 +37,15 @@ void shared_timer(int id, float dt)
     gui_timer(id, dt);
 }
 
-/* Pulse, activate and return the active id (if changed)*/
-
 int shared_point_basic(int id, int x, int y)
 {
+    /* Pulse, activate and return the active id (if changed) */
+
     int jd = gui_point(id, x, y);
+
     if (jd)
         gui_pulse(jd, 1.2f);
+
     return jd;
 }
 
@@ -53,15 +55,18 @@ void shared_point(int id, int x, int y, int dx, int dy)
 }
 
 int shared_stick_basic(int id, int a, int v)
-/* Pulse, activate and return the active id (if changed)*/
 {
+    /* Pulse, activate and return the active id (if changed) */
+
     int jd = 0;
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
+
+    if      (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
         jd = gui_stick(id, v, 0);
     else if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
         jd = gui_stick(id, 0, v);
     if (jd)
         gui_pulse(jd, 1.2f);
+
     return jd;
 }
 
@@ -70,6 +75,11 @@ void shared_stick(int id, int a, int v)
     shared_stick_basic(id, a, v);
 }
 
+void shared_angle(int id, int x, int z)
+{
+    game_set_ang(x, z);
+}
+
 int shared_click(int b, int d)
 {
     if (b < 0 && d == 1)
index f45ca66..e83e984 100644 (file)
@@ -4,11 +4,12 @@
 void shared_leave(int id);
 void shared_paint(int id, float st);
 void shared_timer(int id, float dt);
-int shared_point_basic(int id, int x, int y);
+int  shared_point_basic(int id, int x, int y);
 void shared_point(int id, int x, int y, int dx, int dy);
-int shared_stick_basic(int id, int a, int v);
+int  shared_stick_basic(int id, int a, int v);
 void shared_stick(int id, int a, int v);
-int shared_click(int b, int d);
+void shared_angle(int id, int x, int z);
+int  shared_click(int b, int d);
 
 
 #endif /* ST_SHARED_H */
index 39ba007..5e90fd3 100644 (file)
@@ -328,6 +328,7 @@ struct state st_start = {
     shared_timer,
     start_point,
     start_stick,
+    shared_angle,
     shared_click,
     start_keybd,
     start_buttn,
index 99aa0e3..e893be4 100644 (file)
@@ -135,6 +135,7 @@ struct state st_time_out = {
     shared_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     NULL,
     time_out_buttn,
index 779e4fb..7d5bf97 100644 (file)
@@ -263,6 +263,7 @@ struct state st_title = {
     title_timer,
     shared_point,
     shared_stick,
+    shared_angle,
     shared_click,
     title_keybd,
     title_buttn,
index 611e97b..179f76a 100644 (file)
@@ -3,4 +3,6 @@ set-medium.txt
 set-hard.txt
 set-mym.txt
 set-mym2.txt
+set-fwp.txt
+set-kk.txt
 set-misc.txt
index 3a5a930..977e93a 100644 (file)
@@ -97,6 +97,7 @@ void config_init(void)
     config_set_d(CONFIG_JOYSTICK_CAMERA_1,    DEFAULT_JOYSTICK_CAMERA_1);
     config_set_d(CONFIG_JOYSTICK_CAMERA_2,    DEFAULT_JOYSTICK_CAMERA_2);
     config_set_d(CONFIG_JOYSTICK_CAMERA_3,    DEFAULT_JOYSTICK_CAMERA_3);
+    config_set_s(CONFIG_WIIMOTE_ADDR,         DEFAULT_WIIMOTE_ADDR);
     config_set_d(CONFIG_KEY_CAMERA_1,         DEFAULT_KEY_CAMERA_1);
     config_set_d(CONFIG_KEY_CAMERA_2,         DEFAULT_KEY_CAMERA_2);
     config_set_d(CONFIG_KEY_CAMERA_3,         DEFAULT_KEY_CAMERA_3);
@@ -241,6 +242,8 @@ void config_load(void)
                     config_set_s(CONFIG_PLAYER, val);
                 else if (strcmp(key, "ball") == 0)
                     config_set_s(CONFIG_BALL, val);
+                else if (strcmp(key, "wiimote_addr") == 0)
+                    config_set_s(CONFIG_WIIMOTE_ADDR, val);
 
                 else if (strcmp(key, "cheat") == 0)
                     config_set_d(CONFIG_CHEAT, atoi(val));
@@ -364,8 +367,12 @@ void config_save(void)
         fprintf(fp, "key_restart          %s\n",
                 SDL_GetKeyName((SDLKey) option_d[CONFIG_KEY_RESTART]));
 
-        fprintf(fp, "player               %s\n", option_s[CONFIG_PLAYER]);
-        fprintf(fp, "ball                 %s\n", option_s[CONFIG_BALL]);
+        if (strlen(option_s[CONFIG_PLAYER]) > 0)
+            fprintf(fp, "player       %s\n", option_s[CONFIG_PLAYER]);
+        if (strlen(option_s[CONFIG_BALL]) > 0)
+            fprintf(fp, "ball         %s\n", option_s[CONFIG_BALL]);
+        if (strlen(option_s[CONFIG_WIIMOTE_ADDR]) > 0)
+            fprintf(fp, "wiimote_addr %s\n", option_s[CONFIG_WIIMOTE_ADDR]);
 
         fprintf(fp, "stats                %d\n",
                 option_d[CONFIG_STATS]);
index 79d88cf..21bb482 100644 (file)
@@ -64,6 +64,7 @@ enum {
     CONFIG_JOYSTICK_CAMERA_1,
     CONFIG_JOYSTICK_CAMERA_2,
     CONFIG_JOYSTICK_CAMERA_3,
+    CONFIG_WIIMOTE_ADDR,
     CONFIG_KEY_CAMERA_1,
     CONFIG_KEY_CAMERA_2,
     CONFIG_KEY_CAMERA_3,
@@ -129,6 +130,7 @@ enum {
 #define DEFAULT_JOYSTICK_CAMERA_1    5
 #define DEFAULT_JOYSTICK_CAMERA_2    6
 #define DEFAULT_JOYSTICK_CAMERA_3    7
+#define DEFAULT_WIIMOTE_ADDR         ""
 #define DEFAULT_KEY_CAMERA_1         SDLK_F1
 #define DEFAULT_KEY_CAMERA_2         SDLK_F2
 #define DEFAULT_KEY_CAMERA_3         SDLK_F3
index e79555d..69af6dd 100644 (file)
@@ -244,7 +244,7 @@ static void coin_edge(int n, float radius, float thick)
             float x = fcosf(2.f * PI * i / n);
             float y = fsinf(2.f * PI * i / n);
 
-            glNormal3f(x, y, 0.f);
+            glNormal3f(x, y, 0.0f);
             glVertex3f(radius * x, radius * y, +thick);
             glVertex3f(radius * x, radius * y, -thick);
         }
@@ -311,7 +311,9 @@ void item_init(int b)
 
     glNewList(item_list, GL_COMPILE);
     {
+        glDisable(GL_TEXTURE_2D);
         coin_edge(n, COIN_RADIUS, COIN_THICK);
+        glEnable (GL_TEXTURE_2D);
         coin_head(n, COIN_RADIUS, COIN_THICK);
         coin_tail(n, COIN_RADIUS, COIN_THICK);
     }
index 98bf546..b212ea5 100644 (file)
@@ -177,6 +177,7 @@ struct state st_resol = {
     resol_timer,
     resol_point,
     resol_stick,
+    NULL,
     resol_click,
     resol_keybd,
     resol_buttn,
index 7af4bc0..f7a8f65 100644 (file)
@@ -96,6 +96,12 @@ void st_stick(int a, int k)
         state->stick(state->gui_id, a, k);
 }
 
+void st_angle(int x, int z)
+{
+    if (state && state->angle)
+        state->angle(state->gui_id, x, z);
+}
+
 /*---------------------------------------------------------------------------*/
 
 int st_click(int b, int d)
index c5315b4..0d7ebf0 100644 (file)
@@ -14,6 +14,7 @@ struct state
     void (*timer)(int id, float dt);
     void (*point)(int id, int x, int y, int dx, int dy);
     void (*stick)(int id, int a, int v);
+    void (*angle)(int id, int x, int z);
     int  (*click)(int b,  int d);
     int  (*keybd)(int c,  int d);
     int  (*buttn)(int b,  int d);
@@ -31,6 +32,7 @@ void st_paint(void);
 void st_timer(float);
 void st_point(int, int, int, int);
 void st_stick(int, int);
+void st_angle(int, int);
 int  st_click(int, int);
 int  st_keybd(int, int);
 int  st_buttn(int, int);
diff --git a/share/tilt.c b/share/tilt.c
new file mode 100644 (file)
index 0000000..da8259a
--- /dev/null
@@ -0,0 +1,290 @@
+/*
+ * Copyright (C) 2003 Robert Kooima
+ *
+ * NEVERBALL is  free software; you can redistribute  it and/or modify
+ * it under the  terms of the GNU General  Public License as published
+ * by the Free  Software Foundation; either version 2  of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
+ * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
+ * General Public License for more details.
+ */
+
+#include <SDL.h>
+#include <SDL_thread.h>
+#include <math.h>
+#include <stdio.h>
+
+#include "config.h"
+
+/*---------------------------------------------------------------------------*/
+#ifdef ENABLE_WII
+
+#define _ENABLE_TILT
+#include <libcwiimote/wiimote.h>
+#include <libcwiimote/wiimote_api.h>
+
+struct tilt_state
+{
+    int   status;
+    float x;
+    float z;
+    int   A, last_A;
+    int   B, last_B;
+    int   P, last_P;
+    int   M, last_M;
+    int   H, last_H;
+    int   U;
+    int   D;
+    int   L;
+    int   R;
+};
+
+static struct tilt_state state;
+static SDL_mutex        *mutex  = NULL;
+static SDL_Thread       *thread = NULL;
+
+#define FILTER 8
+
+static int tilt_func(void *data)
+{
+    wiimote_t wiimote = WIIMOTE_INIT;
+    char      address[MAXSTR];
+
+    config_get_s(CONFIG_WIIMOTE_ADDR, address, MAXSTR);
+
+    if (strlen(address) > 0)
+    {
+        if (wiimote_connect(&wiimote, address) < 0)
+            fprintf(stderr, "%s\n", wiimote_get_error());
+        else
+        {
+            int running = 1;
+
+            wiimote.mode.bits = WIIMOTE_MODE_ACC;
+            wiimote.led.one   = 1;
+
+            SDL_mutexP(mutex);
+            state.status = running;
+            SDL_mutexV(mutex);
+
+            while (mutex && running && wiimote_is_open(&wiimote))
+            {
+                if (wiimote_update(&wiimote) < 0)
+                    break;
+
+                SDL_mutexP(mutex);
+                {
+                    running = state.status;
+
+                    state.A = wiimote.keys.a;
+                    state.B = wiimote.keys.b;
+                    state.U = wiimote.keys.up;
+                    state.P = wiimote.keys.plus;
+                    state.M = wiimote.keys.minus;
+                    state.H = wiimote.keys.home;
+                    state.D = wiimote.keys.down;
+                    state.L = wiimote.keys.left;
+                    state.R = wiimote.keys.right;
+
+                    if (isnormal(wiimote.tilt.y))
+                    {
+                        state.x = (state.x * (FILTER - 1) +
+                                   wiimote.tilt.y) / FILTER;
+                    }
+                    if (isnormal(wiimote.tilt.x))
+                    {
+                        state.z = (state.z * (FILTER - 1) +
+                                   wiimote.tilt.x) / FILTER;
+                    }
+                }
+                SDL_mutexV(mutex);
+            }
+
+            wiimote_disconnect(&wiimote);
+        }
+    }
+    return 0;
+}
+
+void tilt_init(void)
+{
+    memset(&state, 0, sizeof (struct tilt_state));
+
+    mutex  = SDL_CreateMutex();
+    thread = SDL_CreateThread(tilt_func, NULL);
+}
+
+void tilt_free(void)
+{
+    int b = 0;
+
+    if (mutex)
+    {
+        /* Get/set the status of the tilt sensor thread. */
+
+        SDL_mutexP(mutex);
+        b = state.status;
+        state.status = 0;
+        SDL_mutexV(mutex);
+
+        /* Kill the thread and destroy the mutex. */
+
+        SDL_KillThread(thread);
+        SDL_DestroyMutex(mutex);
+
+        mutex  = NULL;
+        thread = NULL;
+    }
+}
+
+int tilt_get_button(int *b, int *s)
+{
+    int ch = 0;
+
+    if (mutex)
+    {
+        SDL_mutexP(mutex);
+        {
+            if      (state.A != state.last_A)
+            {
+                *b = config_get_d(CONFIG_JOYSTICK_BUTTON_A);
+                *s = state.last_A = state.A;
+                ch = 1;
+            }
+            else if (state.B != state.last_B)
+            {
+                *b = config_get_d(CONFIG_JOYSTICK_BUTTON_B);
+                *s = state.last_B = state.B;
+                ch = 1;
+            }
+            else if (state.P != state.last_P)
+            {
+                *b = config_get_d(CONFIG_JOYSTICK_BUTTON_R);
+                *s = state.last_P = state.P;
+                ch = 1;
+            }
+            else if (state.M != state.last_M)
+            {
+                *b = config_get_d(CONFIG_JOYSTICK_BUTTON_L);
+                *s = state.last_M = state.M;
+                ch = 1;
+            }
+            else if (state.H != state.last_H)
+            {
+                *b = config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT);
+                *s = state.last_H = state.H;
+                ch = 1;
+            }
+        }
+        SDL_mutexV(mutex);
+    }
+    return ch;
+}
+
+void tilt_get_direct(int *x, int *y)
+{
+    *x = 1;
+    *y = 1;
+
+    if (mutex)
+    {
+        SDL_mutexP(mutex);
+        {
+            if      (state.L)
+                *x = -JOY_MAX;
+            else if (state.R)
+                *x = +JOY_MAX;
+
+            if      (state.U)
+                *y = -JOY_MAX;
+            else if (state.D)
+                *y = +JOY_MAX;
+        }
+        SDL_mutexV(mutex);
+    }
+}
+
+float tilt_get_x(void)
+{
+    float x = 0.0f;
+
+    if (mutex)
+    {
+        SDL_mutexP(mutex);
+        x = state.x;
+        SDL_mutexV(mutex);
+    }
+
+    return x;
+}
+
+float tilt_get_z(void)
+{
+    float z = 0.0f;
+
+    if (mutex)
+    {
+        SDL_mutexP(mutex);
+        z = state.z;
+        SDL_mutexV(mutex);
+    }
+
+    return z;
+}
+
+int tilt_stat(void)
+{
+    int b = 0;
+
+    if (mutex)
+    {
+        SDL_mutexP(mutex);
+        b = state.status;
+        SDL_mutexV(mutex);
+    }
+    return b;
+}
+
+#endif
+/*---------------------------------------------------------------------------*/
+#ifndef ENABLE_WII
+
+void tilt_init(void)
+{
+}
+
+void tilt_free(void)
+{
+}
+
+int tilt_stat(void)
+{
+    return 0;
+}
+
+int  tilt_get_button(int *b, int *s)
+{
+    return 0;
+}
+
+void tilt_get_direct(int *x, int *y)
+{
+    *x = 1;
+    *y = 1;
+}
+
+float tilt_get_x(void)
+{
+    return 0.0f;
+}
+
+float tilt_get_z(void)
+{
+    return 0.0f;
+}
+
+#endif
+/*---------------------------------------------------------------------------*/
diff --git a/share/tilt.h b/share/tilt.h
new file mode 100644 (file)
index 0000000..c0ef6b3
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2003 Robert Kooima
+ *
+ * NEVERBALL is  free software; you can redistribute  it and/or modify
+ * it under the  terms of the GNU General  Public License as published
+ * by the Free  Software Foundation; either version 2  of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
+ * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
+ * General Public License for more details.
+ */
+
+#ifndef TILT_H
+#define TILT_H
+
+/*---------------------------------------------------------------------------*/
+
+void tilt_init(void);
+void tilt_free(void);
+int  tilt_stat(void);
+
+int  tilt_get_button(int *, int *);
+void tilt_get_direct(int *, int *);
+
+float tilt_get_x(void);
+float tilt_get_z(void);
+
+/*---------------------------------------------------------------------------*/
+
+#endif