Skip to content

Commit

Permalink
fixed: FreeBSD build was broken due to joystick code
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsiomb committed Aug 30, 2022
1 parent e5fcc64 commit eb622d9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ IF(UNIX AND NOT(ANDROID OR BLACKBERRY OR FREEGLUT_WAYLAND))
ENDIF()
ENDIF()

# FreeBSD and NetBSD joystick code uses libusbhid
IF(CMAKE_SYSTEM_NAME STREQUAL FreeBSD OR CMAKE_SYSTEM_NAME STREQUAL NetBSD)
IF(HAVE_USBHID_H)
LIST(APPEND LIBS "-lusbhid")
ENDIF()
ENDIF()

# For OpenGL ES (GLES): compile with -DFREEGLUT_GLES to cleanly
# bootstrap headers inclusion in freeglut_std.h; this constant also
# need to be defined in client applications (e.g. through pkg-config),
Expand Down
4 changes: 2 additions & 2 deletions altbuild/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ x11obj = src/x11/fg_state_x11_glx.o src/x11/fg_glutfont_definitions_x11.o \
obj = $(coreobj) $(x11obj)

liba = libglut.a
incpath = -I. -Isrc -Iinclude -I/usr/X11R6/include
libpath = -L/usr/X11R6/lib
incpath = -I. -Isrc -Iinclude -I/usr/local/include -I/usr/X11R6/include
libpath = -L/usr/local/lib -L/usr/X11R6/lib

CFLAGS = -O2 $(incpath) -DHAVE_CONFIG_H
LDFLAGS = $(libpath)
Expand Down
9 changes: 5 additions & 4 deletions src/fg_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1063,10 +1063,11 @@ SFG_Menu* fgCreateMenu( FGCBMenuUC menuCallback, FGCBUserData userData );
void fgDestroyMenu( SFG_Menu* menu );

/* Joystick device management functions, defined in fg_joystick.c */
int fgJoystickDetect( void );
void fgInitialiseJoysticks( void );
void fgJoystickClose( void );
void fgJoystickPollWindow( SFG_Window* window );
int fgJoystickDetect(void);
void fgInitialiseJoysticks(void);
void fgJoystickClose(void);
void fgJoystickPollWindow(SFG_Window *window);
void fgJoystickRawRead(SFG_Joystick *joy, int *buttons, float *axes);

/* InputDevice Initialisation and Closure */
int fgInputDeviceDetect( void );
Expand Down
4 changes: 2 additions & 2 deletions src/fg_joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ];
/*
* Read the raw joystick data
*/
static void fghJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
void fgJoystickRawRead( SFG_Joystick* joy, int* buttons, float* axes )
{
int i;

Expand Down Expand Up @@ -151,7 +151,7 @@ static void fghJoystickRead( SFG_Joystick* joy, int* buttons, float* axes )
axes[ i ] = 0.0f;
}

fghJoystickRawRead( joy, buttons, raw_axes );
fgJoystickRawRead( joy, buttons, raw_axes );

if( axes )
for( i=0; i<joy->num_axes; i++ )
Expand Down
9 changes: 8 additions & 1 deletion src/x11/fg_joystick_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
# else
# include <libusbhid.h>
# endif
#if __FreeBSD_version < 800061
# include <legacy/dev/usb/usb.h>
#else
# include <dev/usb/usb_ioctl.h>
# include <dev/usb/usb.h>
#endif
# endif
# include <dev/usb/usbhid.h>

Expand Down Expand Up @@ -115,6 +120,7 @@ static int hatmap_y[9] = {0, 1, 1, 0, -1, -1, -1, 0, 1};
*/
static char *fghJoystickWalkUSBdev(int f, char *dev, char *out, int outlen)
{
#if __FreeBSD_version < 800061
struct usb_device_info di;
int i, a;
char *cp;
Expand All @@ -136,6 +142,7 @@ static char *fghJoystickWalkUSBdev(int f, char *dev, char *out, int outlen)
return out;
}
}
#endif
return NULL;
}

Expand Down Expand Up @@ -500,7 +507,7 @@ void fgPlatformJoystickOpen( SFG_Joystick* joy )
joy->num_axes = 2;
joy->num_buttons = 32;

fghJoystickRawRead( joy, buttons, axes );
fgJoystickRawRead( joy, buttons, axes );
joy->error = axes[ 0 ] < -1000000000.0f;
if( joy->error )
return;
Expand Down

0 comments on commit eb622d9

Please sign in to comment.