mirror of https://github.com/encounter/SDL.git
Merged default into iOS-improvements
This commit is contained in:
commit
ea5d1a8a3f
122
CMakeLists.txt
122
CMakeLists.txt
|
@ -2,7 +2,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
|||
message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the SDL source code and call cmake from there")
|
||||
endif()
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(SDL2 C)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckLibraryExists)
|
||||
|
@ -117,6 +117,12 @@ else()
|
|||
set(UNIX_OR_MAC_SYS OFF)
|
||||
endif()
|
||||
|
||||
if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN) # JavaScript does not yet have threading support, so disable pthreads when building for Emscripten.
|
||||
set(PTHREADS_ENABLED_BY_DEFAULT ON)
|
||||
else()
|
||||
set(PTHREADS_ENABLED_BY_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
# Default option knobs
|
||||
if(APPLE OR ARCH_64)
|
||||
set(OPT_DEF_SSEMATH ON)
|
||||
|
@ -144,7 +150,7 @@ if("$ENV{CFLAGS}" STREQUAL "")
|
|||
if(USE_GCC OR USE_CLANG)
|
||||
set(CMAKE_C_FLAGS "-g -O3")
|
||||
endif()
|
||||
else("$ENV{CFLAGS}" STREQUAL "")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS "$ENV{CFLAGS}")
|
||||
list(APPEND EXTRA_CFLAGS "$ENV{CFLAGS}")
|
||||
endif()
|
||||
|
@ -161,7 +167,7 @@ if(MSVC)
|
|||
if(${flag_var} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
||||
endif()
|
||||
endforeach(flag_var)
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
@ -170,13 +176,19 @@ endif()
|
|||
set(SDL_LIBS "-lSDL2")
|
||||
set(SDL_CFLAGS "")
|
||||
|
||||
# Emscripten toolchain has a nonempty default value for this, and the checks
|
||||
# in this file need to change that, so remember the original value, and
|
||||
# restore back to that afterwards. For check_function_exists() to work in
|
||||
# Emscripten, this value must be at its default value.
|
||||
set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
|
||||
|
||||
if(CYGWIN)
|
||||
# We build SDL on cygwin without the UNIX emulation layer
|
||||
include_directories("-I/usr/include/mingw")
|
||||
set(CMAKE_REQUIRED_FLAGS "-mno-cygwin")
|
||||
check_c_source_compiles("int main(int argc, char **argv) {}"
|
||||
HAVE_GCC_NO_CYGWIN)
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
|
||||
if(HAVE_GCC_NO_CYGWIN)
|
||||
list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
|
||||
list(APPEND SDL_LIBS "-mno-cygwin")
|
||||
|
@ -188,12 +200,30 @@ add_definitions(-DUSING_GENERATED_CONFIG_H)
|
|||
# General includes
|
||||
include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)
|
||||
|
||||
# All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so
|
||||
# you only need to have a platform override them if they are disabling.
|
||||
if(EMSCRIPTEN)
|
||||
# Set up default values for the currently supported set of subsystems:
|
||||
# Emscripten/Javascript does not have assembly support, a dynamic library
|
||||
# loading architecture, low-level CPU inspection or multithreading.
|
||||
set(OPT_DEF_ASM FALSE)
|
||||
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
|
||||
set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
|
||||
set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
|
||||
set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
|
||||
set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
|
||||
set(DLOPEN_ENABLED_BY_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
set(SDL_SUBSYSTEMS
|
||||
Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
|
||||
File Loadso CPUinfo Filesystem)
|
||||
foreach(_SUB ${SDL_SUBSYSTEMS})
|
||||
string(TOUPPER ${_SUB} _OPT)
|
||||
option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ON)
|
||||
if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
|
||||
set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
|
||||
endif()
|
||||
option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
|
||||
endforeach()
|
||||
|
||||
option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
|
||||
|
@ -216,9 +246,9 @@ dep_option(FUSIONSOUND_SHARED "Dynamically load fusionsound audio support" ON "
|
|||
set_option(VIDEO_DUMMY "Use dummy video driver" ON)
|
||||
set_option(VIDEO_OPENGL "Include OpenGL support" ON)
|
||||
set_option(VIDEO_OPENGLES "Include OpenGL ES support" ON)
|
||||
set_option(PTHREADS "Use POSIX threads for multi-threading" ${UNIX_OR_MAC_SYS})
|
||||
set_option(PTHREADS "Use POSIX threads for multi-threading" ${PTHREADS_ENABLED_BY_DEFAULT})
|
||||
dep_option(PTHREADS_SEM "Use pthread semaphores" ON "PTHREADS" OFF)
|
||||
set_option(SDL_DLOPEN "Use dlopen for shared object loading" ON)
|
||||
set_option(SDL_DLOPEN "Use dlopen for shared object loading" ${DLOPEN_ENABLED_BY_DEFAULT})
|
||||
set_option(OSS "Support the OSS audio API" ${UNIX_SYS})
|
||||
set_option(ALSA "Support the ALSA audio API" ${UNIX_SYS})
|
||||
dep_option(ALSA_SHARED "Dynamically load ALSA audio support" ON "ALSA" OFF)
|
||||
|
@ -251,7 +281,7 @@ set_option(VIDEO_VIVANTE "Use Vivante EGL video driver" ${UNIX_SYS})
|
|||
|
||||
# TODO: We should (should we?) respect cmake's ${BUILD_SHARED_LIBS} flag here
|
||||
# The options below are for compatibility to configure's default behaviour.
|
||||
set(SDL_SHARED ON CACHE BOOL "Build a shared version of the library")
|
||||
set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
|
||||
set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
|
||||
|
||||
# General source files
|
||||
|
@ -317,7 +347,7 @@ if(USE_GCC OR USE_CLANG)
|
|||
set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
|
||||
check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
|
||||
HAVE_GCC_PREFERRED_STACK_BOUNDARY)
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
|
||||
|
||||
set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
|
||||
check_c_source_compiles("
|
||||
|
@ -328,7 +358,7 @@ if(USE_GCC OR USE_CLANG)
|
|||
if(HAVE_GCC_FVISIBILITY)
|
||||
list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
|
||||
|
||||
check_c_compiler_flag(-Wall HAVE_GCC_WALL)
|
||||
if(HAVE_GCC_WALL)
|
||||
|
@ -376,7 +406,7 @@ if(ASSEMBLY)
|
|||
if(HAVE_MMX)
|
||||
list(APPEND EXTRA_CFLAGS "-mmmx")
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
|
||||
endif()
|
||||
|
||||
if(3DNOW)
|
||||
|
@ -393,7 +423,7 @@ if(ASSEMBLY)
|
|||
if(HAVE_3DNOW)
|
||||
list(APPEND EXTRA_CFLAGS "-m3dnow")
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
|
||||
endif()
|
||||
|
||||
if(SSE)
|
||||
|
@ -416,7 +446,7 @@ if(ASSEMBLY)
|
|||
if(HAVE_SSE)
|
||||
list(APPEND EXTRA_CFLAGS "-msse")
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
|
||||
endif()
|
||||
|
||||
if(SSE2)
|
||||
|
@ -439,7 +469,7 @@ if(ASSEMBLY)
|
|||
if(HAVE_SSE2)
|
||||
list(APPEND EXTRA_CFLAGS "-msse2")
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
|
||||
endif()
|
||||
|
||||
if(SSEMATH)
|
||||
|
@ -464,7 +494,7 @@ if(ASSEMBLY)
|
|||
return vec_splat_u32(0);
|
||||
}
|
||||
int main(int argc, char **argv) { }" HAVE_ALTIVEC)
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
|
||||
if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
|
||||
set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
|
||||
list(APPEND EXTRA_CFLAGS "-maltivec")
|
||||
|
@ -486,7 +516,7 @@ if(ASSEMBLY)
|
|||
set(SDL_ASSEMBLY_ROUTINES 1)
|
||||
endif()
|
||||
# TODO:
|
||||
#else(ASSEMBLY)
|
||||
#else()
|
||||
# if(USE_GCC OR USE_CLANG)
|
||||
# list(APPEND EXTRA_CFLAGS "-mno-sse" "-mno-sse2" "-mno-mmx")
|
||||
# endif()
|
||||
|
@ -518,7 +548,7 @@ if(LIBC)
|
|||
set(HAVE_M_PI 1)
|
||||
add_definitions(-D_USE_MATH_DEFINES) # needed for M_PI
|
||||
set(STDC_HEADERS 1)
|
||||
else(WINDOWS AND NOT MINGW)
|
||||
else()
|
||||
set(HAVE_LIBC TRUE)
|
||||
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
|
||||
foreach(_HEADER
|
||||
|
@ -571,7 +601,7 @@ if(LIBC)
|
|||
|
||||
check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
|
||||
endif()
|
||||
else(LIBC)
|
||||
else()
|
||||
if(WINDOWS)
|
||||
set(HAVE_STDARG_H 1)
|
||||
set(HAVE_STDDEF_H 1)
|
||||
|
@ -642,7 +672,49 @@ if(SDL_VIDEO)
|
|||
endif()
|
||||
|
||||
# Platform-specific options and settings
|
||||
if(UNIX AND NOT APPLE)
|
||||
if(EMSCRIPTEN)
|
||||
# Hide noisy warnings that intend to aid mostly during initial stages of porting a new
|
||||
# project. Uncomment at will for verbose cross-compiling -I/../ path info.
|
||||
add_definitions(-Wno-warn-absolute-paths)
|
||||
if(SDL_AUDIO)
|
||||
set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
|
||||
file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif()
|
||||
if(SDL_FILESYSTEM)
|
||||
set(SDL_FILESYSTEM_EMSCRIPTEN 1)
|
||||
file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
|
||||
set(HAVE_SDL_FILESYSTEM TRUE)
|
||||
endif()
|
||||
if(SDL_JOYSTICK)
|
||||
set(SDL_JOYSTICK_EMSCRIPTEN 1)
|
||||
file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
|
||||
set(HAVE_SDL_JOYSTICK TRUE)
|
||||
endif()
|
||||
if(SDL_POWER)
|
||||
set(SDL_POWER_EMSCRIPTEN 1)
|
||||
file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
|
||||
set(HAVE_SDL_POWER TRUE)
|
||||
endif()
|
||||
if(SDL_VIDEO)
|
||||
set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
|
||||
file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
|
||||
set(HAVE_SDL_VIDEO TRUE)
|
||||
|
||||
#enable gles
|
||||
if(VIDEO_OPENGLES)
|
||||
set(SDL_VIDEO_OPENGL_EGL 1)
|
||||
set(HAVE_VIDEO_OPENGLES TRUE)
|
||||
set(SDL_VIDEO_OPENGL_ES2 1)
|
||||
set(SDL_VIDEO_RENDER_OGL_ES2 1)
|
||||
endif()
|
||||
endif()
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
if(SDL_AUDIO)
|
||||
if(SYSV5 OR SOLARIS OR HPUX)
|
||||
set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
|
||||
|
@ -752,7 +824,7 @@ if(UNIX AND NOT APPLE)
|
|||
if(FOUND_CLOCK_GETTIME)
|
||||
list(APPEND EXTRA_LIBS rt)
|
||||
set(HAVE_CLOCK_GETTIME 1)
|
||||
else(FOUND_CLOCK_GETTIME)
|
||||
else()
|
||||
check_library_exists(c clock_gettime "" FOUND_CLOCK_GETTIME)
|
||||
if(FOUND_CLOCK_GETTIME)
|
||||
set(HAVE_CLOCK_GETTIME 1)
|
||||
|
@ -829,7 +901,7 @@ elseif(WINDOWS)
|
|||
link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
|
||||
include_directories($ENV{DXSDK_DIR}\\Include)
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
|
||||
endif()
|
||||
|
||||
if(SDL_AUDIO)
|
||||
|
@ -1193,14 +1265,14 @@ if(NOT WINDOWS OR CYGWIN)
|
|||
if(SDL_STATIC)
|
||||
set(ENABLE_STATIC_TRUE "")
|
||||
set(ENABLE_STATIC_FALSE "#")
|
||||
else(SDL_STATIC)
|
||||
else()
|
||||
set(ENABLE_STATIC_TRUE "#")
|
||||
set(ENABLE_STATIC_FALSE "")
|
||||
endif()
|
||||
if(SDL_SHARED)
|
||||
set(ENABLE_SHARED_TRUE "")
|
||||
set(ENABLE_SHARED_FALSE "#")
|
||||
else(SDL_SHARED)
|
||||
else()
|
||||
set(ENABLE_SHARED_TRUE "#")
|
||||
set(ENABLE_SHARED_FALSE "")
|
||||
endif()
|
||||
|
@ -1281,7 +1353,7 @@ if(SDL_SHARED)
|
|||
VERSION ${LT_VERSION}
|
||||
SOVERSION ${LT_REVISION}
|
||||
OUTPUT_NAME "SDL2-${LT_RELEASE}")
|
||||
else(UNIX)
|
||||
else()
|
||||
set_target_properties(SDL2 PROPERTIES
|
||||
VERSION ${SDL_VERSION}
|
||||
SOVERSION ${LT_REVISION}
|
||||
|
@ -1330,7 +1402,7 @@ if(NOT WINDOWS OR CYGWIN)
|
|||
if(FREEBSD)
|
||||
# FreeBSD uses ${PREFIX}/libdata/pkgconfig
|
||||
install(FILES ${SDL2_BINARY_DIR}/sdl2.pc DESTINATION "libdata/pkgconfig")
|
||||
else(FREEBSD)
|
||||
else()
|
||||
install(FILES ${SDL2_BINARY_DIR}/sdl2.pc
|
||||
DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
|
||||
endif()
|
||||
|
|
|
@ -1534,6 +1534,8 @@ case $os in
|
|||
-pnacl*)
|
||||
os=-pnacl
|
||||
;;
|
||||
-emscripten*)
|
||||
;;
|
||||
-none)
|
||||
;;
|
||||
*)
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
#!/bin/bash
|
||||
|
||||
SDKDIR="/emsdk_portable"
|
||||
ENVSCRIPT="$SDKDIR/emsdk_env.sh"
|
||||
if [ ! -f "$ENVSCRIPT" ]; then
|
||||
echo "ERROR: This script expects the Emscripten SDK to be in '$SDKDIR'." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARBALL="$1"
|
||||
if [ -z $1 ]; then
|
||||
TARBALL=sdl-emscripten.tar.xz
|
||||
fi
|
||||
|
||||
cd `dirname "$0"`
|
||||
cd ..
|
||||
SDLBASE=`pwd`
|
||||
|
||||
if [ -z "$MAKE" ]; then
|
||||
OSTYPE=`uname -s`
|
||||
if [ "$OSTYPE" == "Linux" ]; then
|
||||
NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
|
||||
let NCPU=$NCPU+1
|
||||
elif [ "$OSTYPE" = "Darwin" ]; then
|
||||
NCPU=`sysctl -n hw.ncpu`
|
||||
elif [ "$OSTYPE" = "SunOS" ]; then
|
||||
NCPU=`/usr/sbin/psrinfo |wc -l |sed -e 's/^ *//g;s/ *$//g'`
|
||||
else
|
||||
NCPU=1
|
||||
fi
|
||||
|
||||
if [ -z "$NCPU" ]; then
|
||||
NCPU=1
|
||||
elif [ "$NCPU" = "0" ]; then
|
||||
NCPU=1
|
||||
fi
|
||||
|
||||
MAKE="make -j$NCPU"
|
||||
fi
|
||||
|
||||
echo "\$MAKE is '$MAKE'"
|
||||
|
||||
echo "Setting up Emscripten SDK environment..."
|
||||
source "$ENVSCRIPT"
|
||||
|
||||
echo "Setting up..."
|
||||
set -x
|
||||
cd "$SDLBASE"
|
||||
rm -rf buildbot
|
||||
mkdir buildbot
|
||||
pushd buildbot
|
||||
|
||||
echo "Configuring..."
|
||||
emconfigure ../configure --host=asmjs-unknown-emscripten --disable-assembly --disable-threads --enable-cpuinfo=false CFLAGS="-O2 -Wno-warn-absolute-paths -Wdeclaration-after-statement -Werror=declaration-after-statement" --prefix="$PWD/emscripten-sdl2-installed"
|
||||
|
||||
echo "Building..."
|
||||
emmake $MAKE
|
||||
|
||||
echo "Moving things around..."
|
||||
emmake $MAKE install
|
||||
# Fix up a few things to a real install path
|
||||
perl -w -pi -e "s#$PWD/emscripten-sdl2-installed#/usr/local#g;" ./emscripten-sdl2-installed/lib/libSDL2.la ./emscripten-sdl2-installed/lib/pkgconfig/sdl2.pc ./emscripten-sdl2-installed/bin/sdl2-config
|
||||
mkdir -p ./usr
|
||||
mv ./emscripten-sdl2-installed ./usr/local
|
||||
popd
|
||||
tar -cJvvf $TARBALL -C buildbot usr
|
||||
rm -rf buildbot
|
||||
|
||||
exit 0
|
||||
|
||||
# end of emscripten-buildbot.sh ...
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
@echo off
|
||||
rem just a helper batch file for collecting up files and zipping them.
|
||||
rem usage: windows-buildbot-zipper.bat <zipfilename>
|
||||
rem must be run from root of SDL source tree.
|
||||
|
||||
IF EXIST VisualC\Win32\Release GOTO okaydir
|
||||
echo Please run from root of source tree after doing a Release build.
|
||||
GOTO done
|
||||
|
||||
:okaydir
|
||||
erase /q /f /s zipper
|
||||
IF EXIST zipper GOTO zippermade
|
||||
mkdir zipper
|
||||
:zippermade
|
||||
cd zipper
|
||||
mkdir SDL
|
||||
cd SDL
|
||||
mkdir include
|
||||
mkdir lib
|
||||
mkdir lib\win32
|
||||
copy ..\..\include\*.h include\
|
||||
copy ..\..\VisualC\Win32\Release\SDL2.dll lib\win32\
|
||||
copy ..\..\VisualC\Win32\Release\SDL2.lib lib\win32\
|
||||
copy ..\..\VisualC\Win32\Release\SDL2main.lib lib\win32\
|
||||
cd ..
|
||||
zip -9r ..\%1 SDL
|
||||
cd ..
|
||||
erase /q /f /s zipper
|
||||
|
||||
:done
|
||||
|
|
@ -39,7 +39,7 @@ macro(CheckDLOPEN)
|
|||
set(_DLLIB ${_LIBNAME})
|
||||
set(HAVE_DLOPEN TRUE)
|
||||
break()
|
||||
endif(DLOPEN_LIB)
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
@ -63,7 +63,7 @@ macro(CheckDLOPEN)
|
|||
set(SOURCE_FILES ${SOURCE_FILES} ${DLOPEN_SOURCES})
|
||||
set(HAVE_SDL_LOADSO TRUE)
|
||||
endif()
|
||||
endmacro(CheckDLOPEN)
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - n/a
|
||||
|
@ -78,23 +78,23 @@ macro(CheckOSS)
|
|||
check_c_source_compiles("
|
||||
#include <soundcard.h>
|
||||
int main() { int arg = SNDCTL_DSP_SETFRAGMENT; }" OSS_FOUND)
|
||||
endif(NOT OSS_FOUND)
|
||||
endif()
|
||||
|
||||
if(OSS_FOUND)
|
||||
set(HAVE_OSS TRUE)
|
||||
file(GLOB OSS_SOURCES ${SDL2_SOURCE_DIR}/src/audio/dsp/*.c)
|
||||
if(OSS_HEADER_FILE STREQUAL "soundcard.h")
|
||||
set(SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H 1)
|
||||
endif(OSS_HEADER_FILE STREQUAL "soundcard.h")
|
||||
endif()
|
||||
set(SDL_AUDIO_DRIVER_OSS 1)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${OSS_SOURCES})
|
||||
if(NETBSD OR OPENBSD)
|
||||
list(APPEND EXTRA_LIBS ossaudio)
|
||||
endif(NETBSD OR OPENBSD)
|
||||
endif()
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif(OSS_FOUND)
|
||||
endif(OSS)
|
||||
endmacro(CheckOSS)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - n/a
|
||||
|
@ -117,14 +117,14 @@ macro(CheckALSA)
|
|||
FindLibraryAndSONAME("asound")
|
||||
set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"")
|
||||
set(HAVE_ALSA_SHARED TRUE)
|
||||
endif(NOT HAVE_DLOPEN)
|
||||
else(ALSA_SHARED)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS asound)
|
||||
endif(ALSA_SHARED)
|
||||
endif()
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif(HAVE_ASOUNDLIB_H)
|
||||
endif(ALSA)
|
||||
endmacro(CheckALSA)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - PkgCheckModules
|
||||
|
@ -147,14 +147,14 @@ macro(CheckPulseAudio)
|
|||
FindLibraryAndSONAME("pulse-simple")
|
||||
set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_SIMPLE_LIB_SONAME}\"")
|
||||
set(HAVE_PULSEAUDIO_SHARED TRUE)
|
||||
endif(NOT HAVE_DLOPEN)
|
||||
else(PULSEAUDIO_SHARED)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS})
|
||||
endif(PULSEAUDIO_SHARED)
|
||||
endif()
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif(PKG_PULSEAUDIO_FOUND)
|
||||
endif(PULSEAUDIO)
|
||||
endmacro(CheckPulseAudio)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - PkgCheckModules
|
||||
|
@ -177,14 +177,14 @@ macro(CheckESD)
|
|||
FindLibraryAndSONAME(esd)
|
||||
set(SDL_AUDIO_DRIVER_ESD_DYNAMIC "\"${ESD_LIB_SONAME}\"")
|
||||
set(HAVE_ESD_SHARED TRUE)
|
||||
endif(NOT HAVE_DLOPEN)
|
||||
else(ESD_SHARED)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND EXTRA_LDFLAGS ${PKG_ESD_LDFLAGS})
|
||||
endif(ESD_SHARED)
|
||||
endif()
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif(PKG_ESD_FOUND)
|
||||
endif(ESD)
|
||||
endmacro(CheckESD)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - n/a
|
||||
|
@ -212,14 +212,14 @@ macro(CheckARTS)
|
|||
FindLibraryAndSONAME(artsc)
|
||||
set(SDL_AUDIO_DRIVER_ARTS_DYNAMIC "\"${ARTSC_LIB_SONAME}\"")
|
||||
set(HAVE_ARTS_SHARED TRUE)
|
||||
endif(NOT HAVE_DLOPEN)
|
||||
else(ARTS_SHARED)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND EXTRA_LDFLAGS ${ARTS_LIBS})
|
||||
endif(ARTS_SHARED)
|
||||
endif()
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif(ARTS_CONFIG)
|
||||
endif(ARTS)
|
||||
endmacro(CheckARTS)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - n/a
|
||||
|
@ -243,14 +243,14 @@ macro(CheckNAS)
|
|||
FindLibraryAndSONAME("audio")
|
||||
set(SDL_AUDIO_DRIVER_NAS_DYNAMIC "\"${AUDIO_LIB_SONAME}\"")
|
||||
set(HAVE_NAS_SHARED TRUE)
|
||||
endif(NOT HAVE_DLOPEN)
|
||||
else(NAS_SHARED)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS ${D_NAS_LIB})
|
||||
endif(NAS_SHARED)
|
||||
endif()
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif(HAVE_NAS_H AND D_NAS_LIB)
|
||||
endif(NAS)
|
||||
endmacro(CheckNAS)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - n/a
|
||||
|
@ -274,14 +274,14 @@ macro(CheckSNDIO)
|
|||
FindLibraryAndSONAME("sndio")
|
||||
set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"")
|
||||
set(HAVE_SNDIO_SHARED TRUE)
|
||||
endif(NOT HAVE_DLOPEN)
|
||||
else(SNDIO_SHARED)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
|
||||
endif(SNDIO_SHARED)
|
||||
endif()
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif(HAVE_SNDIO_H AND D_SNDIO_LIB)
|
||||
endif(SNDIO)
|
||||
endmacro(CheckSNDIO)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - PkgCheckModules
|
||||
|
@ -304,14 +304,14 @@ macro(CheckFusionSound)
|
|||
FindLibraryAndSONAME("fusionsound")
|
||||
set(SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC "\"${FUSIONSOUND_LIB_SONAME}\"")
|
||||
set(HAVE_FUSIONSOUND_SHARED TRUE)
|
||||
endif(NOT HAVE_DLOPEN)
|
||||
else(FUSIONSOUND_SHARED)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND EXTRA_LDFLAGS ${PKG_FUSIONSOUND_LDFLAGS})
|
||||
endif(FUSIONSOUND_SHARED)
|
||||
endif()
|
||||
set(HAVE_SDL_AUDIO TRUE)
|
||||
endif(PKG_FUSIONSOUND_FOUND)
|
||||
endif(FUSIONSOUND)
|
||||
endmacro(CheckFusionSound)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - n/a
|
||||
|
@ -353,34 +353,34 @@ macro(CheckX11)
|
|||
|
||||
if(APPLE)
|
||||
set(X11_SHARED OFF)
|
||||
endif(APPLE)
|
||||
endif()
|
||||
|
||||
check_function_exists("shmat" HAVE_SHMAT)
|
||||
if(NOT HAVE_SHMAT)
|
||||
check_library_exists(ipc shmat "" HAVE_SHMAT)
|
||||
if(HAVE_SHMAT)
|
||||
list(APPEND EXTRA_LIBS ipc)
|
||||
endif(HAVE_SHMAT)
|
||||
endif()
|
||||
if(NOT HAVE_SHMAT)
|
||||
add_definitions(-DNO_SHARED_MEMORY)
|
||||
set(X_CFLAGS "${X_CFLAGS} -DNO_SHARED_MEMORY")
|
||||
endif(NOT HAVE_SHMAT)
|
||||
endif(NOT HAVE_SHMAT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(X11_SHARED)
|
||||
if(NOT HAVE_DLOPEN)
|
||||
message_warn("You must have SDL_LoadObject() support for dynamic X11 loading")
|
||||
set(HAVE_X11_SHARED FALSE)
|
||||
else(NOT HAVE_DLOPEN)
|
||||
else()
|
||||
set(HAVE_X11_SHARED TRUE)
|
||||
endif()
|
||||
if(HAVE_X11_SHARED)
|
||||
set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"")
|
||||
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"")
|
||||
else(HAVE_X11_SHARED)
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS ${X11_LIB} ${XEXT_LIB})
|
||||
endif(HAVE_X11_SHARED)
|
||||
endif(X11_SHARED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(SDL_CFLAGS "${SDL_CFLAGS} ${X_CFLAGS}")
|
||||
|
||||
|
@ -394,7 +394,7 @@ macro(CheckX11)
|
|||
int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
|
||||
if(HAVE_CONST_XEXT_ADDDISPLAY)
|
||||
set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY 1)
|
||||
endif(HAVE_CONST_XEXT_ADDDISPLAY)
|
||||
endif()
|
||||
|
||||
check_c_source_compiles("
|
||||
#include <X11/Xlib.h>
|
||||
|
@ -407,7 +407,7 @@ macro(CheckX11)
|
|||
XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
|
||||
if(HAVE_XGENERICEVENT)
|
||||
set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
|
||||
endif(HAVE_XGENERICEVENT)
|
||||
endif()
|
||||
|
||||
check_c_source_compiles("
|
||||
#include <X11/Xlibint.h>
|
||||
|
@ -415,7 +415,7 @@ macro(CheckX11)
|
|||
int main(int argc, char **argv) {}" HAVE_CONST_XDATA32)
|
||||
if(HAVE_CONST_XDATA32)
|
||||
set(SDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32 1)
|
||||
endif(HAVE_CONST_XDATA32)
|
||||
endif()
|
||||
|
||||
check_function_exists(XkbKeycodeToKeysym SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM)
|
||||
|
||||
|
@ -423,29 +423,29 @@ macro(CheckX11)
|
|||
set(HAVE_VIDEO_X11_XCURSOR TRUE)
|
||||
if(HAVE_X11_SHARED AND XCURSOR_LIB)
|
||||
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"")
|
||||
else(HAVE_X11_SHARED AND XCURSOR_LIB)
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS ${XCURSOR_LIB})
|
||||
endif(HAVE_X11_SHARED AND XCURSOR_LIB)
|
||||
endif()
|
||||
set(SDL_VIDEO_DRIVER_X11_XCURSOR 1)
|
||||
endif(VIDEO_X11_XCURSOR AND HAVE_XCURSOR_H)
|
||||
endif()
|
||||
|
||||
if(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
|
||||
set(HAVE_VIDEO_X11_XINERAMA TRUE)
|
||||
if(HAVE_X11_SHARED AND XINERAMA_LIB)
|
||||
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "\"${XINERAMA_LIB_SONAME}\"")
|
||||
else(HAVE_X11_SHARED AND XINERAMA_LIB)
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS ${XINERAMA_LIB})
|
||||
endif(HAVE_X11_SHARED AND XINERAMA_LIB)
|
||||
endif()
|
||||
set(SDL_VIDEO_DRIVER_X11_XINERAMA 1)
|
||||
endif(VIDEO_X11_XINERAMA AND HAVE_XINERAMA_H)
|
||||
endif()
|
||||
|
||||
if(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
|
||||
set(HAVE_VIDEO_X11_XINPUT TRUE)
|
||||
if(HAVE_X11_SHARED AND XI_LIB)
|
||||
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"")
|
||||
else(HAVE_X11_SHARED AND XI_LIB)
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS ${XI_LIB})
|
||||
endif(HAVE_X11_SHARED AND XI_LIB)
|
||||
endif()
|
||||
set(SDL_VIDEO_DRIVER_X11_XINPUT2 1)
|
||||
|
||||
# Check for multitouch
|
||||
|
@ -462,48 +462,48 @@ macro(CheckX11)
|
|||
int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
|
||||
if(HAVE_XINPUT2_MULTITOUCH)
|
||||
set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
|
||||
endif(HAVE_XINPUT2_MULTITOUCH)
|
||||
endif(VIDEO_X11_XINPUT AND HAVE_XINPUT_H)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
|
||||
if(HAVE_X11_SHARED AND XRANDR_LIB)
|
||||
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"")
|
||||
else(HAVE_X11_SHARED AND XRANDR_LIB)
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS ${XRANDR_LIB})
|
||||
endif(HAVE_X11_SHARED AND XRANDR_LIB)
|
||||
endif()
|
||||
set(SDL_VIDEO_DRIVER_X11_XRANDR 1)
|
||||
set(HAVE_VIDEO_X11_XRANDR TRUE)
|
||||
endif(VIDEO_X11_XRANDR AND HAVE_XRANDR_H)
|
||||
endif()
|
||||
|
||||
if(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
|
||||
if(HAVE_X11_SHARED AND XSS_LIB)
|
||||
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"")
|
||||
else(HAVE_X11_SHARED AND XSS_LIB)
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS ${XSS_LIB})
|
||||
endif(HAVE_X11_SHARED AND XSS_LIB)
|
||||
endif()
|
||||
set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1)
|
||||
set(HAVE_VIDEO_X11_XSCRNSAVER TRUE)
|
||||
endif(VIDEO_X11_XSCRNSAVER AND HAVE_XSS_H)
|
||||
endif()
|
||||
|
||||
if(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
|
||||
set(SDL_VIDEO_DRIVER_X11_XSHAPE 1)
|
||||
set(HAVE_VIDEO_X11_XSHAPE TRUE)
|
||||
endif(VIDEO_X11_XSHAPE AND HAVE_XSHAPE_H)
|
||||
endif()
|
||||
|
||||
if(VIDEO_X11_XVM AND HAVE_XF86VM_H)
|
||||
if(HAVE_X11_SHARED AND XXF86VM_LIB)
|
||||
set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "\"${XXF86VM_LIB_SONAME}\"")
|
||||
else(HAVE_X11_SHARED AND XXF86VM_LIB)
|
||||
else()
|
||||
list(APPEND EXTRA_LIBS ${XXF86VM_LIB})
|
||||
endif(HAVE_X11_SHARED AND XXF86VM_LIB)
|
||||
endif()
|
||||
set(SDL_VIDEO_DRIVER_X11_XVIDMODE 1)
|
||||
set(HAVE_VIDEO_X11_XVM TRUE)
|
||||
endif(VIDEO_X11_XVM AND HAVE_XF86VM_H)
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_LIBRARIES)
|
||||
endif(X11_LIB)
|
||||
endif(VIDEO_X11)
|
||||
endmacro(CheckX11)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
macro(CheckMir)
|
||||
# !!! FIXME: hook up dynamic loading here.
|
||||
|
@ -524,8 +524,8 @@ macro(CheckMir)
|
|||
list(APPEND EXTRA_CFLAGS ${MIR_TOOLKIT_CFLAGS} ${EGL_CLFAGS} ${XKB_CLFLAGS})
|
||||
list(APPEND EXTRA_LDFLAGS ${MIR_TOOLKIT_LDFLAGS} ${EGL_LDLAGS} ${XKB_LDLAGS})
|
||||
endif (MIR_LIB AND MIR_TOOLKIT_FOUND AND EGL_FOUND AND XKB_FOUND)
|
||||
endif(VIDEO_MIR)
|
||||
endmacro(CheckMir)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - EGL
|
||||
|
@ -547,9 +547,9 @@ macro(CheckWayland)
|
|||
file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
|
||||
set(SDL_VIDEO_DRIVER_WAYLAND 1)
|
||||
endif(WAYLAND_FOUND)
|
||||
endif(VIDEO_WAYLAND)
|
||||
endmacro(CheckWayland)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - n/a
|
||||
|
@ -558,16 +558,16 @@ macro(CheckCOCOA)
|
|||
if(VIDEO_COCOA)
|
||||
if(APPLE) # Apple always has Cocoa.
|
||||
set(HAVE_VIDEO_COCOA TRUE)
|
||||
endif(APPLE)
|
||||
endif()
|
||||
if(HAVE_VIDEO_COCOA)
|
||||
file(GLOB COCOA_SOURCES ${SDL2_SOURCE_DIR}/src/video/cocoa/*.m)
|
||||
set_source_files_properties(${COCOA_SOURCES} PROPERTIES LANGUAGE C)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${COCOA_SOURCES})
|
||||
set(SDL_VIDEO_DRIVER_COCOA 1)
|
||||
set(HAVE_SDL_VIDEO TRUE)
|
||||
endif(HAVE_VIDEO_COCOA)
|
||||
endif(VIDEO_COCOA)
|
||||
endmacro(CheckCOCOA)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - PkgCheckModules
|
||||
|
@ -591,14 +591,14 @@ macro(CheckDirectFB)
|
|||
FindLibraryAndSONAME("directfb")
|
||||
set(SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC "\"${DIRECTFB_LIB_SONAME}\"")
|
||||
set(HAVE_DIRECTFB_SHARED TRUE)
|
||||
endif(NOT HAVE_DLOPEN)
|
||||
else(DIRECTFB_SHARED)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND EXTRA_LDFLAGS ${PKG_DIRECTFB_LDFLAGS})
|
||||
endif(DIRECTFB_SHARED)
|
||||
endif()
|
||||
set(HAVE_SDL_VIDEO TRUE)
|
||||
endif(PKG_DIRECTFB_FOUND)
|
||||
endif(VIDEO_DIRECTFB)
|
||||
endmacro(CheckDirectFB)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - n/a
|
||||
|
@ -645,9 +645,9 @@ macro(CheckOpenGLX11)
|
|||
set(SDL_VIDEO_OPENGL_GLX 1)
|
||||
set(SDL_VIDEO_RENDER_OGL 1)
|
||||
list(APPEND EXTRA_LIBS GL)
|
||||
endif(HAVE_VIDEO_OPENGL)
|
||||
endif(VIDEO_OPENGL)
|
||||
endmacro(CheckOpenGLX11)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - nada
|
||||
|
@ -659,7 +659,7 @@ macro(CheckOpenGLESX11)
|
|||
int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
|
||||
if(HAVE_VIDEO_OPENGL_EGL)
|
||||
set(SDL_VIDEO_OPENGL_EGL 1)
|
||||
endif(HAVE_VIDEO_OPENGL_EGL)
|
||||
endif()
|
||||
check_c_source_compiles("
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
|
@ -668,7 +668,7 @@ macro(CheckOpenGLESX11)
|
|||
set(HAVE_VIDEO_OPENGLES TRUE)
|
||||
set(SDL_VIDEO_OPENGL_ES 1)
|
||||
set(SDL_VIDEO_RENDER_OGL_ES 1)
|
||||
endif(HAVE_VIDEO_OPENGLES_V1)
|
||||
endif()
|
||||
check_c_source_compiles("
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
@ -677,10 +677,10 @@ macro(CheckOpenGLESX11)
|
|||
set(HAVE_VIDEO_OPENGLES TRUE)
|
||||
set(SDL_VIDEO_OPENGL_ES2 1)
|
||||
set(SDL_VIDEO_RENDER_OGL_ES2 1)
|
||||
endif(HAVE_VIDEO_OPENGLES_V2)
|
||||
endif()
|
||||
|
||||
endif(VIDEO_OPENGLES)
|
||||
endmacro(CheckOpenGLESX11)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Rquires:
|
||||
# - nada
|
||||
|
@ -729,7 +729,7 @@ macro(CheckPTHREAD)
|
|||
else()
|
||||
set(PTHREAD_CFLAGS "-D_REENTRANT")
|
||||
set(PTHREAD_LDFLAGS "-lpthread")
|
||||
endif(LINUX)
|
||||
endif()
|
||||
|
||||
# Run some tests
|
||||
set(CMAKE_REQUIRED_FLAGS "${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
|
||||
|
@ -756,7 +756,7 @@ macro(CheckPTHREAD)
|
|||
}" HAVE_RECURSIVE_MUTEXES)
|
||||
if(HAVE_RECURSIVE_MUTEXES)
|
||||
set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
|
||||
else(HAVE_RECURSIVE_MUTEXES)
|
||||
else()
|
||||
check_c_source_compiles("
|
||||
#include <pthread.h>
|
||||
int main(int argc, char **argv) {
|
||||
|
@ -766,8 +766,8 @@ macro(CheckPTHREAD)
|
|||
}" HAVE_RECURSIVE_MUTEXES_NP)
|
||||
if(HAVE_RECURSIVE_MUTEXES_NP)
|
||||
set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP 1)
|
||||
endif(HAVE_RECURSIVE_MUTEXES_NP)
|
||||
endif(HAVE_RECURSIVE_MUTEXES)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(PTHREADS_SEM)
|
||||
check_c_source_compiles("#include <pthread.h>
|
||||
|
@ -781,8 +781,8 @@ macro(CheckPTHREAD)
|
|||
sem_timedwait(NULL, NULL);
|
||||
return 0;
|
||||
}" HAVE_SEM_TIMEDWAIT)
|
||||
endif(HAVE_PTHREADS_SEM)
|
||||
endif(PTHREADS_SEM)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
check_c_source_compiles("
|
||||
#include <pthread.h>
|
||||
|
@ -801,14 +801,14 @@ macro(CheckPTHREAD)
|
|||
if(HAVE_PTHREADS_SEM)
|
||||
set(SOURCE_FILES ${SOURCE_FILES}
|
||||
${SDL2_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c)
|
||||
else(HAVE_PTHREADS_SEM)
|
||||
else()
|
||||
set(SOURCE_FILES ${SOURCE_FILES}
|
||||
${SDL2_SOURCE_DIR}/src/thread/generic/SDL_syssem.c)
|
||||
endif(HAVE_PTHREADS_SEM)
|
||||
endif()
|
||||
set(HAVE_SDL_THREADS TRUE)
|
||||
endif(HAVE_PTHREADS)
|
||||
endif(PTHREADS)
|
||||
endmacro(CheckPTHREAD)
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires
|
||||
# - nada
|
||||
|
@ -822,27 +822,27 @@ macro(CheckUSBHID)
|
|||
check_include_file(usbhid.h HAVE_USBHID_H)
|
||||
if(HAVE_USBHID_H)
|
||||
set(USB_CFLAGS "-DHAVE_USBHID_H")
|
||||
endif(HAVE_USBHID_H)
|
||||
endif()
|
||||
|
||||
check_include_file(libusbhid.h HAVE_LIBUSBHID_H)
|
||||
if(HAVE_LIBUSBHID_H)
|
||||
set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H")
|
||||
endif(HAVE_LIBUSBHID_H)
|
||||
endif()
|
||||
set(USB_LIBS ${USB_LIBS} usbhid)
|
||||
else(LIBUSBHID)
|
||||
else()
|
||||
check_include_file(usb.h HAVE_USB_H)
|
||||
if(HAVE_USB_H)
|
||||
set(USB_CFLAGS "-DHAVE_USB_H")
|
||||
endif(HAVE_USB_H)
|
||||
endif()
|
||||
check_include_file(libusb.h HAVE_LIBUSB_H)
|
||||
if(HAVE_LIBUSB_H)
|
||||
set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H")
|
||||
endif(HAVE_LIBUSB_H)
|
||||
endif()
|
||||
check_library_exists(usb hid_init "" LIBUSB)
|
||||
if(LIBUSB)
|
||||
set(USB_LIBS ${USB_LIBS} usb)
|
||||
endif(LIBUSB)
|
||||
endif(LIBUSBHID)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_FLAGS "${USB_CFLAGS}")
|
||||
set(CMAKE_REQUIRED_LIBRARIES "${USB_LIBS}")
|
||||
|
@ -898,7 +898,7 @@ macro(CheckUSBHID)
|
|||
}" HAVE_USBHID_UCR_DATA)
|
||||
if(HAVE_USBHID_UCR_DATA)
|
||||
set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA")
|
||||
endif(HAVE_USBHID_UCR_DATA)
|
||||
endif()
|
||||
|
||||
check_c_source_compiles("
|
||||
#include <sys/types.h>
|
||||
|
@ -926,7 +926,7 @@ macro(CheckUSBHID)
|
|||
}" HAVE_USBHID_NEW)
|
||||
if(HAVE_USBHID_NEW)
|
||||
set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW")
|
||||
endif(HAVE_USBHID_NEW)
|
||||
endif()
|
||||
|
||||
check_c_source_compiles("
|
||||
#include <machine/joystick.h>
|
||||
|
@ -936,7 +936,7 @@ macro(CheckUSBHID)
|
|||
}" HAVE_MACHINE_JOYSTICK)
|
||||
if(HAVE_MACHINE_JOYSTICK)
|
||||
set(SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 1)
|
||||
endif(HAVE_MACHINE_JOYSTICK)
|
||||
endif()
|
||||
set(SDL_JOYSTICK_USBHID 1)
|
||||
file(GLOB BSD_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/bsd/*.c)
|
||||
set(SOURCE_FILES ${SOURCE_FILES} ${BSD_JOYSTICK_SOURCES})
|
||||
|
@ -946,8 +946,8 @@ macro(CheckUSBHID)
|
|||
|
||||
set(CMAKE_REQUIRED_LIBRARIES)
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
endif(HAVE_USBHID)
|
||||
endmacro(CheckUSBHID)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Requires:
|
||||
# - n/a
|
||||
|
|
|
@ -21385,6 +21385,78 @@ $as_echo "#define SDL_VIDEO_RENDER_OGL 1" >>confdefs.h
|
|||
fi
|
||||
}
|
||||
|
||||
CheckEmscriptenGLES()
|
||||
{
|
||||
if test x$enable_video = xyes -a x$enable_video_opengles = xyes; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for EGL support" >&5
|
||||
$as_echo_n "checking for EGL support... " >&6; }
|
||||
video_opengl_egl=no
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
|
||||
video_opengl_egl=yes
|
||||
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $video_opengl_egl" >&5
|
||||
$as_echo "$video_opengl_egl" >&6; }
|
||||
if test x$video_opengl_egl = xyes; then
|
||||
|
||||
$as_echo "#define SDL_VIDEO_OPENGL_EGL 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for OpenGL ES v2 headers" >&5
|
||||
$as_echo_n "checking for OpenGL ES v2 headers... " >&6; }
|
||||
video_opengles_v2=no
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
|
||||
video_opengles_v2=yes
|
||||
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $video_opengles_v2" >&5
|
||||
$as_echo "$video_opengles_v2" >&6; }
|
||||
if test x$video_opengles_v2 = xyes; then
|
||||
|
||||
$as_echo "#define SDL_VIDEO_OPENGL_ES2 1" >>confdefs.h
|
||||
|
||||
|
||||
$as_echo "#define SDL_VIDEO_RENDER_OGL_ES2 1" >>confdefs.h
|
||||
|
||||
SUMMARY_video="${SUMMARY_video} opengl_es2"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
CheckInputEvents()
|
||||
{
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Linux 2.4 unified input interface" >&5
|
||||
|
@ -23483,7 +23555,68 @@ $as_echo "#define SDL_FILESYSTEM_NACL 1" >>confdefs.h
|
|||
SOURCES="$SOURCES $srcdir/src/filesystem/nacl/*.c"
|
||||
have_filesystem=yes
|
||||
fi
|
||||
;;
|
||||
*-*-emscripten* )
|
||||
if test x$enable_video = xyes; then
|
||||
|
||||
$as_echo "#define SDL_VIDEO_DRIVER_EMSCRIPTEN 1" >>confdefs.h
|
||||
|
||||
SOURCES="$SOURCES $srcdir/src/video/emscripten/*.c"
|
||||
have_video=yes
|
||||
SUMMARY_video="${SUMMARY_video} emscripten"
|
||||
fi
|
||||
|
||||
if test x$enable_audio = xyes; then
|
||||
|
||||
$as_echo "#define SDL_AUDIO_DRIVER_EMSCRIPTEN 1" >>confdefs.h
|
||||
|
||||
SOURCES="$SOURCES $srcdir/src/audio/emscripten/*.c"
|
||||
have_audio=yes
|
||||
SUMMARY_audio="${SUMMARY_audio} emscripten"
|
||||
fi
|
||||
|
||||
CheckVisibilityHidden
|
||||
CheckDummyVideo
|
||||
CheckDiskAudio
|
||||
CheckDummyAudio
|
||||
CheckDLOPEN
|
||||
CheckClockGettime
|
||||
CheckEmscriptenGLES
|
||||
|
||||
# Set up files for the power library
|
||||
if test x$enable_power = xyes; then
|
||||
|
||||
$as_echo "#define SDL_POWER_EMSCRIPTEN 1" >>confdefs.h
|
||||
|
||||
SOURCES="$SOURCES $srcdir/src/power/emscripten/*.c"
|
||||
have_power=yes
|
||||
fi
|
||||
|
||||
# Set up files for the power library
|
||||
if test x$enable_joystick = xyes; then
|
||||
|
||||
$as_echo "#define SDL_JOYSTICK_EMSCRIPTEN 1" >>confdefs.h
|
||||
|
||||
SOURCES="$SOURCES $srcdir/src/joystick/emscripten/*.c"
|
||||
have_joystick=yes
|
||||
fi
|
||||
|
||||
# Set up files for the filesystem library
|
||||
if test x$enable_filesystem = xyes; then
|
||||
|
||||
$as_echo "#define SDL_FILESYSTEM_EMSCRIPTEN 1" >>confdefs.h
|
||||
|
||||
SOURCES="$SOURCES $srcdir/src/filesystem/emscripten/*.c"
|
||||
have_filesystem=yes
|
||||
fi
|
||||
# Set up files for the timer library
|
||||
if test x$enable_timers = xyes; then
|
||||
|
||||
$as_echo "#define SDL_TIMER_UNIX 1" >>confdefs.h
|
||||
|
||||
SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
|
||||
have_timers=yes
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
as_fn_error $? "
|
||||
|
|
83
configure.in
83
configure.in
|
@ -2130,6 +2130,40 @@ CheckMacGL()
|
|||
fi
|
||||
}
|
||||
|
||||
CheckEmscriptenGLES()
|
||||
{
|
||||
if test x$enable_video = xyes -a x$enable_video_opengles = xyes; then
|
||||
AC_MSG_CHECKING(for EGL support)
|
||||
video_opengl_egl=no
|
||||
AC_TRY_COMPILE([
|
||||
#include <EGL/egl.h>
|
||||
],[
|
||||
],[
|
||||
video_opengl_egl=yes
|
||||
])
|
||||
AC_MSG_RESULT($video_opengl_egl)
|
||||
if test x$video_opengl_egl = xyes; then
|
||||
AC_DEFINE(SDL_VIDEO_OPENGL_EGL, 1, [ ])
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(for OpenGL ES v2 headers)
|
||||
video_opengles_v2=no
|
||||
AC_TRY_COMPILE([
|
||||
#include <GLES2/gl2.h>
|
||||
#include <GLES2/gl2ext.h>
|
||||
],[
|
||||
],[
|
||||
video_opengles_v2=yes
|
||||
])
|
||||
AC_MSG_RESULT($video_opengles_v2)
|
||||
if test x$video_opengles_v2 = xyes; then
|
||||
AC_DEFINE(SDL_VIDEO_OPENGL_ES2, 1, [ ])
|
||||
AC_DEFINE(SDL_VIDEO_RENDER_OGL_ES2, 1, [ ])
|
||||
SUMMARY_video="${SUMMARY_video} opengl_es2"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
dnl See if we can use the new unified event interface in Linux 2.4
|
||||
CheckInputEvents()
|
||||
{
|
||||
|
@ -3302,7 +3336,56 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
|
|||
SOURCES="$SOURCES $srcdir/src/filesystem/nacl/*.c"
|
||||
have_filesystem=yes
|
||||
fi
|
||||
;;
|
||||
*-*-emscripten* )
|
||||
if test x$enable_video = xyes; then
|
||||
AC_DEFINE(SDL_VIDEO_DRIVER_EMSCRIPTEN, 1, [ ])
|
||||
SOURCES="$SOURCES $srcdir/src/video/emscripten/*.c"
|
||||
have_video=yes
|
||||
SUMMARY_video="${SUMMARY_video} emscripten"
|
||||
fi
|
||||
|
||||
if test x$enable_audio = xyes; then
|
||||
AC_DEFINE(SDL_AUDIO_DRIVER_EMSCRIPTEN, 1, [ ])
|
||||
SOURCES="$SOURCES $srcdir/src/audio/emscripten/*.c"
|
||||
have_audio=yes
|
||||
SUMMARY_audio="${SUMMARY_audio} emscripten"
|
||||
fi
|
||||
|
||||
CheckVisibilityHidden
|
||||
CheckDummyVideo
|
||||
CheckDiskAudio
|
||||
CheckDummyAudio
|
||||
CheckDLOPEN
|
||||
CheckClockGettime
|
||||
CheckEmscriptenGLES
|
||||
|
||||
# Set up files for the power library
|
||||
if test x$enable_power = xyes; then
|
||||
AC_DEFINE(SDL_POWER_EMSCRIPTEN, 1, [ ])
|
||||
SOURCES="$SOURCES $srcdir/src/power/emscripten/*.c"
|
||||
have_power=yes
|
||||
fi
|
||||
|
||||
# Set up files for the power library
|
||||
if test x$enable_joystick = xyes; then
|
||||
AC_DEFINE(SDL_JOYSTICK_EMSCRIPTEN, 1, [ ])
|
||||
SOURCES="$SOURCES $srcdir/src/joystick/emscripten/*.c"
|
||||
have_joystick=yes
|
||||
fi
|
||||
|
||||
# Set up files for the filesystem library
|
||||
if test x$enable_filesystem = xyes; then
|
||||
AC_DEFINE(SDL_FILESYSTEM_EMSCRIPTEN, 1, [ ])
|
||||
SOURCES="$SOURCES $srcdir/src/filesystem/emscripten/*.c"
|
||||
have_filesystem=yes
|
||||
fi
|
||||
# Set up files for the timer library
|
||||
if test x$enable_timers = xyes; then
|
||||
AC_DEFINE(SDL_TIMER_UNIX, 1, [ ])
|
||||
SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
|
||||
have_timers=yes
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
Emscripten
|
||||
================================================================================
|
||||
|
||||
Build:
|
||||
|
||||
$ emconfigure ./configure --host=asmjs-unknown-emscripten --disable-assembly --disable-threads --enable-cpuinfo=false CFLAGS="-O2"
|
||||
$ emmake make
|
||||
|
||||
Or with cmake:
|
||||
|
||||
$ emconfigure cmake ..
|
||||
$ make
|
||||
|
||||
To build one of the tests:
|
||||
|
||||
$ cd test/
|
||||
$ emcc -O2 --js-opts 0 -g4 testdraw2.c -I../include ../build/.libs/libSDL2.a ../build/libSDL2_test.a -o a.html
|
||||
|
||||
Uses GLES2 renderer or software
|
||||
|
||||
tests: https://dl.dropboxusercontent.com/u/17360362/SDL2-em/index.html
|
||||
|
||||
Some other SDL2 libraries can be easily built (assuming SDL2 is installed somewhere):
|
||||
|
||||
SDL_mixer (http://www.libsdl.org/projects/SDL_mixer/)
|
||||
|
||||
$ EMCONFIGURE_JS=1 emconfigure ../configure
|
||||
build as usual...
|
||||
|
||||
SDL_gfx (http://cms.ferzkopp.net/index.php/software/13-sdl-gfx):
|
||||
|
||||
$ EMCONFIGURE_JS=1 emconfigure ../configure --disable-mmx
|
||||
build as usual...
|
|
@ -116,29 +116,28 @@ Here is a rough list of what works, and what doens't:
|
|||
|
||||
|
||||
|
||||
Caveats
|
||||
-------
|
||||
Upgrade Notes
|
||||
-------------
|
||||
|
||||
#### SDL_GetPrefPath() usage when upgrading existing WinRT apps to SDL 2.0.4
|
||||
#### SDL_GetPrefPath() usage when upgrading WinRT apps from SDL 2.0.3
|
||||
|
||||
SDL 2.0.4 fixes two bugs found in SDL_GetPrefPath() which can affect
|
||||
an app's save data. These bugs only apply to WinRT apps (and not
|
||||
Windows Desktop / Win32 apps, or to apps on any other SDL platform).
|
||||
In particular, for older versions of SDL (anything before 2.0.4):
|
||||
SDL 2.0.4 fixes two bugs found in the WinRT version of SDL_GetPrefPath().
|
||||
The fixes may affect older, SDL 2.0.3-based apps' save data. Please note
|
||||
that these changes only apply to SDL-based WinRT apps, and not to apps for
|
||||
any other platform.
|
||||
|
||||
1. SDL_GetPrefPath() would return an invalid path, one in which attempts
|
||||
to write files to would fail, in many cases. Some of the path elements
|
||||
returned by SDL_GetPrefPath() would not get created (as done on other
|
||||
SDL platforms). Files could be written to this path, however apps would
|
||||
need to explicitly create the missing directories first.
|
||||
|
||||
2. SDL_GetPrefPath() would return a path inside a WinRT 'Roaming' folder,
|
||||
the contents of which could get automatically synchronized across multiple
|
||||
devices, by Windows. This process could occur while an app was running.
|
||||
Apps which were not explicitly built to handle this scenario could
|
||||
have their SDL_GetPrefPath-backed save data swapped out by Windows at
|
||||
unexpected times, which raised potential for data-loss (if apps weren't
|
||||
designed to support live file-synchronization.)
|
||||
1. SDL_GetPrefPath() would return an invalid path, one in which the path's
|
||||
directory had not been created. Attempts to create files there
|
||||
(via fopen(), for example), would fail, unless that directory was
|
||||
explicitly created beforehand.
|
||||
|
||||
2. SDL_GetPrefPath(), for non-WinPhone-based apps, would return a path inside
|
||||
a WinRT 'Roaming' folder, the contents of which get automatically
|
||||
synchronized across multiple devices. This process can occur while an
|
||||
application runs, and can cause existing save-data to be overwritten
|
||||
at unexpected times, with data from other devices. (Windows Phone apps
|
||||
written with SDL 2.0.3 did not utilize a Roaming folder, due to API
|
||||
restrictions in Windows Phone 8.0).
|
||||
|
||||
|
||||
SDL_GetPrefPath(), starting with SDL 2.0.4, addresses these by:
|
||||
|
@ -146,37 +145,14 @@ SDL_GetPrefPath(), starting with SDL 2.0.4, addresses these by:
|
|||
1. making sure that SDL_GetPrefPath() returns a directory in which data
|
||||
can be written to immediately, without first needing to create directories.
|
||||
|
||||
2. basing SDL_GetPrefPath() off of a non-Roaming / 'Local' folder, the
|
||||
contents of which do not get automatically synchronized across devices,
|
||||
and which may be safer in terms of data-integrity.
|
||||
|
||||
Apps can, at their discretion, choose to utilize WinRT's Roaming
|
||||
functionality by calling the following before calling SDL_GetPrefPath():
|
||||
|
||||
SDL_SetHint(SDL_HINT_WINRT_PREF_PATH_ROOT, "roaming");
|
||||
2. basing SDL_GetPrefPath() off of a different, non-Roaming folder, the
|
||||
contents of which do not automatically get synchronized across devices
|
||||
(and which require less work to use safely, in terms of data integrity).
|
||||
|
||||
Alternatively, to restore SDL_GetPrefPath()'s old behavior (found in
|
||||
SDL 2.0.3, and in many pre-2.0.4 versions of SDL found on hg.libsdl.org),
|
||||
whereby a Roaming path is returned for Windows Store apps, and a Local
|
||||
folder is returned for Windows Phone apps, use the following code:
|
||||
|
||||
SDL_SetHint(SDL_HINT_WINRT_PREF_PATH_ROOT, "old");
|
||||
|
||||
Before using Roaming data in any capacity, it is highly recommended that
|
||||
one read the following:
|
||||
|
||||
1. Microsoft's documentation on the Roaming data. Details on this can be
|
||||
found on MSDN, at:
|
||||
[Guidelines for roaming app data](http://msdn.microsoft.com/en-us/library/windows/apps/hh465094.aspx).
|
||||
|
||||
2. the SDL documentation for SDL_HINT_WINRT_PREF_PATH_ROOT, which is
|
||||
listed inside SDL_hints.h.
|
||||
|
||||
Please note that Roaming support is not available on Windows Phone 8.0,
|
||||
due to limitations in the OS itself. Attempts to use it will fail, with
|
||||
SDL_GetPrefPath() returning NULL (if SDL_HINT_WINRT_PREF_PATH_ROOT is
|
||||
set to "roaming" on that platform). Windows Phone 8.1 does not have this
|
||||
limitation, and does support Roaming data.
|
||||
Apps that wish to get their Roaming folder's path can do so either by using
|
||||
SDL_WinRTGetFSPathUTF8(), SDL_WinRTGetFSPathUNICODE() (which returns a
|
||||
UCS-2/wide-char string), or directly through the WinRT class,
|
||||
Windows.Storage.ApplicationData.
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ More documentation and FAQs are available online at [the wiki](http://wiki.libsd
|
|||
- [CMake](README-cmake.md)
|
||||
- [DirectFB](README-directfb.md)
|
||||
- [DynAPI](README-dynapi.md)
|
||||
- [Emscripten](README-emscripten.md)
|
||||
- [Gesture](README-gesture.md)
|
||||
- [Mercurial](README-hg.md)
|
||||
- [iOS](README-ios.md)
|
||||
|
|
|
@ -122,7 +122,7 @@ extern DECLSPEC void SDLCALL SDL_AtomicUnlock(SDL_SpinLock *lock);
|
|||
void _ReadWriteBarrier(void);
|
||||
#pragma intrinsic(_ReadWriteBarrier)
|
||||
#define SDL_CompilerBarrier() _ReadWriteBarrier()
|
||||
#elif defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
|
||||
#elif (defined(__GNUC__) && !defined(__EMSCRIPTEN__)) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x5120))
|
||||
/* This is correct for all CPUs when using GCC or Solaris Studio 12.1+. */
|
||||
#define SDL_CompilerBarrier() __asm__ __volatile__ ("" : : : "memory")
|
||||
#else
|
||||
|
|
|
@ -217,6 +217,7 @@
|
|||
#cmakedefine SDL_AUDIO_DRIVER_WINMM @SDL_AUDIO_DRIVER_WINMM@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_FUSIONSOUND @SDL_AUDIO_DRIVER_FUSIONSOUND@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC @SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC@
|
||||
#cmakedefine SDL_AUDIO_DRIVER_EMSCRIPTEN @SDL_AUDIO_DRIVER_EMSCRIPTEN@
|
||||
|
||||
/* Enable various input drivers */
|
||||
#cmakedefine SDL_INPUT_LINUXEV @SDL_INPUT_LINUXEV@
|
||||
|
@ -230,6 +231,7 @@
|
|||
#cmakedefine SDL_JOYSTICK_WINMM @SDL_JOYSTICK_WINMM@
|
||||
#cmakedefine SDL_JOYSTICK_USBHID @SDL_JOYSTICK_USBHID@
|
||||
#cmakedefine SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H @SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H@
|
||||
#cmakedefine SDL_JOYSTICK_EMSCRIPTEN @SDL_JOYSTICK_EMSCRIPTEN@
|
||||
#cmakedefine SDL_HAPTIC_DUMMY @SDL_HAPTIC_DUMMY@
|
||||
#cmakedefine SDL_HAPTIC_LINUX @SDL_HAPTIC_LINUX@
|
||||
#cmakedefine SDL_HAPTIC_IOKIT @SDL_HAPTIC_IOKIT@
|
||||
|
@ -279,6 +281,7 @@
|
|||
#cmakedefine SDL_VIDEO_DRIVER_MIR @SDL_VIDEO_DRIVER_MIR@
|
||||
#cmakedefine SDL_VIDEO_DRIVER_MIR_DYNAMIC @SDL_VIDEO_DRIVER_MIR_DYNAMIC@
|
||||
#cmakedefine SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON @SDL_VIDEO_DRIVER_MIR_DYNAMIC_XKBCOMMON@
|
||||
#cmakedefine SDL_VIDEO_DRIVER_EMSCRIPTEN @SDL_VIDEO_DRIVER_EMSCRIPTEN@
|
||||
#cmakedefine SDL_VIDEO_DRIVER_X11 @SDL_VIDEO_DRIVER_X11@
|
||||
#cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC @SDL_VIDEO_DRIVER_X11_DYNAMIC@
|
||||
#cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT @SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT@
|
||||
|
@ -325,6 +328,7 @@
|
|||
#cmakedefine SDL_POWER_WINDOWS @SDL_POWER_WINDOWS@
|
||||
#cmakedefine SDL_POWER_MACOSX @SDL_POWER_MACOSX@
|
||||
#cmakedefine SDL_POWER_HAIKU @SDL_POWER_HAIKU@
|
||||
#cmakedefine SDL_POWER_EMSCRIPTEN @SDL_POWER_EMSCRIPTEN@
|
||||
#cmakedefine SDL_POWER_HARDWIRED @SDL_POWER_HARDWIRED@
|
||||
|
||||
/* Enable system filesystem support */
|
||||
|
@ -333,6 +337,7 @@
|
|||
#cmakedefine SDL_FILESYSTEM_DUMMY @SDL_FILESYSTEM_DUMMY@
|
||||
#cmakedefine SDL_FILESYSTEM_UNIX @SDL_FILESYSTEM_UNIX@
|
||||
#cmakedefine SDL_FILESYSTEM_WINDOWS @SDL_FILESYSTEM_WINDOWS@
|
||||
#cmakedefine SDL_FILESYSTEM_EMSCRIPTEN @SDL_FILESYSTEM_EMSCRIPTEN@
|
||||
|
||||
/* Enable assembly routines */
|
||||
#cmakedefine SDL_ASSEMBLY_ROUTINES @SDL_ASSEMBLY_ROUTINES@
|
||||
|
|
|
@ -228,6 +228,7 @@
|
|||
#undef SDL_AUDIO_DRIVER_WINMM
|
||||
#undef SDL_AUDIO_DRIVER_FUSIONSOUND
|
||||
#undef SDL_AUDIO_DRIVER_FUSIONSOUND_DYNAMIC
|
||||
#undef SDL_AUDIO_DRIVER_EMSCRIPTEN
|
||||
|
||||
/* Enable various input drivers */
|
||||
#undef SDL_INPUT_LINUXEV
|
||||
|
@ -243,6 +244,7 @@
|
|||
#undef SDL_JOYSTICK_WINMM
|
||||
#undef SDL_JOYSTICK_USBHID
|
||||
#undef SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
|
||||
#undef SDL_JOYSTICK_EMSCRIPTEN
|
||||
#undef SDL_HAPTIC_DUMMY
|
||||
#undef SDL_HAPTIC_LINUX
|
||||
#undef SDL_HAPTIC_IOKIT
|
||||
|
@ -287,6 +289,7 @@
|
|||
#undef SDL_VIDEO_DRIVER_X11
|
||||
#undef SDL_VIDEO_DRIVER_RPI
|
||||
#undef SDL_VIDEO_DRIVER_ANDROID
|
||||
#undef SDL_VIDEO_DRIVER_EMSCRIPTEN
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
|
||||
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR
|
||||
|
@ -336,6 +339,7 @@
|
|||
#undef SDL_POWER_MACOSX
|
||||
#undef SDL_POWER_HAIKU
|
||||
#undef SDL_POWER_ANDROID
|
||||
#undef SDL_POWER_EMSCRIPTEN
|
||||
#undef SDL_POWER_HARDWIRED
|
||||
|
||||
/* Enable system filesystem support */
|
||||
|
@ -345,6 +349,7 @@
|
|||
#undef SDL_FILESYSTEM_UNIX
|
||||
#undef SDL_FILESYSTEM_WINDOWS
|
||||
#undef SDL_FILESYSTEM_NACL
|
||||
#undef SDL_FILESYSTEM_EMSCRIPTEN
|
||||
|
||||
/* Enable assembly routines */
|
||||
#undef SDL_ASSEMBLY_ROUTINES
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2014 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
|
||||
|
|
|
@ -260,6 +260,7 @@ typedef struct SDL_MouseWheelEvent
|
|||
Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
|
||||
Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
|
||||
Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
|
||||
Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
|
||||
} SDL_MouseWheelEvent;
|
||||
|
||||
/**
|
||||
|
|
|
@ -492,36 +492,6 @@ extern "C" {
|
|||
*/
|
||||
#define SDL_HINT_WINRT_HANDLE_BACK_BUTTON "SDL_WINRT_HANDLE_BACK_BUTTON"
|
||||
|
||||
/**
|
||||
* \brief A variable that dictates what SDL_GetPrefPath() returns in WinRT apps.
|
||||
*
|
||||
* The variable can be set to the following values:
|
||||
* * "local" - Use the app's 'local' folder to store data.
|
||||
* * "roaming" - Use the app's 'roaming' folder to store data.
|
||||
* On Windows Phone 8.0, this setting is not supported due to
|
||||
* limitations in the OS itself. Attempts to use this (via
|
||||
* SDL_GetPrefPath()) on Windows Phone 8.0 will fail, with
|
||||
* SDL_GetPrefPath() returning NULL. (Windows Phone 8.1 does,
|
||||
* however, support roaming folders.)
|
||||
* * "old" - Use the app's 'local' folder on Windows Phone, and 'roaming'
|
||||
* on non-Phone versions of WinRT. This mimics behavior found
|
||||
* in SDL 2.0.3's implementation of SDL_GetPrefPath() for WinRT
|
||||
* (and was changed for SDL 2.0.4, further details of which are
|
||||
* in the "Caveats" section of SDL's
|
||||
* [WinRT README file](README-winrt.md).
|
||||
*
|
||||
* The default is to use the app's "local" folder.
|
||||
*
|
||||
* Details on 'local' verses 'roaming' folders can be found on MSDN, in
|
||||
* the documentation for WinRT's Windows.Storage.ApplicationData class,
|
||||
* (available at http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata ).
|
||||
*
|
||||
* The application's local and roaming paths may, alternatively, be retrieved
|
||||
* via the SDL_WinRTGetFSPathUTF8() and SDL_WinRTGetFSPathUNICODE() functions,
|
||||
* which are defined in SDL_system.h.
|
||||
*/
|
||||
#define SDL_HINT_WINRT_PREF_PATH_ROOT "SDL_WINRT_PREF_PATH_ROOT"
|
||||
|
||||
/**
|
||||
* \brief A variable that dictates policy for fullscreen Spaces on Mac OS X.
|
||||
*
|
||||
|
@ -563,6 +533,20 @@ extern "C" {
|
|||
*/
|
||||
#define SDL_HINT_IME_INTERNAL_EDITING "SDL_IME_INTERNAL_EDITING"
|
||||
|
||||
/**
|
||||
* \brief override the binding element for keyboard inputs for Emscripten builds
|
||||
*
|
||||
* This hint only applies to the emscripten platform
|
||||
*
|
||||
* The variable can be one of
|
||||
* "#window" - The javascript window object (this is the default)
|
||||
* "#document" - The javascript document object
|
||||
* "#screen" - the javascript window.screen object
|
||||
* "#canvas" - the WebGL canvas element
|
||||
* any other string without a leading # sign applies to the element on the page with that ID.
|
||||
*/
|
||||
#define SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT"
|
||||
|
||||
/**
|
||||
* \brief An enumeration of hint priorities
|
||||
*/
|
||||
|
|
|
@ -142,14 +142,11 @@ extern DECLSPEC void SDLCALL SDL_UnregisterApp(void);
|
|||
* \brief Initializes and launches an SDL/WinRT application.
|
||||
*
|
||||
* \param mainFunction The SDL app's C-style main().
|
||||
* \param xamlBackgroundPanel An optional, XAML-based, background panel.
|
||||
* For Non-XAML apps, this value must be set to NULL. For XAML apps,
|
||||
* pass in a pointer to a SwapChainBackgroundPanel, casted to an
|
||||
* IInspectable (via reinterpret_cast).
|
||||
* \param reserved Reserved for future use; should be NULL
|
||||
* \ret 0 on success, -1 on failure. On failure, use SDL_GetError to retrieve more
|
||||
* information on the failure.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * xamlBackgroundPanel);
|
||||
extern DECLSPEC int SDLCALL SDL_WinRTRunApp(int (*mainFunction)(int, char **), void * reserved);
|
||||
|
||||
#endif /* __WINRT__ */
|
||||
|
||||
|
|
|
@ -60,6 +60,15 @@ typedef enum
|
|||
SDL_NUM_SYSTEM_CURSORS
|
||||
} SDL_SystemCursor;
|
||||
|
||||
/**
|
||||
* \brief Scroll direction types for the Scroll event
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SDL_MOUSEWHEEL_NORMAL, /**< The scroll direction is normal */
|
||||
SDL_MOUSEWHEEL_FLIPPED /**< The scroll direction is flipped / natural */
|
||||
} SDL_MouseWheelDirection;
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/**
|
||||
|
|
|
@ -172,7 +172,7 @@ typedef uint64_t Uint64;
|
|||
#ifdef PRIs64
|
||||
#define SDL_PRIs64 PRIs64
|
||||
#elif defined(__WIN32__)
|
||||
#define SDL_PRIs64 "I64"
|
||||
#define SDL_PRIs64 "I64d"
|
||||
#else
|
||||
#define SDL_PRIs64 "lld"
|
||||
#endif
|
||||
|
@ -186,6 +186,24 @@ typedef uint64_t Uint64;
|
|||
#define SDL_PRIu64 "llu"
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SDL_PRIx64
|
||||
#ifdef PRIx64
|
||||
#define SDL_PRIx64 PRIx64
|
||||
#elif defined(__WIN32__)
|
||||
#define SDL_PRIx64 "I64x"
|
||||
#else
|
||||
#define SDL_PRIx64 "llx"
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SDL_PRIX64
|
||||
#ifdef PRIX64
|
||||
#define SDL_PRIX64 PRIX64
|
||||
#elif defined(__WIN32__)
|
||||
#define SDL_PRIX64 "I64X"
|
||||
#else
|
||||
#define SDL_PRIX64 "llX"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Annotations to help code analysis tools */
|
||||
#ifdef SDL_DISABLE_ANALYZE_MACROS
|
||||
|
@ -361,11 +379,6 @@ SDL_FORCE_INLINE void SDL_memset4(void *dst, Uint32 val, size_t dwords)
|
|||
|
||||
extern DECLSPEC void *SDLCALL SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
|
||||
|
||||
SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
|
||||
{
|
||||
return SDL_memcpy(dst, src, dwords * 4);
|
||||
}
|
||||
|
||||
extern DECLSPEC void *SDLCALL SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len);
|
||||
extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
|
||||
|
||||
|
@ -462,6 +475,39 @@ extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
|
|||
#define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
|
||||
#define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
|
||||
|
||||
/* force builds using Clang's static analysis tools to use literal C runtime
|
||||
here, since there are possibly tests that are ineffective otherwise. */
|
||||
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
|
||||
#define SDL_malloc malloc
|
||||
#define SDL_calloc calloc
|
||||
#define SDL_realloc realloc
|
||||
#define SDL_free free
|
||||
#define SDL_memset memset
|
||||
#define SDL_memcpy memcpy
|
||||
#define SDL_memmove memmove
|
||||
#define SDL_memcmp memcmp
|
||||
#define SDL_strlen strlen
|
||||
#define SDL_strlcpy strlcpy
|
||||
#define SDL_strlcat strlcat
|
||||
#define SDL_strdup strdup
|
||||
#define SDL_strchr strchr
|
||||
#define SDL_strrchr strrchr
|
||||
#define SDL_strstr strstr
|
||||
#define SDL_strcmp strcmp
|
||||
#define SDL_strncmp strncmp
|
||||
#define SDL_strcasecmp strcasecmp
|
||||
#define SDL_strncasecmp strncasecmp
|
||||
#define SDL_sscanf sscanf
|
||||
#define SDL_vsscanf vsscanf
|
||||
#define SDL_snprintf snprintf
|
||||
#define SDL_vsnprintf vsnprintf
|
||||
#endif
|
||||
|
||||
SDL_FORCE_INLINE void *SDL_memcpy4(SDL_OUT_BYTECAP(dwords*4) void *dst, SDL_IN_BYTECAP(dwords*4) const void *src, size_t dwords)
|
||||
{
|
||||
return SDL_memcpy(dst, src, dwords * 4);
|
||||
}
|
||||
|
||||
/* Ends C function definitions when using C++ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -43,19 +43,25 @@ extern "C" {
|
|||
/* Platform specific functions for Windows */
|
||||
#ifdef __WIN32__
|
||||
|
||||
/* Returns the D3D9 adapter index that matches the specified display index.
|
||||
/**
|
||||
\brief Returns the D3D9 adapter index that matches the specified display index.
|
||||
|
||||
This adapter index can be passed to IDirect3D9::CreateDevice and controls
|
||||
on which monitor a full screen application will appear.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
|
||||
|
||||
/* Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
|
||||
typedef struct IDirect3DDevice9 IDirect3DDevice9;
|
||||
/**
|
||||
\brief Returns the D3D device associated with a renderer, or NULL if it's not a D3D renderer.
|
||||
|
||||
Once you are done using the device, you should release it to avoid a resource leak.
|
||||
*/
|
||||
typedef struct IDirect3DDevice9 IDirect3DDevice9;
|
||||
extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
|
||||
|
||||
/* Returns the DXGI Adapter and Output indices for the specified display index.
|
||||
/**
|
||||
\brief Returns the DXGI Adapter and Output indices for the specified display index.
|
||||
|
||||
These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
|
||||
required to create a DX10 or DX11 device and swap chain.
|
||||
*/
|
||||
|
@ -70,12 +76,16 @@ extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *a
|
|||
extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
|
||||
extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
|
||||
|
||||
/* Returns the OpenGL Renderbuffer Object associated with the window's main view.
|
||||
/**
|
||||
\brief Returns the OpenGL Renderbuffer Object associated with the window's main view.
|
||||
|
||||
The Renderbuffer must be bound when calling SDL_GL_SwapWindow.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_iPhoneGetViewRenderbuffer(SDL_Window * window);
|
||||
|
||||
/* Returns the OpenGL Framebuffer Object associated with the window's main view.
|
||||
/**
|
||||
\brief Returns the OpenGL Framebuffer Object associated with the window's main view.
|
||||
|
||||
The Framebuffer must be bound when rendering to the screen.
|
||||
*/
|
||||
extern DECLSPEC Uint32 SDLCALL SDL_iPhoneGetViewFramebuffer(SDL_Window * window);
|
||||
|
@ -86,12 +96,16 @@ extern DECLSPEC Uint32 SDLCALL SDL_iPhoneGetViewFramebuffer(SDL_Window * window)
|
|||
/* Platform specific functions for Android */
|
||||
#if defined(__ANDROID__) && __ANDROID__
|
||||
|
||||
/* Get the JNI environment for the current thread
|
||||
/**
|
||||
\brief Get the JNI environment for the current thread
|
||||
|
||||
This returns JNIEnv*, but the prototype is void* so we don't need jni.h
|
||||
*/
|
||||
extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();
|
||||
|
||||
/* Get the SDL Activity object for the application
|
||||
/**
|
||||
\brief Get the SDL Activity object for the application
|
||||
|
||||
This returns jobject, but the prototype is void* so we don't need jni.h
|
||||
The jobject returned by SDL_AndroidGetActivity is a local reference.
|
||||
It is the caller's responsibility to properly release it
|
||||
|
@ -99,26 +113,33 @@ extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv();
|
|||
*/
|
||||
extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity();
|
||||
|
||||
/* See the official Android developer guide for more information:
|
||||
/**
|
||||
See the official Android developer guide for more information:
|
||||
http://developer.android.com/guide/topics/data/data-storage.html
|
||||
*/
|
||||
#define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
|
||||
#define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
|
||||
|
||||
/* Get the path used for internal storage for this application.
|
||||
/**
|
||||
\brief Get the path used for internal storage for this application.
|
||||
|
||||
This path is unique to your application and cannot be written to
|
||||
by other applications.
|
||||
*/
|
||||
extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath();
|
||||
|
||||
/* Get the current state of external storage, a bitmask of these values:
|
||||
/**
|
||||
\brief Get the current state of external storage, a bitmask of these values:
|
||||
SDL_ANDROID_EXTERNAL_STORAGE_READ
|
||||
SDL_ANDROID_EXTERNAL_STORAGE_WRITE
|
||||
|
||||
If external storage is currently unavailable, this will return 0.
|
||||
*/
|
||||
extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState();
|
||||
|
||||
/* Get the path used for external storage for this application.
|
||||
/**
|
||||
\brief Get the path used for external storage for this application.
|
||||
|
||||
This path is unique to your application, but is public and can be
|
||||
written to by other applications.
|
||||
*/
|
||||
|
@ -161,7 +182,7 @@ typedef enum
|
|||
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
|
||||
*
|
||||
* \param pathType The type of path to retrieve.
|
||||
* \ret A UCS-2 string (16-bit, wide-char) containing the path, or NULL
|
||||
* \return A UCS-2 string (16-bit, wide-char) containing the path, or NULL
|
||||
* if the path is not available for any reason. Not all paths are
|
||||
* available on all versions of Windows. This is especially true on
|
||||
* Windows Phone. Check the documentation for the given
|
||||
|
@ -178,7 +199,7 @@ extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path
|
|||
* http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
|
||||
*
|
||||
* \param pathType The type of path to retrieve.
|
||||
* \ret A UTF-8 string (8-bit, multi-byte) containing the path, or NULL
|
||||
* \return A UTF-8 string (8-bit, multi-byte) containing the path, or NULL
|
||||
* if the path is not available for any reason. Not all paths are
|
||||
* available on all versions of Windows. This is especially true on
|
||||
* Windows Phone. Check the documentation for the given
|
||||
|
|
|
@ -71,6 +71,7 @@ extern AudioBootStrap FUSIONSOUND_bootstrap;
|
|||
extern AudioBootStrap ANDROIDAUD_bootstrap;
|
||||
extern AudioBootStrap PSPAUD_bootstrap;
|
||||
extern AudioBootStrap SNDIO_bootstrap;
|
||||
extern AudioBootStrap EmscriptenAudio_bootstrap;
|
||||
|
||||
|
||||
/* Available audio drivers */
|
||||
|
@ -140,6 +141,9 @@ static const AudioBootStrap *const bootstrap[] = {
|
|||
#endif
|
||||
#if SDL_AUDIO_DRIVER_PSP
|
||||
&PSPAUD_bootstrap,
|
||||
#endif
|
||||
#if SDL_AUDIO_DRIVER_EMSCRIPTEN
|
||||
&EmscriptenAudio_bootstrap,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
|
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_AUDIO_DRIVER_EMSCRIPTEN
|
||||
|
||||
#include "SDL_audio.h"
|
||||
#include "SDL_log.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "SDL_emscriptenaudio.h"
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
static int
|
||||
copyData(_THIS)
|
||||
{
|
||||
int byte_len;
|
||||
|
||||
if (this->hidden->write_off + this->convert.len_cvt > this->hidden->mixlen) {
|
||||
if (this->hidden->write_off > this->hidden->read_off) {
|
||||
SDL_memmove(this->hidden->mixbuf,
|
||||
this->hidden->mixbuf + this->hidden->read_off,
|
||||
this->hidden->mixlen - this->hidden->read_off);
|
||||
this->hidden->write_off = this->hidden->write_off - this->hidden->read_off;
|
||||
} else {
|
||||
this->hidden->write_off = 0;
|
||||
}
|
||||
this->hidden->read_off = 0;
|
||||
}
|
||||
|
||||
SDL_memcpy(this->hidden->mixbuf + this->hidden->write_off,
|
||||
this->convert.buf,
|
||||
this->convert.len_cvt);
|
||||
this->hidden->write_off += this->convert.len_cvt;
|
||||
byte_len = this->hidden->write_off - this->hidden->read_off;
|
||||
|
||||
return byte_len;
|
||||
}
|
||||
|
||||
static void
|
||||
HandleAudioProcess(_THIS)
|
||||
{
|
||||
Uint8 *buf = NULL;
|
||||
int byte_len = 0;
|
||||
int bytes = SDL_AUDIO_BITSIZE(this->spec.format) / 8;
|
||||
int bytes_in = SDL_AUDIO_BITSIZE(this->convert.src_format) / 8;
|
||||
|
||||
/* Only do soemthing if audio is enabled */
|
||||
if (!this->enabled)
|
||||
return;
|
||||
|
||||
if (this->paused)
|
||||
return;
|
||||
|
||||
if (this->convert.needed) {
|
||||
if (this->hidden->conv_in_len != 0) {
|
||||
this->convert.len = this->hidden->conv_in_len * bytes_in * this->spec.channels;
|
||||
}
|
||||
|
||||
(*this->spec.callback) (this->spec.userdata,
|
||||
this->convert.buf,
|
||||
this->convert.len);
|
||||
SDL_ConvertAudio(&this->convert);
|
||||
buf = this->convert.buf;
|
||||
byte_len = this->convert.len_cvt;
|
||||
|
||||
/* size mismatch*/
|
||||
if (byte_len != this->spec.size) {
|
||||
if (!this->hidden->mixbuf) {
|
||||
this->hidden->mixlen = this->spec.size > byte_len ? this->spec.size * 2 : byte_len * 2;
|
||||
this->hidden->mixbuf = SDL_malloc(this->hidden->mixlen);
|
||||
}
|
||||
|
||||
/* copy existing data */
|
||||
byte_len = copyData(this);
|
||||
|
||||
/* read more data*/
|
||||
while (byte_len < this->spec.size) {
|
||||
(*this->spec.callback) (this->spec.userdata,
|
||||
this->convert.buf,
|
||||
this->convert.len);
|
||||
SDL_ConvertAudio(&this->convert);
|
||||
byte_len = copyData(this);
|
||||
}
|
||||
|
||||
byte_len = this->spec.size;
|
||||
buf = this->hidden->mixbuf + this->hidden->read_off;
|
||||
this->hidden->read_off += byte_len;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!this->hidden->mixbuf) {
|
||||
this->hidden->mixlen = this->spec.size;
|
||||
this->hidden->mixbuf = SDL_malloc(this->hidden->mixlen);
|
||||
}
|
||||
(*this->spec.callback) (this->spec.userdata,
|
||||
this->hidden->mixbuf,
|
||||
this->hidden->mixlen);
|
||||
buf = this->hidden->mixbuf;
|
||||
byte_len = this->hidden->mixlen;
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
EM_ASM_ARGS({
|
||||
var numChannels = SDL2.audio.currentOutputBuffer['numberOfChannels'];
|
||||
for (var c = 0; c < numChannels; ++c) {
|
||||
var channelData = SDL2.audio.currentOutputBuffer['getChannelData'](c);
|
||||
if (channelData.length != $1) {
|
||||
throw 'Web Audio output buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + $1 + ' samples!';
|
||||
}
|
||||
|
||||
for (var j = 0; j < $1; ++j) {
|
||||
channelData[j] = getValue($0 + (j*numChannels + c)*4, 'float');
|
||||
}
|
||||
}
|
||||
}, buf, byte_len / bytes / this->spec.channels);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Emscripten_CloseDevice(_THIS)
|
||||
{
|
||||
if (this->hidden != NULL) {
|
||||
if (this->hidden->mixbuf != NULL) {
|
||||
/* Clean up the audio buffer */
|
||||
SDL_free(this->hidden->mixbuf);
|
||||
this->hidden->mixbuf = NULL;
|
||||
}
|
||||
|
||||
SDL_free(this->hidden);
|
||||
this->hidden = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Emscripten_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
SDL_bool valid_format = SDL_FALSE;
|
||||
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
|
||||
int i;
|
||||
float f;
|
||||
|
||||
while ((!valid_format) && (test_format)) {
|
||||
switch (test_format) {
|
||||
case AUDIO_F32: /* web audio only supports floats */
|
||||
this->spec.format = test_format;
|
||||
|
||||
valid_format = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
test_format = SDL_NextAudioFormat();
|
||||
}
|
||||
|
||||
if (!valid_format) {
|
||||
/* Didn't find a compatible format :( */
|
||||
return SDL_SetError("No compatible audio format!");
|
||||
}
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
this->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc((sizeof *this->hidden));
|
||||
if (this->hidden == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
|
||||
|
||||
/* based on parts of library_sdl.js */
|
||||
|
||||
/* create context (TODO: this puts stuff in the global namespace...)*/
|
||||
EM_ASM({
|
||||
if(typeof(SDL2) === 'undefined')
|
||||
SDL2 = {};
|
||||
|
||||
if(typeof(SDL2.audio) === 'undefined')
|
||||
SDL2.audio = {};
|
||||
|
||||
if (!SDL2.audioContext) {
|
||||
if (typeof(AudioContext) !== 'undefined') {
|
||||
SDL2.audioContext = new AudioContext();
|
||||
} else if (typeof(webkitAudioContext) !== 'undefined') {
|
||||
SDL2.audioContext = new webkitAudioContext();
|
||||
} else {
|
||||
throw 'Web Audio API is not available!';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/* limit to native freq */
|
||||
int sampleRate = EM_ASM_INT_V({
|
||||
return SDL2.audioContext['sampleRate'];
|
||||
});
|
||||
|
||||
if(this->spec.freq != sampleRate) {
|
||||
for (i = this->spec.samples; i > 0; i--) {
|
||||
f = (float)i / (float)sampleRate * (float)this->spec.freq;
|
||||
if (SDL_floor(f) == f) {
|
||||
this->hidden->conv_in_len = SDL_floor(f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->spec.freq = sampleRate;
|
||||
}
|
||||
|
||||
SDL_CalculateAudioSpec(&this->spec);
|
||||
|
||||
/* setup a ScriptProcessorNode */
|
||||
EM_ASM_ARGS({
|
||||
SDL2.audio.scriptProcessorNode = SDL2.audioContext['createScriptProcessor']($1, 0, $0);
|
||||
SDL2.audio.scriptProcessorNode['onaudioprocess'] = function (e) {
|
||||
SDL2.audio.currentOutputBuffer = e['outputBuffer'];
|
||||
Runtime.dynCall('vi', $2, [$3]);
|
||||
};
|
||||
SDL2.audio.scriptProcessorNode['connect'](SDL2.audioContext['destination']);
|
||||
}, this->spec.channels, this->spec.samples, HandleAudioProcess, this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
Emscripten_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = Emscripten_OpenDevice;
|
||||
impl->CloseDevice = Emscripten_CloseDevice;
|
||||
|
||||
/* only one output */
|
||||
impl->OnlyHasDefaultOutputDevice = 1;
|
||||
|
||||
/* no threads here */
|
||||
impl->SkipMixerLock = 1;
|
||||
impl->ProvidesOwnCallbackThread = 1;
|
||||
|
||||
/* check availability */
|
||||
int available = EM_ASM_INT_V({
|
||||
if (typeof(AudioContext) !== 'undefined') {
|
||||
return 1;
|
||||
} else if (typeof(webkitAudioContext) !== 'undefined') {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
return available;
|
||||
}
|
||||
|
||||
AudioBootStrap EmscriptenAudio_bootstrap = {
|
||||
"emscripten", "SDL emscripten audio driver", Emscripten_Init, 0
|
||||
};
|
||||
|
||||
#endif /* SDL_AUDIO_DRIVER_EMSCRIPTEN */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifndef _SDL_emscriptenaudio_h
|
||||
#define _SDL_emscriptenaudio_h
|
||||
|
||||
#include "../SDL_sysaudio.h"
|
||||
|
||||
/* Hidden "this" pointer for the audio functions */
|
||||
#define _THIS SDL_AudioDevice *this
|
||||
|
||||
struct SDL_PrivateAudioData
|
||||
{
|
||||
Uint8 *mixbuf;
|
||||
Uint32 mixlen;
|
||||
|
||||
Uint32 conv_in_len;
|
||||
|
||||
Uint32 write_off, read_off;
|
||||
};
|
||||
|
||||
#endif /* _SDL_emscriptenaudio_h */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -44,8 +44,8 @@
|
|||
#define LOG_TAG "SDL_android"
|
||||
/* #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) */
|
||||
/* #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) */
|
||||
#define LOGI(...) do {} while (false)
|
||||
#define LOGE(...) do {} while (false)
|
||||
#define LOGI(...) do {} while (0)
|
||||
#define LOGE(...) do {} while (0)
|
||||
|
||||
/* Uncomment this to log messages entering and exiting methods in this file */
|
||||
/* #define DEBUG_JNI */
|
||||
|
@ -57,7 +57,6 @@ static void Android_JNI_ThreadDestroyed(void*);
|
|||
*******************************************************************************/
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
|
@ -80,7 +79,7 @@ static jmethodID midPollInputDevices;
|
|||
|
||||
/* Accelerometer data storage */
|
||||
static float fLastAccelerometer[3];
|
||||
static bool bHasNewData;
|
||||
static SDL_bool bHasNewData;
|
||||
|
||||
/*******************************************************************************
|
||||
Functions called by JNI
|
||||
|
@ -132,7 +131,7 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
|
|||
midPollInputDevices = (*mEnv)->GetStaticMethodID(mEnv, mActivityClass,
|
||||
"pollInputDevices", "()V");
|
||||
|
||||
bHasNewData = false;
|
||||
bHasNewData = SDL_FALSE;
|
||||
|
||||
if(!midGetNativeSurface || !midFlipBuffers || !midAudioInit ||
|
||||
!midAudioWriteShortBuffer || !midAudioWriteByteBuffer || !midAudioQuit || !midPollInputDevices) {
|
||||
|
@ -302,7 +301,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeAccel(
|
|||
fLastAccelerometer[0] = x;
|
||||
fLastAccelerometer[1] = y;
|
||||
fLastAccelerometer[2] = z;
|
||||
bHasNewData = true;
|
||||
bHasNewData = SDL_TRUE;
|
||||
}
|
||||
|
||||
/* Low memory */
|
||||
|
@ -386,7 +385,7 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeSetComposing
|
|||
(*env)->ReleaseStringUTFChars(env, text, utftext);
|
||||
}
|
||||
|
||||
jstring Java_org_libsdl_app_SDLActivity_nativeGetHint(JNIEnv* env, jclass cls, jstring name) {
|
||||
JNIEXPORT jstring JNICALL Java_org_libsdl_app_SDLActivity_nativeGetHint(JNIEnv* env, jclass cls, jstring name) {
|
||||
const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
|
||||
const char *hint = SDL_GetHint(utfname);
|
||||
|
||||
|
@ -487,7 +486,7 @@ SDL_bool Android_JNI_GetAccelerometerValues(float values[3])
|
|||
for (i = 0; i < 3; ++i) {
|
||||
values[i] = fLastAccelerometer[i];
|
||||
}
|
||||
bHasNewData = false;
|
||||
bHasNewData = SDL_FALSE;
|
||||
retval = SDL_TRUE;
|
||||
}
|
||||
|
||||
|
@ -647,7 +646,7 @@ void Android_JNI_CloseAudioDevice()
|
|||
|
||||
/* Test for an exception and call SDL_SetError with its detail if one occurs */
|
||||
/* If the parameter silent is truthy then SDL_SetError() will not be called. */
|
||||
static bool Android_JNI_ExceptionOccurred(bool silent)
|
||||
static SDL_bool Android_JNI_ExceptionOccurred(SDL_bool silent)
|
||||
{
|
||||
SDL_assert(LocalReferenceHolder_IsActive());
|
||||
JNIEnv *mEnv = Android_JNI_GetEnv();
|
||||
|
@ -681,10 +680,10 @@ static bool Android_JNI_ExceptionOccurred(bool silent)
|
|||
(*mEnv)->ReleaseStringUTFChars(mEnv, exceptionName, exceptionNameUTF8);
|
||||
}
|
||||
|
||||
return true;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
return false;
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
|
||||
|
@ -728,19 +727,19 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
|
|||
*/
|
||||
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager), "openFd", "(Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;");
|
||||
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString);
|
||||
if (Android_JNI_ExceptionOccurred(true)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getStartOffset", "()J");
|
||||
ctx->hidden.androidio.offset = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
|
||||
if (Android_JNI_ExceptionOccurred(true)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream), "getDeclaredLength", "()J");
|
||||
ctx->hidden.androidio.size = (*mEnv)->CallLongMethod(mEnv, inputStream, mid);
|
||||
if (Android_JNI_ExceptionOccurred(true)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_TRUE)) {
|
||||
goto fallback;
|
||||
}
|
||||
|
||||
|
@ -754,7 +753,7 @@ static int Internal_Android_JNI_FileOpen(SDL_RWops* ctx)
|
|||
/* Seek to the correct offset in the file. */
|
||||
lseek(ctx->hidden.androidio.fd, (off_t)ctx->hidden.androidio.offset, SEEK_SET);
|
||||
|
||||
if (false) {
|
||||
if (0) {
|
||||
fallback:
|
||||
/* Disabled log message because of spam on the Nexus 7 */
|
||||
/* __android_log_print(ANDROID_LOG_DEBUG, "SDL", "Falling back to legacy InputStream method for opening file"); */
|
||||
|
@ -766,13 +765,13 @@ fallback:
|
|||
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, assetManager),
|
||||
"open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
|
||||
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
|
||||
// Try fallback to APK Extension files
|
||||
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
|
||||
"openAPKExtensionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
|
||||
inputStream = (*mEnv)->CallObjectMethod(mEnv, context, mid, fileNameJString);
|
||||
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
|
||||
goto failure;
|
||||
}
|
||||
}
|
||||
|
@ -790,7 +789,7 @@ fallback:
|
|||
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, inputStream),
|
||||
"available", "()I");
|
||||
ctx->hidden.androidio.size = (long)(*mEnv)->CallIntMethod(mEnv, inputStream, mid);
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
|
||||
goto failure;
|
||||
}
|
||||
|
||||
|
@ -801,7 +800,7 @@ fallback:
|
|||
"(Ljava/io/InputStream;)Ljava/nio/channels/ReadableByteChannel;");
|
||||
readableByteChannel = (*mEnv)->CallStaticObjectMethod(
|
||||
mEnv, channels, mid, inputStream);
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
|
||||
goto failure;
|
||||
}
|
||||
|
||||
|
@ -814,7 +813,7 @@ fallback:
|
|||
ctx->hidden.androidio.readMethod = mid;
|
||||
}
|
||||
|
||||
if (false) {
|
||||
if (0) {
|
||||
failure:
|
||||
result = -1;
|
||||
|
||||
|
@ -907,7 +906,7 @@ size_t Android_JNI_FileRead(SDL_RWops* ctx, void* buffer,
|
|||
/* result = readableByteChannel.read(...); */
|
||||
int result = (*mEnv)->CallIntMethod(mEnv, readableByteChannel, readMethod, byteBuffer);
|
||||
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
|
||||
LocalReferenceHolder_Cleanup(&refs);
|
||||
return 0;
|
||||
}
|
||||
|
@ -932,7 +931,7 @@ size_t Android_JNI_FileWrite(SDL_RWops* ctx, const void* buffer,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, bool release)
|
||||
static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, SDL_bool release)
|
||||
{
|
||||
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
|
||||
|
||||
|
@ -955,7 +954,7 @@ static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, bool release)
|
|||
"close", "()V");
|
||||
(*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
|
||||
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.assetFileDescriptorRef);
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
|
@ -968,7 +967,7 @@ static int Internal_Android_JNI_FileClose(SDL_RWops* ctx, bool release)
|
|||
(*mEnv)->CallVoidMethod(mEnv, inputStream, mid);
|
||||
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.inputStreamRef);
|
||||
(*mEnv)->DeleteGlobalRef(mEnv, (jobject)ctx->hidden.androidio.readableByteChannelRef);
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
if (Android_JNI_ExceptionOccurred(SDL_FALSE)) {
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
|
@ -1059,7 +1058,7 @@ Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
|
|||
} else if (movement < 0) {
|
||||
/* We can't seek backwards so we have to reopen the file and seek */
|
||||
/* forwards which obviously isn't very efficient */
|
||||
Internal_Android_JNI_FileClose(ctx, false);
|
||||
Internal_Android_JNI_FileClose(ctx, SDL_FALSE);
|
||||
Internal_Android_JNI_FileOpen(ctx);
|
||||
Android_JNI_FileSeek(ctx, newPosition, RW_SEEK_SET);
|
||||
}
|
||||
|
@ -1071,7 +1070,7 @@ Sint64 Android_JNI_FileSeek(SDL_RWops* ctx, Sint64 offset, int whence)
|
|||
|
||||
int Android_JNI_FileClose(SDL_RWops* ctx)
|
||||
{
|
||||
return Internal_Android_JNI_FileClose(ctx, true);
|
||||
return Internal_Android_JNI_FileClose(ctx, SDL_TRUE);
|
||||
}
|
||||
|
||||
/* returns a new global reference which needs to be released later */
|
||||
|
|
|
@ -681,10 +681,10 @@ SDL_EVDEV_Poll(void)
|
|||
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_TRUE, 0, events[i].value);
|
||||
break;
|
||||
case REL_WHEEL:
|
||||
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value);
|
||||
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, 0, events[i].value, SDL_MOUSEWHEEL_NORMAL);
|
||||
break;
|
||||
case REL_HWHEEL:
|
||||
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0);
|
||||
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, events[i].value, 0, SDL_MOUSEWHEEL_NORMAL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -371,10 +371,10 @@ guess_device_class(struct udev_device *dev)
|
|||
devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
|
||||
}
|
||||
|
||||
/* the first 32 bits are ESC, numbers, and Q to D; if we have all of
|
||||
* those, consider it a full keyboard; do not test KEY_RESERVED, though */
|
||||
/* the first 32 bits are ESC, numbers, and Q to D; if we have any of
|
||||
* those, consider it a keyboard device; do not test KEY_RESERVED, though */
|
||||
keyboard_mask = 0xFFFFFFFE;
|
||||
if ((bitmask_key[0] & keyboard_mask) == keyboard_mask)
|
||||
if ((bitmask_key[0] & keyboard_mask) != 0)
|
||||
devclass |= SDL_UDEV_DEVICE_KEYBOARD; /* ID_INPUT_KEYBOARD */
|
||||
|
||||
return devclass;
|
||||
|
|
|
@ -126,6 +126,16 @@ static void WINRT_SetDisplayOrientationsPreference(void *userdata, const char *n
|
|||
{
|
||||
SDL_assert(SDL_strcmp(name, SDL_HINT_ORIENTATIONS) == 0);
|
||||
|
||||
/* HACK: prevent SDL from altering an app's .appxmanifest-set orientation
|
||||
* from being changed on startup, by detecting when SDL_HINT_ORIENTATIONS
|
||||
* is getting registered.
|
||||
*
|
||||
* TODO, WinRT: consider reading in an app's .appxmanifest file, and apply its orientation when 'newValue == NULL'.
|
||||
*/
|
||||
if ((oldValue == NULL) && (newValue == NULL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Start with no orientation flags, then add each in as they're parsed
|
||||
// from newValue.
|
||||
unsigned int orientationFlags = 0;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#ifndef _SDL_winrtapp_xaml_h
|
||||
#define _SDL_winrtapp_xaml_h
|
||||
|
||||
#include "SDL_types.h"
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern SDL_bool WINRT_XAMLWasEnabled;
|
||||
|
|
|
@ -79,6 +79,7 @@ CPU_haveCPUID(void)
|
|||
{
|
||||
int has_CPUID = 0;
|
||||
/* *INDENT-OFF* */
|
||||
#ifndef SDL_CPUINFO_DISABLED
|
||||
#if defined(__GNUC__) && defined(i386)
|
||||
__asm__ (
|
||||
" pushfl # Get original EFLAGS \n"
|
||||
|
@ -165,6 +166,7 @@ done:
|
|||
"1: \n"
|
||||
);
|
||||
#endif
|
||||
#endif
|
||||
/* *INDENT-ON* */
|
||||
return has_CPUID;
|
||||
}
|
||||
|
@ -272,6 +274,7 @@ static int
|
|||
CPU_haveAltiVec(void)
|
||||
{
|
||||
volatile int altivec = 0;
|
||||
#ifndef SDL_CPUINFO_DISABLED
|
||||
#if (defined(__MACOSX__) && (defined(__ppc__) || defined(__ppc64__))) || (defined(__OpenBSD__) && defined(__powerpc__))
|
||||
#ifdef __OpenBSD__
|
||||
int selectors[2] = { CTL_MACHDEP, CPU_ALTIVEC };
|
||||
|
@ -291,6 +294,7 @@ CPU_haveAltiVec(void)
|
|||
altivec = 1;
|
||||
}
|
||||
signal(SIGILL, handler);
|
||||
#endif
|
||||
#endif
|
||||
return altivec;
|
||||
}
|
||||
|
@ -418,6 +422,7 @@ int
|
|||
SDL_GetCPUCount(void)
|
||||
{
|
||||
if (!SDL_CPUCount) {
|
||||
#ifndef SDL_CPUINFO_DISABLED
|
||||
#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
|
||||
if (SDL_CPUCount <= 0) {
|
||||
SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
@ -435,6 +440,7 @@ SDL_GetCPUCount(void)
|
|||
GetSystemInfo(&info);
|
||||
SDL_CPUCount = info.dwNumberOfProcessors;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
/* There has to be at least 1, right? :) */
|
||||
if (SDL_CPUCount <= 0) {
|
||||
|
@ -452,10 +458,11 @@ SDL_GetCPUType(void)
|
|||
|
||||
if (!SDL_CPUType[0]) {
|
||||
int i = 0;
|
||||
int a, b, c, d;
|
||||
|
||||
if (CPU_haveCPUID()) {
|
||||
int a, b, c, d;
|
||||
cpuid(0x00000000, a, b, c, d);
|
||||
(void) a;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
||||
SDL_CPUType[i++] = (char)(b & 0xff); b >>= 8;
|
||||
|
@ -557,15 +564,12 @@ int
|
|||
SDL_GetCPUCacheLineSize(void)
|
||||
{
|
||||
const char *cpuType = SDL_GetCPUType();
|
||||
|
||||
int a, b, c, d;
|
||||
(void) a; (void) b; (void) c; (void) d;
|
||||
if (SDL_strcmp(cpuType, "GenuineIntel") == 0) {
|
||||
int a, b, c, d;
|
||||
|
||||
cpuid(0x00000001, a, b, c, d);
|
||||
return (((b >> 8) & 0xff) * 8);
|
||||
} else if (SDL_strcmp(cpuType, "AuthenticAMD") == 0) {
|
||||
int a, b, c, d;
|
||||
|
||||
cpuid(0x80000005, a, b, c, d);
|
||||
return (c & 0xff);
|
||||
} else {
|
||||
|
@ -723,6 +727,7 @@ int
|
|||
SDL_GetSystemRAM(void)
|
||||
{
|
||||
if (!SDL_SystemRAM) {
|
||||
#ifndef SDL_CPUINFO_DISABLED
|
||||
#if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
|
||||
if (SDL_SystemRAM <= 0) {
|
||||
SDL_SystemRAM = (int)((Sint64)sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE) / (1024*1024));
|
||||
|
@ -756,6 +761,7 @@ SDL_GetSystemRAM(void)
|
|||
SDL_SystemRAM = (int)(stat.ullTotalPhys / (1024 * 1024));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
return SDL_SystemRAM;
|
||||
|
|
|
@ -206,7 +206,14 @@ SDL_DYNAPI_entry(Uint32 apiver, void *table, Uint32 tablesize)
|
|||
static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
|
||||
{
|
||||
HANDLE lib = LoadLibraryA(fname);
|
||||
return lib ? GetProcAddress(lib, sym) : NULL;
|
||||
void *retval = NULL;
|
||||
if (lib) {
|
||||
retval = GetProcAddress(lib, sym);
|
||||
if (retval == NULL) {
|
||||
FreeLibrary(lib);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
#elif defined(__HAIKU__)
|
||||
|
@ -215,8 +222,11 @@ static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
|
|||
{
|
||||
image_id lib = load_add_on(fname);
|
||||
void *retval = NULL;
|
||||
if ((lib < 0) || (get_image_symbol(lib, sym, B_SYMBOL_TYPE_TEXT, &retval) != B_NO_ERROR)) {
|
||||
retval = NULL;
|
||||
if (lib >= 0) {
|
||||
if (get_image_symbol(lib, sym, B_SYMBOL_TYPE_TEXT, &retval) != B_NO_ERROR) {
|
||||
unload_add_on(lib);
|
||||
retval = NULL;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
@ -225,7 +235,14 @@ static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
|
|||
static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym)
|
||||
{
|
||||
void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL);
|
||||
return lib ? dlsym(lib, sym) : NULL;
|
||||
void *retval = NULL;
|
||||
if (lib != NULL) {
|
||||
retval = dlsym(lib, sym);
|
||||
if (retval == NULL) {
|
||||
dlclose(lib);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
#else
|
||||
#error Please define your platform.
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include "TargetConditionals.h"
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IPHONE || __native_client__ /* probably not useful on iOS or NACL. */
|
||||
#if TARGET_OS_IPHONE || __native_client__ || __EMSCRIPTEN__ /* probably not useful on iOS, NACL or Emscripten. */
|
||||
#define SDL_DYNAMIC_API 0
|
||||
#elif SDL_BUILDING_WINRT /* probaly not useful on WinRT, given current .dll loading restrictions */
|
||||
#define SDL_DYNAMIC_API 0
|
||||
|
|
|
@ -397,7 +397,7 @@ SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8
|
|||
}
|
||||
|
||||
int
|
||||
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
|
||||
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
int posted;
|
||||
|
@ -419,6 +419,7 @@ SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
|
|||
event.wheel.which = mouseID;
|
||||
event.wheel.x = x;
|
||||
event.wheel.y = y;
|
||||
event.wheel.direction = (Uint32)direction;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
return posted;
|
||||
|
|
|
@ -120,7 +120,7 @@ extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int rel
|
|||
extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
|
||||
|
||||
/* Send a mouse wheel event */
|
||||
extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y);
|
||||
extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction);
|
||||
|
||||
/* Shutdown the mouse subsystem */
|
||||
extern void SDL_MouseQuit(void);
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifdef SDL_FILESYSTEM_EMSCRIPTEN
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_filesystem.h"
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
char *retval = "/";
|
||||
return SDL_strdup(retval);
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
const char *append = "/libsdl/";
|
||||
char *retval;
|
||||
size_t len = 0;
|
||||
|
||||
len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(retval, len, "%s%s/%s/", append, org, app);
|
||||
|
||||
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
|
||||
SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_EMSCRIPTEN */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -144,49 +144,6 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
* without violating Microsoft's app-store requirements.
|
||||
*/
|
||||
|
||||
/* Default to using a Local/non-Roaming path. WinRT will often attempt
|
||||
* to synchronize files in Roaming paths, and will do so while an app is
|
||||
* running. Using a Local path prevents the possibility that an app's
|
||||
* save-data files will get changed from underneath it, without it
|
||||
* being ready.
|
||||
*
|
||||
* This behavior can be changed via use of the
|
||||
* SDL_HINT_WINRT_PREF_PATH_ROOT hint.
|
||||
*/
|
||||
SDL_WinRT_Path pathType = SDL_WINRT_PATH_LOCAL_FOLDER;
|
||||
|
||||
const char * hint = SDL_GetHint(SDL_HINT_WINRT_PREF_PATH_ROOT);
|
||||
if (hint) {
|
||||
if (SDL_strcasecmp(hint, "local") == 0) {
|
||||
pathType = SDL_WINRT_PATH_LOCAL_FOLDER;
|
||||
} else if (SDL_strcasecmp(hint, "roaming") == 0) {
|
||||
#if (WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP) || (NTDDI_VERSION > NTDDI_WIN8)
|
||||
pathType = SDL_WINRT_PATH_ROAMING_FOLDER;
|
||||
#else
|
||||
/* Don't apply a 'Roaming' path on Windows Phone 8.0. Roaming
|
||||
* data is not supported by that version of the operating system.
|
||||
*/
|
||||
SDL_SetError("A Roaming path was specified via SDL_HINT_WINRT_PREF_PATH_ROOT, but Roaming is not supported on Windows Phone 8.0");
|
||||
return NULL;
|
||||
#endif
|
||||
} else if (SDL_strcasecmp(hint, "old") == 0) {
|
||||
/* Older versions of SDL/WinRT, including 2.0.3, would return a
|
||||
* pref-path that used a Roaming folder on non-Phone versions of
|
||||
* Windows, such as Windows 8.0 and Windows 8.1. This has since
|
||||
* been reverted to using a Local folder, in order to prevent
|
||||
* problems arising from WinRT automatically synchronizing files
|
||||
* during an app's lifetime. In case this functionality is
|
||||
* desired, setting SDL_HINT_WINRT_PREF_PATH_ROOT to "old" will
|
||||
* trigger the older behavior.
|
||||
*/
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
pathType = SDL_WINRT_PATH_LOCAL_FOLDER;
|
||||
#else
|
||||
pathType = SDL_WINRT_PATH_ROAMING_FOLDER;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
const WCHAR * srcPath = NULL;
|
||||
WCHAR path[MAX_PATH];
|
||||
char *retval = NULL;
|
||||
|
@ -195,7 +152,7 @@ SDL_GetPrefPath(const char *org, const char *app)
|
|||
size_t new_wpath_len = 0;
|
||||
BOOL api_result = FALSE;
|
||||
|
||||
srcPath = SDL_WinRTGetFSPathUNICODE(pathType);
|
||||
srcPath = SDL_WinRTGetFSPathUNICODE(SDL_WINRT_PATH_LOCAL_FOLDER);
|
||||
if ( ! srcPath) {
|
||||
SDL_SetError("Unable to find a source path");
|
||||
return NULL;
|
||||
|
|
|
@ -27,12 +27,6 @@
|
|||
#include "SDL_haptic.h"
|
||||
|
||||
|
||||
/*
|
||||
* Number of haptic devices on the system.
|
||||
*/
|
||||
extern Uint8 SDL_numhaptics;
|
||||
|
||||
|
||||
struct haptic_effect
|
||||
{
|
||||
SDL_HapticEffect effect; /* The current event */
|
||||
|
|
|
@ -551,7 +551,7 @@ SDL_SYS_HapticOpenFromService(SDL_Haptic * haptic, io_service_t service)
|
|||
FFReleaseDevice(haptic->hwdata->device);
|
||||
creat_err:
|
||||
if (haptic->hwdata != NULL) {
|
||||
free(haptic->hwdata);
|
||||
SDL_free(haptic->hwdata);
|
||||
haptic->hwdata = NULL;
|
||||
}
|
||||
return -1;
|
||||
|
|
|
@ -441,7 +441,7 @@ SDL_SYS_HapticOpenFromFD(SDL_Haptic * haptic, int fd)
|
|||
open_err:
|
||||
close(fd);
|
||||
if (haptic->hwdata != NULL) {
|
||||
free(haptic->hwdata);
|
||||
SDL_free(haptic->hwdata);
|
||||
haptic->hwdata = NULL;
|
||||
}
|
||||
return -1;
|
||||
|
@ -959,7 +959,7 @@ SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
|
|||
return 0;
|
||||
|
||||
new_effect_err:
|
||||
free(effect->hweffect);
|
||||
SDL_free(effect->hweffect);
|
||||
effect->hweffect = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ typedef struct _ControllerMapping_t
|
|||
|
||||
static ControllerMapping_t *s_pSupportedControllers = NULL;
|
||||
static ControllerMapping_t *s_pXInputMapping = NULL;
|
||||
static ControllerMapping_t *s_pEmscriptenMapping = NULL;
|
||||
|
||||
/* The SDL game controller structure */
|
||||
struct _SDL_GameController
|
||||
|
@ -263,7 +264,13 @@ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
|
|||
return s_pXInputMapping;
|
||||
}
|
||||
else
|
||||
#endif /* SDL_JOYSTICK_XINPUT */
|
||||
#endif
|
||||
#if defined(SDL_JOYSTICK_EMSCRIPTEN)
|
||||
if (s_pEmscriptenMapping) {
|
||||
return s_pEmscriptenMapping;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID(device_index);
|
||||
return SDL_PrivateGetControllerMappingForGUID(&jGUID);
|
||||
|
@ -668,6 +675,7 @@ SDL_GameControllerAddMapping(const char *mappingString)
|
|||
SDL_JoystickGUID jGUID;
|
||||
ControllerMapping_t *pControllerMapping;
|
||||
SDL_bool is_xinput_mapping = SDL_FALSE;
|
||||
SDL_bool is_emscripten_mapping = SDL_FALSE;
|
||||
|
||||
if (!mappingString) {
|
||||
return SDL_InvalidParamError("mappingString");
|
||||
|
@ -680,6 +688,9 @@ SDL_GameControllerAddMapping(const char *mappingString)
|
|||
if (!SDL_strcasecmp(pchGUID, "xinput")) {
|
||||
is_xinput_mapping = SDL_TRUE;
|
||||
}
|
||||
if (!SDL_strcasecmp(pchGUID, "emscripten")) {
|
||||
is_emscripten_mapping = SDL_TRUE;
|
||||
}
|
||||
jGUID = SDL_JoystickGetGUIDFromString(pchGUID);
|
||||
SDL_free(pchGUID);
|
||||
|
||||
|
@ -715,6 +726,9 @@ SDL_GameControllerAddMapping(const char *mappingString)
|
|||
if (is_xinput_mapping) {
|
||||
s_pXInputMapping = pControllerMapping;
|
||||
}
|
||||
if (is_emscripten_mapping) {
|
||||
s_pEmscriptenMapping = pControllerMapping;
|
||||
}
|
||||
pControllerMapping->guid = jGUID;
|
||||
pControllerMapping->name = pchName;
|
||||
pControllerMapping->mapping = pchMapping;
|
||||
|
|
|
@ -76,6 +76,9 @@ static const char *s_ControllerMappings [] =
|
|||
#endif
|
||||
#if defined(__ANDROID__)
|
||||
"4e564944494120436f72706f72617469,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
|
||||
#endif
|
||||
#if defined(SDL_JOYSTICK_EMSCRIPTEN)
|
||||
"emscripten,Standard Gamepad,a:b0,b:b1,x:b2,y:b3,leftshoulder:b4,rightshoulder:b5,lefttrigger:b6,righttrigger:b7,back:b8,start:b9,leftstick:b10,rightstick:b11,dpup:b12,dpdown:b13,dpleft:b14,dpright:b15,guide:b16,leftx:a0,lefty:a1,rightx:a2,righty:a3,",
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
|
|
@ -0,0 +1,426 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_EMSCRIPTEN
|
||||
|
||||
#include <stdio.h> /* For the definition of NULL */
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_events.h"
|
||||
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#endif
|
||||
|
||||
#include "SDL_joystick.h"
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_log.h"
|
||||
#include "SDL_sysjoystick_c.h"
|
||||
#include "../SDL_joystick_c.h"
|
||||
|
||||
static SDL_joylist_item * JoystickByIndex(int index);
|
||||
|
||||
static SDL_joylist_item *SDL_joylist = NULL;
|
||||
static SDL_joylist_item *SDL_joylist_tail = NULL;
|
||||
static int numjoysticks = 0;
|
||||
static int instance_counter = 0;
|
||||
|
||||
int
|
||||
Emscripten_JoyStickConnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
|
||||
{
|
||||
int i;
|
||||
|
||||
SDL_joylist_item *item;
|
||||
|
||||
if (JoystickByIndex(gamepadEvent->index) != NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
SDL_Event event;
|
||||
#endif
|
||||
|
||||
item = (SDL_joylist_item *) SDL_malloc(sizeof (SDL_joylist_item));
|
||||
if (item == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_zerop(item);
|
||||
item->index = gamepadEvent->index;
|
||||
|
||||
item->name = SDL_strdup(gamepadEvent->id);
|
||||
if ( item->name == NULL ) {
|
||||
SDL_free(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
item->mapping = SDL_strdup(gamepadEvent->mapping);
|
||||
if ( item->mapping == NULL ) {
|
||||
SDL_free(item->name);
|
||||
SDL_free(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
item->naxes = gamepadEvent->numAxes;
|
||||
item->nbuttons = gamepadEvent->numButtons;
|
||||
item->device_instance = instance_counter++;
|
||||
|
||||
item->timestamp = gamepadEvent->timestamp;
|
||||
|
||||
for( i = 0; i < item->naxes; i++) {
|
||||
item->axis[i] = gamepadEvent->axis[i];
|
||||
}
|
||||
|
||||
for( i = 0; i < item->nbuttons; i++) {
|
||||
item->analogButton[i] = gamepadEvent->analogButton[i];
|
||||
item->digitalButton[i] = gamepadEvent->digitalButton[i];
|
||||
}
|
||||
|
||||
if (SDL_joylist_tail == NULL) {
|
||||
SDL_joylist = SDL_joylist_tail = item;
|
||||
} else {
|
||||
SDL_joylist_tail->next = item;
|
||||
SDL_joylist_tail = item;
|
||||
}
|
||||
|
||||
++numjoysticks;
|
||||
SDL_Log("%d",numjoysticks);
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
event.type = SDL_JOYDEVICEADDED;
|
||||
|
||||
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
||||
event.jdevice.which = item->device_instance - 1;
|
||||
if ( (SDL_EventOK == NULL) ||
|
||||
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
#endif /* !SDL_EVENTS_DISABLED */
|
||||
|
||||
SDL_Log("Added joystick with index %d", item->index);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_JoyStickDisconnected(int eventType, const EmscriptenGamepadEvent *gamepadEvent, void *userData)
|
||||
{
|
||||
SDL_joylist_item *item = SDL_joylist;
|
||||
SDL_joylist_item *prev = NULL;
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
SDL_Event event;
|
||||
#endif
|
||||
|
||||
while (item != NULL) {
|
||||
if (item->index == gamepadEvent->index) {
|
||||
break;
|
||||
}
|
||||
prev = item;
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
if (item == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const int retval = item->device_instance;
|
||||
if (item->joystick) {
|
||||
item->joystick->hwdata = NULL;
|
||||
}
|
||||
|
||||
if (prev != NULL) {
|
||||
prev->next = item->next;
|
||||
} else {
|
||||
SDL_assert(SDL_joylist == item);
|
||||
SDL_joylist = item->next;
|
||||
}
|
||||
if (item == SDL_joylist_tail) {
|
||||
SDL_joylist_tail = prev;
|
||||
}
|
||||
|
||||
/* Need to decrement the joystick count before we post the event */
|
||||
--numjoysticks;
|
||||
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
event.type = SDL_JOYDEVICEREMOVED;
|
||||
|
||||
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
||||
event.jdevice.which = item->device_instance;
|
||||
if ( (SDL_EventOK == NULL) ||
|
||||
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
}
|
||||
#endif /* !SDL_EVENTS_DISABLED */
|
||||
|
||||
SDL_Log("Removed joystick with index %d", retval);
|
||||
SDL_free(item->name);
|
||||
SDL_free(item->mapping);
|
||||
SDL_free(item);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Function to scan the system for joysticks.
|
||||
* It should return 0, or -1 on an unrecoverable fatal error.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickInit(void)
|
||||
{
|
||||
int retval, i, numjs;
|
||||
EmscriptenGamepadEvent gamepadState;
|
||||
|
||||
numjoysticks = 0;
|
||||
numjs = emscripten_get_num_gamepads();
|
||||
|
||||
/* Check if gamepad is supported by browser */
|
||||
if (numjs == EMSCRIPTEN_RESULT_NOT_SUPPORTED) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* handle already connected gamepads */
|
||||
if (numjs > 0) {
|
||||
for(i = 0; i < numjs; i++) {
|
||||
retval = emscripten_get_gamepad_status(i, &gamepadState);
|
||||
if (retval == EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED,
|
||||
&gamepadState,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retval = emscripten_set_gamepadconnected_callback(NULL,
|
||||
0,
|
||||
Emscripten_JoyStickConnected);
|
||||
|
||||
if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
retval = emscripten_set_gamepaddisconnected_callback(NULL,
|
||||
0,
|
||||
Emscripten_JoyStickDisconnected);
|
||||
if(retval != EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SDL_joylist_item *
|
||||
JoystickByIndex(int index)
|
||||
{
|
||||
SDL_joylist_item *item = SDL_joylist;
|
||||
|
||||
if (index < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (item != NULL) {
|
||||
if (item->index == index) {
|
||||
break;
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
int SDL_SYS_NumJoysticks()
|
||||
{
|
||||
return numjoysticks;
|
||||
}
|
||||
|
||||
void SDL_SYS_JoystickDetect()
|
||||
{
|
||||
}
|
||||
|
||||
// we need to poll to see if the gamepad state has changed
|
||||
SDL_bool SDL_SYS_JoystickNeedsPolling()
|
||||
{
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
/* Function to get the device-dependent name of a joystick */
|
||||
const char *
|
||||
SDL_SYS_JoystickNameForDeviceIndex(int index)
|
||||
{
|
||||
SDL_joylist_item *item = JoystickByIndex(index);
|
||||
if (item == NULL) {
|
||||
SDL_SetError("Joystick with index %d not found", index);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return item->name;
|
||||
}
|
||||
|
||||
/* Function to perform the mapping from device index to the instance id for this index */
|
||||
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
|
||||
{
|
||||
SDL_joylist_item *item = JoystickByIndex(index);
|
||||
if (item == NULL) {
|
||||
SDL_SetError("Joystick with index %d not found", index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return item->device_instance;
|
||||
}
|
||||
|
||||
/* Function to open a joystick for use.
|
||||
The joystick to open is specified by the index field of the joystick.
|
||||
This should fill the nbuttons and naxes fields of the joystick structure.
|
||||
It returns 0, or -1 if there is an error.
|
||||
*/
|
||||
int
|
||||
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int index)
|
||||
{
|
||||
SDL_joylist_item *item = JoystickByIndex(index);
|
||||
|
||||
if (item == NULL ) {
|
||||
return SDL_SetError("No such device");
|
||||
}
|
||||
|
||||
if (item->joystick != NULL) {
|
||||
return SDL_SetError("Joystick already opened");
|
||||
}
|
||||
|
||||
joystick->instance_id = item->device_instance;
|
||||
joystick->hwdata = (struct joystick_hwdata *) item;
|
||||
item->joystick = joystick;
|
||||
|
||||
/* HTML5 Gamepad API doesn't say anything about these */
|
||||
joystick->nhats = 0;
|
||||
joystick->nballs = 0;
|
||||
|
||||
joystick->nbuttons = item->nbuttons;
|
||||
joystick->naxes = item->naxes;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Function to determine is this joystick is attached to the system right now */
|
||||
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
|
||||
{
|
||||
return !joystick->closed && (joystick->hwdata != NULL);
|
||||
}
|
||||
|
||||
/* Function to update the state of a joystick - called as a device poll.
|
||||
* This function shouldn't update the joystick structure directly,
|
||||
* but instead should call SDL_PrivateJoystick*() to deliver events
|
||||
* and update joystick device state.
|
||||
*/
|
||||
void
|
||||
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
|
||||
{
|
||||
EmscriptenGamepadEvent gamepadState;
|
||||
SDL_joylist_item *item = SDL_joylist;
|
||||
int i, result, buttonState;
|
||||
|
||||
while (item != NULL) {
|
||||
result = emscripten_get_gamepad_status(item->index, &gamepadState);
|
||||
if( result == EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
if(gamepadState.timestamp == 0 || gamepadState.timestamp != item->timestamp) {
|
||||
for(i = 0; i < item->nbuttons; i++) {
|
||||
if(item->digitalButton[i] != gamepadState.digitalButton[i]) {
|
||||
buttonState = gamepadState.digitalButton[i]? SDL_PRESSED: SDL_RELEASED;
|
||||
SDL_PrivateJoystickButton(item->joystick, i, buttonState);
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < item->naxes; i++) {
|
||||
if(item->axis[i] != gamepadState.axis[i]) {
|
||||
// do we need to do conversion?
|
||||
SDL_PrivateJoystickAxis(item->joystick, i,
|
||||
(Sint16) (32767.*gamepadState.axis[i]));
|
||||
}
|
||||
}
|
||||
|
||||
item->timestamp = gamepadState.timestamp;
|
||||
for( i = 0; i < item->naxes; i++) {
|
||||
item->axis[i] = gamepadState.axis[i];
|
||||
}
|
||||
|
||||
for( i = 0; i < item->nbuttons; i++) {
|
||||
item->analogButton[i] = gamepadState.analogButton[i];
|
||||
item->digitalButton[i] = gamepadState.digitalButton[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* Function to close a joystick after use */
|
||||
void
|
||||
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
|
||||
{
|
||||
if (joystick->hwdata) {
|
||||
((SDL_joylist_item*)joystick->hwdata)->joystick = NULL;
|
||||
joystick->hwdata = NULL;
|
||||
}
|
||||
joystick->closed = 1;
|
||||
}
|
||||
|
||||
/* Function to perform any system-specific joystick related cleanup */
|
||||
void
|
||||
SDL_SYS_JoystickQuit(void)
|
||||
{
|
||||
SDL_joylist_item *item = NULL;
|
||||
SDL_joylist_item *next = NULL;
|
||||
|
||||
for (item = SDL_joylist; item; item = next) {
|
||||
next = item->next;
|
||||
SDL_free(item->mapping);
|
||||
SDL_free(item->name);
|
||||
SDL_free(item);
|
||||
}
|
||||
|
||||
SDL_joylist = SDL_joylist_tail = NULL;
|
||||
|
||||
numjoysticks = 0;
|
||||
instance_counter = 0;
|
||||
}
|
||||
|
||||
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int index)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = SDL_SYS_JoystickNameForDeviceIndex(index);
|
||||
SDL_zero(guid);
|
||||
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
|
||||
return guid;
|
||||
}
|
||||
|
||||
|
||||
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_JoystickGUID guid;
|
||||
/* the GUID is just the first 16 chars of the name for now */
|
||||
const char *name = joystick->name;
|
||||
SDL_zero(guid);
|
||||
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
|
||||
return guid;
|
||||
}
|
||||
|
||||
#endif /* SDL_JOYSTICK_EMSCRIPTEN */
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_EMSCRIPTEN
|
||||
#include "../SDL_sysjoystick.h"
|
||||
|
||||
|
||||
#include <emscripten/html5.h>
|
||||
|
||||
/* A linked list of available joysticks */
|
||||
typedef struct SDL_joylist_item
|
||||
{
|
||||
int index;
|
||||
char *name;
|
||||
char *mapping;
|
||||
SDL_JoystickID device_instance;
|
||||
SDL_Joystick *joystick;
|
||||
int nbuttons;
|
||||
int naxes;
|
||||
double timestamp;
|
||||
double axis[64];
|
||||
double analogButton[64];
|
||||
EM_BOOL digitalButton[64];
|
||||
|
||||
struct SDL_joylist_item *next;
|
||||
} SDL_joylist_item;
|
||||
|
||||
typedef SDL_joylist_item joystick_hwdata;
|
||||
|
||||
#endif /* SDL_JOYSTICK_EMSCRIPTEN */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -254,7 +254,7 @@ private:
|
|||
return;
|
||||
}
|
||||
win = GetSDLWindow(winID);
|
||||
SDL_SendMouseWheel(win, 0, xTicks, yTicks);
|
||||
SDL_SendMouseWheel(win, 0, xTicks, yTicks, SDL_MOUSEWHEEL_NORMAL);
|
||||
}
|
||||
|
||||
void _HandleKey(BMessage *msg) {
|
||||
|
|
|
@ -38,6 +38,7 @@ SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
|
|||
SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_WinRT(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_Emscripten(SDL_PowerState *, int *, int *);
|
||||
|
||||
#ifndef SDL_POWER_DISABLED
|
||||
#ifdef SDL_POWER_HARDWIRED
|
||||
|
@ -81,6 +82,9 @@ static SDL_GetPowerInfo_Impl implementations[] = {
|
|||
#ifdef SDL_POWER_WINRT /* handles WinRT */
|
||||
SDL_GetPowerInfo_WinRT,
|
||||
#endif
|
||||
#ifdef SDL_POWER_EMSCRIPTEN /* handles Emscripten */
|
||||
SDL_GetPowerInfo_Emscripten,
|
||||
#endif
|
||||
|
||||
#ifdef SDL_POWER_HARDWIRED
|
||||
SDL_GetPowerInfo_Hardwired,
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifndef SDL_POWER_DISABLED
|
||||
#if SDL_POWER_EMSCRIPTEN
|
||||
|
||||
#include <emscripten/html5.h>
|
||||
|
||||
#include "SDL_power.h"
|
||||
|
||||
SDL_bool
|
||||
SDL_GetPowerInfo_Emscripten(SDL_PowerState *state, int *seconds, int *percent)
|
||||
{
|
||||
EmscriptenBatteryEvent batteryState;
|
||||
int haveBattery = 0;
|
||||
|
||||
if (emscripten_get_battery_status(&batteryState) == EMSCRIPTEN_RESULT_NOT_SUPPORTED)
|
||||
return SDL_FALSE;
|
||||
|
||||
haveBattery = batteryState.level != 1.0 || !batteryState.charging || batteryState.chargingTime != 0.0;
|
||||
|
||||
if (!haveBattery) {
|
||||
*state = SDL_POWERSTATE_NO_BATTERY;
|
||||
*seconds = -1;
|
||||
*percent = -1;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
if (batteryState.charging)
|
||||
*state = batteryState.chargingTime == 0.0 ? SDL_POWERSTATE_CHARGED : SDL_POWERSTATE_CHARGING;
|
||||
else
|
||||
*state = SDL_POWERSTATE_ON_BATTERY;
|
||||
|
||||
*seconds = batteryState.dischargingTime;
|
||||
*percent = batteryState.level * 100;
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_EMSCRIPTEN */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -69,3 +69,7 @@ SDL_PROC(GLenum, glCheckFramebufferStatus, (GLenum))
|
|||
SDL_PROC(void, glDeleteFramebuffers, (GLsizei, const GLuint *))
|
||||
SDL_PROC(GLint, glGetAttribLocation, (GLuint, const GLchar *))
|
||||
SDL_PROC(void, glGetProgramInfoLog, (GLuint, GLsizei, GLsizei*, GLchar*))
|
||||
SDL_PROC(void, glGenBuffers, (GLsizei, GLuint *))
|
||||
SDL_PROC(void, glBindBuffer, (GLenum, GLuint))
|
||||
SDL_PROC(void, glBufferData, (GLenum, GLsizeiptr, const GLvoid *, GLenum))
|
||||
SDL_PROC(void, glBufferSubData, (GLenum, GLintptr, GLsizeiptr, const GLvoid *))
|
||||
|
|
|
@ -28,7 +28,20 @@
|
|||
#include "../../video/SDL_blit.h"
|
||||
#include "SDL_shaders_gles2.h"
|
||||
|
||||
/* To prevent unnecessary window recreation,
|
||||
/* !!! FIXME: Emscripten makes these into WebGL calls, and WebGL doesn't offer
|
||||
!!! FIXME: client-side arrays (without an Emscripten compatibility hack,
|
||||
!!! FIXME: at least), but the current VBO code here is dramatically
|
||||
!!! FIXME: slower on actual iOS devices, even though the iOS Simulator
|
||||
!!! FIXME: is okay. Some time after 2.0.4 ships, we should revisit this,
|
||||
!!! FIXME: fix the performance bottleneck, and make everything use VBOs.
|
||||
*/
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#define SDL_GLES2_USE_VBOS 1
|
||||
#else
|
||||
#define SDL_GLES2_USE_VBOS 0
|
||||
#endif
|
||||
|
||||
/* To prevent unnecessary window recreation,
|
||||
* these should match the defaults selected in SDL_GL_ResetAttributes
|
||||
*/
|
||||
#define RENDERER_CONTEXT_MAJOR 2
|
||||
|
@ -180,6 +193,11 @@ typedef struct GLES2_DriverContext
|
|||
GLES2_ProgramCache program_cache;
|
||||
GLES2_ProgramCacheEntry *current_program;
|
||||
Uint8 clear_r, clear_g, clear_b, clear_a;
|
||||
|
||||
#if SDL_GLES2_USE_VBOS
|
||||
GLuint vertex_buffers[4];
|
||||
GLsizeiptr vertex_buffer_size[4];
|
||||
#endif
|
||||
} GLES2_DriverContext;
|
||||
|
||||
#define GLES2_MAX_CACHED_PROGRAMS 8
|
||||
|
@ -1392,6 +1410,33 @@ GLES2_SetDrawingState(SDL_Renderer * renderer)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GLES2_UpdateVertexBuffer(SDL_Renderer *renderer, GLES2_Attribute attr,
|
||||
const void *vertexData, size_t dataSizeInBytes)
|
||||
{
|
||||
GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
|
||||
|
||||
#if !SDL_GLES2_USE_VBOS
|
||||
data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, vertexData);
|
||||
#else
|
||||
if (!data->vertex_buffers[attr])
|
||||
data->glGenBuffers(1, &data->vertex_buffers[attr]);
|
||||
|
||||
data->glBindBuffer(GL_ARRAY_BUFFER, data->vertex_buffers[attr]);
|
||||
|
||||
if (data->vertex_buffer_size[attr] < dataSizeInBytes) {
|
||||
data->glBufferData(GL_ARRAY_BUFFER, dataSizeInBytes, vertexData, GL_STREAM_DRAW);
|
||||
data->vertex_buffer_size[attr] = dataSizeInBytes;
|
||||
} else {
|
||||
data->glBufferSubData(GL_ARRAY_BUFFER, 0, dataSizeInBytes, vertexData);
|
||||
}
|
||||
|
||||
data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
|
||||
{
|
||||
|
@ -1412,7 +1457,8 @@ GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int cou
|
|||
vertices[idx * 2] = x;
|
||||
vertices[(idx * 2) + 1] = y;
|
||||
}
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
|
||||
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, count * 2 * sizeof(GLfloat));
|
||||
data->glDrawArrays(GL_POINTS, 0, count);
|
||||
SDL_stack_free(vertices);
|
||||
return 0;
|
||||
|
@ -1438,7 +1484,8 @@ GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, int coun
|
|||
vertices[idx * 2] = x;
|
||||
vertices[(idx * 2) + 1] = y;
|
||||
}
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
|
||||
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, count * 2 * sizeof(GLfloat));
|
||||
data->glDrawArrays(GL_LINE_STRIP, 0, count);
|
||||
|
||||
/* We need to close the endpoint of the line */
|
||||
|
@ -1479,7 +1526,8 @@ GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
|
|||
vertices[5] = yMax;
|
||||
vertices[6] = xMax;
|
||||
vertices[7] = yMax;
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
|
||||
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
|
||||
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
return GL_CheckError("", renderer);
|
||||
|
@ -1675,7 +1723,8 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
|
|||
vertices[5] = (dstrect->y + dstrect->h);
|
||||
vertices[6] = (dstrect->x + dstrect->w);
|
||||
vertices[7] = (dstrect->y + dstrect->h);
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
|
||||
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
|
||||
texCoords[0] = srcrect->x / (GLfloat)texture->w;
|
||||
texCoords[1] = srcrect->y / (GLfloat)texture->h;
|
||||
texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
|
||||
|
@ -1684,7 +1733,8 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
|
|||
texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
|
||||
texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
|
||||
texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
|
||||
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);*/
|
||||
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_TEXCOORD, texCoords, 8 * sizeof(GLfloat));
|
||||
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
return GL_CheckError("", renderer);
|
||||
|
@ -1734,9 +1784,13 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
|
|||
vertices[5] = vertices[7] = tmp;
|
||||
}
|
||||
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 1, GL_FLOAT, GL_FALSE, 0, &fAngle);
|
||||
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 1, GL_FLOAT, GL_FALSE, 0, &fAngle);
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate);
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/
|
||||
|
||||
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 4 * sizeof(GLfloat));
|
||||
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_CENTER, translate, 8 * sizeof(GLfloat));
|
||||
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat));
|
||||
|
||||
texCoords[0] = srcrect->x / (GLfloat)texture->w;
|
||||
texCoords[1] = srcrect->y / (GLfloat)texture->h;
|
||||
|
@ -1746,7 +1800,8 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
|
|||
texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
|
||||
texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
|
||||
texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
|
||||
data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
|
||||
/*data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);*/
|
||||
GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_TEXCOORD, texCoords, 8 * sizeof(GLfloat));
|
||||
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_CENTER);
|
||||
data->glDisableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE);
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
|
||||
#define SDL_DISABLE_ANALYZE_MACROS 1
|
||||
#endif
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
#if defined(__WIN32__)
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
|
||||
#define SDL_DISABLE_ANALYZE_MACROS 1
|
||||
#endif
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
/* This file contains portable iconv functions for SDL */
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
|
||||
#define SDL_DISABLE_ANALYZE_MACROS 1
|
||||
#endif
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
/* This file contains portable memory management functions for SDL */
|
||||
|
|
|
@ -41,6 +41,11 @@
|
|||
*
|
||||
* Gareth McCaughan Peterhouse Cambridge 1998
|
||||
*/
|
||||
|
||||
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
|
||||
#define SDL_DISABLE_ANALYZE_MACROS 1
|
||||
#endif
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
/*
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
|
||||
#define SDL_DISABLE_ANALYZE_MACROS 1
|
||||
#endif
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
/* This file contains portable stdlib functions for SDL */
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
|
||||
#define SDL_DISABLE_ANALYZE_MACROS 1
|
||||
#endif
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
/* This file contains portable string manipulation functions for SDL */
|
||||
|
|
|
@ -1105,8 +1105,8 @@ SDLTest_PrintEvent(SDL_Event * event)
|
|||
event->button.windowID);
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
SDL_Log("SDL EVENT: Mouse: wheel scrolled %d in x and %d in y in window %d",
|
||||
event->wheel.x, event->wheel.y, event->wheel.windowID);
|
||||
SDL_Log("SDL EVENT: Mouse: wheel scrolled %d in x and %d in y (reversed: %d) in window %d",
|
||||
event->wheel.x, event->wheel.y, event->wheel.direction, event->wheel.windowID);
|
||||
break;
|
||||
case SDL_JOYDEVICEADDED:
|
||||
SDL_Log("SDL EVENT: Joystick index %d attached",
|
||||
|
@ -1203,6 +1203,15 @@ SDLTest_PrintEvent(SDL_Event * event)
|
|||
event->tfinger.x, event->tfinger.y,
|
||||
event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure);
|
||||
break;
|
||||
case SDL_DOLLARGESTURE:
|
||||
SDL_Log("SDL_EVENT: Dollar gesture detect: %"SDL_PRIs64, (long long) event->dgesture.gestureId);
|
||||
break;
|
||||
case SDL_DOLLARRECORD:
|
||||
SDL_Log("SDL_EVENT: Dollar gesture record: %"SDL_PRIs64, (long long) event->dgesture.gestureId);
|
||||
break;
|
||||
case SDL_MULTIGESTURE:
|
||||
SDL_Log("SDL_EVENT: Multi gesture fingers: %d", event->mgesture.numFingers);
|
||||
break;
|
||||
|
||||
case SDL_RENDER_DEVICE_RESET:
|
||||
SDL_Log("SDL EVENT: render device reset");
|
||||
|
@ -1218,7 +1227,7 @@ SDLTest_PrintEvent(SDL_Event * event)
|
|||
SDL_Log("SDL EVENT: User event %d", event->user.code);
|
||||
break;
|
||||
default:
|
||||
SDL_Log("Unknown event %d", event->type);
|
||||
SDL_Log("Unknown event %04x", event->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -741,15 +741,15 @@ SDL_UpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect,
|
|||
dst_y0 += dst->clip_rect.y;
|
||||
dst_y1 += dst->clip_rect.y;
|
||||
|
||||
final_src.x = SDL_floor(src_x0 + 0.5);
|
||||
final_src.y = SDL_floor(src_y0 + 0.5);
|
||||
final_src.w = SDL_floor(src_x1 - src_x0 + 1.5);
|
||||
final_src.h = SDL_floor(src_y1 - src_y0 + 1.5);
|
||||
final_src.x = (int)SDL_floor(src_x0 + 0.5);
|
||||
final_src.y = (int)SDL_floor(src_y0 + 0.5);
|
||||
final_src.w = (int)SDL_floor(src_x1 - src_x0 + 1.5);
|
||||
final_src.h = (int)SDL_floor(src_y1 - src_y0 + 1.5);
|
||||
|
||||
final_dst.x = SDL_floor(dst_x0 + 0.5);
|
||||
final_dst.y = SDL_floor(dst_y0 + 0.5);
|
||||
final_dst.w = SDL_floor(dst_x1 - dst_x0 + 1.5);
|
||||
final_dst.h = SDL_floor(dst_y1 - dst_y0 + 1.5);
|
||||
final_dst.x = (int)SDL_floor(dst_x0 + 0.5);
|
||||
final_dst.y = (int)SDL_floor(dst_y0 + 0.5);
|
||||
final_dst.w = (int)SDL_floor(dst_x1 - dst_x0 + 1.5);
|
||||
final_dst.h = (int)SDL_floor(dst_y1 - dst_y0 + 1.5);
|
||||
|
||||
if (final_dst.w < 0)
|
||||
final_dst.w = 0;
|
||||
|
|
|
@ -394,6 +394,9 @@ extern VideoBootStrap NACL_bootstrap;
|
|||
#if SDL_VIDEO_DRIVER_VIVANTE
|
||||
extern VideoBootStrap VIVANTE_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_EMSCRIPTEN
|
||||
extern VideoBootStrap Emscripten_bootstrap;
|
||||
#endif
|
||||
|
||||
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
|
||||
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
|
||||
|
|
|
@ -98,6 +98,9 @@ static VideoBootStrap *bootstrap[] = {
|
|||
#if SDL_VIDEO_DRIVER_NACL
|
||||
&NACL_bootstrap,
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_EMSCRIPTEN
|
||||
&Emscripten_bootstrap,
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_DUMMY
|
||||
&DUMMY_bootstrap,
|
||||
#endif
|
||||
|
|
|
@ -399,6 +399,13 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
|
|||
|
||||
float x = -[event deltaX];
|
||||
float y = [event deltaY];
|
||||
SDL_MouseWheelDirection direction = SDL_MOUSEWHEEL_NORMAL;
|
||||
|
||||
if ([event respondsToSelector:@selector(isDirectionInvertedFromDevice)]) {
|
||||
if ([event isDirectionInvertedFromDevice] == YES) {
|
||||
direction = SDL_MOUSEWHEEL_FLIPPED;
|
||||
}
|
||||
}
|
||||
|
||||
if (x > 0) {
|
||||
x += 0.9f;
|
||||
|
@ -410,7 +417,7 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
|
|||
} else if (y < 0) {
|
||||
y -= 0.9f;
|
||||
}
|
||||
SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y);
|
||||
SDL_SendMouseWheel(window, mouse->mouseID, (int)x, (int)y, direction);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -156,7 +156,7 @@ DirectFB_CreateDevice(int devindex)
|
|||
return device;
|
||||
error:
|
||||
if (device)
|
||||
free(device);
|
||||
SDL_free(device);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,638 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_EMSCRIPTEN
|
||||
|
||||
#include <emscripten/html5.h>
|
||||
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#include "../../events/SDL_keyboard_c.h"
|
||||
#include "../../events/SDL_touch_c.h"
|
||||
|
||||
#include "SDL_emscriptenevents.h"
|
||||
#include "SDL_emscriptenvideo.h"
|
||||
|
||||
#include "SDL_hints.h"
|
||||
|
||||
#define FULLSCREEN_MASK ( SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN )
|
||||
|
||||
/*
|
||||
.which to scancode
|
||||
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Constants
|
||||
*/
|
||||
static const SDL_Scancode emscripten_scancode_table[] = {
|
||||
/* 0 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 1 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 2 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 3 */ SDL_SCANCODE_CANCEL,
|
||||
/* 4 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 5 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 6 */ SDL_SCANCODE_HELP,
|
||||
/* 7 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 8 */ SDL_SCANCODE_BACKSPACE,
|
||||
/* 9 */ SDL_SCANCODE_TAB,
|
||||
/* 10 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 11 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 12 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 13 */ SDL_SCANCODE_RETURN,
|
||||
/* 14 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 15 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 16 */ SDL_SCANCODE_LSHIFT,
|
||||
/* 17 */ SDL_SCANCODE_LCTRL,
|
||||
/* 18 */ SDL_SCANCODE_LALT,
|
||||
/* 19 */ SDL_SCANCODE_PAUSE,
|
||||
/* 20 */ SDL_SCANCODE_CAPSLOCK,
|
||||
/* 21 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 22 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 23 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 24 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 25 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 26 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 27 */ SDL_SCANCODE_ESCAPE,
|
||||
/* 28 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 29 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 30 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 31 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 32 */ SDL_SCANCODE_SPACE,
|
||||
/* 33 */ SDL_SCANCODE_PAGEUP,
|
||||
/* 34 */ SDL_SCANCODE_PAGEDOWN,
|
||||
/* 35 */ SDL_SCANCODE_END,
|
||||
/* 36 */ SDL_SCANCODE_HOME,
|
||||
/* 37 */ SDL_SCANCODE_LEFT,
|
||||
/* 38 */ SDL_SCANCODE_UP,
|
||||
/* 39 */ SDL_SCANCODE_RIGHT,
|
||||
/* 40 */ SDL_SCANCODE_DOWN,
|
||||
/* 41 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 42 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 43 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 44 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 45 */ SDL_SCANCODE_INSERT,
|
||||
/* 46 */ SDL_SCANCODE_DELETE,
|
||||
/* 47 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 48 */ SDL_SCANCODE_0,
|
||||
/* 49 */ SDL_SCANCODE_1,
|
||||
/* 50 */ SDL_SCANCODE_2,
|
||||
/* 51 */ SDL_SCANCODE_3,
|
||||
/* 52 */ SDL_SCANCODE_4,
|
||||
/* 53 */ SDL_SCANCODE_5,
|
||||
/* 54 */ SDL_SCANCODE_6,
|
||||
/* 55 */ SDL_SCANCODE_7,
|
||||
/* 56 */ SDL_SCANCODE_8,
|
||||
/* 57 */ SDL_SCANCODE_9,
|
||||
/* 58 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 59 */ SDL_SCANCODE_SEMICOLON,
|
||||
/* 60 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 61 */ SDL_SCANCODE_EQUALS,
|
||||
/* 62 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 63 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 64 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 65 */ SDL_SCANCODE_A,
|
||||
/* 66 */ SDL_SCANCODE_B,
|
||||
/* 67 */ SDL_SCANCODE_C,
|
||||
/* 68 */ SDL_SCANCODE_D,
|
||||
/* 69 */ SDL_SCANCODE_E,
|
||||
/* 70 */ SDL_SCANCODE_F,
|
||||
/* 71 */ SDL_SCANCODE_G,
|
||||
/* 72 */ SDL_SCANCODE_H,
|
||||
/* 73 */ SDL_SCANCODE_I,
|
||||
/* 74 */ SDL_SCANCODE_J,
|
||||
/* 75 */ SDL_SCANCODE_K,
|
||||
/* 76 */ SDL_SCANCODE_L,
|
||||
/* 77 */ SDL_SCANCODE_M,
|
||||
/* 78 */ SDL_SCANCODE_N,
|
||||
/* 79 */ SDL_SCANCODE_O,
|
||||
/* 80 */ SDL_SCANCODE_P,
|
||||
/* 81 */ SDL_SCANCODE_Q,
|
||||
/* 82 */ SDL_SCANCODE_R,
|
||||
/* 83 */ SDL_SCANCODE_S,
|
||||
/* 84 */ SDL_SCANCODE_T,
|
||||
/* 85 */ SDL_SCANCODE_U,
|
||||
/* 86 */ SDL_SCANCODE_V,
|
||||
/* 87 */ SDL_SCANCODE_W,
|
||||
/* 88 */ SDL_SCANCODE_X,
|
||||
/* 89 */ SDL_SCANCODE_Y,
|
||||
/* 90 */ SDL_SCANCODE_Z,
|
||||
/* 91 */ SDL_SCANCODE_LGUI,
|
||||
/* 92 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 93 */ SDL_SCANCODE_APPLICATION,
|
||||
/* 94 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 95 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 96 */ SDL_SCANCODE_KP_0,
|
||||
/* 97 */ SDL_SCANCODE_KP_1,
|
||||
/* 98 */ SDL_SCANCODE_KP_2,
|
||||
/* 99 */ SDL_SCANCODE_KP_3,
|
||||
/* 100 */ SDL_SCANCODE_KP_4,
|
||||
/* 101 */ SDL_SCANCODE_KP_5,
|
||||
/* 102 */ SDL_SCANCODE_KP_6,
|
||||
/* 103 */ SDL_SCANCODE_KP_7,
|
||||
/* 104 */ SDL_SCANCODE_KP_8,
|
||||
/* 105 */ SDL_SCANCODE_KP_9,
|
||||
/* 106 */ SDL_SCANCODE_KP_MULTIPLY,
|
||||
/* 107 */ SDL_SCANCODE_KP_PLUS,
|
||||
/* 108 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 109 */ SDL_SCANCODE_KP_MINUS,
|
||||
/* 110 */ SDL_SCANCODE_KP_PERIOD,
|
||||
/* 111 */ SDL_SCANCODE_KP_DIVIDE,
|
||||
/* 112 */ SDL_SCANCODE_F1,
|
||||
/* 113 */ SDL_SCANCODE_F2,
|
||||
/* 114 */ SDL_SCANCODE_F3,
|
||||
/* 115 */ SDL_SCANCODE_F4,
|
||||
/* 116 */ SDL_SCANCODE_F5,
|
||||
/* 117 */ SDL_SCANCODE_F6,
|
||||
/* 118 */ SDL_SCANCODE_F7,
|
||||
/* 119 */ SDL_SCANCODE_F8,
|
||||
/* 120 */ SDL_SCANCODE_F9,
|
||||
/* 121 */ SDL_SCANCODE_F10,
|
||||
/* 122 */ SDL_SCANCODE_F11,
|
||||
/* 123 */ SDL_SCANCODE_F12,
|
||||
/* 124 */ SDL_SCANCODE_F13,
|
||||
/* 125 */ SDL_SCANCODE_F14,
|
||||
/* 126 */ SDL_SCANCODE_F15,
|
||||
/* 127 */ SDL_SCANCODE_F16,
|
||||
/* 128 */ SDL_SCANCODE_F17,
|
||||
/* 129 */ SDL_SCANCODE_F18,
|
||||
/* 130 */ SDL_SCANCODE_F19,
|
||||
/* 131 */ SDL_SCANCODE_F20,
|
||||
/* 132 */ SDL_SCANCODE_F21,
|
||||
/* 133 */ SDL_SCANCODE_F22,
|
||||
/* 134 */ SDL_SCANCODE_F23,
|
||||
/* 135 */ SDL_SCANCODE_F24,
|
||||
/* 136 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 137 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 138 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 139 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 140 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 141 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 142 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 143 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 144 */ SDL_SCANCODE_NUMLOCKCLEAR,
|
||||
/* 145 */ SDL_SCANCODE_SCROLLLOCK,
|
||||
/* 146 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 147 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 148 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 149 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 150 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 151 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 152 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 153 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 154 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 155 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 156 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 157 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 158 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 159 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 160 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 161 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 162 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 163 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 164 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 165 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 166 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 167 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 168 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 169 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 170 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 171 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 172 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 173 */ SDL_SCANCODE_MINUS, /*FX*/
|
||||
/* 174 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 175 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 176 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 177 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 178 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 179 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 180 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 181 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 182 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 183 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 184 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 185 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 186 */ SDL_SCANCODE_SEMICOLON, /*IE, Chrome, D3E legacy*/
|
||||
/* 187 */ SDL_SCANCODE_EQUALS, /*IE, Chrome, D3E legacy*/
|
||||
/* 188 */ SDL_SCANCODE_COMMA,
|
||||
/* 189 */ SDL_SCANCODE_MINUS, /*IE, Chrome, D3E legacy*/
|
||||
/* 190 */ SDL_SCANCODE_PERIOD,
|
||||
/* 191 */ SDL_SCANCODE_SLASH,
|
||||
/* 192 */ SDL_SCANCODE_GRAVE, /*FX, D3E legacy (SDL_SCANCODE_APOSTROPHE in IE/Chrome)*/
|
||||
/* 193 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 194 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 195 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 196 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 197 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 198 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 199 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 200 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 201 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 202 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 203 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 204 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 205 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 206 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 207 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 208 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 209 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 210 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 211 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 212 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 213 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 214 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 215 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 216 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 217 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 218 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 219 */ SDL_SCANCODE_LEFTBRACKET,
|
||||
/* 220 */ SDL_SCANCODE_BACKSLASH,
|
||||
/* 221 */ SDL_SCANCODE_RIGHTBRACKET,
|
||||
/* 222 */ SDL_SCANCODE_APOSTROPHE, /*FX, D3E legacy*/
|
||||
};
|
||||
|
||||
|
||||
/* "borrowed" from SDL_windowsevents.c */
|
||||
int
|
||||
Emscripten_ConvertUTF32toUTF8(Uint32 codepoint, char * text)
|
||||
{
|
||||
if (codepoint <= 0x7F) {
|
||||
text[0] = (char) codepoint;
|
||||
text[1] = '\0';
|
||||
} else if (codepoint <= 0x7FF) {
|
||||
text[0] = 0xC0 | (char) ((codepoint >> 6) & 0x1F);
|
||||
text[1] = 0x80 | (char) (codepoint & 0x3F);
|
||||
text[2] = '\0';
|
||||
} else if (codepoint <= 0xFFFF) {
|
||||
text[0] = 0xE0 | (char) ((codepoint >> 12) & 0x0F);
|
||||
text[1] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
|
||||
text[2] = 0x80 | (char) (codepoint & 0x3F);
|
||||
text[3] = '\0';
|
||||
} else if (codepoint <= 0x10FFFF) {
|
||||
text[0] = 0xF0 | (char) ((codepoint >> 18) & 0x0F);
|
||||
text[1] = 0x80 | (char) ((codepoint >> 12) & 0x3F);
|
||||
text[2] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
|
||||
text[3] = 0x80 | (char) (codepoint & 0x3F);
|
||||
text[4] = '\0';
|
||||
} else {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
|
||||
{
|
||||
SDL_WindowData *window_data = userData;
|
||||
int mx = mouseEvent->canvasX, my = mouseEvent->canvasY;
|
||||
EmscriptenPointerlockChangeEvent pointerlock_status;
|
||||
|
||||
/* check for pointer lock */
|
||||
emscripten_get_pointerlock_status(&pointerlock_status);
|
||||
|
||||
if (pointerlock_status.isActive) {
|
||||
mx = mouseEvent->movementX;
|
||||
my = mouseEvent->movementY;
|
||||
}
|
||||
|
||||
/* rescale (in case canvas is being scaled)*/
|
||||
double client_w, client_h;
|
||||
emscripten_get_element_css_size(NULL, &client_w, &client_h);
|
||||
|
||||
mx = mx * (window_data->window->w / (client_w * window_data->pixel_ratio));
|
||||
my = my * (window_data->window->h / (client_h * window_data->pixel_ratio));
|
||||
|
||||
SDL_SendMouseMotion(window_data->window, 0, pointerlock_status.isActive, mx, my);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleMouseButton(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
|
||||
{
|
||||
SDL_WindowData *window_data = userData;
|
||||
uint32_t sdl_button;
|
||||
switch (mouseEvent->button) {
|
||||
case 0:
|
||||
sdl_button = SDL_BUTTON_LEFT;
|
||||
break;
|
||||
case 1:
|
||||
sdl_button = SDL_BUTTON_MIDDLE;
|
||||
break;
|
||||
case 2:
|
||||
sdl_button = SDL_BUTTON_RIGHT;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
SDL_SendMouseButton(window_data->window, 0, eventType == EMSCRIPTEN_EVENT_MOUSEDOWN ? SDL_PRESSED : SDL_RELEASED, sdl_button);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData)
|
||||
{
|
||||
SDL_WindowData *window_data = userData;
|
||||
SDL_SendWindowEvent(window_data->window, eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? SDL_WINDOWEVENT_ENTER : SDL_WINDOWEVENT_LEAVE, 0, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleWheel(int eventType, const EmscriptenWheelEvent *wheelEvent, void *userData)
|
||||
{
|
||||
SDL_WindowData *window_data = userData;
|
||||
SDL_SendMouseWheel(window_data->window, 0, wheelEvent->deltaX, -wheelEvent->deltaY, SDL_MOUSEWHEEL_NORMAL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleFocus(int eventType, const EmscriptenFocusEvent *wheelEvent, void *userData)
|
||||
{
|
||||
SDL_WindowData *window_data = userData;
|
||||
SDL_SendWindowEvent(window_data->window, eventType == EMSCRIPTEN_EVENT_FOCUS ? SDL_WINDOWEVENT_FOCUS_GAINED : SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
|
||||
{
|
||||
/*SDL_WindowData *window_data = userData;*/
|
||||
int i;
|
||||
|
||||
SDL_TouchID deviceId = 0;
|
||||
if (!SDL_GetTouch(deviceId)) {
|
||||
if (SDL_AddTouch(deviceId, "") < 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < touchEvent->numTouches; i++) {
|
||||
long x, y, id;
|
||||
|
||||
if (!touchEvent->touches[i].isChanged)
|
||||
continue;
|
||||
|
||||
id = touchEvent->touches[i].identifier;
|
||||
x = touchEvent->touches[i].canvasX;
|
||||
y = touchEvent->touches[i].canvasY;
|
||||
|
||||
if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) {
|
||||
SDL_SendTouchMotion(deviceId, id, x, y, 1.0f);
|
||||
} else if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
|
||||
SDL_SendTouch(deviceId, id, SDL_TRUE, x, y, 1.0f);
|
||||
} else {
|
||||
SDL_SendTouch(deviceId, id, SDL_FALSE, x, y, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
|
||||
{
|
||||
Uint32 scancode;
|
||||
|
||||
/* .keyCode is deprecated, but still the most reliable way to get keys */
|
||||
if (keyEvent->keyCode < SDL_arraysize(emscripten_scancode_table)) {
|
||||
scancode = emscripten_scancode_table[keyEvent->keyCode];
|
||||
|
||||
if (scancode != SDL_SCANCODE_UNKNOWN) {
|
||||
|
||||
if (keyEvent->location == DOM_KEY_LOCATION_RIGHT) {
|
||||
switch (scancode) {
|
||||
case SDL_SCANCODE_LSHIFT:
|
||||
scancode = SDL_SCANCODE_RSHIFT;
|
||||
break;
|
||||
case SDL_SCANCODE_LCTRL:
|
||||
scancode = SDL_SCANCODE_RCTRL;
|
||||
break;
|
||||
case SDL_SCANCODE_LALT:
|
||||
scancode = SDL_SCANCODE_RALT;
|
||||
break;
|
||||
case SDL_SCANCODE_LGUI:
|
||||
scancode = SDL_SCANCODE_RGUI;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDL_SendKeyboardKey(eventType == EMSCRIPTEN_EVENT_KEYDOWN ?
|
||||
SDL_PRESSED : SDL_RELEASED, scancode);
|
||||
}
|
||||
}
|
||||
|
||||
/* if we prevent keydown, we won't get keypress
|
||||
* also we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
|
||||
*/
|
||||
return SDL_GetEventState(SDL_TEXTINPUT) != SDL_ENABLE || eventType != EMSCRIPTEN_EVENT_KEYDOWN
|
||||
|| keyEvent->keyCode == 8 /* backspace */ || keyEvent->keyCode == 9 /* tab */;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleKeyPress(int eventType, const EmscriptenKeyboardEvent *keyEvent, void *userData)
|
||||
{
|
||||
char text[5];
|
||||
Emscripten_ConvertUTF32toUTF8(keyEvent->charCode, text);
|
||||
SDL_SendKeyboardText(text);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleFullscreenChange(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData)
|
||||
{
|
||||
/*make sure this is actually our element going fullscreen*/
|
||||
if(SDL_strcmp(fullscreenChangeEvent->id, "SDLFullscreenElement") != 0)
|
||||
return 0;
|
||||
|
||||
SDL_WindowData *window_data = userData;
|
||||
if(fullscreenChangeEvent->isFullscreen)
|
||||
{
|
||||
SDL_bool is_desktop_fullscreen;
|
||||
window_data->window->flags |= window_data->requested_fullscreen_mode;
|
||||
|
||||
if(!window_data->requested_fullscreen_mode)
|
||||
window_data->window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; /*we didn't reqest fullscreen*/
|
||||
|
||||
window_data->requested_fullscreen_mode = 0;
|
||||
|
||||
is_desktop_fullscreen = (window_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
|
||||
/*update size*/
|
||||
if(window_data->window->flags & SDL_WINDOW_RESIZABLE || is_desktop_fullscreen)
|
||||
{
|
||||
emscripten_set_canvas_size(fullscreenChangeEvent->screenWidth, fullscreenChangeEvent->screenHeight);
|
||||
SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, fullscreenChangeEvent->screenWidth, fullscreenChangeEvent->screenHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*preserve ratio*/
|
||||
double w = window_data->window->w;
|
||||
double h = window_data->window->h;
|
||||
double factor = SDL_min(fullscreenChangeEvent->screenWidth / w, fullscreenChangeEvent->screenHeight / h);
|
||||
emscripten_set_element_css_size(NULL, w * factor, h * factor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EM_ASM({
|
||||
//un-reparent canvas (similar to Module.requestFullscreen)
|
||||
var canvas = Module['canvas'];
|
||||
if(canvas.parentNode.id == "SDLFullscreenElement") {
|
||||
var canvasContainer = canvas.parentNode;
|
||||
canvasContainer.parentNode.insertBefore(canvas, canvasContainer);
|
||||
canvasContainer.parentNode.removeChild(canvasContainer);
|
||||
}
|
||||
});
|
||||
double unscaled_w = window_data->windowed_width / window_data->pixel_ratio;
|
||||
double unscaled_h = window_data->windowed_height / window_data->pixel_ratio;
|
||||
emscripten_set_canvas_size(window_data->windowed_width, window_data->windowed_height);
|
||||
|
||||
if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
|
||||
emscripten_set_element_css_size(NULL, unscaled_w, unscaled_h);
|
||||
}
|
||||
|
||||
SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, unscaled_w, unscaled_h);
|
||||
|
||||
window_data->window->flags &= ~FULLSCREEN_MASK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData)
|
||||
{
|
||||
SDL_WindowData *window_data = userData;
|
||||
if(window_data->window->flags & FULLSCREEN_MASK)
|
||||
{
|
||||
SDL_bool is_desktop_fullscreen = (window_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
|
||||
if(window_data->window->flags & SDL_WINDOW_RESIZABLE || is_desktop_fullscreen)
|
||||
{
|
||||
emscripten_set_canvas_size(uiEvent->windowInnerWidth * window_data->pixel_ratio, uiEvent->windowInnerHeight * window_data->pixel_ratio);
|
||||
SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, uiEvent->windowInnerWidth, uiEvent->windowInnerHeight);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* this will only work if the canvas size is set through css */
|
||||
if(window_data->window->flags & SDL_WINDOW_RESIZABLE)
|
||||
{
|
||||
double w = window_data->window->w;
|
||||
double h = window_data->window->h;
|
||||
|
||||
if(window_data->external_size) {
|
||||
emscripten_get_element_css_size(NULL, &w, &h);
|
||||
}
|
||||
|
||||
emscripten_set_canvas_size(w * window_data->pixel_ratio, h * window_data->pixel_ratio);
|
||||
|
||||
/* set_canvas_size unsets this */
|
||||
if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
|
||||
emscripten_set_element_css_size(NULL, w, h);
|
||||
}
|
||||
|
||||
SDL_SendWindowEvent(window_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Emscripten_HandleVisibilityChange(int eventType, const EmscriptenVisibilityChangeEvent *visEvent, void *userData)
|
||||
{
|
||||
SDL_WindowData *window_data = userData;
|
||||
SDL_SendWindowEvent(window_data->window, visEvent->hidden ? SDL_WINDOWEVENT_HIDDEN : SDL_WINDOWEVENT_SHOWN, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
Emscripten_RegisterEventHandlers(SDL_WindowData *data)
|
||||
{
|
||||
/* There is only one window and that window is the canvas */
|
||||
emscripten_set_mousemove_callback("#canvas", data, 0, Emscripten_HandleMouseMove);
|
||||
|
||||
emscripten_set_mousedown_callback("#canvas", data, 0, Emscripten_HandleMouseButton);
|
||||
emscripten_set_mouseup_callback("#canvas", data, 0, Emscripten_HandleMouseButton);
|
||||
|
||||
emscripten_set_mouseenter_callback("#canvas", data, 0, Emscripten_HandleMouseFocus);
|
||||
emscripten_set_mouseleave_callback("#canvas", data, 0, Emscripten_HandleMouseFocus);
|
||||
|
||||
emscripten_set_wheel_callback("#canvas", data, 0, Emscripten_HandleWheel);
|
||||
|
||||
emscripten_set_focus_callback("#canvas", data, 0, Emscripten_HandleFocus);
|
||||
emscripten_set_blur_callback("#canvas", data, 0, Emscripten_HandleFocus);
|
||||
|
||||
emscripten_set_touchstart_callback("#canvas", data, 0, Emscripten_HandleTouch);
|
||||
emscripten_set_touchend_callback("#canvas", data, 0, Emscripten_HandleTouch);
|
||||
emscripten_set_touchmove_callback("#canvas", data, 0, Emscripten_HandleTouch);
|
||||
emscripten_set_touchcancel_callback("#canvas", data, 0, Emscripten_HandleTouch);
|
||||
|
||||
/* Keyboard events are awkward */
|
||||
const char *keyElement = SDL_GetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT);
|
||||
if (!keyElement) keyElement = "#window";
|
||||
|
||||
emscripten_set_keydown_callback(keyElement, data, 0, Emscripten_HandleKey);
|
||||
emscripten_set_keyup_callback(keyElement, data, 0, Emscripten_HandleKey);
|
||||
emscripten_set_keypress_callback(keyElement, data, 0, Emscripten_HandleKeyPress);
|
||||
|
||||
emscripten_set_fullscreenchange_callback("#document", data, 0, Emscripten_HandleFullscreenChange);
|
||||
|
||||
emscripten_set_resize_callback("#window", data, 0, Emscripten_HandleResize);
|
||||
|
||||
emscripten_set_visibilitychange_callback(data, 0, Emscripten_HandleVisibilityChange);
|
||||
}
|
||||
|
||||
void
|
||||
Emscripten_UnregisterEventHandlers(SDL_WindowData *data)
|
||||
{
|
||||
/* only works due to having one window */
|
||||
emscripten_set_mousemove_callback("#canvas", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_mousedown_callback("#canvas", NULL, 0, NULL);
|
||||
emscripten_set_mouseup_callback("#canvas", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_mouseenter_callback("#canvas", NULL, 0, NULL);
|
||||
emscripten_set_mouseleave_callback("#canvas", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_wheel_callback("#canvas", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_focus_callback("#canvas", NULL, 0, NULL);
|
||||
emscripten_set_blur_callback("#canvas", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_touchstart_callback("#canvas", NULL, 0, NULL);
|
||||
emscripten_set_touchend_callback("#canvas", NULL, 0, NULL);
|
||||
emscripten_set_touchmove_callback("#canvas", NULL, 0, NULL);
|
||||
emscripten_set_touchcancel_callback("#canvas", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_keydown_callback("#window", NULL, 0, NULL);
|
||||
emscripten_set_keyup_callback("#window", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_keypress_callback("#window", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_fullscreenchange_callback("#document", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_resize_callback("#window", NULL, 0, NULL);
|
||||
|
||||
emscripten_set_visibilitychange_callback(NULL, 0, NULL);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SDL_emscriptenevents_h
|
||||
#define _SDL_emscriptenevents_h
|
||||
|
||||
#include "SDL_emscriptenvideo.h"
|
||||
|
||||
extern void
|
||||
Emscripten_RegisterEventHandlers(SDL_WindowData *data);
|
||||
|
||||
extern void
|
||||
Emscripten_UnregisterEventHandlers(SDL_WindowData *data);
|
||||
#endif /* _SDL_emscriptenevents_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_EMSCRIPTEN
|
||||
|
||||
#include "SDL_emscriptenvideo.h"
|
||||
#include "SDL_emscriptenframebuffer.h"
|
||||
|
||||
|
||||
int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
const Uint32 surface_format = SDL_PIXELFORMAT_BGR888;
|
||||
int w, h;
|
||||
int bpp;
|
||||
Uint32 Rmask, Gmask, Bmask, Amask;
|
||||
|
||||
/* Free the old framebuffer surface */
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
surface = data->surface;
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
/* Create a new one */
|
||||
SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
|
||||
surface = SDL_CreateRGBSurface(0, w, h, bpp, Rmask, Gmask, Bmask, Amask);
|
||||
if (!surface) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Save the info and return! */
|
||||
data->surface = surface;
|
||||
*format = surface_format;
|
||||
*pixels = surface->pixels;
|
||||
*pitch = surface->pitch;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
surface = data->surface;
|
||||
if (!surface) {
|
||||
return SDL_SetError("Couldn't find dummy surface for window");
|
||||
}
|
||||
|
||||
/* Send the data to the display */
|
||||
|
||||
EM_ASM_INT({
|
||||
//TODO: don't create context every update
|
||||
var ctx = Module['canvas'].getContext('2d');
|
||||
|
||||
//library_sdl.js SDL_UnlockSurface
|
||||
var image = ctx.createImageData($0, $1);
|
||||
var data = image.data;
|
||||
var src = $2 >> 2;
|
||||
var dst = 0;
|
||||
var isScreen = true;
|
||||
var num;
|
||||
if (typeof CanvasPixelArray !== 'undefined' && data instanceof CanvasPixelArray) {
|
||||
// IE10/IE11: ImageData objects are backed by the deprecated CanvasPixelArray,
|
||||
// not UInt8ClampedArray. These don't have buffers, so we need to revert
|
||||
// to copying a byte at a time. We do the undefined check because modern
|
||||
// browsers do not define CanvasPixelArray anymore.
|
||||
num = data.length;
|
||||
while (dst < num) {
|
||||
var val = HEAP32[src]; // This is optimized. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}};
|
||||
data[dst ] = val & 0xff;
|
||||
data[dst+1] = (val >> 8) & 0xff;
|
||||
data[dst+2] = (val >> 16) & 0xff;
|
||||
data[dst+3] = isScreen ? 0xff : ((val >> 24) & 0xff);
|
||||
src++;
|
||||
dst += 4;
|
||||
}
|
||||
} else {
|
||||
var data32 = new Uint32Array(data.buffer);
|
||||
num = data32.length;
|
||||
if (isScreen) {
|
||||
while (dst < num) {
|
||||
// HEAP32[src++] is an optimization. Instead, we could do {{{ makeGetValue('buffer', 'dst', 'i32') }}};
|
||||
data32[dst++] = HEAP32[src++] | 0xff000000;
|
||||
}
|
||||
} else {
|
||||
while (dst < num) {
|
||||
data32[dst++] = HEAP32[src++];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.putImageData(image, 0, 0);
|
||||
return 0;
|
||||
}, surface->w, surface->h, surface->pixels);
|
||||
|
||||
/*if (SDL_getenv("SDL_VIDEO_Emscripten_SAVE_FRAMES")) {
|
||||
static int frame_number = 0;
|
||||
char file[128];
|
||||
SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
|
||||
SDL_GetWindowID(window), ++frame_number);
|
||||
SDL_SaveBMP(surface, file);
|
||||
}*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
SDL_FreeSurface(data->surface);
|
||||
data->surface = NULL;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifndef _SDL_emscriptenframebuffer_h
|
||||
#define _SDL_emscriptenframebuffer_h
|
||||
|
||||
extern int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
|
||||
extern int Emscripten_UpdateWindowFramebuffer(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
|
||||
extern void Emscripten_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
|
||||
|
||||
#endif /* _SDL_emsctiptenframebuffer_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_EMSCRIPTEN
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <emscripten/html5.h>
|
||||
|
||||
#include "SDL_emscriptenmouse.h"
|
||||
|
||||
#include "../../events/SDL_mouse_c.h"
|
||||
#include "SDL_assert.h"
|
||||
|
||||
|
||||
static SDL_Cursor*
|
||||
Emscripten_CreateDefaultCursor()
|
||||
{
|
||||
SDL_Cursor* cursor;
|
||||
Emscripten_CursorData *curdata;
|
||||
|
||||
cursor = SDL_calloc(1, sizeof(SDL_Cursor));
|
||||
if (cursor) {
|
||||
curdata = (Emscripten_CursorData *) SDL_calloc(1, sizeof(*curdata));
|
||||
if (!curdata) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(cursor);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
curdata->system_cursor = "default";
|
||||
cursor->driverdata = curdata;
|
||||
}
|
||||
else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static SDL_Cursor*
|
||||
Emscripten_CreateCursor(SDL_Surface* sruface, int hot_x, int hot_y)
|
||||
{
|
||||
return Emscripten_CreateDefaultCursor();
|
||||
}
|
||||
|
||||
static SDL_Cursor*
|
||||
Emscripten_CreateSystemCursor(SDL_SystemCursor id)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
Emscripten_CursorData *curdata;
|
||||
const char *cursor_name = NULL;
|
||||
|
||||
switch(id) {
|
||||
case SDL_SYSTEM_CURSOR_ARROW:
|
||||
cursor_name = "default";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_IBEAM:
|
||||
cursor_name = "text";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WAIT:
|
||||
cursor_name = "wait";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_CROSSHAIR:
|
||||
cursor_name = "crosshair";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WAITARROW:
|
||||
cursor_name = "progress";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENWSE:
|
||||
cursor_name = "nwse-resize";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENESW:
|
||||
cursor_name = "nesw-resize";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEWE:
|
||||
cursor_name = "ew-resize";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENS:
|
||||
cursor_name = "ns-resize";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEALL:
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_NO:
|
||||
cursor_name = "not-allowed";
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_HAND:
|
||||
cursor_name = "pointer";
|
||||
break;
|
||||
default:
|
||||
SDL_assert(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(*cursor));
|
||||
if (!cursor) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
curdata = (Emscripten_CursorData *) SDL_calloc(1, sizeof(*curdata));
|
||||
if (!curdata) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(cursor);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
curdata->system_cursor = cursor_name;
|
||||
cursor->driverdata = curdata;
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
static void
|
||||
Emscripten_FreeCursor(SDL_Cursor* cursor)
|
||||
{
|
||||
Emscripten_CursorData *curdata;
|
||||
if (cursor) {
|
||||
curdata = (Emscripten_CursorData *) cursor->driverdata;
|
||||
|
||||
if (curdata != NULL) {
|
||||
SDL_free(cursor->driverdata);
|
||||
}
|
||||
|
||||
SDL_free(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
Emscripten_ShowCursor(SDL_Cursor* cursor)
|
||||
{
|
||||
Emscripten_CursorData *curdata;
|
||||
if (SDL_GetMouseFocus() != NULL) {
|
||||
if(cursor && cursor->driverdata) {
|
||||
curdata = (Emscripten_CursorData *) cursor->driverdata;
|
||||
|
||||
if(curdata->system_cursor) {
|
||||
EM_ASM_INT({
|
||||
if (Module['canvas']) {
|
||||
Module['canvas'].style['cursor'] = Module['Pointer_stringify']($0);
|
||||
}
|
||||
return 0;
|
||||
}, curdata->system_cursor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
EM_ASM(
|
||||
if (Module['canvas']) {
|
||||
Module['canvas'].style['cursor'] = 'none';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
Emscripten_WarpMouse(SDL_Window* window, int x, int y)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int
|
||||
Emscripten_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
/* TODO: pointer lock isn't actually enabled yet */
|
||||
if(enabled) {
|
||||
if(emscripten_request_pointerlock(NULL, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if(emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
Emscripten_InitMouse()
|
||||
{
|
||||
SDL_Mouse* mouse = SDL_GetMouse();
|
||||
|
||||
mouse->CreateCursor = Emscripten_CreateCursor;
|
||||
mouse->ShowCursor = Emscripten_ShowCursor;
|
||||
mouse->FreeCursor = Emscripten_FreeCursor;
|
||||
mouse->WarpMouse = Emscripten_WarpMouse;
|
||||
mouse->CreateSystemCursor = Emscripten_CreateSystemCursor;
|
||||
mouse->SetRelativeMouseMode = Emscripten_SetRelativeMouseMode;
|
||||
|
||||
SDL_SetDefaultCursor(Emscripten_CreateDefaultCursor());
|
||||
}
|
||||
|
||||
void
|
||||
Emscripten_FiniMouse()
|
||||
{
|
||||
SDL_Mouse* mouse = SDL_GetMouse();
|
||||
|
||||
Emscripten_FreeCursor(mouse->def_cursor);
|
||||
mouse->def_cursor = NULL;
|
||||
|
||||
mouse->CreateCursor = NULL;
|
||||
mouse->ShowCursor = NULL;
|
||||
mouse->FreeCursor = NULL;
|
||||
mouse->WarpMouse = NULL;
|
||||
mouse->CreateSystemCursor = NULL;
|
||||
mouse->SetRelativeMouseMode = NULL;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _SDL_emscriptenmouse_h
|
||||
#define _SDL_emscriptenmouse_h
|
||||
|
||||
typedef struct _Emscripten_CursorData
|
||||
{
|
||||
const char *system_cursor;
|
||||
} Emscripten_CursorData;
|
||||
|
||||
extern void
|
||||
Emscripten_InitMouse();
|
||||
|
||||
extern void
|
||||
Emscripten_FiniMouse();
|
||||
|
||||
#endif /* _SDL_emscriptenmouse_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
#include "SDL_emscriptenvideo.h"
|
||||
#include "SDL_emscriptenopengles.h"
|
||||
|
||||
#define LOAD_FUNC(NAME) _this->egl_data->NAME = NAME;
|
||||
|
||||
/* EGL implementation of SDL OpenGL support */
|
||||
|
||||
int
|
||||
Emscripten_GLES_LoadLibrary(_THIS, const char *path) {
|
||||
/*we can't load EGL dynamically*/
|
||||
_this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
|
||||
if (!_this->egl_data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
LOAD_FUNC(eglGetDisplay);
|
||||
LOAD_FUNC(eglInitialize);
|
||||
LOAD_FUNC(eglTerminate);
|
||||
LOAD_FUNC(eglGetProcAddress);
|
||||
LOAD_FUNC(eglChooseConfig);
|
||||
LOAD_FUNC(eglGetConfigAttrib);
|
||||
LOAD_FUNC(eglCreateContext);
|
||||
LOAD_FUNC(eglDestroyContext);
|
||||
LOAD_FUNC(eglCreateWindowSurface);
|
||||
LOAD_FUNC(eglDestroySurface);
|
||||
LOAD_FUNC(eglMakeCurrent);
|
||||
LOAD_FUNC(eglSwapBuffers);
|
||||
LOAD_FUNC(eglSwapInterval);
|
||||
LOAD_FUNC(eglWaitNative);
|
||||
LOAD_FUNC(eglWaitGL);
|
||||
LOAD_FUNC(eglBindAPI);
|
||||
|
||||
_this->egl_data->egl_display = _this->egl_data->eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
if (!_this->egl_data->egl_display) {
|
||||
return SDL_SetError("Could not get EGL display");
|
||||
}
|
||||
|
||||
if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
|
||||
return SDL_SetError("Could not initialize EGL");
|
||||
}
|
||||
|
||||
_this->gl_config.driver_loaded = 1;
|
||||
|
||||
if (path) {
|
||||
SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
|
||||
} else {
|
||||
*_this->gl_config.driver_path = '\0';
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
Emscripten_GLES_DeleteContext(_THIS, SDL_GLContext context)
|
||||
{
|
||||
/*
|
||||
WebGL contexts can't actually be deleted, so we need to reset it.
|
||||
ES2 renderer resets state on init anyway, clearing the canvas should be enough
|
||||
*/
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
SDL_EGL_DeleteContext(_this, context);
|
||||
}
|
||||
|
||||
SDL_EGL_CreateContext_impl(Emscripten)
|
||||
SDL_EGL_SwapWindow_impl(Emscripten)
|
||||
SDL_EGL_MakeCurrent_impl(Emscripten)
|
||||
|
||||
void
|
||||
Emscripten_GLES_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h)
|
||||
{
|
||||
SDL_WindowData *data;
|
||||
if (window->driverdata) {
|
||||
data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if (w) {
|
||||
*w = window->w * data->pixel_ratio;
|
||||
}
|
||||
|
||||
if (h) {
|
||||
*h = window->h * data->pixel_ratio;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifndef _SDL_emscriptenopengles_h
|
||||
#define _SDL_emscriptenopengles_h
|
||||
|
||||
#if SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
/* OpenGLES functions */
|
||||
#define Emscripten_GLES_GetAttribute SDL_EGL_GetAttribute
|
||||
#define Emscripten_GLES_GetProcAddress SDL_EGL_GetProcAddress
|
||||
#define Emscripten_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
|
||||
#define Emscripten_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
|
||||
#define Emscripten_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
||||
|
||||
extern int Emscripten_GLES_LoadLibrary(_THIS, const char *path);
|
||||
extern void Emscripten_GLES_DeleteContext(_THIS, SDL_GLContext context);
|
||||
extern SDL_GLContext Emscripten_GLES_CreateContext(_THIS, SDL_Window * window);
|
||||
extern void Emscripten_GLES_SwapWindow(_THIS, SDL_Window * window);
|
||||
extern int Emscripten_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
extern void Emscripten_GLES_GetDrawableSize(_THIS, SDL_Window * window, int * w, int * h);
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
#endif /* _SDL_emscriptenopengles_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,319 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_EMSCRIPTEN
|
||||
|
||||
#include "SDL_video.h"
|
||||
#include "SDL_mouse.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_pixels_c.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
#include "../../events/SDL_events_c.h"
|
||||
|
||||
#include "SDL_emscriptenvideo.h"
|
||||
#include "SDL_emscriptenopengles.h"
|
||||
#include "SDL_emscriptenframebuffer.h"
|
||||
#include "SDL_emscriptenevents.h"
|
||||
#include "SDL_emscriptenmouse.h"
|
||||
|
||||
#define EMSCRIPTENVID_DRIVER_NAME "emscripten"
|
||||
|
||||
/* Initialization/Query functions */
|
||||
static int Emscripten_VideoInit(_THIS);
|
||||
static int Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
||||
static void Emscripten_VideoQuit(_THIS);
|
||||
|
||||
static int Emscripten_CreateWindow(_THIS, SDL_Window * window);
|
||||
static void Emscripten_SetWindowSize(_THIS, SDL_Window * window);
|
||||
static void Emscripten_DestroyWindow(_THIS, SDL_Window * window);
|
||||
static void Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
|
||||
static void Emscripten_PumpEvents(_THIS);
|
||||
|
||||
|
||||
/* Emscripten driver bootstrap functions */
|
||||
|
||||
static int
|
||||
Emscripten_Available(void)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
Emscripten_DeleteDevice(SDL_VideoDevice * device)
|
||||
{
|
||||
SDL_free(device);
|
||||
}
|
||||
|
||||
static SDL_VideoDevice *
|
||||
Emscripten_CreateDevice(int devindex)
|
||||
{
|
||||
SDL_VideoDevice *device;
|
||||
|
||||
/* Initialize all variables that we clean on shutdown */
|
||||
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
|
||||
if (!device) {
|
||||
SDL_OutOfMemory();
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
device->VideoInit = Emscripten_VideoInit;
|
||||
device->VideoQuit = Emscripten_VideoQuit;
|
||||
device->SetDisplayMode = Emscripten_SetDisplayMode;
|
||||
|
||||
|
||||
device->PumpEvents = Emscripten_PumpEvents;
|
||||
|
||||
device->CreateWindow = Emscripten_CreateWindow;
|
||||
/*device->CreateWindowFrom = Emscripten_CreateWindowFrom;
|
||||
device->SetWindowTitle = Emscripten_SetWindowTitle;
|
||||
device->SetWindowIcon = Emscripten_SetWindowIcon;
|
||||
device->SetWindowPosition = Emscripten_SetWindowPosition;*/
|
||||
device->SetWindowSize = Emscripten_SetWindowSize;
|
||||
/*device->ShowWindow = Emscripten_ShowWindow;
|
||||
device->HideWindow = Emscripten_HideWindow;
|
||||
device->RaiseWindow = Emscripten_RaiseWindow;
|
||||
device->MaximizeWindow = Emscripten_MaximizeWindow;
|
||||
device->MinimizeWindow = Emscripten_MinimizeWindow;
|
||||
device->RestoreWindow = Emscripten_RestoreWindow;
|
||||
device->SetWindowGrab = Emscripten_SetWindowGrab;*/
|
||||
device->DestroyWindow = Emscripten_DestroyWindow;
|
||||
device->SetWindowFullscreen = Emscripten_SetWindowFullscreen;
|
||||
|
||||
device->CreateWindowFramebuffer = Emscripten_CreateWindowFramebuffer;
|
||||
device->UpdateWindowFramebuffer = Emscripten_UpdateWindowFramebuffer;
|
||||
device->DestroyWindowFramebuffer = Emscripten_DestroyWindowFramebuffer;
|
||||
|
||||
device->GL_LoadLibrary = Emscripten_GLES_LoadLibrary;
|
||||
device->GL_GetProcAddress = Emscripten_GLES_GetProcAddress;
|
||||
device->GL_UnloadLibrary = Emscripten_GLES_UnloadLibrary;
|
||||
device->GL_CreateContext = Emscripten_GLES_CreateContext;
|
||||
device->GL_MakeCurrent = Emscripten_GLES_MakeCurrent;
|
||||
device->GL_SetSwapInterval = Emscripten_GLES_SetSwapInterval;
|
||||
device->GL_GetSwapInterval = Emscripten_GLES_GetSwapInterval;
|
||||
device->GL_SwapWindow = Emscripten_GLES_SwapWindow;
|
||||
device->GL_DeleteContext = Emscripten_GLES_DeleteContext;
|
||||
device->GL_GetDrawableSize = Emscripten_GLES_GetDrawableSize;
|
||||
|
||||
device->free = Emscripten_DeleteDevice;
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
VideoBootStrap Emscripten_bootstrap = {
|
||||
EMSCRIPTENVID_DRIVER_NAME, "SDL emscripten video driver",
|
||||
Emscripten_Available, Emscripten_CreateDevice
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
Emscripten_VideoInit(_THIS)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
double css_w, css_h;
|
||||
|
||||
/* Use a fake 32-bpp desktop mode */
|
||||
mode.format = SDL_PIXELFORMAT_RGB888;
|
||||
|
||||
emscripten_get_element_css_size(NULL, &css_w, &css_h);
|
||||
|
||||
mode.w = css_w;
|
||||
mode.h = css_h;
|
||||
|
||||
mode.refresh_rate = 0;
|
||||
mode.driverdata = NULL;
|
||||
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_zero(mode);
|
||||
SDL_AddDisplayMode(&_this->displays[0], &mode);
|
||||
|
||||
Emscripten_InitMouse();
|
||||
|
||||
/* We're done! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
Emscripten_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
|
||||
{
|
||||
/* can't do this */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
Emscripten_VideoQuit(_THIS)
|
||||
{
|
||||
Emscripten_FiniMouse();
|
||||
}
|
||||
|
||||
static void
|
||||
Emscripten_PumpEvents(_THIS)
|
||||
{
|
||||
/* do nothing. */
|
||||
}
|
||||
|
||||
static int
|
||||
Emscripten_CreateWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_WindowData *wdata;
|
||||
double scaled_w, scaled_h;
|
||||
double css_w, css_h;
|
||||
|
||||
/* Allocate window internal data */
|
||||
wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
|
||||
if (wdata == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
|
||||
wdata->pixel_ratio = emscripten_get_device_pixel_ratio();
|
||||
} else {
|
||||
wdata->pixel_ratio = 1.0f;
|
||||
}
|
||||
|
||||
scaled_w = SDL_floor(window->w * wdata->pixel_ratio);
|
||||
scaled_h = SDL_floor(window->h * wdata->pixel_ratio);
|
||||
|
||||
emscripten_set_canvas_size(scaled_w, scaled_h);
|
||||
|
||||
emscripten_get_element_css_size(NULL, &css_w, &css_h);
|
||||
|
||||
wdata->external_size = css_w != scaled_w || css_h != scaled_h;
|
||||
|
||||
if ((window->flags & SDL_WINDOW_RESIZABLE) && wdata->external_size) {
|
||||
/* external css has resized us */
|
||||
scaled_w = css_w * wdata->pixel_ratio;
|
||||
scaled_h = css_h * wdata->pixel_ratio;
|
||||
|
||||
emscripten_set_canvas_size(scaled_w, scaled_h);
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, css_w, css_h);
|
||||
}
|
||||
|
||||
/* if the size is not being controlled by css, we need to scale down for hidpi */
|
||||
if (!wdata->external_size) {
|
||||
if (wdata->pixel_ratio != 1.0f) {
|
||||
/*scale canvas down*/
|
||||
emscripten_set_element_css_size(NULL, window->w, window->h);
|
||||
}
|
||||
}
|
||||
|
||||
wdata->windowed_width = scaled_w;
|
||||
wdata->windowed_height = scaled_h;
|
||||
|
||||
if (window->flags & SDL_WINDOW_OPENGL) {
|
||||
if (!_this->egl_data) {
|
||||
if (SDL_GL_LoadLibrary(NULL) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
wdata->egl_surface = SDL_EGL_CreateSurface(_this, 0);
|
||||
|
||||
if (wdata->egl_surface == EGL_NO_SURFACE) {
|
||||
return SDL_SetError("Could not create GLES window surface");
|
||||
}
|
||||
}
|
||||
|
||||
wdata->window = window;
|
||||
|
||||
/* Setup driver data for this window */
|
||||
window->driverdata = wdata;
|
||||
|
||||
/* One window, it always has focus */
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_SetKeyboardFocus(window);
|
||||
|
||||
Emscripten_RegisterEventHandlers(wdata);
|
||||
|
||||
/* Window has been successfully created */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void Emscripten_SetWindowSize(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_WindowData *data;
|
||||
|
||||
if (window->driverdata) {
|
||||
data = (SDL_WindowData *) window->driverdata;
|
||||
emscripten_set_canvas_size(window->w * data->pixel_ratio, window->h * data->pixel_ratio);
|
||||
|
||||
/*scale canvas down*/
|
||||
if (!data->external_size && data->pixel_ratio != 1.0f) {
|
||||
emscripten_set_element_css_size(NULL, window->w, window->h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Emscripten_DestroyWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_WindowData *data;
|
||||
|
||||
if(window->driverdata) {
|
||||
data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
Emscripten_UnregisterEventHandlers(data);
|
||||
if (data->egl_surface != EGL_NO_SURFACE) {
|
||||
SDL_EGL_DestroySurface(_this, data->egl_surface);
|
||||
data->egl_surface = EGL_NO_SURFACE;
|
||||
}
|
||||
SDL_free(window->driverdata);
|
||||
window->driverdata = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
|
||||
{
|
||||
SDL_WindowData *data;
|
||||
if(window->driverdata) {
|
||||
data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if(fullscreen) {
|
||||
data->requested_fullscreen_mode = window->flags & (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
|
||||
/*unset the fullscreen flags as we're not actually fullscreen yet*/
|
||||
window->flags &= ~(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN);
|
||||
|
||||
EM_ASM({
|
||||
//reparent canvas (similar to Module.requestFullscreen)
|
||||
var canvas = Module['canvas'];
|
||||
if(canvas.parentNode.id != "SDLFullscreenElement") {
|
||||
var canvasContainer = document.createElement("div");
|
||||
canvasContainer.id = "SDLFullscreenElement";
|
||||
canvas.parentNode.insertBefore(canvasContainer, canvas);
|
||||
canvasContainer.appendChild(canvas);
|
||||
}
|
||||
});
|
||||
|
||||
int is_fullscreen;
|
||||
emscripten_get_canvas_size(&data->windowed_width, &data->windowed_height, &is_fullscreen);
|
||||
emscripten_request_fullscreen("SDLFullscreenElement", 1);
|
||||
}
|
||||
else
|
||||
emscripten_exit_fullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_EMSCRIPTEN */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2014 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, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#ifndef _SDL_emscriptenvideo_h
|
||||
#define _SDL_emscriptenvideo_h
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <emscripten/html5.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
typedef struct SDL_WindowData
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
EGLSurface egl_surface;
|
||||
#endif
|
||||
SDL_Window *window;
|
||||
SDL_Surface *surface;
|
||||
|
||||
int windowed_width;
|
||||
int windowed_height;
|
||||
|
||||
float pixel_ratio;
|
||||
|
||||
SDL_bool external_size;
|
||||
|
||||
int requested_fullscreen_mode;
|
||||
} SDL_WindowData;
|
||||
|
||||
#endif /* _SDL_emscriptenvideo_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
|
@ -137,7 +137,7 @@ HandleTouchMotion(int device_id, int source_id, float x, float y, float pressure
|
|||
static void
|
||||
HandleMouseScroll(SDL_Window* sdl_window, int hscroll, int vscroll)
|
||||
{
|
||||
SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll);
|
||||
SDL_SendMouseWheel(sdl_window, 0, hscroll, vscroll, SDL_MOUSEWHEEL_NORMAL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -357,7 +357,7 @@ void NACL_PumpEvents(_THIS) {
|
|||
case PP_INPUTEVENT_TYPE_WHEEL:
|
||||
/* FIXME: GetTicks provides high resolution scroll events */
|
||||
fp = driverdata->ppb_wheel_input_event->GetDelta(event);
|
||||
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y);
|
||||
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y, SDL_MOUSEWHEEL_NORMAL);
|
||||
break;
|
||||
|
||||
case PP_INPUTEVENT_TYPE_MOUSEENTER:
|
||||
|
|
|
@ -184,7 +184,7 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer,
|
|||
return;
|
||||
}
|
||||
|
||||
SDL_SendMouseWheel(window->sdlwindow, 0, x, y);
|
||||
SDL_SendMouseWheel(window->sdlwindow, 0, x, y, SDL_MOUSEWHEEL_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,6 @@ typedef struct {
|
|||
uint32_t shm_formats;
|
||||
} SDL_VideoData;
|
||||
|
||||
#endif /* _SDL_nullvideo_h */
|
||||
#endif /* _SDL_waylandvideo_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
@ -498,12 +498,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam);
|
||||
if (s_AccumulatedMotion > 0) {
|
||||
while (s_AccumulatedMotion >= WHEEL_DELTA) {
|
||||
SDL_SendMouseWheel(data->window, 0, 0, 1);
|
||||
SDL_SendMouseWheel(data->window, 0, 0, 1, SDL_MOUSEWHEEL_NORMAL);
|
||||
s_AccumulatedMotion -= WHEEL_DELTA;
|
||||
}
|
||||
} else {
|
||||
while (s_AccumulatedMotion <= -WHEEL_DELTA) {
|
||||
SDL_SendMouseWheel(data->window, 0, 0, -1);
|
||||
SDL_SendMouseWheel(data->window, 0, 0, -1, SDL_MOUSEWHEEL_NORMAL);
|
||||
s_AccumulatedMotion += WHEEL_DELTA;
|
||||
}
|
||||
}
|
||||
|
@ -517,12 +517,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam);
|
||||
if (s_AccumulatedMotion > 0) {
|
||||
while (s_AccumulatedMotion >= WHEEL_DELTA) {
|
||||
SDL_SendMouseWheel(data->window, 0, 1, 0);
|
||||
SDL_SendMouseWheel(data->window, 0, 1, 0, SDL_MOUSEWHEEL_NORMAL);
|
||||
s_AccumulatedMotion -= WHEEL_DELTA;
|
||||
}
|
||||
} else {
|
||||
while (s_AccumulatedMotion <= -WHEEL_DELTA) {
|
||||
SDL_SendMouseWheel(data->window, 0, -1, 0);
|
||||
SDL_SendMouseWheel(data->window, 0, -1, 0, SDL_MOUSEWHEEL_NORMAL);
|
||||
s_AccumulatedMotion += WHEEL_DELTA;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ WINRT_ProcessPointerWheelChangedEvent(SDL_Window *window, Windows::UI::Input::Po
|
|||
|
||||
// FIXME: This may need to accumulate deltas up to WHEEL_DELTA
|
||||
short motion = pointerPoint->Properties->MouseWheelDelta / WHEEL_DELTA;
|
||||
SDL_SendMouseWheel(window, 0, 0, motion);
|
||||
SDL_SendMouseWheel(window, 0, 0, motion, SDL_MOUSEWHEEL_NORMAL);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -990,7 +990,7 @@ X11_DispatchEvent(_THIS)
|
|||
case ButtonPress:{
|
||||
int ticks = 0;
|
||||
if (X11_IsWheelEvent(display,&xevent,&ticks)) {
|
||||
SDL_SendMouseWheel(data->window, 0, 0, ticks);
|
||||
SDL_SendMouseWheel(data->window, 0, 0, ticks, SDL_MOUSEWHEEL_NORMAL);
|
||||
} else {
|
||||
if(xevent.xbutton.button == Button1) {
|
||||
if (ProcessHitTest(_this, data, &xevent)) {
|
||||
|
|
|
@ -196,6 +196,15 @@ testnative$(EXE): $(srcdir)/testnative.c \
|
|||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @XLIB@
|
||||
endif
|
||||
|
||||
#there's probably a better way of doing this
|
||||
ifeq (@ISMACOSX@,false)
|
||||
ifeq (@ISWINDOWS@,false)
|
||||
ifeq (@ISUNIX@,false)
|
||||
testnative$(EXE): ;
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
testoverlay2$(EXE): $(srcdir)/testoverlay2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
|
|
@ -19,8 +19,14 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
|
@ -128,12 +134,37 @@ PrintText(char *text)
|
|||
SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
/* Check for events */
|
||||
/*SDL_WaitEvent(&event); emscripten does not like waiting*/
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
//case SDL_KEYUP:
|
||||
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
PrintText(event.text.text);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Any button press quits the app... */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Event event;
|
||||
int done;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -163,26 +194,14 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Watch keystrokes */
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
SDL_WaitEvent(&event);
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
PrintText(event.text.text);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Any button press quits the app... */
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
|
|
|
@ -2980,6 +2980,11 @@ fi
|
|||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGLES_CM"
|
||||
;;
|
||||
*-*-emscripten* )
|
||||
EXE=".bc"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*)
|
||||
ISUNIX="true"
|
||||
EXE=""
|
||||
|
|
|
@ -65,6 +65,12 @@ case "$host" in
|
|||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGLES_CM"
|
||||
;;
|
||||
*-*-emscripten* )
|
||||
dnl This should really be .js, but we need to specify extra flags when compiling to js
|
||||
EXE=".bc"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*)
|
||||
dnl Oh well, call it Unix...
|
||||
ISUNIX="true"
|
||||
|
|
|
@ -191,7 +191,6 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
step->button = -1;
|
||||
step->hat = -1;
|
||||
step->hat_value = -1;
|
||||
SDL_SetClipboardText("TESTING TESTING 123");
|
||||
|
||||
switch(step->marker) {
|
||||
case MARKER_AXIS:
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
Module['arguments'] = ['0'];
|
||||
//Gamepads don't appear until a button is pressed and the joystick/gamepad tests expect one to be connected
|
||||
Module['preRun'].push(function()
|
||||
{
|
||||
Module['print']("Waiting for gamepad...");
|
||||
Module['addRunDependency']("gamepad");
|
||||
window.addEventListener('gamepadconnected', function()
|
||||
{
|
||||
//OK, got one
|
||||
Module['removeRunDependency']("gamepad");
|
||||
}, false);
|
||||
|
||||
//chrome
|
||||
if(!!navigator.webkitGetGamepads)
|
||||
{
|
||||
var timeout = function()
|
||||
{
|
||||
if(navigator.webkitGetGamepads()[0] !== undefined)
|
||||
Module['removeRunDependency']("gamepad");
|
||||
else
|
||||
setTimeout(timeout, 100);
|
||||
}
|
||||
setTimeout(timeout, 100);
|
||||
}
|
||||
});
|
|
@ -24,6 +24,10 @@
|
|||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_audio.h"
|
||||
|
||||
|
@ -75,6 +79,15 @@ poked(int sig)
|
|||
done = 1;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
void
|
||||
loop()
|
||||
{
|
||||
if(done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING))
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -131,8 +144,13 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Let the audio run */
|
||||
SDL_PauseAudio(0);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
|
||||
SDL_Delay(1000);
|
||||
#endif
|
||||
|
||||
/* Clean up on signal */
|
||||
SDL_CloseAudio();
|
||||
|
|
|
@ -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], "%llu", (long long unsigned int *)&userExecKey);
|
||||
SDL_sscanf(argv[i + 1], "%"SDL_PRIu64, (long long unsigned int *)&userExecKey);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -92,11 +92,7 @@ int platform_testEndianessAndSwap(void *arg)
|
|||
|
||||
/* Test 64 swap. */
|
||||
SDLTest_AssertCheck( SDL_Swap64(value64) == swapped64,
|
||||
#ifdef _MSC_VER
|
||||
"SDL_Swap64(): 64 bit swapped: 0x%I64X => 0x%I64X",
|
||||
#else
|
||||
"SDL_Swap64(): 64 bit swapped: 0x%llX => 0x%llX",
|
||||
#endif
|
||||
"SDL_Swap64(): 64 bit swapped: 0x%"SDL_PRIX64" => 0x%"SDL_PRIX64,
|
||||
value64, SDL_Swap64(value64) );
|
||||
|
||||
return TEST_COMPLETED;
|
||||
|
|
|
@ -105,7 +105,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
|||
/* Set to start. */
|
||||
i = SDL_RWseek(rw, 0, RW_SEEK_SET );
|
||||
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
|
||||
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %lli", i);
|
||||
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %"SDL_PRIs64, i);
|
||||
|
||||
/* Test write. */
|
||||
s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
|
||||
|
@ -120,12 +120,12 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
|||
/* Test seek to random position */
|
||||
i = SDL_RWseek( rw, seekPos, RW_SEEK_SET );
|
||||
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
|
||||
SDLTest_AssertCheck(i == (Sint64)seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %lli", seekPos, seekPos, i);
|
||||
SDLTest_AssertCheck(i == (Sint64)seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %"SDL_PRIs64, seekPos, seekPos, i);
|
||||
|
||||
/* Test seek back to start */
|
||||
i = SDL_RWseek(rw, 0, RW_SEEK_SET );
|
||||
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
|
||||
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %lli", i);
|
||||
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %"SDL_PRIs64, i);
|
||||
|
||||
/* Test read */
|
||||
s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
|
||||
|
@ -144,7 +144,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
|||
SDLTest_AssertPass("Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-5),
|
||||
"Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %lli",
|
||||
"Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %"SDL_PRIs64,
|
||||
sizeof(RWopsHelloWorldTestString)-5,
|
||||
i);
|
||||
|
||||
|
@ -152,7 +152,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
|||
SDLTest_AssertPass("Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-2),
|
||||
"Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %lli",
|
||||
"Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %"SDL_PRIs64,
|
||||
sizeof(RWopsHelloWorldTestString)-2,
|
||||
i);
|
||||
|
||||
|
@ -161,7 +161,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
|||
SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
i == (Sint64)(-1),
|
||||
"Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %lli",
|
||||
"Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %"SDL_PRIs64,
|
||||
i);
|
||||
}
|
||||
|
||||
|
@ -560,7 +560,7 @@ rwops_testCompareRWFromMemWithRWFromFile(void)
|
|||
|
||||
/* Compare */
|
||||
SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", rv_mem, rv_file);
|
||||
SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%llu sv_file=%llu", sv_mem, sv_file);
|
||||
SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%"SDL_PRIu64" sv_file=%"SDL_PRIu64, sv_mem, sv_file);
|
||||
SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]);
|
||||
SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]);
|
||||
SDLTest_AssertCheck(
|
||||
|
@ -668,7 +668,7 @@ rwops_testFileWriteReadEndian(void)
|
|||
/* Test seek to start */
|
||||
result = SDL_RWseek( rw, 0, RW_SEEK_SET );
|
||||
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %lli", result);
|
||||
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %"SDL_PRIs64, result);
|
||||
|
||||
/* Read test data */
|
||||
BE16test = SDL_ReadBE16(rw);
|
||||
|
@ -679,7 +679,7 @@ rwops_testFileWriteReadEndian(void)
|
|||
SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %u, got: %u", BE32value, BE32test);
|
||||
BE64test = SDL_ReadBE64(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadBE64()");
|
||||
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %llu, got: %llu", BE64value, BE64test);
|
||||
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %"SDL_PRIu64", got: %"SDL_PRIu64, BE64value, BE64test);
|
||||
LE16test = SDL_ReadLE16(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadLE16()");
|
||||
SDLTest_AssertCheck(LE16test == LE16value, "Validate return value from SDL_ReadLE16, expected: %hu, got: %hu", LE16value, LE16test);
|
||||
|
@ -688,7 +688,7 @@ rwops_testFileWriteReadEndian(void)
|
|||
SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %u, got: %u", LE32value, LE32test);
|
||||
LE64test = SDL_ReadLE64(rw);
|
||||
SDLTest_AssertPass("Call to SDL_ReadLE64()");
|
||||
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %llu, got: %llu", LE64value, LE64test);
|
||||
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %"SDL_PRIu64", got: %"SDL_PRIu64, LE64value, LE64test);
|
||||
|
||||
/* Close handle */
|
||||
cresult = SDL_RWclose(rw);
|
||||
|
|
|
@ -93,35 +93,35 @@ sdltest_randomNumber(void *arg)
|
|||
result = (Sint64)SDLTest_RandomUint8();
|
||||
umax = (1 << 8) - 1;
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint8");
|
||||
SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
|
||||
SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%"SDL_PRIu64"], got: %"SDL_PRIs64, umax, result);
|
||||
|
||||
result = (Sint64)SDLTest_RandomSint8();
|
||||
min = 0 - (1 << 7);
|
||||
max = (1 << 7) - 1;
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint8");
|
||||
SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
|
||||
SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%"SDL_PRIs64",%"SDL_PRIs64"], got: %"SDL_PRIs64, min, max, result);
|
||||
|
||||
result = (Sint64)SDLTest_RandomUint16();
|
||||
umax = (1 << 16) - 1;
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint16");
|
||||
SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
|
||||
SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%"SDL_PRIu64"], got: %"SDL_PRIs64, umax, result);
|
||||
|
||||
result = (Sint64)SDLTest_RandomSint16();
|
||||
min = 0 - (1 << 15);
|
||||
max = (1 << 15) - 1;
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint16");
|
||||
SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
|
||||
SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%"SDL_PRIs64",%"SDL_PRIs64"], got: %"SDL_PRIs64, min, max, result);
|
||||
|
||||
result = (Sint64)SDLTest_RandomUint32();
|
||||
umax = ((Uint64)1 << 32) - 1;
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint32");
|
||||
SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
|
||||
SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%"SDL_PRIu64"], got: %"SDL_PRIs64, umax, result);
|
||||
|
||||
result = (Sint64)SDLTest_RandomSint32();
|
||||
min = 0 - ((Sint64)1 << 31);
|
||||
max = ((Sint64)1 << 31) - 1;
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32");
|
||||
SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
|
||||
SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%"SDL_PRIs64",%"SDL_PRIs64"], got: %"SDL_PRIs64, min, max, result);
|
||||
|
||||
uresult = SDLTest_RandomUint64();
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64");
|
||||
|
@ -166,63 +166,63 @@ sdltest_randomBoundaryNumberUint8(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10,
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
|
||||
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 11, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11,
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
|
||||
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 12, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 12,
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
|
||||
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 13, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13,
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 20, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(20, 10, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
|
||||
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(1, 20, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0 || uresult == 21,
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult);
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */
|
||||
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(0, 99, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 100,
|
||||
"Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult);
|
||||
"Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(1, 0xff, SDL_FALSE) returns 0 (no error) */
|
||||
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(1, 255, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0,
|
||||
"Validate result value for parameters (1,255,SDL_FALSE); expected: 0, got: %lld", uresult);
|
||||
"Validate result value for parameters (1,255,SDL_FALSE); expected: 0, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -232,7 +232,7 @@ sdltest_randomBoundaryNumberUint8(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0xff,
|
||||
"Validate result value for parameters (0,254,SDL_FALSE); expected: 0xff, got: %lld", uresult);
|
||||
"Validate result value for parameters (0,254,SDL_FALSE); expected: 0xff, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -242,7 +242,7 @@ sdltest_randomBoundaryNumberUint8(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0,
|
||||
"Validate result value for parameters(0,255,SDL_FALSE); expected: 0, got: %lld", uresult);
|
||||
"Validate result value for parameters(0,255,SDL_FALSE); expected: 0, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
|
||||
|
@ -276,63 +276,63 @@ sdltest_randomBoundaryNumberUint16(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10,
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
|
||||
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 11, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11,
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
|
||||
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 12, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 12,
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
|
||||
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 13, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13,
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 20, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(20, 10, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
|
||||
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(1, 20, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0 || uresult == 21,
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult);
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */
|
||||
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(0, 99, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 100,
|
||||
"Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult);
|
||||
"Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(1, 0xffff, SDL_FALSE) returns 0 (no error) */
|
||||
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(1, 0xffff, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0,
|
||||
"Validate result value for parameters (1,0xffff,SDL_FALSE); expected: 0, got: %lld", uresult);
|
||||
"Validate result value for parameters (1,0xffff,SDL_FALSE); expected: 0, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -342,7 +342,7 @@ sdltest_randomBoundaryNumberUint16(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0xffff,
|
||||
"Validate result value for parameters (0,0xfffe,SDL_FALSE); expected: 0xffff, got: %lld", uresult);
|
||||
"Validate result value for parameters (0,0xfffe,SDL_FALSE); expected: 0xffff, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -352,7 +352,7 @@ sdltest_randomBoundaryNumberUint16(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0,
|
||||
"Validate result value for parameters(0,0xffff,SDL_FALSE); expected: 0, got: %lld", uresult);
|
||||
"Validate result value for parameters(0,0xffff,SDL_FALSE); expected: 0, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
|
||||
|
@ -386,63 +386,63 @@ sdltest_randomBoundaryNumberUint32(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10,
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
|
||||
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 11, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11,
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
|
||||
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 12, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 12,
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
|
||||
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 13, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13,
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 20, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(20, 10, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
|
||||
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(1, 20, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0 || uresult == 21,
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult);
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */
|
||||
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(0, 99, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 100,
|
||||
"Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult);
|
||||
"Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(1, 0xffffffff, SDL_FALSE) returns 0 (no error) */
|
||||
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(1, 0xffffffff, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0,
|
||||
"Validate result value for parameters (1,0xffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
|
||||
"Validate result value for parameters (1,0xffffffff,SDL_FALSE); expected: 0, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -452,7 +452,7 @@ sdltest_randomBoundaryNumberUint32(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0xffffffff,
|
||||
"Validate result value for parameters (0,0xfffffffe,SDL_FALSE); expected: 0xffffffff, got: %lld", uresult);
|
||||
"Validate result value for parameters (0,0xfffffffe,SDL_FALSE); expected: 0xffffffff, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -462,7 +462,7 @@ sdltest_randomBoundaryNumberUint32(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0,
|
||||
"Validate result value for parameters(0,0xffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
|
||||
"Validate result value for parameters(0,0xffffffff,SDL_FALSE); expected: 0, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
|
||||
|
@ -496,63 +496,63 @@ sdltest_randomBoundaryNumberUint64(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10,
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
|
||||
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 11, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11,
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
|
||||
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 12, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 12,
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
|
||||
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 13, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13,
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 20, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(20, 10, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20,
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult);
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
|
||||
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(1, 20, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0 || uresult == 21,
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult);
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */
|
||||
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(0, 99, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 100,
|
||||
"Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult);
|
||||
"Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %"SDL_PRIs64, uresult);
|
||||
|
||||
/* RandomUintXBoundaryValue(1, 0xffffffffffffffff, SDL_FALSE) returns 0 (no error) */
|
||||
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(1, (Uint64)0xffffffffffffffffULL, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0,
|
||||
"Validate result value for parameters (1,0xffffffffffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
|
||||
"Validate result value for parameters (1,0xffffffffffffffff,SDL_FALSE); expected: 0, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -562,7 +562,7 @@ sdltest_randomBoundaryNumberUint64(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == (Uint64)0xffffffffffffffffULL,
|
||||
"Validate result value for parameters (0,0xfffffffffffffffe,SDL_FALSE); expected: 0xffffffffffffffff, got: %lld", uresult);
|
||||
"Validate result value for parameters (0,0xfffffffffffffffe,SDL_FALSE); expected: 0xffffffffffffffff, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -572,7 +572,7 @@ sdltest_randomBoundaryNumberUint64(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
uresult == 0,
|
||||
"Validate result value for parameters(0,0xffffffffffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
|
||||
"Validate result value for parameters(0,0xffffffffffffffff,SDL_FALSE); expected: 0, got: %"SDL_PRIs64, uresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
|
||||
|
@ -606,63 +606,63 @@ sdltest_randomBoundaryNumberSint8(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10,
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
|
||||
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 11, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11,
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
|
||||
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 12, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 12,
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
|
||||
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 13, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13,
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 20, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(20, 10, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
|
||||
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(1, 20, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 0 || sresult == 21,
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult);
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(SCHAR_MIN, 99, SDL_FALSE) returns 100 */
|
||||
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN, 99, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 100,
|
||||
"Validate result value for parameters (SCHAR_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult);
|
||||
"Validate result value for parameters (SCHAR_MIN,99,SDL_FALSE); expected: 100, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(SCHAR_MIN + 1, SCHAR_MAX, SDL_FALSE) returns SCHAR_MIN (no error) */
|
||||
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN + 1, SCHAR_MAX, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == SCHAR_MIN,
|
||||
"Validate result value for parameters (SCHAR_MIN + 1,SCHAR_MAX,SDL_FALSE); expected: %d, got: %lld", SCHAR_MIN, sresult);
|
||||
"Validate result value for parameters (SCHAR_MIN + 1,SCHAR_MAX,SDL_FALSE); expected: %d, got: %"SDL_PRIs64, SCHAR_MIN, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -672,7 +672,7 @@ sdltest_randomBoundaryNumberSint8(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == SCHAR_MAX,
|
||||
"Validate result value for parameters (SCHAR_MIN,SCHAR_MAX - 1,SDL_FALSE); expected: %d, got: %lld", SCHAR_MAX, sresult);
|
||||
"Validate result value for parameters (SCHAR_MIN,SCHAR_MAX - 1,SDL_FALSE); expected: %d, got: %"SDL_PRIs64, SCHAR_MAX, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -682,7 +682,7 @@ sdltest_randomBoundaryNumberSint8(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == SCHAR_MIN,
|
||||
"Validate result value for parameters(SCHAR_MIN,SCHAR_MAX,SDL_FALSE); expected: %d, got: %lld", SCHAR_MIN, sresult);
|
||||
"Validate result value for parameters(SCHAR_MIN,SCHAR_MAX,SDL_FALSE); expected: %d, got: %"SDL_PRIs64, SCHAR_MIN, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
|
||||
|
@ -716,63 +716,63 @@ sdltest_randomBoundaryNumberSint16(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10,
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
|
||||
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 11, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11,
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
|
||||
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 12, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 12,
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
|
||||
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 13, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13,
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 20, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(20, 10, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
|
||||
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(1, 20, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 0 || sresult == 21,
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult);
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(SHRT_MIN, 99, SDL_FALSE) returns 100 */
|
||||
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN, 99, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 100,
|
||||
"Validate result value for parameters (SHRT_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult);
|
||||
"Validate result value for parameters (SHRT_MIN,99,SDL_FALSE); expected: 100, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(SHRT_MIN + 1, SHRT_MAX, SDL_FALSE) returns SHRT_MIN (no error) */
|
||||
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN + 1, SHRT_MAX, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == SHRT_MIN,
|
||||
"Validate result value for parameters (SHRT_MIN+1,SHRT_MAX,SDL_FALSE); expected: %d, got: %lld", SHRT_MIN, sresult);
|
||||
"Validate result value for parameters (SHRT_MIN+1,SHRT_MAX,SDL_FALSE); expected: %d, got: %"SDL_PRIs64, SHRT_MIN, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -782,7 +782,7 @@ sdltest_randomBoundaryNumberSint16(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == SHRT_MAX,
|
||||
"Validate result value for parameters (SHRT_MIN,SHRT_MAX - 1,SDL_FALSE); expected: %d, got: %lld", SHRT_MAX, sresult);
|
||||
"Validate result value for parameters (SHRT_MIN,SHRT_MAX - 1,SDL_FALSE); expected: %d, got: %"SDL_PRIs64, SHRT_MAX, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -792,7 +792,7 @@ sdltest_randomBoundaryNumberSint16(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == SHRT_MIN,
|
||||
"Validate result value for parameters(SHRT_MIN,SHRT_MAX,SDL_FALSE); expected: %d, got: %lld", SHRT_MIN, sresult);
|
||||
"Validate result value for parameters(SHRT_MIN,SHRT_MAX,SDL_FALSE); expected: %d, got: %"SDL_PRIs64, SHRT_MIN, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
|
||||
|
@ -833,63 +833,63 @@ sdltest_randomBoundaryNumberSint32(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10,
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
|
||||
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 11, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11,
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
|
||||
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 12, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 12,
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
|
||||
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 13, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13,
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 20, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(20, 10, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
|
||||
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(1, 20, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 0 || sresult == 21,
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult);
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(LONG_MIN, 99, SDL_FALSE) returns 100 */
|
||||
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min, 99, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 100,
|
||||
"Validate result value for parameters (LONG_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult);
|
||||
"Validate result value for parameters (LONG_MIN,99,SDL_FALSE); expected: 100, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(LONG_MIN + 1, LONG_MAX, SDL_FALSE) returns LONG_MIN (no error) */
|
||||
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min + 1, long_max, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == long_min,
|
||||
"Validate result value for parameters (LONG_MIN+1,LONG_MAX,SDL_FALSE); expected: %d, got: %lld", long_min, sresult);
|
||||
"Validate result value for parameters (LONG_MIN+1,LONG_MAX,SDL_FALSE); expected: %d, got: %"SDL_PRIs64, long_min, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -899,7 +899,7 @@ sdltest_randomBoundaryNumberSint32(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == long_max,
|
||||
"Validate result value for parameters (LONG_MIN,LONG_MAX - 1,SDL_FALSE); expected: %d, got: %lld", long_max, sresult);
|
||||
"Validate result value for parameters (LONG_MIN,LONG_MAX - 1,SDL_FALSE); expected: %d, got: %"SDL_PRIs64, long_max, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -909,7 +909,7 @@ sdltest_randomBoundaryNumberSint32(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == long_min,
|
||||
"Validate result value for parameters(LONG_MIN,LONG_MAX,SDL_FALSE); expected: %d, got: %lld", long_min, sresult);
|
||||
"Validate result value for parameters(LONG_MIN,LONG_MAX,SDL_FALSE); expected: %d, got: %"SDL_PRIs64, long_min, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
|
||||
|
@ -943,63 +943,63 @@ sdltest_randomBoundaryNumberSint64(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10,
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 11, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11,
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 12, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 12,
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 13, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13,
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 20, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
|
||||
"Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(20, 10, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20,
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult);
|
||||
"Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(1, 20, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 0 || sresult == 21,
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult);
|
||||
"Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(LLONG_MIN, 99, SDL_FALSE) returns 100 */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, 99, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == 100,
|
||||
"Validate result value for parameters (LLONG_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult);
|
||||
"Validate result value for parameters (LLONG_MIN,99,SDL_FALSE); expected: 100, got: %"SDL_PRIs64, sresult);
|
||||
|
||||
/* RandomSintXBoundaryValue(LLONG_MIN + 1, LLONG_MAX, SDL_FALSE) returns LLONG_MIN (no error) */
|
||||
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN + 1, LLONG_MAX, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == LLONG_MIN,
|
||||
"Validate result value for parameters (LLONG_MIN+1,LLONG_MAX,SDL_FALSE); expected: %lld, got: %lld", LLONG_MIN, sresult);
|
||||
"Validate result value for parameters (LLONG_MIN+1,LLONG_MAX,SDL_FALSE); expected: %"SDL_PRIs64", got: %"SDL_PRIs64, LLONG_MIN, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -1009,7 +1009,7 @@ sdltest_randomBoundaryNumberSint64(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == LLONG_MAX,
|
||||
"Validate result value for parameters (LLONG_MIN,LLONG_MAX - 1,SDL_FALSE); expected: %lld, got: %lld", LLONG_MAX, sresult);
|
||||
"Validate result value for parameters (LLONG_MIN,LLONG_MAX - 1,SDL_FALSE); expected: %"SDL_PRIs64", got: %"SDL_PRIs64, LLONG_MAX, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
|
||||
|
@ -1019,7 +1019,7 @@ sdltest_randomBoundaryNumberSint64(void *arg)
|
|||
SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue");
|
||||
SDLTest_AssertCheck(
|
||||
sresult == LLONG_MIN,
|
||||
"Validate result value for parameters(LLONG_MIN,LLONG_MAX,SDL_FALSE); expected: %lld, got: %lld", LLONG_MIN, sresult);
|
||||
"Validate result value for parameters(LLONG_MIN,LLONG_MAX,SDL_FALSE); expected: %"SDL_PRIs64", got: %"SDL_PRIs64, LLONG_MIN, sresult);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0,
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||
|
||||
#include <stdio.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
|
|
@ -42,7 +42,7 @@ timer_getPerformanceCounter(void *arg)
|
|||
|
||||
result = SDL_GetPerformanceCounter();
|
||||
SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %llu", result);
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ timer_getPerformanceFrequency(void *arg)
|
|||
|
||||
result = SDL_GetPerformanceFrequency();
|
||||
SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %llu", result);
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#define NUM_OBJECTS 100
|
||||
|
@ -29,6 +33,8 @@ static int current_alpha = 255;
|
|||
static int current_color = 255;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawPoints(SDL_Renderer * renderer)
|
||||
{
|
||||
|
@ -169,11 +175,35 @@ DrawRects(SDL_Renderer * renderer)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawRects(renderer);
|
||||
DrawLines(renderer);
|
||||
DrawPoints(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
Uint32 then, now, frames;
|
||||
|
||||
/* Enable standard application logging */
|
||||
|
@ -245,26 +275,16 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
loop();
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
#endif
|
||||
|
||||
DrawRects(renderer);
|
||||
DrawLines(renderer);
|
||||
DrawPoints(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
SDLTest_CommonQuit(state);
|
||||
|
||||
|
|
|
@ -14,8 +14,19 @@
|
|||
|
||||
/* Sample program: Draw a Chess Board by using SDL_CreateSoftwareRenderer API */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawChessBoard(SDL_Renderer * renderer)
|
||||
{
|
||||
|
@ -44,12 +55,33 @@ DrawChessBoard(SDL_Renderer * renderer)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
SDL_Event e;
|
||||
if (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT) {
|
||||
done = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if(e.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DrawChessBoard(renderer);
|
||||
|
||||
/* Got everything on rendering surface,
|
||||
now Update the drawing image on window screen */
|
||||
SDL_UpdateWindowSurface(window);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Surface *surface;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -83,24 +115,14 @@ main(int argc, char *argv[])
|
|||
|
||||
|
||||
/* Draw the Image on rendering surface */
|
||||
while(1)
|
||||
{
|
||||
SDL_Event e;
|
||||
if (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_QUIT)
|
||||
break;
|
||||
|
||||
if(e.key.keysym.sym == SDLK_ESCAPE)
|
||||
break;
|
||||
}
|
||||
|
||||
DrawChessBoard(renderer);
|
||||
|
||||
/* Got everything on rendering surface,
|
||||
now Update the drawing image on window screen */
|
||||
SDL_UpdateWindowSurface(window);
|
||||
|
||||
done = 0;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,25 @@ main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
char *base_path = SDL_GetBasePath();
|
||||
if(base_path == NULL){
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
|
||||
SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Log("base path: '%s'\n", SDL_GetBasePath());
|
||||
SDL_free(base_path);
|
||||
|
||||
char *pref_path = SDL_GetPrefPath("libsdl", "testfilesystem");
|
||||
if(pref_path == NULL){
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
|
||||
SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
SDL_Log("pref path: '%s'\n", SDL_GetPrefPath("libsdl", "testfilesystem"));
|
||||
SDL_free(pref_path);
|
||||
|
||||
SDL_Log("base path: '%s'\n", SDL_GetBasePath());
|
||||
SDL_Log("pref path: '%s'\n", SDL_GetPrefPath("libsdl", "testfilesystem"));
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#ifndef SDL_JOYSTICK_DISABLED
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
|
@ -28,6 +32,40 @@
|
|||
#define SCREEN_HEIGHT 317
|
||||
#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 */
|
||||
};
|
||||
|
||||
/* This is indexed by SDL_GameControllerAxis. */
|
||||
static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{75, 154, 0.0}, /* LEFTX */
|
||||
{75, 154, 90.0}, /* LEFTY */
|
||||
{305, 230, 0.0}, /* RIGHTX */
|
||||
{305, 230, 90.0}, /* RIGHTY */
|
||||
{91, 0, 90.0}, /* TRIGGERLEFT */
|
||||
{375, 0, 90.0}, /* TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Texture *background, *button, *axis;
|
||||
|
||||
static SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
|
||||
{
|
||||
|
@ -60,50 +98,71 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
|
|||
return texture;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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, 0);
|
||||
}
|
||||
}
|
||||
|
||||
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, 0);
|
||||
} 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, 0);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (!SDL_GameControllerGetAttached(gamecontroller)) {
|
||||
done = SDL_TRUE;
|
||||
retval = SDL_TRUE; /* keep going, wait for reattach. */
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
WatchGameController(SDL_GameController * gamecontroller)
|
||||
{
|
||||
/* 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 */
|
||||
};
|
||||
|
||||
/* This is indexed by SDL_GameControllerAxis. */
|
||||
static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{75, 154, 0.0}, /* LEFTX */
|
||||
{75, 154, 90.0}, /* LEFTY */
|
||||
{305, 230, 0.0}, /* RIGHTX */
|
||||
{305, 230, 90.0}, /* RIGHTY */
|
||||
{91, 0, 90.0}, /* TRIGGERLEFT */
|
||||
{375, 0, 90.0}, /* TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
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_Texture *background, *button, *axis;
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
||||
if (title) {
|
||||
SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
|
||||
}
|
||||
|
@ -151,56 +210,13 @@ WatchGameController(SDL_GameController * gamecontroller)
|
|||
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) {
|
||||
/* 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);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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, 0);
|
||||
}
|
||||
}
|
||||
|
||||
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, 0);
|
||||
} 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, 0);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (!SDL_GameControllerGetAttached(gamecontroller)) {
|
||||
done = SDL_TRUE;
|
||||
retval = SDL_TRUE; /* keep going, wait for reattach. */
|
||||
}
|
||||
loop(gamecontroller);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
|
|
|
@ -15,12 +15,11 @@
|
|||
* l to load all touches from "./gestureSave"
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_touch.h"
|
||||
#include "SDL_gesture.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#define WIDTH 640
|
||||
#define HEIGHT 480
|
||||
|
@ -33,13 +32,16 @@
|
|||
|
||||
#define VERBOSE 0
|
||||
|
||||
static SDL_Window *window;
|
||||
static SDL_Event events[EVENT_BUF_SIZE];
|
||||
static int eventWrite;
|
||||
|
||||
|
||||
static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
|
||||
|
||||
SDL_Surface *screen;
|
||||
SDL_Window *window;
|
||||
SDL_bool quitting = SDL_FALSE;
|
||||
|
||||
typedef struct {
|
||||
float x,y;
|
||||
} Point;
|
||||
|
@ -51,18 +53,6 @@ typedef struct {
|
|||
|
||||
static Knob knob;
|
||||
|
||||
void handler (int sig)
|
||||
{
|
||||
SDL_Log ("exiting...(%d)", sig);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
void perror_exit (char *error)
|
||||
{
|
||||
perror (error);
|
||||
handler (9);
|
||||
}
|
||||
|
||||
void setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
|
||||
{
|
||||
Uint32 *pixmem32;
|
||||
|
@ -104,7 +94,7 @@ void drawCircle(SDL_Surface* screen,float x,float y,float r,unsigned int c)
|
|||
float tx,ty;
|
||||
float xr;
|
||||
for(ty = (float)-SDL_fabs(r);ty <= (float)SDL_fabs((int)r);ty++) {
|
||||
xr = (float)sqrt(r*r - ty*ty);
|
||||
xr = (float)SDL_sqrt(r*r - ty*ty);
|
||||
if(r > 0) { /* r > 0 ==> filled circle */
|
||||
for(tx=-xr+.5f;tx<=xr-.5;tx++) {
|
||||
setpix(screen,x+tx,y+ty,c);
|
||||
|
@ -123,7 +113,7 @@ void drawKnob(SDL_Surface* screen,Knob k) {
|
|||
(k.p.y+k.r/2*SDL_sinf(k.ang))*screen->h,k.r/4*screen->w,0);
|
||||
}
|
||||
|
||||
void DrawScreen(SDL_Surface* screen)
|
||||
void DrawScreen(SDL_Surface* screen, SDL_Window* window)
|
||||
{
|
||||
int i;
|
||||
#if 1
|
||||
|
@ -165,44 +155,24 @@ void DrawScreen(SDL_Surface* screen)
|
|||
SDL_UpdateWindowSurface(window);
|
||||
}
|
||||
|
||||
SDL_Surface* initScreen(int width,int height)
|
||||
/* Returns a new SDL_Window if window is NULL or window if not. */
|
||||
SDL_Window* initWindow(SDL_Window *window, int width,int height)
|
||||
{
|
||||
if (!window) {
|
||||
window = SDL_CreateWindow("Gesture Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
width, height, SDL_WINDOW_RESIZABLE);
|
||||
}
|
||||
if (!window) {
|
||||
return NULL;
|
||||
}
|
||||
return SDL_GetWindowSurface(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
void loop()
|
||||
{
|
||||
SDL_Surface *screen;
|
||||
SDL_Event event;
|
||||
SDL_bool quitting = SDL_FALSE;
|
||||
SDL_RWops *stream;
|
||||
SDL_Event event;
|
||||
SDL_RWops *stream;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* gesture variables */
|
||||
knob.r = .1f;
|
||||
knob.ang = 0;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
|
||||
|
||||
if (!(screen = initScreen(WIDTH,HEIGHT)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
while(!quitting) {
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
{
|
||||
/* Record _all_ events */
|
||||
events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
|
||||
eventWrite++;
|
||||
|
@ -244,10 +214,11 @@ int main(int argc, char* argv[])
|
|||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
if (!(screen = initScreen(event.window.data1, event.window.data2)))
|
||||
if (!(window = initWindow(window, event.window.data1, event.window.data2)) ||
|
||||
!(screen = SDL_GetWindowSurface(window)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -292,9 +263,40 @@ int main(int argc, char* argv[])
|
|||
SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
DrawScreen(screen);
|
||||
}
|
||||
DrawScreen(screen, window);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
window = NULL;
|
||||
screen = NULL;
|
||||
quitting = SDL_FALSE;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* gesture variables */
|
||||
knob.r = .1f;
|
||||
knob.ang = 0;
|
||||
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
|
||||
|
||||
if (!(window = initWindow(window, WIDTH, HEIGHT)) ||
|
||||
!(screen = SDL_GetWindowSurface(window)))
|
||||
{
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while(!quitting) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
|
117
test/testgles2.c
117
test/testgles2.c
|
@ -14,6 +14,10 @@
|
|||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__NACL__)
|
||||
|
@ -408,17 +412,72 @@ Render(unsigned int width, unsigned int height, shader_data* data)
|
|||
GL_CHECK(ctx.glDrawArrays(GL_TRIANGLES, 0, 36));
|
||||
}
|
||||
|
||||
int done;
|
||||
Uint32 frames;
|
||||
shader_data *datas;
|
||||
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
int status;
|
||||
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event) && !done) {
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
|
||||
int w, h;
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
break;
|
||||
}
|
||||
/* Change view port to the new window dimensions */
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
state->window_w = event.window.data1;
|
||||
state->window_h = event.window.data2;
|
||||
/* Update window content */
|
||||
Render(event.window.data1, event.window.data2, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
if (!done) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
int i, done;
|
||||
int i;
|
||||
SDL_DisplayMode mode;
|
||||
SDL_Event event;
|
||||
Uint32 then, now, frames;
|
||||
Uint32 then, now;
|
||||
int status;
|
||||
shader_data *datas, *data;
|
||||
shader_data *data;
|
||||
|
||||
/* Initialize parameters */
|
||||
fsaa = 0;
|
||||
|
@ -581,6 +640,7 @@ main(int argc, char *argv[])
|
|||
/* Set rendering settings for each context */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
|
||||
int w, h;
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
@ -588,7 +648,8 @@ main(int argc, char *argv[])
|
|||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
ctx.glViewport(0, 0, state->window_w, state->window_h);
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
|
||||
data = &datas[i];
|
||||
data->angle_x = 0; data->angle_y = 0; data->angle_z = 0;
|
||||
|
@ -630,48 +691,14 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event) && !done) {
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
break;
|
||||
}
|
||||
/* Change view port to the new window dimensions */
|
||||
ctx.glViewport(0, 0, event.window.data1, event.window.data2);
|
||||
/* Update window content */
|
||||
Render(event.window.data1, event.window.data2, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
if (!done) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
|
|
|
@ -16,6 +16,10 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#define SWAP(typ,a,b) do{typ t=a;a=b;b=t;}while(0)
|
||||
|
@ -30,6 +34,9 @@ static int current_alpha = 255;
|
|||
static int current_color = 255;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
|
||||
int mouse_begin_x = -1, mouse_begin_y = -1;
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawPoints(SDL_Renderer * renderer)
|
||||
{
|
||||
|
@ -191,12 +198,71 @@ DrawRectRectIntersections(SDL_Renderer * renderer)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
switch (event.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
mouse_begin_x = event.button.x;
|
||||
mouse_begin_y = event.button.y;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (event.button.button == 3)
|
||||
add_line(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
if (event.button.button == 1)
|
||||
add_rect(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case 'l':
|
||||
if (event.key.keysym.mod & KMOD_SHIFT)
|
||||
num_lines = 0;
|
||||
else
|
||||
add_line(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
break;
|
||||
case 'r':
|
||||
if (event.key.keysym.mod & KMOD_SHIFT)
|
||||
num_rects = 0;
|
||||
else
|
||||
add_rect(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawRects(renderer);
|
||||
DrawPoints(renderer);
|
||||
DrawRectRectIntersections(renderer);
|
||||
DrawLines(renderer);
|
||||
DrawRectLineIntersections(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int mouse_begin_x = -1, mouse_begin_y = -1;
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
Uint32 then, now, frames;
|
||||
|
||||
/* Enable standard application logging */
|
||||
|
@ -268,62 +334,15 @@ main(int argc, char *argv[])
|
|||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
switch (event.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
mouse_begin_x = event.button.x;
|
||||
mouse_begin_y = event.button.y;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (event.button.button == 3)
|
||||
add_line(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
if (event.button.button == 1)
|
||||
add_rect(mouse_begin_x, mouse_begin_y, event.button.x,
|
||||
event.button.y);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case 'l':
|
||||
if (event.key.keysym.mod & KMOD_SHIFT)
|
||||
num_lines = 0;
|
||||
else
|
||||
add_line(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
break;
|
||||
case 'r':
|
||||
if (event.key.keysym.mod & KMOD_SHIFT)
|
||||
num_rects = 0;
|
||||
else
|
||||
add_rect(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
DrawRects(renderer);
|
||||
DrawPoints(renderer);
|
||||
DrawRectRectIntersections(renderer);
|
||||
DrawLines(renderer);
|
||||
DrawRectLineIntersections(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
SDLTest_CommonQuit(state);
|
||||
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#ifndef SDL_JOYSTICK_DISABLED
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
|
@ -28,6 +32,9 @@
|
|||
#define SCREEN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
|
||||
static void
|
||||
DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
|
||||
|
@ -36,50 +43,15 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
|
|||
SDL_RenderFillRect(r, &area);
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
void
|
||||
loop(void *arg)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
const char *name = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Event event;
|
||||
int i;
|
||||
SDL_Joystick *joystick = (SDL_Joystick *)arg;
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Joystick 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 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);
|
||||
|
||||
/* 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! */
|
||||
while (!done) {
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
SDL_SetRenderDrawColor(screen, 0x0, 0x0, 0x0, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
|
@ -197,8 +169,53 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
done = SDL_TRUE;
|
||||
retval = SDL_TRUE; /* keep going, wait for reattach. */
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
const char *name = NULL;
|
||||
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Joystick 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 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);
|
||||
|
||||
/* 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);
|
||||
#else
|
||||
while (!done) {
|
||||
loop(joystick);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return retval;
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
|
||||
#include <stdio.h> /* for fflush() and stdout */
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
static SDL_AudioSpec spec;
|
||||
static Uint8 *sound = NULL; /* Pointer to wave data */
|
||||
static Uint32 soundlen = 0; /* Length of wave data */
|
||||
|
@ -24,6 +28,8 @@ typedef struct
|
|||
volatile int done;
|
||||
} callback_data;
|
||||
|
||||
callback_data cbd[64];
|
||||
|
||||
void SDLCALL
|
||||
play_through_once(void *arg, Uint8 * stream, int len)
|
||||
{
|
||||
|
@ -44,16 +50,30 @@ play_through_once(void *arg, Uint8 * stream, int len)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
if(cbd[0].done) {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_cancel_main_loop();
|
||||
#endif
|
||||
SDL_PauseAudioDevice(cbd[0].dev, 1);
|
||||
SDL_CloseAudioDevice(cbd[0].dev);
|
||||
SDL_FreeWAV(sound);
|
||||
SDL_Quit();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_multi_audio(int devcount)
|
||||
{
|
||||
callback_data cbd[64];
|
||||
int keep_going = 1;
|
||||
int i;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
SDL_Event event;
|
||||
|
||||
/* Create a Window to get fully initialized event processing for testing pause on Android. */
|
||||
SDL_CreateWindow("testmultiaudio", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0);
|
||||
#endif
|
||||
|
||||
|
@ -77,13 +97,19 @@ test_multi_audio(int devcount)
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device failed: %s\n", SDL_GetError());
|
||||
} else {
|
||||
SDL_PauseAudioDevice(cbd[0].dev, 0);
|
||||
while (!cbd[0].done) {
|
||||
#ifdef __ANDROID__
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!cbd[0].done)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
/* Empty queue, some application events would prevent pause. */
|
||||
while (SDL_PollEvent(&event)){}
|
||||
#endif
|
||||
#endif
|
||||
SDL_Delay(100);
|
||||
}
|
||||
SDL_PauseAudioDevice(cbd[0].dev, 1);
|
||||
#endif
|
||||
SDL_Log("done.\n");
|
||||
SDL_CloseAudioDevice(cbd[0].dev);
|
||||
}
|
||||
|
@ -114,12 +140,15 @@ test_multi_audio(int devcount)
|
|||
keep_going = 1;
|
||||
}
|
||||
}
|
||||
#ifdef __ANDROID__
|
||||
#ifdef __ANDROID__
|
||||
/* Empty queue, some application events would prevent pause. */
|
||||
while (SDL_PollEvent(&event)){}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SDL_Delay(100);
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
for (i = 0; i < devcount; i++) {
|
||||
if (cbd[i].dev) {
|
||||
SDL_PauseAudioDevice(cbd[i].dev, 1);
|
||||
|
@ -128,6 +157,7 @@ test_multi_audio(int devcount)
|
|||
}
|
||||
|
||||
SDL_Log("All done!\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,10 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#define MOOSEPIC_W 64
|
||||
|
@ -135,6 +139,18 @@ SDL_Color MooseColors[84] = {
|
|||
, {239, 206, 173}
|
||||
};
|
||||
|
||||
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE*2];
|
||||
SDL_Texture *MooseTexture;
|
||||
SDL_Rect displayrect;
|
||||
int window_w;
|
||||
int window_h;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
int paused = 0;
|
||||
int i;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
Uint32 pixel_format = SDL_PIXELFORMAT_YV12;
|
||||
int fpsdelay;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
|
@ -246,21 +262,65 @@ PrintUsage(char *argv0)
|
|||
SDL_Log("\n");
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
SDL_RenderSetViewport(renderer, NULL);
|
||||
displayrect.w = window_w = event.window.data1;
|
||||
displayrect.h = window_h = event.window.data2;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
displayrect.x = event.button.x - window_w / 2;
|
||||
displayrect.y = event.button.y - window_h / 2;
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
if (event.motion.state) {
|
||||
displayrect.x = event.motion.x - window_w / 2;
|
||||
displayrect.y = event.motion.y - window_h / 2;
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
paused = !paused;
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
SDL_Delay(fpsdelay);
|
||||
#endif
|
||||
|
||||
if (!paused) {
|
||||
i = (i + 1) % MOOSEFRAMES_COUNT;
|
||||
|
||||
SDL_UpdateTexture(MooseTexture, NULL, MooseFrame[i], MOOSEPIC_W*SDL_BYTESPERPIXEL(pixel_format));
|
||||
}
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, MooseTexture, NULL, &displayrect);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
Uint8 *RawMooseData;
|
||||
SDL_RWops *handle;
|
||||
int window_w;
|
||||
int window_h;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE*2];
|
||||
SDL_Texture *MooseTexture;
|
||||
SDL_Rect displayrect;
|
||||
SDL_Event event;
|
||||
int paused = 0;
|
||||
int i, j;
|
||||
int j;
|
||||
int fps = 12;
|
||||
int fpsdelay;
|
||||
int nodelay = 0;
|
||||
|
@ -270,7 +330,6 @@ main(int argc, char **argv)
|
|||
Uint32 pixel_format = SDL_PIXELFORMAT_YV12;
|
||||
#endif
|
||||
int scale = 5;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
@ -430,50 +489,14 @@ main(int argc, char **argv)
|
|||
SDL_EventState(SDL_KEYUP, SDL_IGNORE);
|
||||
|
||||
/* Loop, waiting for QUIT or RESIZE */
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, nodelay ? 0 : fps, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_WINDOWEVENT:
|
||||
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
|
||||
SDL_RenderSetViewport(renderer, NULL);
|
||||
displayrect.w = window_w = event.window.data1;
|
||||
displayrect.h = window_h = event.window.data2;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
displayrect.x = event.button.x - window_w / 2;
|
||||
displayrect.y = event.button.y - window_h / 2;
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
if (event.motion.state) {
|
||||
displayrect.x = event.motion.x - window_w / 2;
|
||||
displayrect.y = event.motion.y - window_h / 2;
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
paused = !paused;
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
loop();
|
||||
}
|
||||
}
|
||||
SDL_Delay(fpsdelay);
|
||||
#endif
|
||||
|
||||
if (!paused) {
|
||||
i = (i + 1) % MOOSEFRAMES_COUNT;
|
||||
|
||||
SDL_UpdateTexture(MooseTexture, NULL, MooseFrame[i], MOOSEPIC_W*SDL_BYTESPERPIXEL(pixel_format));
|
||||
}
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, MooseTexture, NULL, &displayrect);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
SDL_DestroyRenderer(renderer);
|
||||
quit(0);
|
||||
return 0;
|
||||
|
|
|
@ -119,14 +119,8 @@ TestEndian(SDL_bool verbose)
|
|||
++error;
|
||||
}
|
||||
if (verbose) {
|
||||
#ifdef _MSC_VER
|
||||
SDL_Log("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64,
|
||||
SDL_Log("Value 64 = 0x%"SDL_PRIX64", swapped = 0x%"SDL_PRIX64"\n", value64,
|
||||
SDL_Swap64(value64));
|
||||
#else
|
||||
SDL_Log("Value 64 = 0x%llX, swapped = 0x%llX\n",
|
||||
(unsigned long long) value64,
|
||||
(unsigned long long) SDL_Swap64(value64));
|
||||
#endif
|
||||
}
|
||||
if (SDL_Swap64(value64) != swapped64) {
|
||||
if (verbose) {
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue