lots of makefile fixes, and sdl joystick stuff
authorBradley Bell <btb@icculus.org>
Mon, 3 Dec 2001 02:43:02 +0000 (02:43 +0000)
committerBradley Bell <btb@icculus.org>
Mon, 3 Dec 2001 02:43:02 +0000 (02:43 +0000)
Makefile.am
acconfig.h
arch/linux/Makefile.am
arch/sdl/Makefile.am
arch/sdl/event.c
arch/sdl/init.c
arch/sdl/joy.c
arch/svgalib/Makefile.am
configure.ac

index 601a220..443b6ee 100644 (file)
@@ -10,24 +10,10 @@ CCLD = ${CC}
 LDFLAGS = -export-dynamic
 LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
 
-if DJGPP
-ARCH_LIBS = arch/dos/libarch_dos.a
-else
-if USE_OPENGL
-if MINGW32
-ARCH_LIBS = arch/win32/libarch_win32.a arch/sdl/libarch_sdl.a arch/ogl/libarch_ogl.a
-LD_KLUDGE = main/inferno.o
-else
-ARCH_LIBS = arch/linux/libarch_linux.a arch/sdl/libarch_sdl.a arch/ogl/libarch_ogl.a
-endif
-else
+ARCH_LIBS = $(foreach subdir,${D2X_ARCH_SUBDIRS},arch/${subdir}/libarch_${subdir}.a)
+
 if MINGW32
-ARCH_LIBS = arch/win32/libarch_win32.a arch/sdl/libarch_sdl.a
 LD_KLUDGE = main/inferno.o
-else
-ARCH_LIBS = arch/linux/libarch_linux.a arch/sdl/libarch_sdl.a
-endif
-endif
 endif
 
 if EDITOR
index c8a4780..6d3b4f1 100644 (file)
@@ -28,6 +28,9 @@
 /* Define to render endlevel flythrough sequences (instead of movies) */
 #undef NMOVIES
 
+/* Define to use SDL Joystick */
+#undef SDL_JOYSTICK
+
 @BOTTOM@
 
 /* General defines */
@@ -62,7 +65,6 @@
 # define __SDL__ 1
 # define SDL_AUDIO 1
 # define SDL_INPUT 1
-# define SDL_JOYSTICK 1
 # ifdef OGL
 #  define SDL_GL_VIDEO 1
 # else
index b98c5e2..bb181f0 100644 (file)
@@ -4,15 +4,19 @@ noinst_LIBRARIES = libarch_linux.a
 
 INCLUDES = -I$(top_srcdir)/arch/include -I$(top_srcdir)/includes -I$(top_srcdir)/main -I$(srcdir)/include
 
+
 if USE_NETWORK
-libarch_linux_a_SOURCES = joydefs.c joystick.c findfile.c init.c \
-ipx_bsd.c ipx_kali.c ipx_lin.c linuxnet.c ukali.c
-else
-libarch_linux_a_SOURCES = joydefs.c joystick.c findfile.c init.c
+NETWORK_SRCS = ipx_bsd.c ipx_kali.c ipx_lin.c linuxnet.c ukali.c
+endif
+
+if !SDL_JOYSTICK
+JOYSTICK_SRCS = joydefs.c joystick.c
 endif
 
+libarch_linux_a_SOURCES = ${NETWORK_SRCS} ${JOYSTICK_SRCS} findfile.c init.c
+
 EXTRA_libarch_linux_a_SOURCES = \
-ipx_bsd.c ipx_kali.c ipx_lin.c linuxnet.c ukali.c
+ipx_bsd.c ipx_kali.c ipx_lin.c joydefs.c joystick.c linuxnet.c ukali.c
 
 EXTRA_DIST = ${EXTRA_SUBDIRS} \
 alsadigi.c hmistub.c hmiplay.c ipx_udp.c mono.c serial.c timer.c ukali.c
index 164eb52..edb9f1d 100644 (file)
@@ -4,16 +4,22 @@ noinst_LIBRARIES = libarch_sdl.a
 
 INCLUDES = -I$(top_srcdir)/arch/include -I$(top_srcdir)/includes -I$(top_srcdir)/main
 
-if USE_OPENGL
-if MINGW32
-libarch_sdl_a_SOURCES = cdrom.c digi.c event.c init.c joy.c joydefs.c key.c mouse.c timer.c
-else
-libarch_sdl_a_SOURCES = cdrom.c digi.c event.c init.c key.c mouse.c timer.c
+if SDL_JOYSTICK
+JOYSTICK_SRCS = joy.c joydefs.c
 endif
