diff --git a/autobuild.xml b/autobuild.xml index aed50ad..ec16faf 100644 --- a/autobuild.xml +++ b/autobuild.xml @@ -7,7 +7,7 @@ autobuild installables - SDL2 + SDL3 platforms @@ -16,54 +16,26 @@ archive hash - ad1b738a7cef16d5cec63ab99b1c80146626f47b + 06226c54c57afd601707c0f5f7a2e0736ab1f326 hash_algorithm sha1 url - https://github.com/secondlife/3p-sdl2/releases/download/v2.30.9-r1/SDL2-2.30.9-r1-linux64-11943333704.tar.zst + https://github.com/secondlife/3p-sdl3/releases/download/v3.2.24-r1/SDL3-3.2.24-r1-linux64-18539840462.tar.zst name linux64 - darwin64 - - archive - - hash - a6aa829c1e7f193b624f05415588e4d727454c8f - hash_algorithm - sha1 - url - https://github.com/secondlife/3p-sdl2/releases/download/v2.30.9-r1/SDL2-2.30.9-r1-darwin64-11943333704.tar.zst - - name - darwin64 - - windows64 - - archive - - hash - 97153f9d302f964142df971b57680724824f458f - hash_algorithm - sha1 - url - https://github.com/secondlife/3p-sdl2/releases/download/v2.30.9-r1/SDL2-2.30.9-r1-windows64-11943333704.tar.zst - - name - windows64 - license lgpl license_file - LICENSES/SDL2.txt + LICENSES/SDL3.txt copyright Copyright (C) 1997-2022 Sam Lantinga (slouken@libsdl.org) version - 2.30.9-r1 + 3.2.24-r1 name - SDL2 + SDL3 description Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. diff --git a/build-cmd.sh b/build-cmd.sh index 3481fce..5e846c3 100644 --- a/build-cmd.sh +++ b/build-cmd.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -TOP="$(dirname "$0")" +cd "$(dirname "$0")" # turn on verbose debugging output for parabuild logs. exec 4>&1; export BASH_XTRACEFD=4; set -x @@ -9,11 +9,7 @@ set -e # complain about unset env variables set -u -PROJECT="libndofdev" -VERSION=$(gawk 'END{print MAJOR"."MINOR} /NDOFDEV_MAJOR/{MAJOR=$3} /NDOFDEV_MINOR/{MINOR=$3}' ${TOP}/${PROJECT}/ndofdev_version.h) -SOURCE_DIR="$PROJECT" - -if [ -z "$AUTOBUILD" ] ; then +if [ -z "$AUTOBUILD" ] ; then exit 1 fi @@ -23,44 +19,58 @@ else autobuild="$AUTOBUILD" fi -stage="$(pwd)" -if [ ! -d "$stage/include" ] -then - mkdir -p "$stage/include" -fi +top="$(pwd)" +stage="$(pwd)/stage" +stage_include="$stage/include/" +stage_release="$stage/lib/release/" + +mkdir -p ${stage_include} +mkdir -p ${stage_release} + +PROJECT="libndofdev" +# 2nd line of CHANGELOG is most recent version number: +# * 0.3 +# Tease out just the version number from that line. +VERSION=$(gawk 'END{print MAJOR"."MINOR} /NDOFDEV_MAJOR/{MAJOR=$3} /NDOFDEV_MINOR/{MINOR=$3}' ${PROJECT}/ndofdev_version.h) +SOURCE_DIR="$PROJECT" "$autobuild" source_environment > "$stage/variables_setup.sh" || exit 1 . "$stage/variables_setup.sh" - build=${AUTOBUILD_BUILD_ID:=0} echo "${VERSION}.${build}" > "${stage}/VERSION.txt" +# remove_cxxstd +source "$(dirname "$AUTOBUILD_VARIABLES_FILE")/functions" + +pushd "$SOURCE_DIR" case "$AUTOBUILD_PLATFORM" in windows*|darwin*) # Given forking and future development work, it seems unwise to # hardcode the actual URL of the current project's libndofdev # repository in this message. Try to determine the URL of this # open-libndofdev repository and remove "open-" as a suggestion. - echo "Windows/Mac libndofdev is in a separate bitbucket repository \ --- try $(hg paths default | sed -E 's/open-(libndofdev)/\1/')" 1>&2 ; exit 1 - ;; - linux) - echo "Platform linux is unsupported" - exit 1 - ;; - linux64) - opts="-DTARGET_OS_LINUX -m$AUTOBUILD_ADDRSIZE $LL_BUILD_RELEASE" - #Dumb - $LL_BUILD_RELEASE contains c++ standard flags which are meaningful to the c++ - #compiler only, SDL is written in C and polluting CFLAGS with that nonsense just makes - #the compiler spew out a whole load of noise, so lets strip that junk out from CFLAGS - opts=$(echo "$opts" | sed 's/-std=c++[0-9][0-9]*//') - cmake ../libndofdev -DCMAKE_CXX_FLAGS="$opts" -DCMAKE_C_FLAGS="$opts" \ - -DCMAKE_OSX_ARCHITECTURES="$AUTOBUILD_CONFIGURE_ARCH" \ - -DCMAKE_BUILD_TYPE:STRING=Release - make - cp -a ../libndofdev/*.h $stage/include - cp -a ../libndofdev/LICENSES LICENSES + echo "Windows/Mac libndofdev is in a separate GitHub repository" 1>&2 ; exit 1 + ;; + linux*) + # Default target per autobuild build --address-size + opts="-m$AUTOBUILD_ADDRSIZE $LL_BUILD_RELEASE" + plainopts="$(remove_cxxstd $opts)" + + # release build + CFLAGS="$plainopts -I${stage}/packages/include -Wl,-L${stage}/packages/lib/release" \ + CXXFLAGS="$opts -I${stage}/packages/include -Wl,-L${stage}/packages/lib/release" \ + LDFLAGS="-L${stage}/packages/lib/release" \ + USE_SDL3=1 \ + make all + + cp libndofdev.a ${stage_release} + cp ndofdev_external.h ${stage_include} ;; esac + +mkdir -p ${stage}/LICENSES +cp LICENSES/libndofdev.txt ${stage}/LICENSES/libndofdev.txt + +popd diff --git a/libndofdev/Makefile b/libndofdev/Makefile index 933a218..1e2a60e 100644 --- a/libndofdev/Makefile +++ b/libndofdev/Makefile @@ -1,9 +1,22 @@ -CFLAGS=-pipe -Wall -Wunused-result +CFLAGS := $(CFLAGS) -pipe -Wall -Wunused-result +ifeq ($(USE_SDL3),1) +CFLAGS := $(CFLAGS) -DUSE_SDL3 +ifeq ($(DEBUG),1) +LDFLAGS := ${LDFLAGS} -lSDL3d +else +LDFLAGS := ${LDFLAGS} -lSDL3 +endif +else ifeq ($(USE_SDL2),1) CFLAGS := $(CFLAGS) -DUSE_SDL2 -LDFLAGS=-lSDL2 +ifeq ($(DEBUG),1) +LDFLAGS := ${LDFLAGS} -lSDL2d else -LDFLAGS=-lSDL +LDFLAGS := ${LDFLAGS} -lSDL2 +endif +else +LDFLAGS := ${LDFLAGS} -lSDL +endif endif diff --git a/libndofdev/README.md b/libndofdev/README.md index d2e629c..262d1f7 100644 --- a/libndofdev/README.md +++ b/libndofdev/README.md @@ -41,7 +41,7 @@ from the list above - that's the only way to get the problems fixed. In addition, the library supports every joystick/gamepad device supported by the SDL library. SDL2 is supported by passing a flag to -the makefile: `USE_SDL2=1 make` +the makefile: `USE_SDL2=1 make` SDL3 is supported by passing USE_SDL3 C A U T I O N !!! diff --git a/libndofdev/ndofdev.c b/libndofdev/ndofdev.c index 6354553..ff5a962 100644 --- a/libndofdev/ndofdev.c +++ b/libndofdev/ndofdev.c @@ -48,7 +48,9 @@ #include #include -#ifdef USE_SDL2 +#ifdef USE_SDL3 +#include +#elif defined(USE_SDL2) #include #else #include @@ -258,6 +260,32 @@ int ndof_init_first(NDOF_Device *in_out_dev, void *param) return 0; } else { +#ifdef USE_SDL3 + // SpaceNavigator not found, use SDL Joystick + SDL_Joystick *j = SDL_OpenJoystick(0); + if(j) + { + in_out_dev->axes_count = SDL_GetNumJoystickAxes(j) + SDL_GetNumJoystickHats(j) * 2; // each hat has 2 axes + in_out_dev->btn_count = SDL_GetNumJoystickButtons(j); + in_out_dev->absolute = 0; // always relative on Linux + in_out_dev->valid = 1; + in_out_dev->axes_max = 32767; + in_out_dev->axes_min = -32767; + + strncpy(in_out_dev->product, SDL_GetJoystickName(j), 255); + + // private data + LinJoystickPrivate *priv = (LinJoystickPrivate *) malloc (sizeof(LinJoystickPrivate)); + priv->j = j; + priv->fd = -1; + priv->USE_SDL = 1; + // remember number of hats for later axis mapping in ndof_update() + priv->num_hats = SDL_GetNumJoystickHats(j); + in_out_dev->private_data = priv; + + return 0; + } +#else // SpaceNavigator not found, use SDL Joystick SDL_Joystick *j = SDL_JoystickOpen(0); if(j) @@ -268,7 +296,7 @@ int ndof_init_first(NDOF_Device *in_out_dev, void *param) in_out_dev->valid = 1; in_out_dev->axes_max = 32767; in_out_dev->axes_min = -32767; -#ifdef USE_SDL2 +#if defined(USE_SDL2) strncpy(in_out_dev->product, SDL_JoystickName(j), 255); #else strncpy(in_out_dev->product, SDL_JoystickName(0), 255); @@ -283,7 +311,9 @@ int ndof_init_first(NDOF_Device *in_out_dev, void *param) in_out_dev->private_data = priv; return 0; - } else { + } +#endif + else { // no joysticks found return -1; @@ -348,6 +378,50 @@ void ndof_update(NDOF_Device *in_dev) if(priv->USE_SDL) { +#ifdef USE_SDL3 + SDL_UpdateJoysticks(); + SDL_Joystick *j = priv->j; + + for(i = 0; i < in_dev->axes_count - priv->num_hats*2; i++) // hats will get mapped to uppermost axes + { + in_dev->axes[i] = (int) (SDL_GetJoystickAxis(j, i)); + } + + for(i = 0; i < priv->num_hats; i++) + { + int x = 0; + int y = 0; + + int value = SDL_GetJoystickHat(j, i); + + // map hat values (1, 2, 4, 8) to axis data (-32768, 32768) + if(value & 1) + { + y = -32767; + } + else if(value & 4) + { + y = 32768; + } + if(value & 2) + { + x = 32767; + } + else if(value & 8) + { + x = -32768; + } + + // add the hat data to the uppermost axes data + in_dev->axes[in_dev->axes_count - priv->num_hats*2 + i*2 ] = x; + in_dev->axes[in_dev->axes_count - priv->num_hats*2 + i*2+1] = y; + } + + for(i = 0; i < in_dev->btn_count; i++) + { + in_dev->buttons[i] = SDL_GetJoystickButton(j, i); + } +#else SDL_JoystickUpdate(); SDL_Joystick *j = priv->j; @@ -390,18 +464,18 @@ void ndof_update(NDOF_Device *in_dev) { in_dev->buttons[i] = SDL_JoystickGetButton(j, i); } +#endif } else { // update SpaceNavigator struct input_event ev; - int mapped_code; while(read(priv->fd, &ev, sizeof(struct input_event)) > 0) { switch (ev.type) { case EV_KEY: - mapped_code = SPACE_MOUSE_BUTTON_MAPPING[ev.code & 0xff]; + int mapped_code = SPACE_MOUSE_BUTTON_MAPPING[ev.code & 0xff]; // printf("Key %d (mapped to %d) pressed %d .\n", ev.code, mapped_code, ev.value); priv->buttons[mapped_code] = ev.value; break;