+
#-------------------------------------------------------------------------------
VERSION := $(shell sh scripts/version.sh)
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
OGL_LIBS := -framework OpenGL
else
+ ifneq ($(ENABLE_WII),0)
+ TILT_LIBS := -lcwiimote -lbluetooth
+ endif
+
OGL_LIBS := -lGL -lm
endif
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)
#------------------------------------------------------------------------------
share/audio.o \
share/text.o \
share/sync.o \
+ share/tilt.o \
ball/hud.o \
ball/mode.o \
ball/game.o \
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));
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);
#include "gui.h"
#include "set.h"
#include "text.h"
+#include "tilt.h"
#include "st_conf.h"
#include "st_title.h"
SDL_Event e;
int d = 1;
int c;
+ int x;
+ int y;
while (d && SDL_PollEvent(&e))
{
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))
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;
}
/* Initialize the audio. */
audio_init();
+ tilt_init();
/* Require 16-bit double buffer with 16-bit depth buffer. */
if (SDL_JoystickOpened(0))
SDL_JoystickClose(joy);
+ tilt_free();
SDL_Quit();
config_save();
shared_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
NULL,
conf_buttn,
NULL,
NULL,
NULL,
+ NULL,
1, 0
};
demo_timer,
demo_point,
demo_stick,
+ shared_stick,
shared_click,
NULL,
demo_buttn,
NULL,
NULL,
NULL,
+ NULL,
demo_play_keybd,
demo_play_buttn,
1, 0
shared_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
demo_end_keybd,
demo_end_buttn,
shared_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
NULL,
demo_del_buttn,
shared_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
NULL,
done_buttn,
fall_out_timer,
shared_point,
shared_stick,
+ NULL,
shared_click,
NULL,
fall_out_buttn,
goal_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
NULL,
goal_buttn,
shared_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
NULL,
help_buttn,
NULL,
NULL,
NULL,
+ NULL,
help_demo_buttn,
1, 0
};
level_timer,
NULL,
NULL,
+ NULL,
level_click,
level_keybd,
level_buttn,
NULL,
NULL,
NULL,
+ NULL,
poser_buttn,
1, 0
};
shared_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
name_keybd,
name_buttn,
over_timer,
NULL,
NULL,
+ NULL,
over_click,
NULL,
over_buttn,
pause_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
pause_keybd,
pause_buttn,
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;
play_ready_timer,
NULL,
NULL,
+ NULL,
play_ready_click,
play_ready_keybd,
play_ready_buttn,
play_set_timer,
NULL,
NULL,
+ NULL,
play_set_click,
play_set_keybd,
play_set_buttn,
play_loop_timer,
play_loop_point,
play_loop_stick,
+ shared_angle,
play_loop_click,
play_loop_keybd,
play_loop_buttn,
look_point,
NULL,
NULL,
+ NULL,
look_keybd,
look_buttn,
0, 0
shared_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
save_keybd,
save_buttn,
shared_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
NULL,
clobber_buttn,
shared_timer,
set_point,
set_stick,
+ shared_angle,
shared_click,
NULL,
set_buttn,
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;
}
}
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;
}
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)
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 */
shared_timer,
start_point,
start_stick,
+ shared_angle,
shared_click,
start_keybd,
start_buttn,
shared_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
NULL,
time_out_buttn,
title_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
title_keybd,
title_buttn,
set-hard.txt
set-mym.txt
set-mym2.txt
+set-fwp.txt
+set-kk.txt
set-misc.txt
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);
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));
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]);
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,
#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
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);
}
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);
}
resol_timer,
resol_point,
resol_stick,
+ NULL,
resol_click,
resol_keybd,
resol_buttn,
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)
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);
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);
--- /dev/null
+/*
+ * 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
+/*---------------------------------------------------------------------------*/
--- /dev/null
+/*
+ * 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