Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions autobuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<string>autobuild</string>
<key>installables</key>
<map>
<key>SDL2</key>
<key>SDL3</key>
<map>
<key>platforms</key>
<map>
Expand All @@ -16,54 +16,26 @@
<key>archive</key>
<map>
<key>hash</key>
<string>ad1b738a7cef16d5cec63ab99b1c80146626f47b</string>
<string>06226c54c57afd601707c0f5f7a2e0736ab1f326</string>
<key>hash_algorithm</key>
<string>sha1</string>
<key>url</key>
<string>https://github.com/secondlife/3p-sdl2/releases/download/v2.30.9-r1/SDL2-2.30.9-r1-linux64-11943333704.tar.zst</string>
<string>https://github.com/secondlife/3p-sdl3/releases/download/v3.2.24-r1/SDL3-3.2.24-r1-linux64-18539840462.tar.zst</string>
</map>
<key>name</key>
<string>linux64</string>
</map>
<key>darwin64</key>
<map>
<key>archive</key>
<map>
<key>hash</key>
<string>a6aa829c1e7f193b624f05415588e4d727454c8f</string>
<key>hash_algorithm</key>
<string>sha1</string>
<key>url</key>
<string>https://github.com/secondlife/3p-sdl2/releases/download/v2.30.9-r1/SDL2-2.30.9-r1-darwin64-11943333704.tar.zst</string>
</map>
<key>name</key>
<string>darwin64</string>
</map>
<key>windows64</key>
<map>
<key>archive</key>
<map>
<key>hash</key>
<string>97153f9d302f964142df971b57680724824f458f</string>
<key>hash_algorithm</key>
<string>sha1</string>
<key>url</key>
<string>https://github.com/secondlife/3p-sdl2/releases/download/v2.30.9-r1/SDL2-2.30.9-r1-windows64-11943333704.tar.zst</string>
</map>
<key>name</key>
<string>windows64</string>
</map>
</map>
<key>license</key>
<string>lgpl</string>
<key>license_file</key>
<string>LICENSES/SDL2.txt</string>
<string>LICENSES/SDL3.txt</string>
<key>copyright</key>
<string>Copyright (C) 1997-2022 Sam Lantinga (slouken@libsdl.org)</string>
<key>version</key>
<string>2.30.9-r1</string>
<string>3.2.24-r1</string>
<key>name</key>
<string>SDL2</string>
<string>SDL3</string>
<key>description</key>
<string>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.</string>
</map>
Expand Down
72 changes: 41 additions & 31 deletions build-cmd.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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
19 changes: 16 additions & 3 deletions libndofdev/Makefile
Original file line number Diff line number Diff line change
@@ -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


Expand Down
2 changes: 1 addition & 1 deletion libndofdev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 !!!
Expand Down
84 changes: 79 additions & 5 deletions libndofdev/ndofdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
#include <stdlib.h>
#include <unistd.h>

#ifdef USE_SDL2
#ifdef USE_SDL3
#include <SDL3/SDL.h>
#elif defined(USE_SDL2)
#include <SDL2/SDL.h>
#else
#include <SDL/SDL.h>
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down