-else
-if MINGW32
-libarch_sdl_a_SOURCES = cdrom.c digi.c event.c gr.c init.c joy.c joydefs.c key.c mouse.c timer.c
-else
-libarch_sdl_a_SOURCES = cdrom.c digi.c event.c gr.c init.c key.c mouse.c timer.c
+
+if !USE_SVGALIB
+if !USE_GGI
+INPUT_SRCS = event.c key.c mouse.c
+endif
+endif
+
+if !USE_OPENGL
+VIDEO_SRCS = gr.c 
 endif
-endif
\ No newline at end of file
+
+libarch_sdl_a_SOURCES = ${JOYSTICK_SRCS} ${VIDEO_SRCS} ${INPUT_SRCS} \
+cdrom.c digi.c init.c timer.c
+
+EXTRA_libarch_sdl_a_SOURCES = \
+event.c gr.c joy.c joydefs.c key.c mouse.c
index 38ca99a..244634d 100644 (file)
@@ -1,12 +1,15 @@
 /*
  * $Source: /cvs/cvsroot/d2x/arch/sdl/event.c,v $
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
  * $Author: bradleyb $
- * $Date: 2001-11-14 10:43:10 $
+ * $Date: 2001-12-03 02:43:02 $
  *
  * SDL Event related stuff
  *
  * $Log: not supported by cvs2svn $
+ * Revision 1.3  2001/11/14 10:43:10  bradleyb
+ * remove cruft, fix formatting, begin joystick stuff
+ *
  * Revision 1.2  2001/10/31 07:41:54  bradleyb
  * Sync with d1x
  *
@@ -30,6 +33,8 @@
 extern void key_handler(SDL_KeyboardEvent *event);
 extern void mouse_button_handler(SDL_MouseButtonEvent *mbe);
 extern void mouse_motion_handler(SDL_MouseMotionEvent *mme);
+extern void joy_button_handler(SDL_JoyButtonEvent *jbe);
+extern void joy_axis_handler(SDL_JoyAxisEvent *jae);
 
 static int initialised=0;
 
@@ -50,13 +55,13 @@ void event_poll()
                case SDL_MOUSEMOTION:
                        mouse_motion_handler((SDL_MouseMotionEvent *)&event);
                        break;
-#if 0
+#if SDL_JOYSTICK
                case SDL_JOYBUTTONDOWN:
                case SDL_JOYBUTTONUP:
                        joy_button_handler((SDL_JoyButtonEvent *)&event);
                        break;
                case SDL_JOYAXISMOTION:
-                       joy_motion_handler((SDL_JoyAxisEvent *)&event);
+                       joy_axis_handler((SDL_JoyAxisEvent *)&event);
                        break;
                case SDL_JOYBALLMOTION:
                case SDL_JOYHATMOTION:
index a3f9c69..4e8f169 100644 (file)
@@ -1,12 +1,15 @@
 /*
  * $Source: /cvs/cvsroot/d2x/arch/sdl/init.c,v $
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
  * $Author: bradleyb $
- * $Date: 2001-11-14 03:56:16 $
+ * $Date: 2001-12-03 02:43:02 $
  *
  * SDL architecture support
  *
  * $Log: not supported by cvs2svn $
+ * Revision 1.6  2001/11/14 03:56:16  bradleyb
+ * SDL joystick stuff
+ *
  * Revision 1.5  2001/10/31 07:41:54  bradleyb
  * Sync with d1x
  *
@@ -43,7 +46,7 @@ void arch_sdl_init()
  // Initialise the library
 //edited on 01/03/99 by Matt Mueller - if we use SDL_INIT_EVERYTHING, cdrom is initialized even if -nocdaudio is used
  if (SDL_Init(
-#if 0 //def SDL_JOYSTICK
+#ifdef SDL_JOYSTICK
        SDL_INIT_JOYSTICK |
 #endif
 #if defined(SDL_VIDEO) || defined(SDL_GL_VIDEO)
index 68bd776..69002fa 100644 (file)
@@ -1,12 +1,15 @@
 /*
  * $Source: /cvs/cvsroot/d2x/arch/sdl/joy.c,v $
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
  * $Author: bradleyb $
- * $Date: 2001-10-24 09:25:05 $
+ * $Date: 2001-12-03 02:43:02 $
  *
  * SDL joystick support
  *
  * $Log: not supported by cvs2svn $
+ * Revision 1.1  2001/10/24 09:25:05  bradleyb
+ * Moved input stuff to arch subdirs, as in d1x.
+ *
  * Revision 1.1  2001/10/10 03:01:29  bradleyb
  * Replacing win32 joystick (broken) with SDL joystick (stubs)
  *
 
 #include "joy.h"
 #include "error.h"
+#include "timer.h"
+#include "console.h"
+
+#define MAX_JOYSTICKS 16
+#define MAX_AXES 32
+
+#define MAX_AXES_PER_JOYSTICK 8
+#define MAX_BUTTONS_PER_JOYSTICK 16
 
 char joy_present = 0;
+int num_joysticks = 0;
+
+struct joybutton {
+       int state;
+       fix time_went_down;
+       fix time_held_down;
+       int num_downs;
+       int num_ups;
+};
+
+static struct joyinfo {
+       int n_axes;
+       int n_buttons;
+       int axes[MAX_AXES];
+       struct joybutton buttons[MAX_BUTTONS];
+} Joystick;
+
+static struct {
+       SDL_Joystick *handle;
+       int n_axes;
+       int n_buttons;
+       int axis_map[MAX_AXES_PER_JOYSTICK];
+       int button_map[MAX_BUTTONS_PER_JOYSTICK];
+} SDL_Joysticks[MAX_JOYSTICKS];
+
+void joy_button_handler(SDL_JoyButtonEvent *jbe)
+{
+       int button;
+
+       button = SDL_Joysticks[jbe->which].button_map[jbe->button];
+
+       Joystick.buttons[button].state = jbe->state;
+
+       switch (jbe->type) {
+       case SDL_JOYBUTTONDOWN:
+               Joystick.buttons[button].time_went_down
+                       = timer_get_fixed_seconds();
+               Joystick.buttons[button].num_downs++;
+               break;
+       case SDL_JOYBUTTONUP:
+               Joystick.buttons[button].time_held_down
+                       += timer_get_fixed_seconds()
+                       - Joystick.buttons[button].time_went_down;
+               Joystick.buttons[button].num_ups++;
+               break;
+       }
+}
 
-int
-joy_init()
+void joy_axis_handler(SDL_JoyAxisEvent *jae)
 {
-  if (SDL_Init( SDL_INIT_JOYSTICK ) < 0)
-    {
-      Warning("SDL library initialisation failed: %s.", SDL_GetError());
-      return 0;
-    }
+       int axis;
+
+       axis = SDL_Joysticks[jae->which].axis_map[jae->axis];
+       
+       Joystick.axes[axis] = jae->value;
+}
 
 
+/* ----------------------------------------------- */
 
