early-access version 1617
This commit is contained in:
2
externals/SDL/test/CMakeLists.txt
vendored
2
externals/SDL/test/CMakeLists.txt
vendored
@@ -94,7 +94,7 @@ add_executable(testoffscreen testoffscreen.c)
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c "int main(int argc, const char **argv){ return 1; }\n")
|
||||
add_executable(SDL2_test_resoureces ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c)
|
||||
|
||||
file(GLOB RESOURCE_FILES *.bmp *.wav)
|
||||
file(GLOB RESOURCE_FILES *.bmp *.wav moose.dat utf8.txt)
|
||||
foreach(RESOURCE_FILE ${RESOURCE_FILES})
|
||||
add_custom_command(TARGET SDL2_test_resoureces POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:SDL2_test_resoureces>)
|
||||
endforeach(RESOURCE_FILE)
|
||||
|
16
externals/SDL/test/Makefile.in
vendored
16
externals/SDL/test/Makefile.in
vendored
@@ -24,6 +24,7 @@ TARGETS = \
|
||||
testdrawchessboard$(EXE) \
|
||||
testdropfile$(EXE) \
|
||||
testerror$(EXE) \
|
||||
testevdev$(EXE) \
|
||||
testfile$(EXE) \
|
||||
testfilesystem$(EXE) \
|
||||
testgamecontroller$(EXE) \
|
||||
@@ -37,6 +38,7 @@ TARGETS = \
|
||||
testjoystick$(EXE) \
|
||||
testkeys$(EXE) \
|
||||
testloadso$(EXE) \
|
||||
testlocale$(EXE) \
|
||||
testlock$(EXE) \
|
||||
testmessage$(EXE) \
|
||||
testmultiaudio$(EXE) \
|
||||
@@ -59,6 +61,7 @@ TARGETS = \
|
||||
teststreaming$(EXE) \
|
||||
testthread$(EXE) \
|
||||
testtimer$(EXE) \
|
||||
testurl$(EXE) \
|
||||
testver$(EXE) \
|
||||
testviewport$(EXE) \
|
||||
testvulkan$(EXE) \
|
||||
@@ -146,6 +149,9 @@ testdropfile$(EXE): $(srcdir)/testdropfile.c
|
||||
testerror$(EXE): $(srcdir)/testerror.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testevdev$(EXE): $(srcdir)/testevdev.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testfile$(EXE): $(srcdir)/testfile.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
@@ -264,6 +270,9 @@ teststreaming$(EXE): $(srcdir)/teststreaming.c
|
||||
testtimer$(EXE): $(srcdir)/testtimer.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testurl$(EXE): $(srcdir)/testurl.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testver$(EXE): $(srcdir)/testver.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
@@ -303,6 +312,10 @@ controllermap$(EXE): $(srcdir)/controllermap.c
|
||||
testvulkan$(EXE): $(srcdir)/testvulkan.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testlocale$(EXE): $(srcdir)/testlocale.c
|
||||
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
rm -f $(TARGETS)
|
||||
@@ -312,7 +325,7 @@ distclean: clean
|
||||
rm -f config.status config.cache config.log
|
||||
rm -rf $(srcdir)/autom4te*
|
||||
|
||||
|
||||
ifneq ($(srcdir), .)
|
||||
%.bmp: $(srcdir)/%.bmp
|
||||
cp $< $@
|
||||
|
||||
@@ -321,6 +334,7 @@ distclean: clean
|
||||
|
||||
%.dat: $(srcdir)/%.dat
|
||||
cp $< $@
|
||||
endif
|
||||
|
||||
copydatafiles: copybmpfiles copywavfiles copydatfiles
|
||||
.PHONY : copydatafiles
|
||||
|
10
externals/SDL/test/Makefile.os2
vendored
10
externals/SDL/test/Makefile.os2
vendored
@@ -3,7 +3,7 @@ BINPATH = .
|
||||
TARGETS = testatomic.exe testdisplayinfo.exe testbounds.exe testdraw2.exe &
|
||||
testdrawchessboard.exe testdropfile.exe testerror.exe testfile.exe &
|
||||
testfilesystem.exe testgamecontroller.exe testgesture.exe &
|
||||
testhittesting.exe testhotplug.exe testiconv.exe testime.exe &
|
||||
testhittesting.exe testhotplug.exe testiconv.exe testime.exe testlocale.exe &
|
||||
testintersections.exe testjoystick.exe testkeys.exe testloadso.exe &
|
||||
testlock.exe testmessage.exe testoverlay2.exe testplatform.exe &
|
||||
testpower.exe testsensor.exe testrelative.exe testrendercopyex.exe &
|
||||
@@ -13,7 +13,7 @@ TARGETS = testatomic.exe testdisplayinfo.exe testbounds.exe testdraw2.exe &
|
||||
testviewport.exe testwm2.exe torturethread.exe checkkeys.exe &
|
||||
controllermap.exe testhaptic.exe testqsort.exe testresample.exe &
|
||||
testaudioinfo.exe testaudiocapture.exe loopwave.exe loopwavequeue.exe &
|
||||
testyuv.exe testgl2.exe testvulkan.exe testautomation.exe
|
||||
testyuv.exe testgl2.exe testvulkan.exe testnative.exe testautomation.exe
|
||||
|
||||
# SDL2test.lib sources (../src/test)
|
||||
|
||||
@@ -55,7 +55,7 @@ LIBS = SDL2.lib $(TESTLIB)
|
||||
.c: ../src/test
|
||||
|
||||
$(TESTLIB): $(COBJS)
|
||||
wlib -q -b -n $@ $(COBJS)
|
||||
wlib -q -b -n -c $@ $(COBJS)
|
||||
|
||||
.obj.exe:
|
||||
@%make $(TESTLIB)
|
||||
@@ -69,6 +69,10 @@ testautomation.exe: $(TAOBJS)
|
||||
@%make $(TESTLIB)
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
|
||||
|
||||
testnative.exe: testnative.obj testnativeos2.obj
|
||||
@%make $(TESTLIB)
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
|
||||
|
||||
testoverlay2.exe: testoverlay2.obj testyuv_cvt.obj
|
||||
@%make $(TESTLIB)
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
|
||||
|
1
externals/SDL/test/README
vendored
1
externals/SDL/test/README
vendored
@@ -12,6 +12,7 @@ These are test programs for the SDL library:
|
||||
testjoystick List joysticks and watch joystick events
|
||||
testkeys List the available keyboard keys
|
||||
testloadso Tests the loadable library layer
|
||||
testlocale Test Locale API
|
||||
testlock Hacked up test of multi-threading and locking
|
||||
testmultiaudio Tests using several audio devices
|
||||
testoverlay2 Tests the overlay flickering/scaling during playback.
|
||||
|
36
externals/SDL/test/acinclude.m4
vendored
36
externals/SDL/test/acinclude.m4
vendored
@@ -7,7 +7,7 @@
|
||||
|
||||
# serial 1
|
||||
|
||||
dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
|
||||
dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
|
||||
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
|
||||
dnl
|
||||
AC_DEFUN([AM_PATH_SDL2],
|
||||
@@ -21,7 +21,7 @@ AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL
|
||||
AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
|
||||
, enable_sdltest=yes)
|
||||
|
||||
min_sdl_version=ifelse([$1], ,0.9.0,$1)
|
||||
min_sdl_version=ifelse([$1], ,2.0.0,$1)
|
||||
|
||||
if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
|
||||
PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
|
||||
@@ -31,42 +31,42 @@ AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run
|
||||
sdl_pc=no
|
||||
if test x$sdl_exec_prefix != x ; then
|
||||
sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
|
||||
if test x${SDL_CONFIG+set} != xset ; then
|
||||
SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
|
||||
if test x${SDL2_CONFIG+set} != xset ; then
|
||||
SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config
|
||||
fi
|
||||
fi
|
||||
if test x$sdl_prefix != x ; then
|
||||
sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
|
||||
if test x${SDL_CONFIG+set} != xset ; then
|
||||
SDL_CONFIG=$sdl_prefix/bin/sdl2-config
|
||||
if test x${SDL2_CONFIG+set} != xset ; then
|
||||
SDL2_CONFIG=$sdl_prefix/bin/sdl2-config
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x$sdl_pc" = xyes ; then
|
||||
no_sdl=""
|
||||
SDL_CONFIG="pkg-config sdl2"
|
||||
SDL2_CONFIG="pkg-config sdl2"
|
||||
else
|
||||
as_save_PATH="$PATH"
|
||||
if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
|
||||
PATH="$prefix/bin:$prefix/usr/bin:$PATH"
|
||||
fi
|
||||
AC_PATH_PROG(SDL_CONFIG, sdl2-config, no, [$PATH])
|
||||
AC_PATH_PROG(SDL2_CONFIG, sdl2-config, no, [$PATH])
|
||||
PATH="$as_save_PATH"
|
||||
AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
|
||||
no_sdl=""
|
||||
|
||||
if test "$SDL_CONFIG" = "no" ; then
|
||||
if test "$SDL2_CONFIG" = "no" ; then
|
||||
no_sdl=yes
|
||||
else
|
||||
SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
|
||||
SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
|
||||
SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags`
|
||||
SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs`
|
||||
|
||||
sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
|
||||
sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
|
||||
sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
|
||||
if test "x$enable_sdltest" = "xyes" ; then
|
||||
ac_save_CFLAGS="$CFLAGS"
|
||||
@@ -130,7 +130,7 @@ int main (int argc, char *argv[])
|
||||
printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
|
||||
printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
|
||||
printf("*** best to upgrade to the required version.\n");
|
||||
printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
|
||||
printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n");
|
||||
printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
|
||||
printf("*** config.cache before re-running configure\n");
|
||||
return 1;
|
||||
@@ -152,10 +152,10 @@ int main (int argc, char *argv[])
|
||||
if test "x$no_sdl" = x ; then
|
||||
ifelse([$2], , :, [$2])
|
||||
else
|
||||
if test "$SDL_CONFIG" = "no" ; then
|
||||
if test "$SDL2_CONFIG" = "no" ; then
|
||||
echo "*** The sdl2-config script installed by SDL could not be found"
|
||||
echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
|
||||
echo "*** your path, or set the SDL_CONFIG environment variable to the"
|
||||
echo "*** your path, or set the SDL2_CONFIG environment variable to the"
|
||||
echo "*** full path to sdl2-config."
|
||||
else
|
||||
if test -f conf.sdltest ; then
|
||||
@@ -186,7 +186,7 @@ int main(int argc, char *argv[])
|
||||
[ echo "*** The test program failed to compile or link. See the file config.log for the"
|
||||
echo "*** exact error that occured. This usually means SDL was incorrectly installed"
|
||||
echo "*** or that you have moved SDL since it was installed. In the latter case, you"
|
||||
echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" ])
|
||||
echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG" ])
|
||||
CFLAGS="$ac_save_CFLAGS"
|
||||
CXXFLAGS="$ac_save_CXXFLAGS"
|
||||
LIBS="$ac_save_LIBS"
|
||||
|
97
externals/SDL/test/configure
vendored
97
externals/SDL/test/configure
vendored
@@ -594,7 +594,7 @@ OPENGLES2_TARGETS
|
||||
OPENGLES1_TARGETS
|
||||
CPP
|
||||
XMKMF
|
||||
SDL_CONFIG
|
||||
SDL2_CONFIG
|
||||
SDL_LIBS
|
||||
SDL_CFLAGS
|
||||
PKG_CONFIG_LIBDIR
|
||||
@@ -1919,6 +1919,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
|
||||
|
||||
ac_aux_dir=
|
||||
for ac_dir in $srcdir/../build-scripts; do
|
||||
if test -f "$ac_dir/install-sh"; then
|
||||
@@ -2020,7 +2021,6 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
|
||||
|
||||
|
||||
|
||||
|
||||
ac_ext=c
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
@@ -2812,7 +2812,6 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5
|
||||
$as_echo_n "checking for an ANSI C-conforming const... " >&6; }
|
||||
if ${ac_cv_c_const+:} false; then :
|
||||
@@ -3226,21 +3225,21 @@ fi
|
||||
sdl_pc=no
|
||||
if test x$sdl_exec_prefix != x ; then
|
||||
sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
|
||||
if test x${SDL_CONFIG+set} != xset ; then
|
||||
SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
|
||||
if test x${SDL2_CONFIG+set} != xset ; then
|
||||
SDL2_CONFIG=$sdl_exec_prefix/bin/sdl2-config
|
||||
fi
|
||||
fi
|
||||
if test x$sdl_prefix != x ; then
|
||||
sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
|
||||
if test x${SDL_CONFIG+set} != xset ; then
|
||||
SDL_CONFIG=$sdl_prefix/bin/sdl2-config
|
||||
if test x${SDL2_CONFIG+set} != xset ; then
|
||||
SDL2_CONFIG=$sdl_prefix/bin/sdl2-config
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x$sdl_pc" = xyes ; then
|
||||
no_sdl=""
|
||||
SDL_CONFIG="pkg-config sdl2"
|
||||
SDL2_CONFIG="pkg-config sdl2"
|
||||
else
|
||||
as_save_PATH="$PATH"
|
||||
if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
|
||||
@@ -3250,12 +3249,12 @@ fi
|
||||
set dummy sdl2-config; ac_word=$2
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
|
||||
$as_echo_n "checking for $ac_word... " >&6; }
|
||||
if ${ac_cv_path_SDL_CONFIG+:} false; then :
|
||||
if ${ac_cv_path_SDL2_CONFIG+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
case $SDL_CONFIG in
|
||||
case $SDL2_CONFIG in
|
||||
[\\/]* | ?:[\\/]*)
|
||||
ac_cv_path_SDL_CONFIG="$SDL_CONFIG" # Let the user override the test with a path.
|
||||
ac_cv_path_SDL2_CONFIG="$SDL2_CONFIG" # Let the user override the test with a path.
|
||||
;;
|
||||
*)
|
||||
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
|
||||
@@ -3265,7 +3264,7 @@ do
|
||||
test -z "$as_dir" && as_dir=.
|
||||
for ac_exec_ext in '' $ac_executable_extensions; do
|
||||
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
|
||||
ac_cv_path_SDL_CONFIG="$as_dir/$ac_word$ac_exec_ext"
|
||||
ac_cv_path_SDL2_CONFIG="$as_dir/$ac_word$ac_exec_ext"
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
|
||||
break 2
|
||||
fi
|
||||
@@ -3273,14 +3272,14 @@ done
|
||||
done
|
||||
IFS=$as_save_IFS
|
||||
|
||||
test -z "$ac_cv_path_SDL_CONFIG" && ac_cv_path_SDL_CONFIG="no"
|
||||
test -z "$ac_cv_path_SDL2_CONFIG" && ac_cv_path_SDL2_CONFIG="no"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
SDL_CONFIG=$ac_cv_path_SDL_CONFIG
|
||||
if test -n "$SDL_CONFIG"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SDL_CONFIG" >&5
|
||||
$as_echo "$SDL_CONFIG" >&6; }
|
||||
SDL2_CONFIG=$ac_cv_path_SDL2_CONFIG
|
||||
if test -n "$SDL2_CONFIG"; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SDL2_CONFIG" >&5
|
||||
$as_echo "$SDL2_CONFIG" >&6; }
|
||||
else
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
@@ -3292,17 +3291,17 @@ fi
|
||||
$as_echo_n "checking for SDL - version >= $min_sdl_version... " >&6; }
|
||||
no_sdl=""
|
||||
|
||||
if test "$SDL_CONFIG" = "no" ; then
|
||||
if test "$SDL2_CONFIG" = "no" ; then
|
||||
no_sdl=yes
|
||||
else
|
||||
SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
|
||||
SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
|
||||
SDL_CFLAGS=`$SDL2_CONFIG $sdl_config_args --cflags`
|
||||
SDL_LIBS=`$SDL2_CONFIG $sdl_config_args --libs`
|
||||
|
||||
sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sdl_major_version=`$SDL2_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/'`
|
||||
sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sdl_minor_version=`$SDL2_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/'`
|
||||
sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
|
||||
sdl_micro_version=`$SDL2_CONFIG $sdl_config_args --version | \
|
||||
sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/'`
|
||||
if test "x$enable_sdltest" = "xyes" ; then
|
||||
ac_save_CFLAGS="$CFLAGS"
|
||||
@@ -3367,7 +3366,7 @@ int main (int argc, char *argv[])
|
||||
printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
|
||||
printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
|
||||
printf("*** best to upgrade to the required version.\n");
|
||||
printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
|
||||
printf("*** If sdl2-config was wrong, set the environment variable SDL2_CONFIG\n");
|
||||
printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
|
||||
printf("*** config.cache before re-running configure\n");
|
||||
return 1;
|
||||
@@ -3401,10 +3400,10 @@ $as_echo "no" >&6; }
|
||||
if test "x$no_sdl" = x ; then
|
||||
:
|
||||
else
|
||||
if test "$SDL_CONFIG" = "no" ; then
|
||||
if test "$SDL2_CONFIG" = "no" ; then
|
||||
echo "*** The sdl2-config script installed by SDL could not be found"
|
||||
echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
|
||||
echo "*** your path, or set the SDL_CONFIG environment variable to the"
|
||||
echo "*** your path, or set the SDL2_CONFIG environment variable to the"
|
||||
echo "*** full path to sdl2-config."
|
||||
else
|
||||
if test -f conf.sdltest ; then
|
||||
@@ -3447,7 +3446,7 @@ else
|
||||
echo "*** The test program failed to compile or link. See the file config.log for the"
|
||||
echo "*** exact error that occured. This usually means SDL was incorrectly installed"
|
||||
echo "*** or that you have moved SDL since it was installed. In the latter case, you"
|
||||
echo "*** may want to edit the sdl2-config script: $SDL_CONFIG"
|
||||
echo "*** may want to edit the sdl2-config script: $SDL2_CONFIG"
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
@@ -3626,8 +3625,34 @@ else
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
# One or both of the vars are not set, and there is no cached value.
|
||||
ac_x_includes=no ac_x_libraries=no
|
||||
rm -f -r conftest.dir
|
||||
ac_x_includes=no
|
||||
ac_x_libraries=no
|
||||
# Do we need to do anything special at all?
|
||||
ac_save_LIBS=$LIBS
|
||||
LIBS="-lX11 $LIBS"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
#include <X11/Xlib.h>
|
||||
int
|
||||
main ()
|
||||
{
|
||||
XrmInitialize ()
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
# We can compile and link X programs with no special options.
|
||||
ac_x_includes=
|
||||
ac_x_libraries=
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS="$ac_save_LIBS"
|
||||
# If that didn't work, only try xmkmf and filesystem searches
|
||||
# for native compilation.
|
||||
if test x"$ac_x_includes" = xno && test "$cross_compiling" = no; then :
|
||||
rm -f -r conftest.dir
|
||||
if mkdir conftest.dir; then
|
||||
cd conftest.dir
|
||||
cat >Imakefile <<'_ACEOF'
|
||||
@@ -3666,7 +3691,7 @@ _ACEOF
|
||||
rm -f -r conftest.dir
|
||||
fi
|
||||
|
||||
# Standard set of common directories for X headers.
|
||||
# Standard set of common directories for X headers.
|
||||
# Check X11 before X11Rn because it is often a symlink to the current release.
|
||||
ac_x_header_dirs='
|
||||
/usr/X11/include
|
||||
@@ -3693,6 +3718,8 @@ ac_x_header_dirs='
|
||||
/usr/local/include/X11R5
|
||||
/usr/local/include/X11R4
|
||||
|
||||
/opt/X11/include
|
||||
|
||||
/usr/X386/include
|
||||
/usr/x386/include
|
||||
/usr/XFree86/include/X11
|
||||
@@ -3766,15 +3793,17 @@ rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
fi # $ac_x_libraries = no
|
||||
|
||||
fi
|
||||
# Record the results.
|
||||
case $ac_x_includes,$ac_x_libraries in #(
|
||||
no,* | *,no | *\'*)
|
||||
no,* | *,no | *\'*) :
|
||||
# Didn't find X, or a directory has "'" in its name.
|
||||
ac_cv_have_x="have_x=no";; #(
|
||||
*)
|
||||
ac_cv_have_x="have_x=no" ;; #(
|
||||
*) :
|
||||
# Record where we found X for the cache.
|
||||
ac_cv_have_x="have_x=yes\
|
||||
ac_x_includes='$ac_x_includes'\
|
||||
ac_x_libraries='$ac_x_libraries'"
|
||||
ac_x_libraries='$ac_x_libraries'" ;;
|
||||
esac
|
||||
fi
|
||||
;; #(
|
||||
|
10
externals/SDL/test/configure.ac
vendored
10
externals/SDL/test/configure.ac
vendored
@@ -1,16 +1,15 @@
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT(README)
|
||||
AC_INIT
|
||||
AC_CONFIG_SRCDIR([README])
|
||||
|
||||
dnl Detect the canonical build and host environments
|
||||
AC_CONFIG_AUX_DIRS($srcdir/../build-scripts)
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
dnl Check for tools
|
||||
|
||||
AC_PROG_CC
|
||||
|
||||
dnl Check for compiler environment
|
||||
|
||||
AC_C_CONST
|
||||
|
||||
dnl We only care about this for building testnative at the moment, so these
|
||||
@@ -42,7 +41,7 @@ case "$host" in
|
||||
*-*-aix*)
|
||||
ISUNIX="true"
|
||||
EXE=""
|
||||
if test x$ac_cv_prog_gcc = xyes; then
|
||||
if test x$ac_cv_c_compiler_gnu = xyes; then
|
||||
CFLAGS="-mthreads"
|
||||
fi
|
||||
SYS_GL_LIBS=""
|
||||
@@ -201,4 +200,5 @@ fi
|
||||
AC_SUBST(SDL_TTF_LIB)
|
||||
|
||||
dnl Finally create all the generated files
|
||||
AC_OUTPUT([Makefile])
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
|
BIN
externals/SDL/test/controllermap.bmp
vendored
BIN
externals/SDL/test/controllermap.bmp
vendored
Binary file not shown.
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 160 KiB |
108
externals/SDL/test/controllermap.c
vendored
108
externals/SDL/test/controllermap.c
vendored
@@ -24,13 +24,8 @@
|
||||
/* Define this for verbose output while mapping controllers */
|
||||
#define DEBUG_CONTROLLERMAP
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 480
|
||||
#else
|
||||
#define SCREEN_WIDTH 512
|
||||
#define SCREEN_HEIGHT 320
|
||||
#endif
|
||||
|
||||
#define MARKER_BUTTON 1
|
||||
#define MARKER_AXIS 2
|
||||
@@ -64,7 +59,7 @@ static struct
|
||||
{ 342, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_X */
|
||||
{ 389, 101, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_Y */
|
||||
{ 174, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{ 233, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{ 232, 128, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{ 289, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{ 75, 154, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{ 305, 230, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
@@ -74,6 +69,12 @@ static struct
|
||||
{ 154, 249, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{ 116, 217, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
{ 186, 217, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
|
||||
{ 232, 174, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_MISC1 */
|
||||
{ 132, 135, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE1 */
|
||||
{ 330, 135, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
|
||||
{ 132, 175, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
|
||||
{ 330, 175, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
|
||||
{ 0, 0, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
|
||||
{ 74, 153, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE */
|
||||
{ 74, 153, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE */
|
||||
{ 74, 153, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE */
|
||||
@@ -112,6 +113,11 @@ static int s_arrBindingOrder[BINDING_COUNT] = {
|
||||
SDL_CONTROLLER_BUTTON_BACK,
|
||||
SDL_CONTROLLER_BUTTON_GUIDE,
|
||||
SDL_CONTROLLER_BUTTON_START,
|
||||
SDL_CONTROLLER_BUTTON_MISC1,
|
||||
SDL_CONTROLLER_BUTTON_PADDLE1,
|
||||
SDL_CONTROLLER_BUTTON_PADDLE2,
|
||||
SDL_CONTROLLER_BUTTON_PADDLE3,
|
||||
SDL_CONTROLLER_BUTTON_PADDLE4,
|
||||
};
|
||||
|
||||
typedef struct
|
||||
@@ -155,6 +161,9 @@ static int s_iCurrentBinding;
|
||||
static Uint32 s_unPendingAdvanceTime;
|
||||
static SDL_bool s_bBindingComplete;
|
||||
|
||||
static SDL_Window *window;
|
||||
static SDL_bool done = SDL_FALSE;
|
||||
|
||||
SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
{
|
||||
@@ -357,34 +366,23 @@ BMergeAxisBindings(int iIndex)
|
||||
static void
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_Texture *background, *button, *axis, *marker;
|
||||
SDL_Texture *background_front, *background_back, *button, *axis, *marker;
|
||||
const char *name = NULL;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Event event;
|
||||
SDL_Rect dst;
|
||||
Uint8 alpha=200, alpha_step = -1;
|
||||
Uint32 alpha_ticks = 0;
|
||||
SDL_JoystickID nJoystickID;
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Game Controller Map", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return;
|
||||
}
|
||||
|
||||
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE);
|
||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
||||
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
|
||||
SDL_RaiseWindow(window);
|
||||
@@ -451,7 +449,12 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
if (s_arrBindingOrder[s_iCurrentBinding] >= SDL_CONTROLLER_BUTTON_PADDLE1 &&
|
||||
s_arrBindingOrder[s_iCurrentBinding] <= SDL_CONTROLLER_BUTTON_PADDLE4) {
|
||||
SDL_RenderCopy(screen, background_back, NULL, NULL);
|
||||
} else {
|
||||
SDL_RenderCopy(screen, background_front, NULL, NULL);
|
||||
}
|
||||
SDL_SetTextureAlphaMod(marker, alpha);
|
||||
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
||||
SDL_RenderCopyEx(screen, marker, NULL, &dst, s_arrBindingDisplay[iElement].angle, NULL, SDL_FLIP_NONE);
|
||||
@@ -473,7 +476,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
if (!pAxisState->m_bMoving) {
|
||||
Sint16 nInitialValue;
|
||||
pAxisState->m_bMoving = SDL_JoystickGetAxisInitialState(joystick, event.jaxis.axis, &nInitialValue);
|
||||
pAxisState->m_nLastValue = nInitialValue;
|
||||
pAxisState->m_nLastValue = nValue;
|
||||
pAxisState->m_nStartingValue = nInitialValue;
|
||||
pAxisState->m_nFarthestValue = nInitialValue;
|
||||
} else if (SDL_abs(nValue - pAxisState->m_nLastValue) <= MAX_ALLOWED_JITTER) {
|
||||
@@ -705,7 +708,6 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
s_arrAxisState = NULL;
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -715,6 +717,8 @@ main(int argc, char *argv[])
|
||||
int i;
|
||||
SDL_Joystick *joystick;
|
||||
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
@@ -724,6 +728,34 @@ main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Game Controller Map", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return 2;
|
||||
}
|
||||
|
||||
while (SDL_NumJoysticks() == 0) {
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Print information about the joysticks */
|
||||
SDL_Log("There are %d joysticks attached\n", SDL_NumJoysticks());
|
||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
||||
@@ -748,28 +780,16 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
if (SDL_NumJoysticks() > 0) {
|
||||
#else
|
||||
if (argv[1]) {
|
||||
#endif
|
||||
int device;
|
||||
#ifdef __ANDROID__
|
||||
device = 0;
|
||||
#else
|
||||
device = atoi(argv[1]);
|
||||
#endif
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
if (joystick == NULL) {
|
||||
SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
|
||||
} else {
|
||||
WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
else {
|
||||
SDL_Log("\n\nUsage: ./controllermap number\nFor example: ./controllermap 0\nOr: ./controllermap 0 >> gamecontrollerdb.txt");
|
||||
joystick = SDL_JoystickOpen(0);
|
||||
if (joystick == NULL) {
|
||||
SDL_Log("Couldn't open joystick 0: %s\n", SDL_GetError());
|
||||
} else {
|
||||
WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
||||
|
||||
return 0;
|
||||
|
BIN
externals/SDL/test/controllermap_back.bmp
vendored
Executable file
BIN
externals/SDL/test/controllermap_back.bmp
vendored
Executable file
Binary file not shown.
After Width: | Height: | Size: 476 KiB |
2
externals/SDL/test/testautomation.c
vendored
2
externals/SDL/test/testautomation.c
vendored
@@ -62,7 +62,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
SDL_sscanf(argv[i + 1], "%"SDL_PRIu64, (long long unsigned int *)&userExecKey);
|
||||
SDL_sscanf(argv[i + 1], "%"SDL_PRIu64, &userExecKey);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
|
8
externals/SDL/test/testautomation_sdltest.c
vendored
8
externals/SDL/test/testautomation_sdltest.c
vendored
@@ -1163,7 +1163,7 @@ sdltest_randomAsciiStringWithMaximumLength(void *arg)
|
||||
|
||||
targetLen = 16 + SDLTest_RandomUint8();
|
||||
result = SDLTest_RandomAsciiStringWithMaximumLength((int) targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", (int) targetLen);
|
||||
SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
|
||||
if (result != NULL) {
|
||||
len = SDL_strlen(result);
|
||||
@@ -1184,7 +1184,7 @@ sdltest_randomAsciiStringWithMaximumLength(void *arg)
|
||||
/* Negative test */
|
||||
targetLen = 0;
|
||||
result = SDLTest_RandomAsciiStringWithMaximumLength((int) targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", (int) targetLen);
|
||||
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
@@ -1217,7 +1217,7 @@ sdltest_randomAsciiStringOfSize(void *arg)
|
||||
/* Positive test */
|
||||
targetLen = 16 + SDLTest_RandomUint8();
|
||||
result = SDLTest_RandomAsciiStringOfSize((int) targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", (int) targetLen);
|
||||
SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL");
|
||||
if (result != NULL) {
|
||||
len = SDL_strlen(result);
|
||||
@@ -1238,7 +1238,7 @@ sdltest_randomAsciiStringOfSize(void *arg)
|
||||
/* Negative test */
|
||||
targetLen = 0;
|
||||
result = SDLTest_RandomAsciiStringOfSize((int) targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", targetLen);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", (int) targetLen);
|
||||
SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
|
1031
externals/SDL/test/testevdev.c
vendored
Executable file
1031
externals/SDL/test/testevdev.c
vendored
Executable file
File diff suppressed because it is too large
Load Diff
573
externals/SDL/test/testgamecontroller.c
vendored
573
externals/SDL/test/testgamecontroller.c
vendored
@@ -24,47 +24,187 @@
|
||||
|
||||
#ifndef SDL_JOYSTICK_DISABLED
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#define SCREEN_WIDTH 480
|
||||
#define SCREEN_HEIGHT 320
|
||||
#else
|
||||
#define SCREEN_WIDTH 512
|
||||
#define SCREEN_HEIGHT 320
|
||||
#endif
|
||||
|
||||
/* This is indexed by SDL_GameControllerButton. */
|
||||
static const struct { int x; int y; } button_positions[] = {
|
||||
{387, 167}, /* A */
|
||||
{431, 132}, /* B */
|
||||
{342, 132}, /* X */
|
||||
{389, 101}, /* Y */
|
||||
{174, 132}, /* BACK */
|
||||
{233, 132}, /* GUIDE */
|
||||
{289, 132}, /* START */
|
||||
{75, 154}, /* LEFTSTICK */
|
||||
{305, 230}, /* RIGHTSTICK */
|
||||
{77, 40}, /* LEFTSHOULDER */
|
||||
{396, 36}, /* RIGHTSHOULDER */
|
||||
{154, 188}, /* DPAD_UP */
|
||||
{154, 249}, /* DPAD_DOWN */
|
||||
{116, 217}, /* DPAD_LEFT */
|
||||
{186, 217}, /* DPAD_RIGHT */
|
||||
{387, 167}, /* SDL_CONTROLLER_BUTTON_A */
|
||||
{431, 132}, /* SDL_CONTROLLER_BUTTON_B */
|
||||
{342, 132}, /* SDL_CONTROLLER_BUTTON_X */
|
||||
{389, 101}, /* SDL_CONTROLLER_BUTTON_Y */
|
||||
{174, 132}, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{232, 128}, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{289, 132}, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{75, 154}, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{305, 230}, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
{77, 40}, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{396, 36}, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{154, 188}, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
|
||||
{154, 249}, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{116, 217}, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
{186, 217}, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
|
||||
{232, 174}, /* SDL_CONTROLLER_BUTTON_MISC1 */
|
||||
{132, 135}, /* SDL_CONTROLLER_BUTTON_PADDLE1 */
|
||||
{330, 135}, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
|
||||
{132, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
|
||||
{330, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
|
||||
};
|
||||
|
||||
/* This is indexed by SDL_GameControllerAxis. */
|
||||
static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{74, 153, 270.0}, /* LEFTX */
|
||||
{74, 153, 0.0}, /* LEFTY */
|
||||
{74, 153, 0.0}, /* LEFTY */
|
||||
{306, 231, 270.0}, /* RIGHTX */
|
||||
{306, 231, 0.0}, /* RIGHTY */
|
||||
{91, -20, 0.0}, /* TRIGGERLEFT */
|
||||
{375, -20, 0.0}, /* TRIGGERRIGHT */
|
||||
{306, 231, 0.0}, /* RIGHTY */
|
||||
{91, -20, 0.0}, /* TRIGGERLEFT */
|
||||
{375, -20, 0.0}, /* TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Texture *background, *button, *axis;
|
||||
SDL_bool set_LED = SDL_FALSE;
|
||||
SDL_Texture *background_front, *background_back, *button, *axis;
|
||||
SDL_GameController *gamecontroller;
|
||||
SDL_GameController **gamecontrollers;
|
||||
int num_controllers = 0;
|
||||
|
||||
static void UpdateWindowTitle()
|
||||
{
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamecontroller) {
|
||||
const char *name = SDL_GameControllerName(gamecontroller);
|
||||
const char *serial = SDL_GameControllerGetSerial(gamecontroller);
|
||||
const char *basetitle = "Game Controller Test: ";
|
||||
const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + (serial ? 3 + SDL_strlen(serial) : 0) + 1;
|
||||
char *title = (char *)SDL_malloc(titlelen);
|
||||
|
||||
retval = SDL_FALSE;
|
||||
done = SDL_FALSE;
|
||||
|
||||
if (title) {
|
||||
SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
|
||||
if (serial) {
|
||||
SDL_strlcat(title, " (", titlelen);
|
||||
SDL_strlcat(title, serial, titlelen);
|
||||
SDL_strlcat(title, ")", titlelen);
|
||||
}
|
||||
SDL_SetWindowTitle(window, title);
|
||||
SDL_free(title);
|
||||
}
|
||||
} else {
|
||||
SDL_SetWindowTitle(window, "Waiting for controller...");
|
||||
}
|
||||
}
|
||||
|
||||
static int FindController(SDL_JoystickID controller_id)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < num_controllers; ++i) {
|
||||
if (controller_id == SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(gamecontrollers[i]))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void AddController(int device_index, SDL_bool verbose)
|
||||
{
|
||||
SDL_JoystickID controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
SDL_GameController *controller;
|
||||
SDL_GameController **controllers;
|
||||
|
||||
controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
if (controller_id < 0) {
|
||||
SDL_Log("Couldn't get controller ID: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
if (FindController(controller_id) >= 0) {
|
||||
/* We already have this controller */
|
||||
return;
|
||||
}
|
||||
|
||||
controller = SDL_GameControllerOpen(device_index);
|
||||
if (!controller) {
|
||||
SDL_Log("Couldn't open controller: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
controllers = (SDL_GameController **)SDL_realloc(gamecontrollers, (num_controllers + 1) * sizeof(*controllers));
|
||||
if (!controllers) {
|
||||
SDL_GameControllerClose(controller);
|
||||
return;
|
||||
}
|
||||
|
||||
controllers[num_controllers++] = controller;
|
||||
gamecontrollers = controllers;
|
||||
gamecontroller = controller;
|
||||
|
||||
if (verbose) {
|
||||
const char *name = SDL_GameControllerName(gamecontroller);
|
||||
SDL_Log("Opened game controller %s\n", name);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_ACCEL)) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling accelerometer\n");
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_ACCEL, SDL_TRUE);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_GYRO)) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling gyro\n");
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_GYRO, SDL_TRUE);
|
||||
}
|
||||
|
||||
UpdateWindowTitle();
|
||||
}
|
||||
|
||||
static void SetController(SDL_JoystickID controller)
|
||||
{
|
||||
int i = FindController(controller);
|
||||
|
||||
if (i < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (gamecontroller != gamecontrollers[i]) {
|
||||
gamecontroller = gamecontrollers[i];
|
||||
UpdateWindowTitle();
|
||||
}
|
||||
}
|
||||
|
||||
static void DelController(SDL_JoystickID controller)
|
||||
{
|
||||
int i = FindController(controller);
|
||||
|
||||
if (i < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_GameControllerClose(gamecontrollers[i]);
|
||||
|
||||
--num_controllers;
|
||||
if (i < num_controllers) {
|
||||
SDL_memcpy(&gamecontrollers[i], &gamecontrollers[i+1], (num_controllers - i) * sizeof(*gamecontrollers));
|
||||
}
|
||||
|
||||
if (num_controllers > 0) {
|
||||
gamecontroller = gamecontrollers[0];
|
||||
} else {
|
||||
gamecontroller = NULL;
|
||||
}
|
||||
UpdateWindowTitle();
|
||||
}
|
||||
|
||||
static SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
@@ -94,27 +234,74 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
return texture;
|
||||
}
|
||||
|
||||
static Uint16 ConvertAxisToRumble(Sint16 axis)
|
||||
{
|
||||
/* Only start rumbling if the axis is past the halfway point */
|
||||
const Sint16 half_axis = (Sint16)SDL_ceil(SDL_JOYSTICK_AXIS_MAX / 2.0f);
|
||||
if (axis > half_axis) {
|
||||
return (Uint16)(axis - half_axis) * 4;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
SDL_GameController *gamecontroller = (SDL_GameController *)arg;
|
||||
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
SDL_bool showing_front = SDL_TRUE;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
SDL_Log("Game controller device %d added.\n", (int) SDL_JoystickGetDeviceInstanceID(event.cdevice.which));
|
||||
AddController(event.cdevice.which, SDL_TRUE);
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERDEVICEREMOVED:
|
||||
SDL_Log("Game controller device %d removed.\n", (int) event.cdevice.which);
|
||||
DelController(event.cdevice.which);
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERTOUCHPADDOWN:
|
||||
case SDL_CONTROLLERTOUCHPADMOTION:
|
||||
case SDL_CONTROLLERTOUCHPADUP:
|
||||
SDL_Log("Controller touchpad %d finger %d %s %.2f, %.2f, %.2f\n",
|
||||
event.ctouchpad.touchpad,
|
||||
event.ctouchpad.finger,
|
||||
(event.type == SDL_CONTROLLERTOUCHPADDOWN ? "pressed at" :
|
||||
(event.type == SDL_CONTROLLERTOUCHPADUP ? "released at" :
|
||||
"moved to")),
|
||||
event.ctouchpad.x,
|
||||
event.ctouchpad.y,
|
||||
event.ctouchpad.pressure);
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERSENSORUPDATE:
|
||||
SDL_Log("Controller sensor %s: %.2f, %.2f, %.2f\n",
|
||||
event.csensor.sensor == SDL_SENSOR_ACCEL ? "accelerometer" :
|
||||
event.csensor.sensor == SDL_SENSOR_GYRO ? "gyro" : "unknown",
|
||||
event.csensor.data[0],
|
||||
event.csensor.data[1],
|
||||
event.csensor.data[2]);
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
if (event.caxis.value <= (-SDL_JOYSTICK_AXIS_MAX / 2) || event.caxis.value >= (SDL_JOYSTICK_AXIS_MAX / 2)) {
|
||||
SetController(event.caxis.which);
|
||||
}
|
||||
SDL_Log("Controller axis %s changed to %d\n", SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
if (event.type == SDL_CONTROLLERBUTTONDOWN) {
|
||||
SetController(event.cbutton.which);
|
||||
}
|
||||
SDL_Log("Controller button %s %s\n", SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
@@ -128,42 +315,99 @@ loop(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
/* Update visual controller state */
|
||||
for (i = 0; i < SDL_CONTROLLER_BUTTON_MAX; ++i) {
|
||||
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
|
||||
const SDL_Rect dst = { button_positions[i].x, button_positions[i].y, 50, 50 };
|
||||
SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, SDL_FLIP_NONE);
|
||||
if (gamecontroller) {
|
||||
/* Show the back of the controller if the paddles are being held */
|
||||
for (i = SDL_CONTROLLER_BUTTON_PADDLE1; i <= SDL_CONTROLLER_BUTTON_PADDLE4; ++i) {
|
||||
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
|
||||
showing_front = SDL_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
|
||||
if (value < -deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
} else if (value > deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle + 180.0;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, showing_front ? background_front : background_back, NULL, NULL);
|
||||
|
||||
/* Update rumble based on trigger state */
|
||||
{
|
||||
Uint16 low_frequency_rumble = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT) * 2;
|
||||
Uint16 high_frequency_rumble = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) * 2;
|
||||
SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
|
||||
if (gamecontroller) {
|
||||
/* Update visual controller state */
|
||||
for (i = 0; i < SDL_CONTROLLER_BUTTON_TOUCHPAD; ++i) {
|
||||
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
|
||||
SDL_bool on_front = (i < SDL_CONTROLLER_BUTTON_PADDLE1 || i > SDL_CONTROLLER_BUTTON_PADDLE4);
|
||||
if (on_front == showing_front) {
|
||||
const SDL_Rect dst = { button_positions[i].x, button_positions[i].y, 50, 50 };
|
||||
SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showing_front) {
|
||||
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
|
||||
if (value < -deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
} else if (value > deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle + 180.0;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Update LED based on left thumbstick position */
|
||||
{
|
||||
Sint16 x = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTX);
|
||||
Sint16 y = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTY);
|
||||
|
||||
if (!set_LED) {
|
||||
set_LED = (x < -8000 || x > 8000 || y > 8000);
|
||||
}
|
||||
if (set_LED) {
|
||||
Uint8 r, g, b;
|
||||
|
||||
if (x < 0) {
|
||||
r = (Uint8)(((int)(~x) * 255) / 32767);
|
||||
b = 0;
|
||||
} else {
|
||||
r = 0;
|
||||
b = (Uint8)(((int)(x) * 255) / 32767);
|
||||
}
|
||||
if (y > 0) {
|
||||
g = (Uint8)(((int)(y) * 255) / 32767);
|
||||
} else {
|
||||
g = 0;
|
||||
}
|
||||
|
||||
SDL_GameControllerSetLED(gamecontroller, r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update rumble based on trigger state */
|
||||
{
|
||||
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
|
||||
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
|
||||
Uint16 low_frequency_rumble = ConvertAxisToRumble(left);
|
||||
Uint16 high_frequency_rumble = ConvertAxisToRumble(right);
|
||||
SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
|
||||
}
|
||||
|
||||
/* Update trigger rumble based on thumbstick state */
|
||||
{
|
||||
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTY);
|
||||
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY);
|
||||
Uint16 left_rumble = ConvertAxisToRumble(~left);
|
||||
Uint16 right_rumble = ConvertAxisToRumble(~right);
|
||||
|
||||
SDL_GameControllerRumbleTriggers(gamecontroller, left_rumble, right_rumble, 250);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (!SDL_GameControllerGetAttached(gamecontroller)) {
|
||||
done = SDL_TRUE;
|
||||
retval = SDL_TRUE; /* keep going, wait for reattach. */
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done) {
|
||||
emscripten_cancel_main_loop();
|
||||
@@ -171,92 +415,17 @@ loop(void *arg)
|
||||
#endif
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
WatchGameController(SDL_GameController * gamecontroller)
|
||||
{
|
||||
const char *name = SDL_GameControllerName(gamecontroller);
|
||||
const char *basetitle = "Game Controller Test: ";
|
||||
const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
|
||||
char *title = (char *)SDL_malloc(titlelen);
|
||||
SDL_Window *window = NULL;
|
||||
|
||||
retval = SDL_FALSE;
|
||||
done = SDL_FALSE;
|
||||
|
||||
if (title) {
|
||||
SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
|
||||
}
|
||||
|
||||
/* Create a window to display controller state */
|
||||
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, 0);
|
||||
SDL_free(title);
|
||||
title = NULL;
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderPresent(screen);
|
||||
SDL_RaiseWindow(window);
|
||||
|
||||
/* scale for platforms that don't give you the window size you asked for. */
|
||||
SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
||||
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
|
||||
|
||||
if (!background || !button || !axis) {
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
SDL_SetTextureColorMod(button, 10, 255, 21);
|
||||
SDL_SetTextureColorMod(axis, 10, 255, 21);
|
||||
|
||||
/* !!! FIXME: */
|
||||
/*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/
|
||||
|
||||
/* Print info about the controller we are watching */
|
||||
SDL_Log("Watching controller %s\n", name ? name : "Unknown Controller");
|
||||
|
||||
/* Loop, getting controller events! */
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop_arg(loop, gamecontroller, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop(gamecontroller);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
screen = NULL;
|
||||
background = NULL;
|
||||
button = NULL;
|
||||
axis = NULL;
|
||||
SDL_DestroyWindow(window);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int nController = 0;
|
||||
int retcode = 0;
|
||||
int controller_count = 0;
|
||||
int controller_index = 0;
|
||||
char guid[64];
|
||||
SDL_GameController *gamecontroller;
|
||||
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
@@ -270,7 +439,7 @@ main(int argc, char *argv[])
|
||||
SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
|
||||
|
||||
/* Print information about the mappings */
|
||||
if (!argv[1]) {
|
||||
if (argv[1] && SDL_strcmp(argv[1], "--mappings") == 0) {
|
||||
SDL_Log("Supported mappings:\n");
|
||||
for (i = 0; i < SDL_GameControllerNumMappings(); ++i) {
|
||||
char *mapping = SDL_GameControllerMappingForIndex(i);
|
||||
@@ -290,9 +459,8 @@ main(int argc, char *argv[])
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
|
||||
guid, sizeof (guid));
|
||||
|
||||
if ( SDL_IsGameController(i) )
|
||||
{
|
||||
nController++;
|
||||
if (SDL_IsGameController(i)) {
|
||||
controller_count++;
|
||||
name = SDL_GameControllerNameForIndex(i);
|
||||
switch (SDL_GameControllerTypeForIndex(i)) {
|
||||
case SDL_CONTROLLER_TYPE_XBOX360:
|
||||
@@ -310,10 +478,14 @@ main(int argc, char *argv[])
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
|
||||
description = "Nintendo Switch Pro Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_VIRTUAL:
|
||||
description = "Virtual Game Controller";
|
||||
break;
|
||||
default:
|
||||
description = "Game Controller";
|
||||
break;
|
||||
}
|
||||
AddController(i, SDL_FALSE);
|
||||
} else {
|
||||
name = SDL_JoystickNameForIndex(i);
|
||||
description = "Joystick";
|
||||
@@ -322,64 +494,71 @@ main(int argc, char *argv[])
|
||||
description, i, name ? name : "Unknown", guid,
|
||||
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i), SDL_JoystickGetDevicePlayerIndex(i));
|
||||
}
|
||||
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks());
|
||||
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", controller_count, SDL_NumJoysticks());
|
||||
|
||||
if (argv[1]) {
|
||||
SDL_bool reportederror = SDL_FALSE;
|
||||
SDL_bool keepGoing = SDL_TRUE;
|
||||
SDL_Event event;
|
||||
int device = atoi(argv[1]);
|
||||
if (device >= SDL_NumJoysticks()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%i is an invalid joystick index.\n", device);
|
||||
retcode = 1;
|
||||
} else {
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(device),
|
||||
guid, sizeof (guid));
|
||||
SDL_Log("Attempting to open device %i, guid %s\n", device, guid);
|
||||
gamecontroller = SDL_GameControllerOpen(device);
|
||||
|
||||
if (gamecontroller != NULL) {
|
||||
SDL_assert(SDL_GameControllerFromInstanceID(SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(gamecontroller))) == gamecontroller);
|
||||
}
|
||||
|
||||
while (keepGoing) {
|
||||
if (gamecontroller == NULL) {
|
||||
if (!reportederror) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open gamecontroller %d: %s\n", device, SDL_GetError());
|
||||
retcode = 1;
|
||||
keepGoing = SDL_FALSE;
|
||||
reportederror = SDL_TRUE;
|
||||
}
|
||||
} else {
|
||||
reportederror = SDL_FALSE;
|
||||
keepGoing = WatchGameController(gamecontroller);
|
||||
SDL_GameControllerClose(gamecontroller);
|
||||
}
|
||||
|
||||
gamecontroller = NULL;
|
||||
if (keepGoing) {
|
||||
SDL_Log("Waiting for attach\n");
|
||||
}
|
||||
while (keepGoing) {
|
||||
SDL_WaitEvent(&event);
|
||||
if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN)
|
||||
|| (event.type == SDL_MOUSEBUTTONDOWN)) {
|
||||
keepGoing = SDL_FALSE;
|
||||
} else if (event.type == SDL_CONTROLLERDEVICEADDED) {
|
||||
gamecontroller = SDL_GameControllerOpen(event.cdevice.which);
|
||||
if (gamecontroller != NULL) {
|
||||
SDL_assert(SDL_GameControllerFromInstanceID(SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(gamecontroller))) == gamecontroller);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Create a window to display controller state */
|
||||
window = SDL_CreateWindow("Game Controller Test", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return 2;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return 2;
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
/* scale for platforms that don't give you the window size you asked for. */
|
||||
SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
|
||||
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE);
|
||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
||||
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
|
||||
|
||||
if (!background_front || !background_back || !button || !axis) {
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return 2;
|
||||
}
|
||||
SDL_SetTextureColorMod(button, 10, 255, 21);
|
||||
SDL_SetTextureColorMod(axis, 10, 255, 21);
|
||||
|
||||
/* !!! FIXME: */
|
||||
/*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/
|
||||
|
||||
if (argv[1] && *argv[1] != '-') {
|
||||
controller_index = SDL_atoi(argv[1]);
|
||||
}
|
||||
if (controller_index < num_controllers) {
|
||||
gamecontroller = gamecontrollers[controller_index];
|
||||
} else {
|
||||
gamecontroller = NULL;
|
||||
}
|
||||
UpdateWindowTitle();
|
||||
|
||||
/* Loop, getting controller events! */
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop_arg(loop, NULL, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop(NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
return retcode;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
369
externals/SDL/test/testjoystick.c
vendored
369
externals/SDL/test/testjoystick.c
vendored
@@ -32,9 +32,62 @@
|
||||
#define SCREEN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_Renderer *screen = NULL;
|
||||
static SDL_Joystick *joystick = NULL;
|
||||
static SDL_bool done = SDL_FALSE;
|
||||
|
||||
static void
|
||||
PrintJoystick(SDL_Joystick *joystick)
|
||||
{
|
||||
const char *type;
|
||||
char guid[64];
|
||||
|
||||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joystick)) == joystick);
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), guid, sizeof (guid));
|
||||
switch (SDL_JoystickGetType(joystick)) {
|
||||
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
|
||||
type = "Game Controller";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_WHEEL:
|
||||
type = "Wheel";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_ARCADE_STICK:
|
||||
type = "Arcade Stick";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_FLIGHT_STICK:
|
||||
type = "Flight Stick";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_DANCE_PAD:
|
||||
type = "Dance Pad";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_GUITAR:
|
||||
type = "Guitar";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_DRUM_KIT:
|
||||
type = "Drum Kit";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_ARCADE_PAD:
|
||||
type = "Arcade Pad";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_THROTTLE:
|
||||
type = "Throttle";
|
||||
break;
|
||||
default:
|
||||
type = "Unknown";
|
||||
break;
|
||||
}
|
||||
SDL_Log("Joystick\n");
|
||||
SDL_Log(" name: %s\n", SDL_JoystickName(joystick));
|
||||
SDL_Log(" type: %s\n", type);
|
||||
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
|
||||
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
|
||||
}
|
||||
|
||||
static void
|
||||
DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
|
||||
@@ -48,72 +101,97 @@ loop(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
SDL_Joystick *joystick = (SDL_Joystick *)arg;
|
||||
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
SDL_SetRenderDrawColor(screen, 0x0, 0x0, 0x0, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderClear(screen);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
SDL_Log("Joystick device %d removed.\n", (int) event.jdevice.which);
|
||||
SDL_Log("Our instance ID is %d\n", (int) SDL_JoystickInstanceID(joystick));
|
||||
break;
|
||||
|
||||
case SDL_JOYAXISMOTION:
|
||||
SDL_Log("Joystick %d axis %d value: %d\n",
|
||||
event.jaxis.which,
|
||||
event.jaxis.axis, event.jaxis.value);
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
SDL_Log("Joystick %d hat %d value:",
|
||||
event.jhat.which, event.jhat.hat);
|
||||
if (event.jhat.value == SDL_HAT_CENTERED)
|
||||
SDL_Log(" centered");
|
||||
if (event.jhat.value & SDL_HAT_UP)
|
||||
SDL_Log(" up");
|
||||
if (event.jhat.value & SDL_HAT_RIGHT)
|
||||
SDL_Log(" right");
|
||||
if (event.jhat.value & SDL_HAT_DOWN)
|
||||
SDL_Log(" down");
|
||||
if (event.jhat.value & SDL_HAT_LEFT)
|
||||
SDL_Log(" left");
|
||||
SDL_Log("\n");
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
SDL_Log("Joystick %d ball %d delta: (%d,%d)\n",
|
||||
event.jball.which,
|
||||
event.jball.ball, event.jball.xrel, event.jball.yrel);
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
SDL_Log("Joystick %d button %d down\n",
|
||||
event.jbutton.which, event.jbutton.button);
|
||||
/* First button triggers a 0.5 second full strength rumble */
|
||||
if (event.jbutton.button == 0) {
|
||||
SDL_JoystickRumble(joystick, 0xFFFF, 0xFFFF, 500);
|
||||
case SDL_JOYDEVICEADDED:
|
||||
SDL_Log("Joystick device %d added.\n", (int) event.jdevice.which);
|
||||
if (!joystick) {
|
||||
joystick = SDL_JoystickOpen(event.jdevice.which);
|
||||
if (joystick) {
|
||||
PrintJoystick(joystick);
|
||||
} else {
|
||||
SDL_Log("Couldn't open joystick: %s\n", SDL_GetError());
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
SDL_Log("Joystick %d button %d up\n",
|
||||
event.jbutton.which, event.jbutton.button);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE) &&
|
||||
(event.key.keysym.sym != SDLK_AC_BACK)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
SDL_Log("Joystick device %d removed.\n", (int) event.jdevice.which);
|
||||
if (event.jdevice.which == SDL_JoystickInstanceID(joystick)) {
|
||||
SDL_JoystickClose(joystick);
|
||||
joystick = SDL_JoystickOpen(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_JOYAXISMOTION:
|
||||
SDL_Log("Joystick %d axis %d value: %d\n",
|
||||
event.jaxis.which,
|
||||
event.jaxis.axis, event.jaxis.value);
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
SDL_Log("Joystick %d hat %d value:",
|
||||
event.jhat.which, event.jhat.hat);
|
||||
if (event.jhat.value == SDL_HAT_CENTERED)
|
||||
SDL_Log(" centered");
|
||||
if (event.jhat.value & SDL_HAT_UP)
|
||||
SDL_Log(" up");
|
||||
if (event.jhat.value & SDL_HAT_RIGHT)
|
||||
SDL_Log(" right");
|
||||
if (event.jhat.value & SDL_HAT_DOWN)
|
||||
SDL_Log(" down");
|
||||
if (event.jhat.value & SDL_HAT_LEFT)
|
||||
SDL_Log(" left");
|
||||
SDL_Log("\n");
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
SDL_Log("Joystick %d ball %d delta: (%d,%d)\n",
|
||||
event.jball.which,
|
||||
event.jball.ball, event.jball.xrel, event.jball.yrel);
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
SDL_Log("Joystick %d button %d down\n",
|
||||
event.jbutton.which, event.jbutton.button);
|
||||
/* First button triggers a 0.5 second full strength rumble */
|
||||
if (event.jbutton.button == 0) {
|
||||
SDL_JoystickRumble(joystick, 0xFFFF, 0xFFFF, 500);
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
SDL_Log("Joystick %d button %d up\n",
|
||||
event.jbutton.which, event.jbutton.button);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
/* Press the L key to lag for 3 seconds, to see what happens
|
||||
when SDL doesn't service the event loop quickly. */
|
||||
if (event.key.keysym.sym == SDLK_l) {
|
||||
SDL_Log("Lagging for 3 seconds...\n");
|
||||
SDL_Delay(3000);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE) &&
|
||||
(event.key.keysym.sym != SDLK_AC_BACK)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (joystick) {
|
||||
|
||||
/* Update visual joystick state */
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumButtons(joystick); ++i) {
|
||||
@@ -172,13 +250,9 @@ loop(void *arg)
|
||||
|
||||
DrawRect(screen, x, y, 8, 8);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (SDL_JoystickGetAttached( joystick ) == 0) {
|
||||
done = SDL_TRUE;
|
||||
retval = SDL_TRUE; /* keep going, wait for reattach. */
|
||||
}
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done) {
|
||||
@@ -187,14 +261,19 @@ loop(void *arg)
|
||||
#endif
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
const char *name = NULL;
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
|
||||
retval = SDL_FALSE;
|
||||
done = SDL_FALSE;
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL (Note: video is required to start event loop) */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Joystick Test", SDL_WINDOWPOS_CENTERED,
|
||||
@@ -215,159 +294,19 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderPresent(screen);
|
||||
SDL_RaiseWindow(window);
|
||||
|
||||
/* Print info about the joystick we are watching */
|
||||
name = SDL_JoystickName(joystick);
|
||||
SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
|
||||
name ? name : "Unknown Joystick");
|
||||
SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
|
||||
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
|
||||
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
|
||||
|
||||
/* Loop, getting joystick events! */
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop_arg(loop, joystick, 0, 1);
|
||||
emscripten_set_main_loop_arg(loop, NULL, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop(joystick);
|
||||
loop(NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
screen = NULL;
|
||||
SDL_DestroyWindow(window);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *name, *type;
|
||||
int i;
|
||||
SDL_Joystick *joystick;
|
||||
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL (Note: video is required to start event loop) */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Print information about the joysticks */
|
||||
SDL_Log("There are %d joysticks attached\n", SDL_NumJoysticks());
|
||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
||||
name = SDL_JoystickNameForIndex(i);
|
||||
SDL_Log("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
|
||||
joystick = SDL_JoystickOpen(i);
|
||||
if (joystick == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
|
||||
SDL_GetError());
|
||||
} else {
|
||||
char guid[64];
|
||||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joystick)) == joystick);
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
|
||||
guid, sizeof (guid));
|
||||
switch (SDL_JoystickGetType(joystick)) {
|
||||
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
|
||||
type = "Game Controller";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_WHEEL:
|
||||
type = "Wheel";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_ARCADE_STICK:
|
||||
type = "Arcade Stick";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_FLIGHT_STICK:
|
||||
type = "Flight Stick";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_DANCE_PAD:
|
||||
type = "Dance Pad";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_GUITAR:
|
||||
type = "Guitar";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_DRUM_KIT:
|
||||
type = "Drum Kit";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_ARCADE_PAD:
|
||||
type = "Arcade Pad";
|
||||
break;
|
||||
case SDL_JOYSTICK_TYPE_THROTTLE:
|
||||
type = "Throttle";
|
||||
break;
|
||||
default:
|
||||
type = "Unknown";
|
||||
break;
|
||||
}
|
||||
SDL_Log(" type: %s\n", type);
|
||||
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
|
||||
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__) || defined(__IPHONEOS__)
|
||||
if (SDL_NumJoysticks() > 0) {
|
||||
#else
|
||||
if (argv[1]) {
|
||||
#endif
|
||||
SDL_bool reportederror = SDL_FALSE;
|
||||
SDL_bool keepGoing = SDL_TRUE;
|
||||
SDL_Event event;
|
||||
int device;
|
||||
#if defined(__ANDROID__) || defined(__IPHONEOS__)
|
||||
device = 0;
|
||||
#else
|
||||
device = atoi(argv[1]);
|
||||
#endif
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
if (joystick != NULL) {
|
||||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joystick)) == joystick);
|
||||
}
|
||||
|
||||
while ( keepGoing ) {
|
||||
if (joystick == NULL) {
|
||||
if ( !reportederror ) {
|
||||
SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
|
||||
keepGoing = SDL_FALSE;
|
||||
reportederror = SDL_TRUE;
|
||||
}
|
||||
} else {
|
||||
reportederror = SDL_FALSE;
|
||||
keepGoing = WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
|
||||
joystick = NULL;
|
||||
if (keepGoing) {
|
||||
SDL_Log("Waiting for attach\n");
|
||||
}
|
||||
while (keepGoing) {
|
||||
SDL_WaitEvent(&event);
|
||||
if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN)
|
||||
|| (event.type == SDL_MOUSEBUTTONDOWN)) {
|
||||
keepGoing = SDL_FALSE;
|
||||
} else if (event.type == SDL_JOYDEVICEADDED) {
|
||||
device = event.jdevice.which;
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
if (joystick != NULL) {
|
||||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joystick)) == joystick);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
|
||||
|
||||
return 0;
|
||||
|
67
externals/SDL/test/testlocale.c
vendored
Executable file
67
externals/SDL/test/testlocale.c
vendored
Executable file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "SDL.h"
|
||||
|
||||
/* !!! FIXME: move this to the test framework */
|
||||
|
||||
static void log_locales(void)
|
||||
{
|
||||
SDL_Locale *locales = SDL_GetPreferredLocales();
|
||||
if (locales == NULL) {
|
||||
SDL_Log("Couldn't determine locales: %s", SDL_GetError());
|
||||
} else {
|
||||
SDL_Locale *l;
|
||||
unsigned int total = 0;
|
||||
SDL_Log("Locales, in order of preference:");
|
||||
for (l = locales; l->language; l++) {
|
||||
const char *c = l->country;
|
||||
SDL_Log(" - %s%s%s", l->language, c ? "_" : "", c ? c : "");
|
||||
total++;
|
||||
}
|
||||
SDL_Log("%u locales seen.", total);
|
||||
SDL_free(locales);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Print locales and languages */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != -1) {
|
||||
log_locales();
|
||||
|
||||
if ((argc == 2) && (SDL_strcmp(argv[1], "--listen") == 0)) {
|
||||
SDL_bool keep_going = SDL_TRUE;
|
||||
while (keep_going) {
|
||||
SDL_Event e;
|
||||
while (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT) {
|
||||
keep_going = SDL_FALSE;
|
||||
} else if (e.type == SDL_LOCALECHANGED) {
|
||||
SDL_Log("Saw SDL_LOCALECHANGED event!");
|
||||
log_locales();
|
||||
}
|
||||
}
|
||||
SDL_Delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
18
externals/SDL/test/testmessage.c
vendored
18
externals/SDL/test/testmessage.c
vendored
@@ -106,6 +106,24 @@ main(int argc, char *argv[])
|
||||
quit(1);
|
||||
}
|
||||
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
NULL,
|
||||
"NULL Title",
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"NULL Message",
|
||||
NULL,
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
/* Google says this is Traditional Chinese for "beef with broccoli" */
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"UTF-8 Simple MessageBox",
|
||||
|
3
externals/SDL/test/testnative.c
vendored
3
externals/SDL/test/testnative.c
vendored
@@ -31,6 +31,9 @@ static NativeWindowFactory *factories[] = {
|
||||
#endif
|
||||
#ifdef TEST_NATIVE_COCOA
|
||||
&CocoaWindowFactory,
|
||||
#endif
|
||||
#ifdef TEST_NATIVE_OS2
|
||||
&OS2WindowFactory,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
5
externals/SDL/test/testnative.h
vendored
5
externals/SDL/test/testnative.h
vendored
@@ -44,3 +44,8 @@ extern NativeWindowFactory X11WindowFactory;
|
||||
#define TEST_NATIVE_COCOA
|
||||
extern NativeWindowFactory CocoaWindowFactory;
|
||||
#endif
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_OS2
|
||||
#define TEST_NATIVE_OS2
|
||||
extern NativeWindowFactory OS2WindowFactory;
|
||||
#endif
|
||||
|
59
externals/SDL/test/testnativeos2.c
vendored
Executable file
59
externals/SDL/test/testnativeos2.c
vendored
Executable file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
|
||||
#include "testnative.h"
|
||||
|
||||
#ifdef TEST_NATIVE_OS2
|
||||
|
||||
#define WIN_CLIENT_CLASS "SDL Test"
|
||||
|
||||
static void *CreateWindowNative(int w, int h);
|
||||
static void DestroyWindowNative(void *window);
|
||||
|
||||
NativeWindowFactory OS2WindowFactory = {
|
||||
"DIVE",
|
||||
CreateWindowNative,
|
||||
DestroyWindowNative
|
||||
};
|
||||
|
||||
static void *CreateWindowNative(int w, int h)
|
||||
{
|
||||
HWND hwnd;
|
||||
HWND hwndFrame;
|
||||
ULONG ulFrameFlags = FCF_TASKLIST | FCF_DLGBORDER | FCF_TITLEBAR |
|
||||
FCF_SYSMENU | FCF_SHELLPOSITION |
|
||||
FCF_SIZEBORDER | FCF_MINBUTTON | FCF_MAXBUTTON;
|
||||
|
||||
WinRegisterClass( 0, WIN_CLIENT_CLASS, WinDefWindowProc,
|
||||
CS_SIZEREDRAW | CS_MOVENOTIFY,
|
||||
sizeof(ULONG) ); // We should have minimum 4 bytes.
|
||||
|
||||
hwndFrame = WinCreateStdWindow( HWND_DESKTOP, 0, &ulFrameFlags,
|
||||
WIN_CLIENT_CLASS, "SDL Test", 0, 0, 1, &hwnd );
|
||||
if ( hwndFrame == NULLHANDLE )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
WinSetWindowPos( hwndFrame, HWND_TOP, 0, 0, w, h,
|
||||
SWP_ZORDER | SWP_ACTIVATE | SWP_SIZE | SWP_SHOW );
|
||||
|
||||
return (void *)hwndFrame; // We may returns client or frame window handle
|
||||
// for SDL_CreateWindowFrom().
|
||||
}
|
||||
|
||||
static void DestroyWindowNative(void *window)
|
||||
{
|
||||
WinDestroyWindow( (HWND)window );
|
||||
}
|
||||
|
||||
#endif /* TEST_NATIVE_OS2 */
|
1
externals/SDL/test/testspriteminimal.c
vendored
1
externals/SDL/test/testspriteminimal.c
vendored
@@ -38,6 +38,7 @@ int done;
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
|
2
externals/SDL/test/testtimer.c
vendored
2
externals/SDL/test/testtimer.c
vendored
@@ -107,7 +107,7 @@ main(int argc, char *argv[])
|
||||
now = SDL_GetPerformanceCounter();
|
||||
SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
|
||||
|
||||
SDL_Log("Performance counter frequency: %"SDL_PRIu64"\n", (unsigned long long) SDL_GetPerformanceFrequency());
|
||||
SDL_Log("Performance counter frequency: %"SDL_PRIu64"\n", SDL_GetPerformanceFrequency());
|
||||
start32 = SDL_GetTicks();
|
||||
start = SDL_GetPerformanceCounter();
|
||||
SDL_Delay(1000);
|
||||
|
36
externals/SDL/test/testurl.c
vendored
Executable file
36
externals/SDL/test/testurl.c
vendored
Executable file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely.
|
||||
*/
|
||||
#include "SDL.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
if (SDL_Init(SDL_INIT_VIDEO) == -1) {
|
||||
SDL_Log("SDL_Init failed: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *url = argv[i];
|
||||
SDL_Log("Opening '%s' ...", url);
|
||||
if (SDL_OpenURL(url) == 0) {
|
||||
SDL_Log(" success!");
|
||||
} else {
|
||||
SDL_Log(" failed! %s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
3
externals/SDL/test/testvulkan.c
vendored
3
externals/SDL/test/testvulkan.c
vendored
@@ -164,8 +164,7 @@ static const char *getVulkanResultString(VkResult result)
|
||||
return "VK_ERROR_OUT_OF_POOL_MEMORY_KHR";
|
||||
case VK_ERROR_INVALID_SHADER_NV:
|
||||
return "VK_ERROR_INVALID_SHADER_NV";
|
||||
case VK_RESULT_MAX_ENUM:
|
||||
case VK_RESULT_RANGE_SIZE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(result < 0)
|
||||
|
Reference in New Issue
Block a user