-  return 1;
+int joy_init()
+{
+       int i,j,n;
+
+       memset(&Joystick,0,sizeof(Joystick));
+
+       n = SDL_NumJoysticks();
+
+       con_printf(CON_VERBOSE, "Joystick: found %d joysticks\n", n);
+       for (i = 0; i < n; i++) {
+               con_printf(CON_VERBOSE, "Joystick %d: %s\n", i, SDL_JoystickName(i));
+               SDL_Joysticks[num_joysticks].handle = SDL_JoystickOpen(i);
+               if (SDL_Joysticks[num_joysticks].handle) {
+                       joy_present = 1;
+                       SDL_Joysticks[num_joysticks].n_axes
+                               = SDL_JoystickNumAxes(SDL_Joysticks[num_joysticks].handle);
+                       SDL_Joysticks[num_joysticks].n_buttons
+                               = SDL_JoystickNumButtons(SDL_Joysticks[num_joysticks].handle);
+                       con_printf(CON_VERBOSE, "Joystick: %d axes\n", SDL_Joysticks[num_joysticks].n_axes);
+                       con_printf(CON_VERBOSE, "Joystick: %d buttons\n", SDL_Joysticks[num_joysticks].n_buttons);
+                       for (j=0; j < SDL_Joysticks[num_joysticks].n_axes; j++)
+                               SDL_Joysticks[num_joysticks].axis_map[j] = Joystick.n_axes++;
+                       for (j=0; j < SDL_Joysticks[num_joysticks].n_buttons; j++)
+                               SDL_Joysticks[num_joysticks].button_map[j] = Joystick.n_buttons++;
+                       num_joysticks++;
+               } else
+                       con_printf(CON_VERBOSE, "Joystick: initialization failed!\n");
+       }
+               
+       return joy_present;
 }
 
-void
-joy_close()
+void joy_close()
 {
-  return;
+       while (num_joysticks)
+               SDL_JoystickClose(SDL_Joysticks[--num_joysticks].handle);
 }
 
-void
-joy_get_pos(int *x, int *y)
+void joy_get_pos(int *x, int *y)
 {
-  *x = *y = 0;
-  return;
+       *x = Joystick.axes[0] << 8;
+       *y = Joystick.axes[1] << 8;
 }
 
-int
-joy_get_btns()
+int joy_get_btns()
 {
-  return 0;
+       return 0;
 }
 
-int
-joy_get_button_down_cnt(int btn)
+int joy_get_button_down_cnt( int btn )
 {
-  return 0;
+       return 0;
 }
 
-fix
-joy_get_button_down_time(int btn)
+fix joy_get_button_down_time(int btn)
 {
-  return 0;
+       fix time;
+
+       time = Joystick.buttons[btn].time_held_down;
+       Joystick.buttons[btn].time_held_down = 0;
+
+       return time;
 }
 
-ubyte
-joystick_read_raw_axis(ubyte mask, int *axis)
+ubyte joystick_read_raw_axis( ubyte mask, int * axis )
 {
-  return 0;
+       return 0;
 }
 
-void
-joy_flush()
+void joy_flush()
 {
-  return;
 }
 
-int
-joy_get_button_state(int btn)
+int joy_get_button_state( int btn )
 {
-  return 0;
+       return 0;
 }
 
-void
-joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max)
+void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max)
 {
-  return;
 }
 
-void
-joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max)
+void joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max)
 {
-  return;
 }
 
-int
-joy_get_scaled_reading(int raw, int axn)
+int joy_get_scaled_reading( int raw, int axn )
 {
-  return 0;
+       return 0;
 }
 
-void
-joy_set_slow_reading(int flag)
+void joy_set_slow_reading( int flag )
 {
-  return;
 }
index e4f2668..1eda751 100644 (file)
@@ -2,4 +2,6 @@ EXTRA_SUBDIRS = linux
 
 noinst_LIBRARIES = libarch_svgalib.a
 
+INCLUDES = -I$(top_srcdir)/includes -I$(top_srcdir)/main -I$(top_srcdir)/arch/include
+
 libarch_svgalib_a_SOURCES = event.c gr.c key.c mouse.c init.c
index 49e5f0b..015a6ca 100644 (file)
@@ -127,7 +127,7 @@ else
     done
     AC_DEFINE(OGL)
     TARGETS=d2x-ogl
-    D2X_ARCH_SUBDIRS="${D2X_ARCH_SUBDIRS} ogl"
+    D2X_ARCH_SUBDIRS="ogl ${D2X_ARCH_SUBDIRS}"
   fi
   AC_SUBST(OGL_LIBS)
   AM_CONDITIONAL(USE_OPENGL, test x$with_opengl = xyes)
@@ -144,7 +144,7 @@ else
       [AC_MSG_ERROR([GII not found, GGI version cannot be built]); ggi=false])
     AC_DEFINE(GGI)
     TARGETS=d2x-ggi
-    D2X_ARCH_SUBDIRS="${D2X_ARCH_SUBDIRS} ggi"
+    D2X_ARCH_SUBDIRS="ggi ${D2X_ARCH_SUBDIRS}"
   fi
   AC_SUBST(GGI_LIBS)
   AM_CONDITIONAL(USE_GGI, test x$with_ggi = xyes)
@@ -165,16 +165,25 @@ else
        -lvga)
     AC_DEFINE(SVGA)
     TARGETS=d2x-svga
-    D2X_ARCH_SUBDIRS="${D2X_ARCH_SUBDIRS} svgalib"
+    D2X_ARCH_SUBDIRS="svgalib ${D2X_ARCH_SUBDIRS}"
   fi
   AC_SUBST(SVGA_LIBS)
-  AM_CONDITIONAL(USE_SVGALIB, test x$with_svga = yes)
+  AM_CONDITIONAL(USE_SVGALIB, test x$with_svga = xyes)
 
   if test x$MINGW32 = xyes; then
-    D2X_ARCH_SUBDIRS="${D2X_ARCH_SUBDIRS} win32"
+    D2X_ARCH_SUBDIRS="win32 ${D2X_ARCH_SUBDIRS}"
+    AC_DEFINE(SDL_JOYSTICK)
   else
     CFLAGS="-I \$(top_srcdir)/arch/linux/include $CFLAGS"
-    D2X_ARCH_SUBDIRS="${D2X_ARCH_SUBDIRS} linux"
+    D2X_ARCH_SUBDIRS="linux ${D2X_ARCH_SUBDIRS}"
+
+    dnl Check for SDL joystick
+    AC_ARG_ENABLE(sdl-joystick,
+      [  --enable-sdl-joystick   Use SDL joystick (required for mingw) ],,)
+    if test x$enable_sdl_joystick = xyes; then
+        AC_DEFINE(SDL_JOYSTICK)
+    fi
+    AM_CONDITIONAL(SDL_JOYSTICK, test x$enable_sdl_joystick = xyes)
   fi
 fi