mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 15:14:35 +00:00
Updates the SDL library to the latest standard bugfix release
This commit is contained in:
parent
cb766f2878
commit
083d2175ea
1280 changed files with 343926 additions and 179615 deletions
|
|
@ -1,20 +1,46 @@
|
|||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(SDL2 C)
|
||||
include(CTest)
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(SDL2_test)
|
||||
|
||||
include(CheckCCompilerFlag)
|
||||
include(CMakeParseArguments)
|
||||
include(CMakePushCheckState)
|
||||
|
||||
set(SDL_TEST_EXECUTABLES)
|
||||
set(SDL_TESTS_NONINTERACTIVE)
|
||||
set(SDL_TESTS_NEEDS_ESOURCES)
|
||||
|
||||
macro(add_sdl_test_executable TARGET)
|
||||
cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES" "" "" ${ARGN})
|
||||
add_executable(${TARGET} ${AST_UNPARSED_ARGUMENTS})
|
||||
|
||||
list(APPEND SDL_TEST_EXECUTABLES ${TARGET})
|
||||
if(AST_NONINTERACTIVE)
|
||||
list(APPEND SDL_TESTS_NONINTERACTIVE ${TARGET})
|
||||
endif()
|
||||
if(AST_NEEDS_RESOURCES)
|
||||
list(APPEND SDL_TESTS_NEEDS_ESOURCES ${TARGET})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
if(NOT TARGET SDL2::SDL2-static)
|
||||
find_package(SDL2 2.0.23 REQUIRED COMPONENTS SDL2-static SDL2test)
|
||||
endif()
|
||||
|
||||
enable_testing()
|
||||
|
||||
if(SDL_INSTALL_TESTS)
|
||||
include(GNUInstallDirs)
|
||||
endif()
|
||||
|
||||
# Global settings for all of the test targets
|
||||
# FIXME: is this wrong?
|
||||
remove_definitions(-DUSING_GENERATED_CONFIG_H)
|
||||
if(N3DS)
|
||||
link_libraries(SDL2::SDL2main)
|
||||
endif()
|
||||
|
||||
if(PSP)
|
||||
link_libraries(
|
||||
SDL2main
|
||||
SDL2_test
|
||||
SDL2-static
|
||||
SDL2::SDL2main
|
||||
SDL2::SDL2test
|
||||
SDL2::SDL2-static
|
||||
GL
|
||||
pspvram
|
||||
pspvfpu
|
||||
|
|
@ -26,8 +52,18 @@ if(PSP)
|
|||
psphprm
|
||||
psppower
|
||||
)
|
||||
elseif(PS2)
|
||||
link_libraries(
|
||||
SDL2main
|
||||
SDL2_test
|
||||
SDL2-static
|
||||
patches
|
||||
gskit
|
||||
dmakit
|
||||
ps2_drivers
|
||||
)
|
||||
else()
|
||||
link_libraries(SDL2_test SDL2-static)
|
||||
link_libraries(SDL2::SDL2test SDL2::SDL2-static)
|
||||
endif()
|
||||
|
||||
if(WINDOWS)
|
||||
|
|
@ -36,6 +72,11 @@ if(WINDOWS)
|
|||
link_libraries(mingw32)
|
||||
endif()
|
||||
|
||||
# CET support was added in VS 16.7
|
||||
if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64")
|
||||
link_libraries(-CETCOMPAT)
|
||||
endif()
|
||||
|
||||
# FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
|
||||
# but we need them for VS as well.
|
||||
link_libraries(SDL2main)
|
||||
|
|
@ -44,6 +85,8 @@ endif()
|
|||
|
||||
# CMake incorrectly detects opengl32.lib being present on MSVC ARM64
|
||||
if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
|
||||
# Prefer GLVND, if present
|
||||
set(OpenGL_GL_PREFERENCE GLVND)
|
||||
find_package(OpenGL)
|
||||
endif()
|
||||
|
||||
|
|
@ -51,196 +94,132 @@ if (OPENGL_FOUND)
|
|||
add_definitions(-DHAVE_OPENGL)
|
||||
endif()
|
||||
|
||||
add_executable(checkkeys checkkeys.c)
|
||||
add_executable(checkkeysthreads checkkeysthreads.c)
|
||||
add_executable(loopwave loopwave.c testutils.c)
|
||||
add_executable(loopwavequeue loopwavequeue.c testutils.c)
|
||||
add_executable(testsurround testsurround.c)
|
||||
add_executable(testresample testresample.c)
|
||||
add_executable(testaudioinfo testaudioinfo.c)
|
||||
add_sdl_test_executable(checkkeys checkkeys.c)
|
||||
add_sdl_test_executable(checkkeysthreads checkkeysthreads.c)
|
||||
add_sdl_test_executable(loopwave NEEDS_RESOURCES loopwave.c testutils.c)
|
||||
add_sdl_test_executable(loopwavequeue NEEDS_RESOURCES loopwavequeue.c testutils.c)
|
||||
add_sdl_test_executable(testsurround testsurround.c)
|
||||
add_sdl_test_executable(testresample NEEDS_RESOURCES testresample.c)
|
||||
add_sdl_test_executable(testaudioinfo testaudioinfo.c)
|
||||
|
||||
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
|
||||
add_executable(testautomation ${TESTAUTOMATION_SOURCE_FILES})
|
||||
|
||||
add_executable(testmultiaudio testmultiaudio.c testutils.c)
|
||||
add_executable(testaudiohotplug testaudiohotplug.c testutils.c)
|
||||
add_executable(testaudiocapture testaudiocapture.c)
|
||||
add_executable(testatomic testatomic.c)
|
||||
add_executable(testintersections testintersections.c)
|
||||
add_executable(testrelative testrelative.c)
|
||||
add_executable(testhittesting testhittesting.c)
|
||||
add_executable(testdraw2 testdraw2.c)
|
||||
add_executable(testdrawchessboard testdrawchessboard.c)
|
||||
add_executable(testdropfile testdropfile.c)
|
||||
add_executable(testerror testerror.c)
|
||||
add_sdl_test_executable(testautomation NEEDS_RESOURCES ${TESTAUTOMATION_SOURCE_FILES})
|
||||
add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES testmultiaudio.c testutils.c)
|
||||
add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES testaudiohotplug.c testutils.c)
|
||||
add_sdl_test_executable(testaudiocapture testaudiocapture.c)
|
||||
add_sdl_test_executable(testatomic NONINTERACTIVE testatomic.c)
|
||||
add_sdl_test_executable(testintersections testintersections.c)
|
||||
add_sdl_test_executable(testrelative testrelative.c)
|
||||
add_sdl_test_executable(testhittesting testhittesting.c)
|
||||
add_sdl_test_executable(testdraw2 testdraw2.c)
|
||||
add_sdl_test_executable(testdrawchessboard testdrawchessboard.c)
|
||||
add_sdl_test_executable(testdropfile testdropfile.c)
|
||||
add_sdl_test_executable(testerror NONINTERACTIVE testerror.c)
|
||||
|
||||
if(LINUX)
|
||||
add_executable(testevdev testevdev.c)
|
||||
add_sdl_test_executable(testevdev NONINTERACTIVE testevdev.c)
|
||||
endif()
|
||||
|
||||
add_executable(testfile testfile.c)
|
||||
add_executable(testgamecontroller testgamecontroller.c testutils.c)
|
||||
add_executable(testgeometry testgeometry.c testutils.c)
|
||||
add_executable(testgesture testgesture.c)
|
||||
add_executable(testgl2 testgl2.c)
|
||||
add_executable(testgles testgles.c)
|
||||
add_executable(testgles2 testgles2.c)
|
||||
add_executable(testhaptic testhaptic.c)
|
||||
add_executable(testhotplug testhotplug.c)
|
||||
add_executable(testrumble testrumble.c)
|
||||
add_executable(testthread testthread.c)
|
||||
add_executable(testiconv testiconv.c testutils.c)
|
||||
add_executable(testime testime.c testutils.c)
|
||||
add_executable(testjoystick testjoystick.c)
|
||||
add_executable(testkeys testkeys.c)
|
||||
add_executable(testloadso testloadso.c)
|
||||
add_executable(testlocale testlocale.c)
|
||||
add_executable(testlock testlock.c)
|
||||
add_executable(testmouse testmouse.c)
|
||||
add_sdl_test_executable(testfile testfile.c)
|
||||
add_sdl_test_executable(testgamecontroller NEEDS_RESOURCES testgamecontroller.c testutils.c)
|
||||
add_sdl_test_executable(testgeometry testgeometry.c testutils.c)
|
||||
add_sdl_test_executable(testgesture testgesture.c)
|
||||
add_sdl_test_executable(testgl2 testgl2.c)
|
||||
add_sdl_test_executable(testgles testgles.c)
|
||||
add_sdl_test_executable(testgles2 testgles2.c)
|
||||
add_sdl_test_executable(testgles2_sdf NEEDS_RESOURCES testgles2_sdf.c testutils.c)
|
||||
add_sdl_test_executable(testhaptic testhaptic.c)
|
||||
add_sdl_test_executable(testhotplug testhotplug.c)
|
||||
add_sdl_test_executable(testrumble testrumble.c)
|
||||
add_sdl_test_executable(testthread NONINTERACTIVE testthread.c)
|
||||
add_sdl_test_executable(testiconv NEEDS_RESOURCES testiconv.c testutils.c)
|
||||
add_sdl_test_executable(testime NEEDS_RESOURCES testime.c testutils.c)
|
||||
add_sdl_test_executable(testjoystick testjoystick.c)
|
||||
add_sdl_test_executable(testkeys testkeys.c)
|
||||
add_sdl_test_executable(testloadso testloadso.c)
|
||||
add_sdl_test_executable(testlocale NONINTERACTIVE testlocale.c)
|
||||
add_sdl_test_executable(testlock testlock.c)
|
||||
add_sdl_test_executable(testmouse testmouse.c)
|
||||
|
||||
if(APPLE)
|
||||
add_executable(testnative testnative.c
|
||||
testnativecocoa.m
|
||||
testnativex11.c
|
||||
testutils.c)
|
||||
add_sdl_test_executable(testnative NEEDS_RESOURCES
|
||||
testnative.c
|
||||
testnativecocoa.m
|
||||
testnativex11.c
|
||||
testutils.c
|
||||
)
|
||||
|
||||
cmake_push_check_state(RESET)
|
||||
check_c_compiler_flag(-Wno-error=deprecated-declarations HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
|
||||
cmake_pop_check_state()
|
||||
if(HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS)
|
||||
set_property(SOURCE "testnativecocoa.m" APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-error=deprecated-declarations")
|
||||
endif()
|
||||
elseif(WINDOWS)
|
||||
add_executable(testnative testnative.c testnativew32.c testutils.c)
|
||||
elseif(SDL_X11)
|
||||
add_executable(testnative testnative.c testnativex11.c testutils.c)
|
||||
add_sdl_test_executable(testnative NEEDS_RESOURCES testnative.c testnativew32.c testutils.c)
|
||||
elseif(HAVE_X11)
|
||||
add_sdl_test_executable(testnative NEEDS_RESOURCES testnative.c testnativex11.c testutils.c)
|
||||
target_link_libraries(testnative X11)
|
||||
endif()
|
||||
|
||||
add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c testutils.c)
|
||||
add_executable(testplatform testplatform.c)
|
||||
add_executable(testpower testpower.c)
|
||||
add_executable(testfilesystem testfilesystem.c)
|
||||
add_executable(testrendertarget testrendertarget.c testutils.c)
|
||||
add_executable(testscale testscale.c testutils.c)
|
||||
add_executable(testsem testsem.c)
|
||||
add_executable(testsensor testsensor.c)
|
||||
add_executable(testshader testshader.c)
|
||||
add_executable(testshape testshape.c)
|
||||
add_executable(testsprite2 testsprite2.c testutils.c)
|
||||
add_executable(testspriteminimal testspriteminimal.c testutils.c)
|
||||
add_executable(teststreaming teststreaming.c testutils.c)
|
||||
add_executable(testtimer testtimer.c)
|
||||
add_executable(testurl testurl.c)
|
||||
add_executable(testver testver.c)
|
||||
add_executable(testviewport testviewport.c testutils.c)
|
||||
add_executable(testwm2 testwm2.c)
|
||||
add_executable(testyuv testyuv.c testyuv_cvt.c)
|
||||
add_executable(torturethread torturethread.c)
|
||||
add_executable(testrendercopyex testrendercopyex.c testutils.c)
|
||||
add_executable(testmessage testmessage.c)
|
||||
add_executable(testdisplayinfo testdisplayinfo.c)
|
||||
add_executable(testqsort testqsort.c)
|
||||
add_executable(testbounds testbounds.c)
|
||||
add_executable(testcustomcursor testcustomcursor.c)
|
||||
add_executable(controllermap controllermap.c testutils.c)
|
||||
add_executable(testvulkan testvulkan.c)
|
||||
add_executable(testoffscreen testoffscreen.c)
|
||||
add_sdl_test_executable(testoverlay2 NEEDS_RESOURCES testoverlay2.c testyuv_cvt.c testutils.c)
|
||||
add_sdl_test_executable(testplatform NONINTERACTIVE testplatform.c)
|
||||
add_sdl_test_executable(testpower NONINTERACTIVE testpower.c)
|
||||
add_sdl_test_executable(testfilesystem NONINTERACTIVE testfilesystem.c)
|
||||
add_sdl_test_executable(testrendertarget NEEDS_RESOURCES testrendertarget.c testutils.c)
|
||||
add_sdl_test_executable(testscale NEEDS_RESOURCES testscale.c testutils.c)
|
||||
add_sdl_test_executable(testsem testsem.c)
|
||||
add_sdl_test_executable(testsensor testsensor.c)
|
||||
add_sdl_test_executable(testshader NEEDS_RESOURCES testshader.c)
|
||||
add_sdl_test_executable(testshape NEEDS_RESOURCES testshape.c)
|
||||
add_sdl_test_executable(testsprite2 NEEDS_RESOURCES testsprite2.c testutils.c)
|
||||
add_sdl_test_executable(testspriteminimal NEEDS_RESOURCES testspriteminimal.c testutils.c)
|
||||
add_sdl_test_executable(teststreaming NEEDS_RESOURCES teststreaming.c testutils.c)
|
||||
add_sdl_test_executable(testtimer NONINTERACTIVE testtimer.c)
|
||||
add_sdl_test_executable(testurl testurl.c)
|
||||
add_sdl_test_executable(testver NONINTERACTIVE testver.c)
|
||||
add_sdl_test_executable(testviewport NEEDS_RESOURCES testviewport.c testutils.c)
|
||||
add_sdl_test_executable(testwm2 testwm2.c)
|
||||
add_sdl_test_executable(testyuv NEEDS_RESOURCES testyuv.c testyuv_cvt.c)
|
||||
add_sdl_test_executable(torturethread torturethread.c)
|
||||
add_sdl_test_executable(testrendercopyex NEEDS_RESOURCES testrendercopyex.c testutils.c)
|
||||
add_sdl_test_executable(testmessage testmessage.c)
|
||||
add_sdl_test_executable(testdisplayinfo testdisplayinfo.c)
|
||||
add_sdl_test_executable(testqsort NONINTERACTIVE testqsort.c)
|
||||
add_sdl_test_executable(testbounds testbounds.c)
|
||||
add_sdl_test_executable(testcustomcursor testcustomcursor.c)
|
||||
add_sdl_test_executable(controllermap NEEDS_RESOURCES controllermap.c testutils.c)
|
||||
add_sdl_test_executable(testvulkan testvulkan.c)
|
||||
add_sdl_test_executable(testoffscreen testoffscreen.c)
|
||||
|
||||
SET(ALL_TESTS
|
||||
checkkeys
|
||||
checkkeysthreads
|
||||
controllermap
|
||||
loopwave
|
||||
loopwavequeue
|
||||
testatomic
|
||||
testaudiocapture
|
||||
testaudiohotplug
|
||||
testaudioinfo
|
||||
testautomation
|
||||
testbounds
|
||||
testcustomcursor
|
||||
testdisplayinfo
|
||||
testdraw2
|
||||
testdrawchessboard
|
||||
testdropfile
|
||||
testerror
|
||||
testfile
|
||||
testfilesystem
|
||||
testgamecontroller
|
||||
testgeometry
|
||||
testgesture
|
||||
testgl2
|
||||
testgles
|
||||
testgles2
|
||||
testhaptic
|
||||
testhittesting
|
||||
testhotplug
|
||||
testiconv
|
||||
testime
|
||||
testintersections
|
||||
testjoystick
|
||||
testkeys
|
||||
testloadso
|
||||
testlocale
|
||||
testlock
|
||||
testmessage
|
||||
testmouse
|
||||
testmultiaudio
|
||||
testoffscreen
|
||||
testoverlay2
|
||||
testplatform
|
||||
testpower
|
||||
testqsort
|
||||
testrelative
|
||||
testrendercopyex
|
||||
testrendertarget
|
||||
testresample
|
||||
testrumble
|
||||
testscale
|
||||
testsem
|
||||
testsensor
|
||||
testshader
|
||||
testshape
|
||||
testsprite2
|
||||
testspriteminimal
|
||||
teststreaming
|
||||
testsurround
|
||||
testthread
|
||||
testtimer
|
||||
testurl
|
||||
testver
|
||||
testviewport
|
||||
testvulkan
|
||||
testwm2
|
||||
testyuv
|
||||
torturethread
|
||||
)
|
||||
cmake_push_check_state(RESET)
|
||||
|
||||
set(NONINTERACTIVE
|
||||
testatomic
|
||||
testerror
|
||||
testfilesystem
|
||||
testlocale
|
||||
testplatform
|
||||
testpower
|
||||
testqsort
|
||||
testthread
|
||||
testtimer
|
||||
testver
|
||||
)
|
||||
|
||||
if(WINDOWS OR APPLE OR SDL_X11)
|
||||
list(APPEND ALL_TESTS testnative)
|
||||
check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
|
||||
if(HAVE_WFORMAT_OVERFLOW)
|
||||
target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_OVERFLOW)
|
||||
endif()
|
||||
|
||||
if(LINUX)
|
||||
list(APPEND ALL_TESTS testevdev)
|
||||
list(APPEND NONINTERACTIVE testevdev)
|
||||
check_c_compiler_flag(-Wformat HAVE_WFORMAT)
|
||||
if(HAVE_WFORMAT)
|
||||
target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT)
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS)
|
||||
if(HAVE_WFORMAT_EXTRA_ARGS)
|
||||
target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_EXTRA_ARGS)
|
||||
endif()
|
||||
|
||||
cmake_pop_check_state()
|
||||
|
||||
if(SDL_DUMMYAUDIO)
|
||||
set(NEEDS_AUDIO
|
||||
list(APPEND SDL_TESTS_NONINTERACTIVE
|
||||
testaudioinfo
|
||||
testsurround
|
||||
)
|
||||
endif()
|
||||
|
||||
if(SDL_DUMMYVIDEO)
|
||||
set(NEEDS_DISPLAY
|
||||
list(APPEND SDL_TESTS_NONINTERACTIVE
|
||||
testkeys
|
||||
testbounds
|
||||
testdisplayinfo
|
||||
|
|
@ -248,100 +227,58 @@ if(SDL_DUMMYVIDEO)
|
|||
endif()
|
||||
|
||||
if(OPENGL_FOUND)
|
||||
add_dependencies(testshader OpenGL::GL)
|
||||
add_dependencies(testgl2 OpenGL::GL)
|
||||
target_link_libraries(testshader OpenGL::GL)
|
||||
target_link_libraries(testgl2 OpenGL::GL)
|
||||
if(TARGET OpenGL::GL)
|
||||
target_link_libraries(testshader OpenGL::GL)
|
||||
target_link_libraries(testgl2 OpenGL::GL)
|
||||
else()
|
||||
if(EMSCRIPTEN AND OPENGL_gl_LIBRARY STREQUAL "nul")
|
||||
set(OPENGL_gl_LIBRARY GL)
|
||||
endif()
|
||||
# emscripten's FindOpenGL.cmake does not create OpenGL::GL
|
||||
target_link_libraries(testshader ${OPENGL_gl_LIBRARY})
|
||||
target_link_libraries(testgl2 ${OPENGL_gl_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
if(EMSCRIPTEN)
|
||||
target_link_libraries(testshader -sLEGACY_GL_EMULATION)
|
||||
endif()
|
||||
|
||||
file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
|
||||
file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
if(PSP)
|
||||
set(NEEDS_RESOURCES
|
||||
testscale
|
||||
testrendercopyex
|
||||
controllermap
|
||||
testyuv
|
||||
testgamecontroller
|
||||
testshape
|
||||
testshader
|
||||
testspriteminimal
|
||||
testautomation
|
||||
testrendertarget
|
||||
testsprite2
|
||||
loopwave
|
||||
loopwavequeue
|
||||
testresample
|
||||
testaudiohotplug
|
||||
testmultiaudio
|
||||
testiconv
|
||||
testoverlay2
|
||||
teststreaming
|
||||
testviewport
|
||||
)
|
||||
else()
|
||||
set(NEEDS_RESOURCES
|
||||
testscale
|
||||
testrendercopyex
|
||||
controllermap
|
||||
testyuv
|
||||
testgamecontroller
|
||||
testshape
|
||||
testshader
|
||||
testspriteminimal
|
||||
testautomation
|
||||
testcustomcursor
|
||||
testrendertarget
|
||||
testsprite2
|
||||
loopwave
|
||||
loopwavequeue
|
||||
testresample
|
||||
testaudiohotplug
|
||||
testmultiaudio
|
||||
testime
|
||||
testiconv
|
||||
testoverlay2
|
||||
teststreaming
|
||||
testviewport
|
||||
)
|
||||
if(WINDOWS OR APPLE OR SDL_X11)
|
||||
list(APPEND NEEDS_RESOURCES testnative)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(PSP)
|
||||
# Build EBOOT files if building for PSP
|
||||
set(BUILD_EBOOT
|
||||
${NEEDS_RESOURCES}
|
||||
testbounds
|
||||
testgl2
|
||||
testsem
|
||||
testdisplayinfo
|
||||
teststreaming
|
||||
testgeometry
|
||||
testfile
|
||||
testdraw2
|
||||
testviewport
|
||||
testhittesting
|
||||
testoverlay2
|
||||
testver
|
||||
testdrawchessboard
|
||||
testsurround
|
||||
testintersections
|
||||
testmessage
|
||||
testaudiocapture
|
||||
testerror
|
||||
${SDL_TESTS_NEEDS_ESOURCES}
|
||||
testatomic
|
||||
testjoystick
|
||||
testiconv
|
||||
testfilesystem
|
||||
testplatform
|
||||
testthread
|
||||
testqsort
|
||||
testaudiocapture
|
||||
testaudioinfo
|
||||
testbounds
|
||||
testdisplayinfo
|
||||
testdraw2
|
||||
testdrawchessboard
|
||||
testerror
|
||||
testfile
|
||||
testfilesystem
|
||||
testgeometry
|
||||
testgl2
|
||||
testhittesting
|
||||
testiconv
|
||||
testintersections
|
||||
testjoystick
|
||||
testlock
|
||||
testtimer
|
||||
testmessage
|
||||
testoverlay2
|
||||
testplatform
|
||||
testpower
|
||||
testqsort
|
||||
testsem
|
||||
teststreaming
|
||||
testsurround
|
||||
testthread
|
||||
testtimer
|
||||
testver
|
||||
testviewport
|
||||
testwm2
|
||||
torturethread
|
||||
)
|
||||
|
|
@ -386,9 +323,30 @@ if(PSP)
|
|||
endforeach()
|
||||
endif()
|
||||
|
||||
if(N3DS)
|
||||
set(ROMFS_DIR "${CMAKE_CURRENT_BINARY_DIR}/romfs")
|
||||
file(COPY ${RESOURCE_FILES} DESTINATION "${ROMFS_DIR}")
|
||||
|
||||
foreach(APP IN LISTS SDL_TEST_EXECUTABLES)
|
||||
get_target_property(TARGET_BINARY_DIR ${APP} BINARY_DIR)
|
||||
set(SMDH_FILE "${TARGET_BINARY_DIR}/${APP}.smdh")
|
||||
ctr_generate_smdh("${SMDH_FILE}"
|
||||
NAME "SDL-${APP}"
|
||||
DESCRIPTION "SDL2 Test suite"
|
||||
AUTHOR "SDL2 Contributors"
|
||||
ICON "${CMAKE_CURRENT_SOURCE_DIR}/n3ds/logo48x48.png"
|
||||
)
|
||||
ctr_create_3dsx(
|
||||
${APP}
|
||||
ROMFS "${ROMFS_DIR}"
|
||||
SMDH "${SMDH_FILE}"
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if(RISCOS)
|
||||
set(ALL_TESTS_AIF "")
|
||||
foreach(APP IN LISTS ALL_TESTS)
|
||||
set(SDL_TEST_EXECUTABLES_AIF)
|
||||
foreach(APP IN LISTS SDL_TEST_EXECUTABLES)
|
||||
target_link_options(${APP} PRIVATE -static)
|
||||
add_custom_command(
|
||||
OUTPUT ${APP},ff8
|
||||
|
|
@ -396,20 +354,20 @@ if(RISCOS)
|
|||
DEPENDS ${APP}
|
||||
)
|
||||
add_custom_target(${APP}-aif ALL DEPENDS ${APP},ff8)
|
||||
list(APPEND ALL_TESTS_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8)
|
||||
list(APPEND SDL_TEST_EXECUTABLES_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
foreach(APP IN LISTS NEEDS_RESOURCES)
|
||||
foreach(APP IN LISTS SDL_TESTS_NEEDS_RESOURCES)
|
||||
foreach(RESOURCE_FILE ${RESOURCE_FILES})
|
||||
if(PSP)
|
||||
if(PSP OR PS2)
|
||||
add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
|
||||
else()
|
||||
add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
|
||||
endif()
|
||||
endforeach(RESOURCE_FILE)
|
||||
if(APPLE)
|
||||
# Make sure resource files get installed into macOS/iOS .app bundles.
|
||||
# Make sure resource files get installed into macOS/iOS .app bundles.
|
||||
target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
|
||||
set_target_properties(${APP} PROPERTIES RESOURCE "${RESOURCE_FILES}")
|
||||
endif()
|
||||
|
|
@ -442,15 +400,16 @@ set(TESTS_ENVIRONMENT
|
|||
SDL_VIDEODRIVER=dummy
|
||||
)
|
||||
|
||||
foreach(TESTCASE ${NONINTERACTIVE} ${NEEDS_AUDIO} ${NEEDS_DISPLAY})
|
||||
foreach(TESTCASE ${SDL_TESTS_NONINTERACTIVE})
|
||||
add_test(
|
||||
NAME ${TESTCASE}
|
||||
COMMAND ${TESTCASE}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
set_tests_properties(
|
||||
${TESTCASE}
|
||||
PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}"
|
||||
set_tests_properties(${TESTCASE}
|
||||
PROPERTIES
|
||||
ENVIRONMENT "${TESTS_ENVIRONMENT}"
|
||||
TIMEOUT 10
|
||||
)
|
||||
if(SDL_INSTALL_TESTS)
|
||||
set(exe ${TESTCASE})
|
||||
|
|
@ -463,15 +422,18 @@ foreach(TESTCASE ${NONINTERACTIVE} ${NEEDS_AUDIO} ${NEEDS_DISPLAY})
|
|||
endif()
|
||||
endforeach()
|
||||
|
||||
set_tests_properties(testthread PROPERTIES TIMEOUT 40)
|
||||
set_tests_properties(testtimer PROPERTIES TIMEOUT 60)
|
||||
|
||||
if(SDL_INSTALL_TESTS)
|
||||
if(RISCOS)
|
||||
install(
|
||||
FILES ${ALL_TESTS_AIF}
|
||||
FILES ${SDL_TEST_EXECUTABLES_AIF}
|
||||
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
|
||||
)
|
||||
else()
|
||||
install(
|
||||
TARGETS ${ALL_TESTS}
|
||||
TARGETS ${SDL_TEST_EXECUTABLES}
|
||||
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
|
||||
)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -137,8 +137,12 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
|
|||
$(srcdir)/testautomation_audio.c \
|
||||
$(srcdir)/testautomation_clipboard.c \
|
||||
$(srcdir)/testautomation_events.c \
|
||||
$(srcdir)/testautomation_guid.c \
|
||||
$(srcdir)/testautomation_hints.c \
|
||||
$(srcdir)/testautomation_joystick.c \
|
||||
$(srcdir)/testautomation_keyboard.c \
|
||||
$(srcdir)/testautomation_main.c \
|
||||
$(srcdir)/testautomation_math.c \
|
||||
$(srcdir)/testautomation_mouse.c \
|
||||
$(srcdir)/testautomation_pixels.c \
|
||||
$(srcdir)/testautomation_platform.c \
|
||||
|
|
@ -150,8 +154,7 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
|
|||
$(srcdir)/testautomation_surface.c \
|
||||
$(srcdir)/testautomation_syswm.c \
|
||||
$(srcdir)/testautomation_timer.c \
|
||||
$(srcdir)/testautomation_video.c \
|
||||
$(srcdir)/testautomation_hints.c
|
||||
$(srcdir)/testautomation_video.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c $(srcdir)/testutils.c
|
||||
|
|
@ -201,7 +204,7 @@ testgeometry$(EXE): $(srcdir)/testgeometry.c $(srcdir)/testutils.c
|
|||
|
||||
testgesture$(EXE): $(srcdir)/testgesture.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
|
||||
testgl2$(EXE): $(srcdir)/testgl2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
# Open Watcom makefile to build SDL2 tests for OS/2
|
||||
# wmake -f Makefile.os2
|
||||
#
|
||||
# To error out upon warnings: wmake -f Makefile.os2 ENABLE_WERROR=1
|
||||
|
||||
SYSTEM = os2v2
|
||||
|
||||
|
|
@ -7,6 +9,10 @@ INCPATH = -I"$(%WATCOM)/h/os2" -I"$(%WATCOM)/h"
|
|||
|
||||
CFLAGS = -bt=os2 -d0 -q -bm -5s -fp5 -fpi87 -sg -oteanbmier -ei
|
||||
CFLAGS+= -wx -wcd=303
|
||||
CFLAGS+= -DHAVE_SIGNAL_H
|
||||
!ifeq ENABLE_WERROR 1
|
||||
CFLAGS+= -we
|
||||
!endif
|
||||
|
||||
TNSRCS = testnative.c testnativeos2.c
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
# Open Watcom makefile to build SDL2 tests for Win32
|
||||
# wmake -f Makefile.w32
|
||||
#
|
||||
# To error out upon warnings: wmake -f Makefile.w32 ENABLE_WERROR=1
|
||||
|
||||
SYSTEM = nt
|
||||
|
||||
|
|
@ -7,8 +9,11 @@ INCPATH = -I"$(%WATCOM)/h/nt" -I"$(%WATCOM)/h" -I"../src/video/khronos"
|
|||
|
||||
CFLAGS = -bt=nt -d0 -q -bm -5s -fp5 -fpi87 -sg -oteanbmier -ei
|
||||
CFLAGS+= -wx -wcd=303
|
||||
!ifeq ENABLE_WERROR 1
|
||||
CFLAGS+= -we
|
||||
!endif
|
||||
CFLAGS+= -DSDL_MAIN_HANDLED
|
||||
CFLAGS+= -DHAVE_OPENGL
|
||||
CFLAGS+= -DHAVE_OPENGL -DHAVE_SIGNAL_H
|
||||
GLLIBS = opengl32.lib
|
||||
|
||||
TNSRCS = testnative.c testnativew32.c
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
cp acinclude.m4 aclocal.m4
|
||||
|
||||
if test "$AUTOCONF"x = x; then
|
||||
AUTOCONF=autoconf
|
||||
fi
|
||||
|
||||
$AUTOCONF || exit 1
|
||||
"${AUTOCONF:-autoconf}"
|
||||
rm aclocal.m4
|
||||
rm -rf autom4te.cache
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -24,8 +24,12 @@
|
|||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test_font.h"
|
||||
|
||||
int done;
|
||||
static SDL_Window *window;
|
||||
static SDL_Renderer *renderer;
|
||||
static SDLTest_TextWindow *textwin;
|
||||
static int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
|
|
@ -45,8 +49,8 @@ print_string(char **text, size_t *maxlen, const char *fmt, ...)
|
|||
len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
|
||||
if (len > 0) {
|
||||
*text += len;
|
||||
if ( ((size_t) len) < *maxlen ) {
|
||||
*maxlen -= (size_t) len;
|
||||
if (((size_t)len) < *maxlen) {
|
||||
*maxlen -= (size_t)len;
|
||||
} else {
|
||||
*maxlen = 0;
|
||||
}
|
||||
|
|
@ -64,30 +68,42 @@ print_modifiers(char **text, size_t *maxlen)
|
|||
print_string(text, maxlen, " (none)");
|
||||
return;
|
||||
}
|
||||
if (mod & KMOD_LSHIFT)
|
||||
if (mod & KMOD_LSHIFT) {
|
||||
print_string(text, maxlen, " LSHIFT");
|
||||
if (mod & KMOD_RSHIFT)
|
||||
}
|
||||
if (mod & KMOD_RSHIFT) {
|
||||
print_string(text, maxlen, " RSHIFT");
|
||||
if (mod & KMOD_LCTRL)
|
||||
}
|
||||
if (mod & KMOD_LCTRL) {
|
||||
print_string(text, maxlen, " LCTRL");
|
||||
if (mod & KMOD_RCTRL)
|
||||
}
|
||||
if (mod & KMOD_RCTRL) {
|
||||
print_string(text, maxlen, " RCTRL");
|
||||
if (mod & KMOD_LALT)
|
||||
}
|
||||
if (mod & KMOD_LALT) {
|
||||
print_string(text, maxlen, " LALT");
|
||||
if (mod & KMOD_RALT)
|
||||
}
|
||||
if (mod & KMOD_RALT) {
|
||||
print_string(text, maxlen, " RALT");
|
||||
if (mod & KMOD_LGUI)
|
||||
}
|
||||
if (mod & KMOD_LGUI) {
|
||||
print_string(text, maxlen, " LGUI");
|
||||
if (mod & KMOD_RGUI)
|
||||
}
|
||||
if (mod & KMOD_RGUI) {
|
||||
print_string(text, maxlen, " RGUI");
|
||||
if (mod & KMOD_NUM)
|
||||
}
|
||||
if (mod & KMOD_NUM) {
|
||||
print_string(text, maxlen, " NUM");
|
||||
if (mod & KMOD_CAPS)
|
||||
}
|
||||
if (mod & KMOD_CAPS) {
|
||||
print_string(text, maxlen, " CAPS");
|
||||
if (mod & KMOD_MODE)
|
||||
}
|
||||
if (mod & KMOD_MODE) {
|
||||
print_string(text, maxlen, " MODE");
|
||||
if (mod & KMOD_SCROLL)
|
||||
}
|
||||
if (mod & KMOD_SCROLL) {
|
||||
print_string(text, maxlen, " SCROLL");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -105,7 +121,7 @@ PrintModifierState()
|
|||
}
|
||||
|
||||
static void
|
||||
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
|
||||
PrintKey(SDL_Keysym *sym, SDL_bool pressed, SDL_bool repeat)
|
||||
{
|
||||
char message[512];
|
||||
char *spot;
|
||||
|
|
@ -117,17 +133,17 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
|
|||
/* Print the keycode, name and state */
|
||||
if (sym->sym) {
|
||||
print_string(&spot, &left,
|
||||
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
|
||||
pressed ? "pressed " : "released",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
sym->sym, SDL_GetKeyName(sym->sym));
|
||||
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
|
||||
pressed ? "pressed " : "released",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
sym->sym, SDL_GetKeyName(sym->sym));
|
||||
} else {
|
||||
print_string(&spot, &left,
|
||||
"Unknown Key (scancode %d = %s) %s ",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
pressed ? "pressed " : "released");
|
||||
"Unknown Key (scancode %d = %s) %s ",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
pressed ? "pressed " : "released");
|
||||
}
|
||||
print_modifiers(&spot, &left);
|
||||
if (repeat) {
|
||||
|
|
@ -143,16 +159,14 @@ PrintText(const char *eventtype, const char *text)
|
|||
char expanded[1024];
|
||||
|
||||
expanded[0] = '\0';
|
||||
for ( spot = text; *spot; ++spot )
|
||||
{
|
||||
for (spot = text; *spot; ++spot) {
|
||||
size_t length = SDL_strlen(expanded);
|
||||
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
|
||||
(void)SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
|
||||
}
|
||||
SDL_Log("%s Text (%s): \"%s%s\"\n", eventtype, expanded, *text == '"' ? "\\" : "", text);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
/* Check for events */
|
||||
|
|
@ -163,6 +177,18 @@ loop()
|
|||
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);
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_BACKSPACE:
|
||||
SDLTest_TextWindowAddText(textwin, "\b");
|
||||
break;
|
||||
case SDLK_RETURN:
|
||||
SDLTest_TextWindowAddText(textwin, "\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_TEXTEDITING:
|
||||
PrintText("EDIT", event.edit.text);
|
||||
|
|
@ -173,6 +199,16 @@ loop()
|
|||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
PrintText("INPUT", event.text.text);
|
||||
SDLTest_TextWindowAddText(textwin, "%s", event.text.text);
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
if (SDL_IsTextInputActive()) {
|
||||
SDL_Log("Stopping text input\n");
|
||||
SDL_StopTextInput();
|
||||
} else {
|
||||
SDL_Log("Starting text input\n");
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Left button quits the app, other buttons toggles text input */
|
||||
|
|
@ -195,6 +231,16 @@ loop()
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_TextWindowDisplay(textwin, renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* Slow down framerate */
|
||||
SDL_Delay(100);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done) {
|
||||
emscripten_cancel_main_loop();
|
||||
|
|
@ -202,39 +248,41 @@ loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Disable mouse emulation */
|
||||
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
|
||||
|
||||
/* Enable extended text editing events */
|
||||
SDL_SetHint(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, "1");
|
||||
|
||||
/* Initialize SDL */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Set 640x480 video mode */
|
||||
window = SDL_CreateWindow("CheckKeys Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
640, 480, 0);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* On wayland, no window will actually show until something has
|
||||
actually been displayed.
|
||||
*/
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
SDL_RenderPresent(renderer);
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n",
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
textwin = SDLTest_TextWindowCreate(0, 0, 640, 480);
|
||||
|
||||
#if __IPHONEOS__
|
||||
/* Creating the context creates the view, which we need to show keyboard */
|
||||
|
|
@ -259,7 +307,7 @@ main(int argc, char *argv[])
|
|||
#endif
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -45,8 +45,8 @@ print_string(char **text, size_t *maxlen, const char *fmt, ...)
|
|||
len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
|
||||
if (len > 0) {
|
||||
*text += len;
|
||||
if ( ((size_t) len) < *maxlen ) {
|
||||
*maxlen -= (size_t) len;
|
||||
if (((size_t)len) < *maxlen) {
|
||||
*maxlen -= (size_t)len;
|
||||
} else {
|
||||
*maxlen = 0;
|
||||
}
|
||||
|
|
@ -64,30 +64,42 @@ print_modifiers(char **text, size_t *maxlen)
|
|||
print_string(text, maxlen, " (none)");
|
||||
return;
|
||||
}
|
||||
if (mod & KMOD_LSHIFT)
|
||||
if (mod & KMOD_LSHIFT) {
|
||||
print_string(text, maxlen, " LSHIFT");
|
||||
if (mod & KMOD_RSHIFT)
|
||||
}
|
||||
if (mod & KMOD_RSHIFT) {
|
||||
print_string(text, maxlen, " RSHIFT");
|
||||
if (mod & KMOD_LCTRL)
|
||||
}
|
||||
if (mod & KMOD_LCTRL) {
|
||||
print_string(text, maxlen, " LCTRL");
|
||||
if (mod & KMOD_RCTRL)
|
||||
}
|
||||
if (mod & KMOD_RCTRL) {
|
||||
print_string(text, maxlen, " RCTRL");
|
||||
if (mod & KMOD_LALT)
|
||||
}
|
||||
if (mod & KMOD_LALT) {
|
||||
print_string(text, maxlen, " LALT");
|
||||
if (mod & KMOD_RALT)
|
||||
}
|
||||
if (mod & KMOD_RALT) {
|
||||
print_string(text, maxlen, " RALT");
|
||||
if (mod & KMOD_LGUI)
|
||||
}
|
||||
if (mod & KMOD_LGUI) {
|
||||
print_string(text, maxlen, " LGUI");
|
||||
if (mod & KMOD_RGUI)
|
||||
}
|
||||
if (mod & KMOD_RGUI) {
|
||||
print_string(text, maxlen, " RGUI");
|
||||
if (mod & KMOD_NUM)
|
||||
}
|
||||
if (mod & KMOD_NUM) {
|
||||
print_string(text, maxlen, " NUM");
|
||||
if (mod & KMOD_CAPS)
|
||||
}
|
||||
if (mod & KMOD_CAPS) {
|
||||
print_string(text, maxlen, " CAPS");
|
||||
if (mod & KMOD_MODE)
|
||||
}
|
||||
if (mod & KMOD_MODE) {
|
||||
print_string(text, maxlen, " MODE");
|
||||
if (mod & KMOD_SCROLL)
|
||||
}
|
||||
if (mod & KMOD_SCROLL) {
|
||||
print_string(text, maxlen, " SCROLL");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -105,7 +117,7 @@ PrintModifierState()
|
|||
}
|
||||
|
||||
static void
|
||||
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
|
||||
PrintKey(SDL_Keysym *sym, SDL_bool pressed, SDL_bool repeat)
|
||||
{
|
||||
char message[512];
|
||||
char *spot;
|
||||
|
|
@ -117,24 +129,23 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
|
|||
/* Print the keycode, name and state */
|
||||
if (sym->sym) {
|
||||
print_string(&spot, &left,
|
||||
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
|
||||
pressed ? "pressed " : "released",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
sym->sym, SDL_GetKeyName(sym->sym));
|
||||
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
|
||||
pressed ? "pressed " : "released",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
sym->sym, SDL_GetKeyName(sym->sym));
|
||||
} else {
|
||||
print_string(&spot, &left,
|
||||
"Unknown Key (scancode %d = %s) %s ",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
pressed ? "pressed " : "released");
|
||||
"Unknown Key (scancode %d = %s) %s ",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
pressed ? "pressed " : "released");
|
||||
}
|
||||
print_modifiers(&spot, &left);
|
||||
if (repeat) {
|
||||
print_string(&spot, &left, " (repeat)");
|
||||
}
|
||||
SDL_Log("%s\n", message);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -144,25 +155,24 @@ PrintText(const char *eventtype, const char *text)
|
|||
char expanded[1024];
|
||||
|
||||
expanded[0] = '\0';
|
||||
for ( spot = text; *spot; ++spot )
|
||||
{
|
||||
for (spot = text; *spot; ++spot) {
|
||||
size_t length = SDL_strlen(expanded);
|
||||
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
|
||||
(void)SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
|
||||
}
|
||||
SDL_Log("%s Text (%s): \"%s%s\"\n", eventtype, expanded, *text == '"' ? "\\" : "", text);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
/* Check for events */
|
||||
/*SDL_WaitEvent(&event); emscripten does not like waiting*/
|
||||
|
||||
fprintf(stderr, "starting loop\n"); fflush(stderr);
|
||||
(void)fprintf(stderr, "starting loop\n");
|
||||
(void)fflush(stderr);
|
||||
// while (SDL_PollEvent(&event)) {
|
||||
while (!done && SDL_WaitEvent(&event)) {
|
||||
fprintf(stderr, "got event type: %d\n", event.type); fflush(stderr);
|
||||
SDL_Log("Got event type: %" SDL_PRIu32 "\n", event.type);
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
|
|
@ -176,7 +186,8 @@ loop()
|
|||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Left button quits the app, other buttons toggles text input */
|
||||
fprintf(stderr, "mouse button down button: %d (LEFT=%d)\n", event.button.button, SDL_BUTTON_LEFT); fflush(stderr);
|
||||
(void)fprintf(stderr, "mouse button down button: %d (LEFT=%d)\n", event.button.button, SDL_BUTTON_LEFT);
|
||||
(void)fflush(stderr);
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
done = 1;
|
||||
} else {
|
||||
|
|
@ -195,9 +206,11 @@ loop()
|
|||
default:
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "waiting new event\n"); fflush(stderr);
|
||||
(void)fprintf(stderr, "waiting new event\n");
|
||||
(void)fflush(stderr);
|
||||
}
|
||||
fprintf(stderr, "exiting event loop\n"); fflush(stderr);
|
||||
(void)fprintf(stderr, "exiting event loop\n");
|
||||
(void)fflush(stderr);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done) {
|
||||
emscripten_cancel_main_loop();
|
||||
|
|
@ -210,9 +223,10 @@ static int SDLCALL ping_thread(void *ptr)
|
|||
{
|
||||
int cnt;
|
||||
SDL_Event sdlevent;
|
||||
SDL_memset(&sdlevent, 0 , sizeof(SDL_Event));
|
||||
SDL_memset(&sdlevent, 0, sizeof(SDL_Event));
|
||||
for (cnt = 0; cnt < 10; ++cnt) {
|
||||
fprintf(stderr, "sending event (%d/%d) from thread.\n", cnt + 1, 10); fflush(stderr);
|
||||
(void)fprintf(stderr, "sending event (%d/%d) from thread.\n", cnt + 1, 10);
|
||||
(void)fflush(stderr);
|
||||
sdlevent.type = SDL_KEYDOWN;
|
||||
sdlevent.key.keysym.sym = SDLK_1;
|
||||
SDL_PushEvent(&sdlevent);
|
||||
|
|
@ -221,8 +235,7 @@ static int SDLCALL ping_thread(void *ptr)
|
|||
return cnt;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
|
|
@ -234,16 +247,16 @@ main(int argc, char *argv[])
|
|||
/* Initialize SDL */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Set 640x480 video mode */
|
||||
window = SDL_CreateWindow("CheckKeys Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
640, 480, 0);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
|
|
@ -267,7 +280,7 @@ main(int argc, char *argv[])
|
|||
/* Watch keystrokes */
|
||||
done = 0;
|
||||
|
||||
thread = SDL_CreateThread(ping_thread, "PingThread", (void *)NULL);
|
||||
thread = SDL_CreateThread(ping_thread, "PingThread", NULL);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
|
|
@ -279,7 +292,7 @@ main(int argc, char *argv[])
|
|||
|
||||
SDL_WaitThread(thread, NULL);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
2581
Engine/lib/sdl/test/configure
vendored
2581
Engine/lib/sdl/test/configure
vendored
File diff suppressed because it is too large
Load diff
|
|
@ -184,6 +184,80 @@ if test x$have_opengl = xyes; then
|
|||
OPENGL_TARGETS="TARGETS"
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(for GCC -Wformat)
|
||||
have_wformat=no
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$save_CFLAGS -Wformat"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
|
||||
[have_wformat=yes], [])
|
||||
AC_MSG_RESULT($have_wformat)
|
||||
CFLAGS="$save_CFLAGS"
|
||||
if test x$have_wformat = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_WFORMAT"
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(for GCC -Wformat-overflow)
|
||||
have_wformat_overflow=no
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$save_CFLAGS -Wformat-overflow"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
|
||||
[have_wformat_overflow=yes], [])
|
||||
AC_MSG_RESULT($have_wformat_overflow)
|
||||
CFLAGS="$save_CFLAGS"
|
||||
if test x$have_wformat_overflow = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_WFORMAT_OVERFLOW"
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING(for GCC -Wformat-extra-args)
|
||||
have_wformat_extra_args=no
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$save_CFLAGS -Wformat-extra-args"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
|
||||
[have_wformat_extra_args=yes], [])
|
||||
AC_MSG_RESULT($have_wformat_extra_args)
|
||||
CFLAGS="$save_CFLAGS"
|
||||
if test x$have_wformat_extra_args = xyes; then
|
||||
CFLAGS="$CFLAGS -DHAVE_WFORMAT_EXTRA_ARGS"
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(werror,
|
||||
[AS_HELP_STRING([--enable-werror], [treat warnings as errors [default=no]])],
|
||||
enable_werror=$enableval, enable_werror=no)
|
||||
if test x$enable_werror = xyes; then
|
||||
AC_MSG_CHECKING(for GCC -Werror option)
|
||||
have_gcc_werror=no
|
||||
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$save_CFLAGS -Werror"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x = 0;]],[])],
|
||||
[have_gcc_werror=yes], [])
|
||||
AC_MSG_RESULT($have_gcc_werror)
|
||||
CFLAGS="$save_CFLAGS"
|
||||
|
||||
if test x$have_gcc_werror = xyes; then
|
||||
CFLAGS="$CFLAGS -Werror"
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$host" in
|
||||
*-ios-*|*-*-darwin* )
|
||||
AC_MSG_CHECKING(for GCC -Wno-error=deprecated-declarations option)
|
||||
have_gcc_wno_error_deprecated_declarations=no
|
||||
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$save_CFLAGS -Wno-error=deprecated-declarations"
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
int x = 0;
|
||||
]],[])], [have_gcc_wno_error_deprecated_declarations=yes],[])
|
||||
AC_MSG_RESULT($have_gcc_werror)
|
||||
CFLAGS="$save_CFLAGS"
|
||||
|
||||
if test x$have_gcc_wno_error_deprecated_declarations = xyes; then
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS -Wno-error=deprecated-declarations"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_SUBST(OPENGLES1_TARGETS)
|
||||
AC_SUBST(OPENGLES2_TARGETS)
|
||||
AC_SUBST(OPENGL_TARGETS)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -25,11 +25,14 @@
|
|||
/* Define this for verbose output while mapping controllers */
|
||||
#define DEBUG_CONTROLLERMAP
|
||||
|
||||
#define SCREEN_WIDTH 512
|
||||
#define SCREEN_HEIGHT 320
|
||||
#define SCREEN_WIDTH 512
|
||||
#define SCREEN_HEIGHT 320
|
||||
|
||||
#define MARKER_BUTTON 1
|
||||
#define MARKER_AXIS 2
|
||||
enum marker_type
|
||||
{
|
||||
MARKER_BUTTON,
|
||||
MARKER_AXIS,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
@ -48,11 +51,11 @@ enum
|
|||
|
||||
#define BINDING_COUNT (SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_MAX)
|
||||
|
||||
static struct
|
||||
static struct
|
||||
{
|
||||
int x, y;
|
||||
double angle;
|
||||
int marker;
|
||||
enum marker_type marker;
|
||||
|
||||
} s_arrBindingDisplay[] = {
|
||||
{ 387, 167, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_A */
|
||||
|
|
@ -62,10 +65,10 @@ static struct
|
|||
{ 174, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{ 232, 128, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{ 289, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{ 75, 154, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{ 75, 154, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{ 305, 230, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
{ 77, 40, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{ 396, 36, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{ 77, 40, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{ 396, 36, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{ 154, 188, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
|
||||
{ 154, 249, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{ 116, 217, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
|
|
@ -75,16 +78,16 @@ static struct
|
|||
{ 330, 135, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
|
||||
{ 132, 175, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
|
||||
{ 330, 175, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
|
||||
{ 0, 0, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
|
||||
{ 74, 153, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE */
|
||||
{ 74, 153, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE */
|
||||
{ 74, 153, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE */
|
||||
{ 74, 153, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE */
|
||||
{ 0, 0, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
|
||||
{ 74, 153, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE */
|
||||
{ 74, 153, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE */
|
||||
{ 74, 153, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE */
|
||||
{ 74, 153, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE */
|
||||
{ 306, 231, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE */
|
||||
{ 306, 231, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE */
|
||||
{ 306, 231, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE */
|
||||
{ 306, 231, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE */
|
||||
{ 306, 231, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE */
|
||||
{ 306, 231, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE */
|
||||
{ 91, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT */
|
||||
{ 91, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT */
|
||||
{ 375, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT */
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(s_arrBindingDisplay, SDL_arraysize(s_arrBindingDisplay) == BINDING_COUNT);
|
||||
|
|
@ -131,13 +134,15 @@ typedef struct
|
|||
{
|
||||
int button;
|
||||
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
int axis;
|
||||
int axis_min;
|
||||
int axis_max;
|
||||
} axis;
|
||||
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
int hat;
|
||||
int hat_mask;
|
||||
} hat;
|
||||
|
|
@ -160,7 +165,7 @@ typedef struct
|
|||
|
||||
static int s_nNumAxes;
|
||||
static AxisState *s_arrAxisState;
|
||||
|
||||
|
||||
static int s_iCurrentBinding;
|
||||
static Uint32 s_unPendingAdvanceTime;
|
||||
static SDL_bool s_bBindingComplete;
|
||||
|
|
@ -173,9 +178,9 @@ static SDL_bool bind_touchpad = SDL_FALSE;
|
|||
static int
|
||||
StandardizeAxisValue(int nValue)
|
||||
{
|
||||
if (nValue > SDL_JOYSTICK_AXIS_MAX/2) {
|
||||
if (nValue > SDL_JOYSTICK_AXIS_MAX / 2) {
|
||||
return SDL_JOYSTICK_AXIS_MAX;
|
||||
} else if (nValue < SDL_JOYSTICK_AXIS_MIN/2) {
|
||||
} else if (nValue < SDL_JOYSTICK_AXIS_MIN / 2) {
|
||||
return SDL_JOYSTICK_AXIS_MIN;
|
||||
} else {
|
||||
return 0;
|
||||
|
|
@ -197,15 +202,13 @@ SetCurrentBinding(int iBinding)
|
|||
return;
|
||||
}
|
||||
|
||||
if (s_arrBindingOrder[iBinding] == -1)
|
||||
{
|
||||
if (s_arrBindingOrder[iBinding] == -1) {
|
||||
SetCurrentBinding(iBinding + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_arrBindingOrder[iBinding] == SDL_CONTROLLER_BUTTON_TOUCHPAD &&
|
||||
!bind_touchpad)
|
||||
{
|
||||
!bind_touchpad) {
|
||||
SetCurrentBinding(iBinding + 1);
|
||||
return;
|
||||
}
|
||||
|
|
@ -225,12 +228,10 @@ SetCurrentBinding(int iBinding)
|
|||
static SDL_bool
|
||||
BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const SDL_GameControllerExtendedBind *pBindingB)
|
||||
{
|
||||
if (pBindingA->bindType != pBindingB->bindType)
|
||||
{
|
||||
if (pBindingA->bindType != pBindingB->bindType) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
switch (pBindingA->bindType)
|
||||
{
|
||||
switch (pBindingA->bindType) {
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
if (pBindingA->value.axis.axis != pBindingB->value.axis.axis) {
|
||||
return SDL_FALSE;
|
||||
|
|
@ -243,7 +244,7 @@ BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const S
|
|||
int maxA = SDL_max(pBindingA->value.axis.axis_min, pBindingA->value.axis.axis_max);
|
||||
int minB = SDL_min(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max);
|
||||
int maxB = SDL_max(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max);
|
||||
return (minA <= minB && maxA >= maxB);
|
||||
return minA <= minB && maxA >= maxB;
|
||||
}
|
||||
/* Not reached */
|
||||
default:
|
||||
|
|
@ -280,19 +281,18 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
|
|||
}
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
switch ( pBinding->bindType )
|
||||
{
|
||||
switch (pBinding->bindType) {
|
||||
case SDL_CONTROLLER_BINDTYPE_NONE:
|
||||
break;
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_BUTTON:
|
||||
SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
|
||||
break;
|
||||
SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
|
||||
break;
|
||||
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_HAT:
|
||||
SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
break;
|
||||
SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
break;
|
||||
}
|
||||
#endif /* DEBUG_CONTROLLERMAP */
|
||||
|
||||
|
|
@ -301,7 +301,7 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
|
|||
if (pCurrent->bindType != SDL_CONTROLLER_BINDTYPE_NONE) {
|
||||
SDL_bool bNativeDPad, bCurrentDPad;
|
||||
SDL_bool bNativeAxis, bCurrentAxis;
|
||||
|
||||
|
||||
bNativeDPad = (iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_UP ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_DOWN ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_LEFT ||
|
||||
|
|
@ -335,7 +335,7 @@ static SDL_bool
|
|||
BMergeAxisBindings(int iIndex)
|
||||
{
|
||||
SDL_GameControllerExtendedBind *pBindingA = &s_arrBindings[iIndex];
|
||||
SDL_GameControllerExtendedBind *pBindingB = &s_arrBindings[iIndex+1];
|
||||
SDL_GameControllerExtendedBind *pBindingB = &s_arrBindings[iIndex + 1];
|
||||
if (pBindingA->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
|
||||
pBindingB->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
|
||||
pBindingA->value.axis.axis == pBindingB->value.axis.axis) {
|
||||
|
|
@ -350,13 +350,13 @@ BMergeAxisBindings(int iIndex)
|
|||
}
|
||||
|
||||
static void
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
WatchJoystick(SDL_Joystick *joystick)
|
||||
{
|
||||
SDL_Texture *background_front, *background_back, *button, *axis, *marker;
|
||||
SDL_Texture *background_front, *background_back, *button, *axis, *marker = NULL;
|
||||
const char *name = NULL;
|
||||
SDL_Event event;
|
||||
SDL_Rect dst;
|
||||
Uint8 alpha=200, alpha_step = -1;
|
||||
Uint8 alpha = 200, alpha_step = -1;
|
||||
Uint32 alpha_ticks = 0;
|
||||
SDL_JoystickID nJoystickID;
|
||||
|
||||
|
|
@ -371,12 +371,12 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
|
||||
/* 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("Watching joystick %" SDL_PRIs32 ": (%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));
|
||||
|
||||
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
|
||||
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
|
||||
|
||||
SDL_Log("\n\n\
|
||||
====================================================================================\n\
|
||||
Press the buttons on your controller when indicated\n\
|
||||
|
|
@ -393,7 +393,6 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
|
||||
/* Skip any spurious events at start */
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Loop, getting joystick events! */
|
||||
|
|
@ -401,16 +400,14 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
int iElement = s_arrBindingOrder[s_iCurrentBinding];
|
||||
|
||||
switch (s_arrBindingDisplay[iElement].marker) {
|
||||
case MARKER_AXIS:
|
||||
marker = axis;
|
||||
break;
|
||||
case MARKER_BUTTON:
|
||||
marker = button;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case MARKER_AXIS:
|
||||
marker = axis;
|
||||
break;
|
||||
case MARKER_BUTTON:
|
||||
marker = button;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
dst.x = s_arrBindingDisplay[iElement].x;
|
||||
dst.y = s_arrBindingDisplay[iElement].y;
|
||||
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
|
||||
|
|
@ -438,7 +435,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
||||
SDL_RenderCopyEx(screen, marker, NULL, &dst, s_arrBindingDisplay[iElement].angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
switch (event.type) {
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
|
|
@ -448,7 +445,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
if (event.jaxis.which == nJoystickID) {
|
||||
const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
|
||||
const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
|
||||
AxisState *pAxisState = &s_arrAxisState[event.jaxis.axis];
|
||||
int nValue = event.jaxis.value;
|
||||
int nCurrentDistance, nFarthestDistance;
|
||||
|
|
@ -504,9 +501,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP:
|
||||
if (event.jbutton.which == nJoystickID) {
|
||||
SDL_GameControllerExtendedBind binding;
|
||||
|
||||
|
|
@ -535,7 +530,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
break;
|
||||
}
|
||||
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
SDL_FALLTHROUGH;
|
||||
|
|
@ -549,15 +544,17 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
|
||||
SDL_Delay(15);
|
||||
|
||||
/* Wait 100 ms for joystick events to stop coming in,
|
||||
/* Wait 30 ms for joystick events to stop coming in,
|
||||
in case a controller sends multiple events for a single control (e.g. axis and button for trigger)
|
||||
*/
|
||||
if (s_unPendingAdvanceTime && SDL_GetTicks() - s_unPendingAdvanceTime >= 100) {
|
||||
if (s_unPendingAdvanceTime && SDL_GetTicks() - s_unPendingAdvanceTime >= 30) {
|
||||
SetCurrentBinding(s_iCurrentBinding + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (s_bBindingComplete) {
|
||||
SDL_JoystickGUID guid;
|
||||
Uint16 crc;
|
||||
char mapping[1024];
|
||||
char trimmed_name[128];
|
||||
char *spot;
|
||||
|
|
@ -576,13 +573,28 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
}
|
||||
|
||||
/* Initialize mapping with GUID and name */
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), mapping, SDL_arraysize(mapping));
|
||||
guid = SDL_JoystickGetGUID(joystick);
|
||||
SDL_GetJoystickGUIDInfo(guid, NULL, NULL, NULL, &crc);
|
||||
if (crc) {
|
||||
/* Clear the CRC from the GUID for the mapping */
|
||||
guid.data[2] = 0;
|
||||
guid.data[3] = 0;
|
||||
}
|
||||
SDL_JoystickGetGUIDString(guid, mapping, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, trimmed_name, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, "platform:", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, SDL_GetPlatform(), SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
if (crc) {
|
||||
char crc_string[5];
|
||||
|
||||
SDL_strlcat(mapping, "crc:", SDL_arraysize(mapping));
|
||||
(void)SDL_snprintf(crc_string, sizeof(crc_string), "%.4x", crc);
|
||||
SDL_strlcat(mapping, crc_string, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
}
|
||||
|
||||
for (iIndex = 0; iIndex < SDL_arraysize(s_arrBindings); ++iIndex) {
|
||||
SDL_GameControllerExtendedBind *pBinding = &s_arrBindings[iIndex];
|
||||
|
|
@ -594,7 +606,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
SDL_GameControllerButton eButton = (SDL_GameControllerButton)iIndex;
|
||||
SDL_strlcat(mapping, SDL_GameControllerGetStringForButton(eButton), SDL_arraysize(mapping));
|
||||
} else {
|
||||
const char *pszAxisName;
|
||||
const char *pszAxisName = NULL;
|
||||
switch (iIndex - SDL_CONTROLLER_BUTTON_MAX) {
|
||||
case SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE:
|
||||
if (!BMergeAxisBindings(iIndex)) {
|
||||
|
|
@ -643,24 +655,26 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
|
||||
break;
|
||||
}
|
||||
SDL_strlcat(mapping, pszAxisName, SDL_arraysize(mapping));
|
||||
if (pszAxisName) {
|
||||
SDL_strlcat(mapping, pszAxisName, SDL_arraysize(mapping));
|
||||
}
|
||||
}
|
||||
SDL_strlcat(mapping, ":", SDL_arraysize(mapping));
|
||||
|
||||
pszElement[0] = '\0';
|
||||
switch (pBinding->bindType) {
|
||||
case SDL_CONTROLLER_BINDTYPE_BUTTON:
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "b%d", pBinding->value.button);
|
||||
(void)SDL_snprintf(pszElement, sizeof(pszElement), "b%d", pBinding->value.button);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
if (pBinding->value.axis.axis_min == 0 && pBinding->value.axis.axis_max == SDL_JOYSTICK_AXIS_MIN) {
|
||||
/* The negative half axis */
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "-a%d", pBinding->value.axis.axis);
|
||||
(void)SDL_snprintf(pszElement, sizeof(pszElement), "-a%d", pBinding->value.axis.axis);
|
||||
} else if (pBinding->value.axis.axis_min == 0 && pBinding->value.axis.axis_max == SDL_JOYSTICK_AXIS_MAX) {
|
||||
/* The positive half axis */
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "+a%d", pBinding->value.axis.axis);
|
||||
(void)SDL_snprintf(pszElement, sizeof(pszElement), "+a%d", pBinding->value.axis.axis);
|
||||
} else {
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "a%d", pBinding->value.axis.axis);
|
||||
(void)SDL_snprintf(pszElement, sizeof(pszElement), "a%d", pBinding->value.axis.axis);
|
||||
if (pBinding->value.axis.axis_min > pBinding->value.axis.axis_max) {
|
||||
/* Invert the axis */
|
||||
SDL_strlcat(pszElement, "~", SDL_arraysize(pszElement));
|
||||
|
|
@ -668,7 +682,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
}
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_HAT:
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "h%d.%d", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
(void)SDL_snprintf(pszElement, sizeof(pszElement), "h%d.%d", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
break;
|
||||
default:
|
||||
SDL_assert(!"Unknown bind type");
|
||||
|
|
@ -685,15 +699,15 @@ WatchJoystick(SDL_Joystick * joystick)
|
|||
|
||||
SDL_free(s_arrAxisState);
|
||||
s_arrAxisState = NULL;
|
||||
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *name;
|
||||
int i;
|
||||
int joystick_index;
|
||||
SDL_Joystick *joystick;
|
||||
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
|
|
@ -732,7 +746,7 @@ main(int argc, char *argv[])
|
|||
while (SDL_PollEvent(&event) > 0) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
SDL_FALLTHROUGH;
|
||||
|
|
@ -754,25 +768,32 @@ main(int argc, char *argv[])
|
|||
joystick = SDL_JoystickOpen(i);
|
||||
if (joystick == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
} else {
|
||||
char guid[64];
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
|
||||
guid, sizeof (guid));
|
||||
guid, sizeof(guid));
|
||||
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
|
||||
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log("instance id: %" SDL_PRIu32 "\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
|
||||
joystick = SDL_JoystickOpen(0);
|
||||
joystick_index = 0;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (argv[i] && *argv[i] != '-') {
|
||||
joystick_index = SDL_atoi(argv[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
joystick = SDL_JoystickOpen(joystick_index);
|
||||
if (joystick == NULL) {
|
||||
SDL_Log("Couldn't open joystick 0: %s\n", SDL_GetError());
|
||||
SDL_Log("Couldn't open joystick %d: %s\n", joystick_index, SDL_GetError());
|
||||
} else {
|
||||
WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
|
|
|
|||
|
|
@ -1,110 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Build Universal binaries on Mac OS X, thanks Ryan!
|
||||
#
|
||||
# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf ppc x86
|
||||
|
||||
# PowerPC compiler flags (10.2 runtime compatibility)
|
||||
GCC_COMPILE_PPC="gcc-3.3 -arch ppc \
|
||||
-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \
|
||||
-nostdinc \
|
||||
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
|
||||
-I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
|
||||
-isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include"
|
||||
|
||||
GCC_LINK_PPC="\
|
||||
-L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
|
||||
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
|
||||
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
|
||||
|
||||
# Intel compiler flags (10.4 runtime compatibility)
|
||||
GCC_COMPILE_X86="gcc-4.0 -arch i386 -mmacosx-version-min=10.4 \
|
||||
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
|
||||
-nostdinc \
|
||||
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
|
||||
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/include \
|
||||
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
|
||||
|
||||
GCC_LINK_X86="\
|
||||
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.0 \
|
||||
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
|
||||
|
||||
# Output both PowerPC and Intel object files
|
||||
args="$*"
|
||||
compile=yes
|
||||
link=yes
|
||||
while test x$1 != x; do
|
||||
case $1 in
|
||||
--version) exec gcc $1;;
|
||||
-v) exec gcc $1;;
|
||||
-V) exec gcc $1;;
|
||||
-print-prog-name=*) exec gcc $1;;
|
||||
-print-search-dirs) exec gcc $1;;
|
||||
-E) GCC_COMPILE_PPC="$GCC_COMPILE_PPC -E"
|
||||
GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
|
||||
compile=no; link=no;;
|
||||
-c) link=no;;
|
||||
-o) output=$2;;
|
||||
*.c|*.cc|*.cpp|*.S) source=$1;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
if test x$link = xyes; then
|
||||
GCC_COMPILE_PPC="$GCC_COMPILE_PPC $GCC_LINK_PPC"
|
||||
GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
|
||||
fi
|
||||
if test x"$output" = x; then
|
||||
if test x$link = xyes; then
|
||||
output=a.out
|
||||
elif test x$compile = xyes; then
|
||||
output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
|
||||
fi
|
||||
fi
|
||||
|
||||
if test x"$output" != x; then
|
||||
dir=ppc/`dirname $output`
|
||||
if test -d $dir; then
|
||||
:
|
||||
else
|
||||
mkdir -p $dir
|
||||
fi
|
||||
fi
|
||||
set -- $args
|
||||
while test x$1 != x; do
|
||||
if test -f "ppc/$1" && test "$1" != "$output"; then
|
||||
ppc_args="$ppc_args ppc/$1"
|
||||
else
|
||||
ppc_args="$ppc_args $1"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
$GCC_COMPILE_PPC $ppc_args || exit $?
|
||||
if test x"$output" != x; then
|
||||
cp $output ppc/$output
|
||||
fi
|
||||
|
||||
if test x"$output" != x; then
|
||||
dir=x86/`dirname $output`
|
||||
if test -d $dir; then
|
||||
:
|
||||
else
|
||||
mkdir -p $dir
|
||||
fi
|
||||
fi
|
||||
set -- $args
|
||||
while test x$1 != x; do
|
||||
if test -f "x86/$1" && test "$1" != "$output"; then
|
||||
x86_args="$x86_args x86/$1"
|
||||
else
|
||||
x86_args="$x86_args $1"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
$GCC_COMPILE_X86 $x86_args || exit $?
|
||||
if test x"$output" != x; then
|
||||
cp $output x86/$output
|
||||
fi
|
||||
|
||||
if test x"$output" != x; then
|
||||
lipo -create -o $output ppc/$output x86/$output
|
||||
fi
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -30,9 +30,9 @@
|
|||
static struct
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
Uint32 soundlen; /* Length of wave data */
|
||||
int soundpos; /* Current play position */
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
Uint32 soundlen; /* Length of wave data */
|
||||
int soundpos; /* Current play position */
|
||||
} wave;
|
||||
|
||||
static SDL_AudioDeviceID device;
|
||||
|
|
@ -65,20 +65,20 @@ open_audio()
|
|||
quit(2);
|
||||
}
|
||||
|
||||
|
||||
/* Let the audio run */
|
||||
SDL_PauseAudioDevice(device, SDL_FALSE);
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
static void reopen_audio()
|
||||
{
|
||||
close_audio();
|
||||
open_audio();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void SDLCALL
|
||||
fillerup(void *unused, Uint8 * stream, int len)
|
||||
fillerup(void *unused, Uint8 *stream, int len)
|
||||
{
|
||||
Uint8 *waveptr;
|
||||
int waveleft;
|
||||
|
|
@ -103,16 +103,15 @@ fillerup(void *unused, Uint8 * stream, int len)
|
|||
static int done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
if(done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING))
|
||||
if (done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING)) {
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char *filename = NULL;
|
||||
|
|
@ -121,9 +120,9 @@ main(int argc, char *argv[])
|
|||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO|SDL_INIT_EVENTS) < 0) {
|
||||
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
|
||||
|
|
@ -177,7 +176,7 @@ main(int argc, char *argv[])
|
|||
SDL_FreeWAV(wave.sound);
|
||||
SDL_free(filename);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -30,11 +30,10 @@
|
|||
static struct
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
Uint32 soundlen; /* Length of wave data */
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
Uint32 soundlen; /* Length of wave data */
|
||||
} wave;
|
||||
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
|
|
@ -44,37 +43,33 @@ quit(int rc)
|
|||
}
|
||||
|
||||
static int done = 0;
|
||||
void
|
||||
poked(int sig)
|
||||
void poked(int sig)
|
||||
{
|
||||
done = 1;
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)) {
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
/* The device from SDL_OpenAudio() is always device #1. */
|
||||
const Uint32 queued = SDL_GetQueuedAudioSize(1);
|
||||
SDL_Log("Device has %u bytes queued.\n", (unsigned int) queued);
|
||||
if (queued <= 8192) { /* time to requeue the whole thing? */
|
||||
SDL_Log("Device has %u bytes queued.\n", (unsigned int)queued);
|
||||
if (queued <= 8192) { /* time to requeue the whole thing? */
|
||||
if (SDL_QueueAudio(1, wave.sound, wave.soundlen) == 0) {
|
||||
SDL_Log("Device queued %u more bytes.\n", (unsigned int) wave.soundlen);
|
||||
SDL_Log("Device queued %u more bytes.\n", (unsigned int)wave.soundlen);
|
||||
} else {
|
||||
SDL_Log("Device FAILED to queue %u more bytes: %s\n", (unsigned int) wave.soundlen, SDL_GetError());
|
||||
SDL_Log("Device FAILED to queue %u more bytes: %s\n", (unsigned int)wave.soundlen, SDL_GetError());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *filename = NULL;
|
||||
|
||||
|
|
@ -84,7 +79,7 @@ main(int argc, char *argv[])
|
|||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
|
||||
|
|
@ -100,18 +95,18 @@ main(int argc, char *argv[])
|
|||
quit(1);
|
||||
}
|
||||
|
||||
wave.spec.callback = NULL; /* we'll push audio. */
|
||||
wave.spec.callback = NULL; /* we'll push audio. */
|
||||
|
||||
#if HAVE_SIGNAL_H
|
||||
/* Set the signals */
|
||||
#ifdef SIGHUP
|
||||
signal(SIGHUP, poked);
|
||||
(void)signal(SIGHUP, poked);
|
||||
#endif
|
||||
signal(SIGINT, poked);
|
||||
(void)signal(SIGINT, poked);
|
||||
#ifdef SIGQUIT
|
||||
signal(SIGQUIT, poked);
|
||||
(void)signal(SIGQUIT, poked);
|
||||
#endif
|
||||
signal(SIGTERM, poked);
|
||||
(void)signal(SIGTERM, poked);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
|
||||
/* Initialize fillerup() variables */
|
||||
|
|
@ -131,15 +126,14 @@ main(int argc, char *argv[])
|
|||
/* Note that we stuff the entire audio buffer into the queue in one
|
||||
shot. Most apps would want to feed it a little at a time, as it
|
||||
plays, but we're going for simplicity here. */
|
||||
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
|
||||
{
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING)) {
|
||||
loop();
|
||||
|
||||
SDL_Delay(100); /* let it play for awhile. */
|
||||
SDL_Delay(100); /* let it play for awhile. */
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
BIN
Engine/lib/sdl/test/n3ds/logo48x48.png
Normal file
BIN
Engine/lib/sdl/test/n3ds/logo48x48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3 KiB |
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -18,23 +18,20 @@
|
|||
after calling each function.
|
||||
*/
|
||||
|
||||
static
|
||||
const char *
|
||||
static const char *
|
||||
tf(SDL_bool _tf)
|
||||
{
|
||||
static const char *t = "TRUE";
|
||||
static const char *f = "FALSE";
|
||||
|
||||
if (_tf)
|
||||
{
|
||||
return t;
|
||||
if (_tf) {
|
||||
return t;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static
|
||||
void RunBasicTest()
|
||||
static void RunBasicTest()
|
||||
{
|
||||
int value;
|
||||
SDL_SpinLock lock = 0;
|
||||
|
|
@ -96,15 +93,16 @@ void RunBasicTest()
|
|||
/* Number of concurrent incrementers */
|
||||
#define NThreads 2
|
||||
#define CountInc 100
|
||||
#define VALBITS (sizeof(atomicValue)*8)
|
||||
#define VALBITS (sizeof(atomicValue) * 8)
|
||||
|
||||
#define atomicValue int
|
||||
#define CountTo ((atomicValue)((unsigned int)(1<<(VALBITS-1))-1))
|
||||
#define NInter (CountTo/CountInc/NThreads)
|
||||
#define Expect (CountTo-NInter*CountInc*NThreads)
|
||||
#define CountTo ((atomicValue)((unsigned int)(1 << (VALBITS - 1)) - 1))
|
||||
#define NInter (CountTo / CountInc / NThreads)
|
||||
#define Expect (CountTo - NInter * CountInc * NThreads)
|
||||
|
||||
enum {
|
||||
CountTo_GreaterThanZero = CountTo > 0,
|
||||
enum
|
||||
{
|
||||
CountTo_GreaterThanZero = CountTo > 0,
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(size, CountTo_GreaterThanZero); /* check for rollover */
|
||||
|
||||
|
|
@ -116,25 +114,23 @@ static SDL_atomic_t threadsRunning;
|
|||
|
||||
static SDL_sem *threadDone;
|
||||
|
||||
static
|
||||
int SDLCALL adder(void* junk)
|
||||
static int SDLCALL adder(void *junk)
|
||||
{
|
||||
unsigned long N=NInter;
|
||||
SDL_Log("Thread subtracting %d %lu times\n",CountInc,N);
|
||||
unsigned long N = NInter;
|
||||
SDL_Log("Thread subtracting %d %lu times\n", CountInc, N);
|
||||
while (N--) {
|
||||
SDL_AtomicAdd(&good, -CountInc);
|
||||
bad-=CountInc;
|
||||
bad -= CountInc;
|
||||
}
|
||||
SDL_AtomicAdd(&threadsRunning, -1);
|
||||
SDL_SemPost(threadDone);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
void runAdder(void)
|
||||
static void runAdder(void)
|
||||
{
|
||||
Uint32 start, end;
|
||||
int T=NThreads;
|
||||
int T = NThreads;
|
||||
|
||||
start = SDL_GetTicks();
|
||||
|
||||
|
|
@ -142,11 +138,13 @@ void runAdder(void)
|
|||
|
||||
SDL_AtomicSet(&threadsRunning, NThreads);
|
||||
|
||||
while (T--)
|
||||
while (T--) {
|
||||
SDL_CreateThread(adder, "Adder", NULL);
|
||||
}
|
||||
|
||||
while (SDL_AtomicGet(&threadsRunning) > 0)
|
||||
while (SDL_AtomicGet(&threadsRunning) > 0) {
|
||||
SDL_SemWait(threadDone);
|
||||
}
|
||||
|
||||
SDL_DestroySemaphore(threadDone);
|
||||
|
||||
|
|
@ -155,8 +153,7 @@ void runAdder(void)
|
|||
SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
|
||||
}
|
||||
|
||||
static
|
||||
void RunEpicTest()
|
||||
static void RunEpicTest()
|
||||
{
|
||||
int b;
|
||||
atomicValue v;
|
||||
|
|
@ -164,80 +161,80 @@ void RunEpicTest()
|
|||
SDL_Log("\nepic test---------------------------------------\n\n");
|
||||
|
||||
SDL_Log("Size asserted to be >= 32-bit\n");
|
||||
SDL_assert(sizeof(atomicValue)>=4);
|
||||
SDL_assert(sizeof(atomicValue) >= 4);
|
||||
|
||||
SDL_Log("Check static initializer\n");
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==42);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == 42);
|
||||
|
||||
SDL_assert(bad==42);
|
||||
SDL_assert(bad == 42);
|
||||
|
||||
SDL_Log("Test negative values\n");
|
||||
SDL_AtomicSet(&good, -5);
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==-5);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == -5);
|
||||
|
||||
SDL_Log("Verify maximum value\n");
|
||||
SDL_AtomicSet(&good, CountTo);
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==CountTo);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == CountTo);
|
||||
|
||||
SDL_Log("Test compare and exchange\n");
|
||||
|
||||
b=SDL_AtomicCAS(&good, 500, 43);
|
||||
b = SDL_AtomicCAS(&good, 500, 43);
|
||||
SDL_assert(!b); /* no swap since CountTo!=500 */
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==CountTo); /* ensure no swap */
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == CountTo); /* ensure no swap */
|
||||
|
||||
b=SDL_AtomicCAS(&good, CountTo, 44);
|
||||
b = SDL_AtomicCAS(&good, CountTo, 44);
|
||||
SDL_assert(!!b); /* will swap */
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==44);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == 44);
|
||||
|
||||
SDL_Log("Test Add\n");
|
||||
|
||||
v=SDL_AtomicAdd(&good, 1);
|
||||
SDL_assert(v==44);
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==45);
|
||||
v = SDL_AtomicAdd(&good, 1);
|
||||
SDL_assert(v == 44);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == 45);
|
||||
|
||||
v=SDL_AtomicAdd(&good, 10);
|
||||
SDL_assert(v==45);
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==55);
|
||||
v = SDL_AtomicAdd(&good, 10);
|
||||
SDL_assert(v == 45);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == 55);
|
||||
|
||||
SDL_Log("Test Add (Negative values)\n");
|
||||
|
||||
v=SDL_AtomicAdd(&good, -20);
|
||||
SDL_assert(v==55);
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==35);
|
||||
v = SDL_AtomicAdd(&good, -20);
|
||||
SDL_assert(v == 55);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == 35);
|
||||
|
||||
v=SDL_AtomicAdd(&good, -50); /* crossing zero down */
|
||||
SDL_assert(v==35);
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==-15);
|
||||
v = SDL_AtomicAdd(&good, -50); /* crossing zero down */
|
||||
SDL_assert(v == 35);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == -15);
|
||||
|
||||
v=SDL_AtomicAdd(&good, 30); /* crossing zero up */
|
||||
SDL_assert(v==-15);
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==15);
|
||||
v = SDL_AtomicAdd(&good, 30); /* crossing zero up */
|
||||
SDL_assert(v == -15);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == 15);
|
||||
|
||||
SDL_Log("Reset before count down test\n");
|
||||
SDL_AtomicSet(&good, CountTo);
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_assert(v==CountTo);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_assert(v == CountTo);
|
||||
|
||||
bad=CountTo;
|
||||
SDL_assert(bad==CountTo);
|
||||
bad = CountTo;
|
||||
SDL_assert(bad == CountTo);
|
||||
|
||||
SDL_Log("Counting down from %d, Expect %d remaining\n",CountTo,Expect);
|
||||
SDL_Log("Counting down from %d, Expect %d remaining\n", CountTo, Expect);
|
||||
runAdder();
|
||||
|
||||
v=SDL_AtomicGet(&good);
|
||||
SDL_Log("Atomic %d Non-Atomic %d\n",v,bad);
|
||||
SDL_assert(v==Expect);
|
||||
SDL_assert(bad!=Expect);
|
||||
v = SDL_AtomicGet(&good);
|
||||
SDL_Log("Atomic %d Non-Atomic %d\n", v, bad);
|
||||
SDL_assert(v == Expect);
|
||||
SDL_assert(bad != Expect);
|
||||
}
|
||||
|
||||
/* End atomic operation test */
|
||||
|
|
@ -251,13 +248,13 @@ void RunEpicTest()
|
|||
*/
|
||||
#define TEST_SPINLOCK_FIFO
|
||||
|
||||
#define NUM_READERS 4
|
||||
#define NUM_WRITERS 4
|
||||
#define EVENTS_PER_WRITER 1000000
|
||||
#define NUM_READERS 4
|
||||
#define NUM_WRITERS 4
|
||||
#define EVENTS_PER_WRITER 1000000
|
||||
|
||||
/* The number of entries must be a power of 2 */
|
||||
#define MAX_ENTRIES 256
|
||||
#define WRAP_MASK (MAX_ENTRIES-1)
|
||||
#define WRAP_MASK (MAX_ENTRIES - 1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
@ -269,22 +266,22 @@ typedef struct
|
|||
{
|
||||
SDL_EventQueueEntry entries[MAX_ENTRIES];
|
||||
|
||||
char cache_pad1[SDL_CACHELINE_SIZE-((sizeof(SDL_EventQueueEntry)*MAX_ENTRIES)%SDL_CACHELINE_SIZE)];
|
||||
char cache_pad1[SDL_CACHELINE_SIZE - ((sizeof(SDL_EventQueueEntry) * MAX_ENTRIES) % SDL_CACHELINE_SIZE)];
|
||||
|
||||
SDL_atomic_t enqueue_pos;
|
||||
|
||||
char cache_pad2[SDL_CACHELINE_SIZE-sizeof(SDL_atomic_t)];
|
||||
char cache_pad2[SDL_CACHELINE_SIZE - sizeof(SDL_atomic_t)];
|
||||
|
||||
SDL_atomic_t dequeue_pos;
|
||||
|
||||
char cache_pad3[SDL_CACHELINE_SIZE-sizeof(SDL_atomic_t)];
|
||||
char cache_pad3[SDL_CACHELINE_SIZE - sizeof(SDL_atomic_t)];
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
SDL_SpinLock lock;
|
||||
SDL_atomic_t rwcount;
|
||||
SDL_atomic_t watcher;
|
||||
|
||||
char cache_pad4[SDL_CACHELINE_SIZE-sizeof(SDL_SpinLock)-2*sizeof(SDL_atomic_t)];
|
||||
char cache_pad4[SDL_CACHELINE_SIZE - sizeof(SDL_SpinLock) - 2 * sizeof(SDL_atomic_t)];
|
||||
#endif
|
||||
|
||||
SDL_atomic_t active;
|
||||
|
|
@ -328,14 +325,14 @@ static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *ev
|
|||
#endif
|
||||
|
||||
queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos);
|
||||
for ( ; ; ) {
|
||||
for (;;) {
|
||||
entry = &queue->entries[queue_pos & WRAP_MASK];
|
||||
entry_seq = (unsigned)SDL_AtomicGet(&entry->sequence);
|
||||
|
||||
delta = (int)(entry_seq - queue_pos);
|
||||
if (delta == 0) {
|
||||
/* The entry and the queue position match, try to increment the queue position */
|
||||
if (SDL_AtomicCAS(&queue->enqueue_pos, (int)queue_pos, (int)(queue_pos+1))) {
|
||||
if (SDL_AtomicCAS(&queue->enqueue_pos, (int)queue_pos, (int)(queue_pos + 1))) {
|
||||
/* We own the object, fill it! */
|
||||
entry->event = *event;
|
||||
SDL_AtomicSet(&entry->sequence, (int)(queue_pos + 1));
|
||||
|
|
@ -353,7 +350,7 @@ static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *ev
|
|||
}
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
(void) SDL_AtomicDecRef(&queue->rwcount);
|
||||
(void)SDL_AtomicDecRef(&queue->rwcount);
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
|
@ -375,17 +372,17 @@ static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
|
|||
#endif
|
||||
|
||||
queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos);
|
||||
for ( ; ; ) {
|
||||
for (;;) {
|
||||
entry = &queue->entries[queue_pos & WRAP_MASK];
|
||||
entry_seq = (unsigned)SDL_AtomicGet(&entry->sequence);
|
||||
|
||||
delta = (int)(entry_seq - (queue_pos + 1));
|
||||
if (delta == 0) {
|
||||
/* The entry and the queue position match, try to increment the queue position */
|
||||
if (SDL_AtomicCAS(&queue->dequeue_pos, (int)queue_pos, (int)(queue_pos+1))) {
|
||||
if (SDL_AtomicCAS(&queue->dequeue_pos, (int)queue_pos, (int)(queue_pos + 1))) {
|
||||
/* We own the object, fill it! */
|
||||
*event = entry->event;
|
||||
SDL_AtomicSet(&entry->sequence, (int)(queue_pos+MAX_ENTRIES));
|
||||
SDL_AtomicSet(&entry->sequence, (int)(queue_pos + MAX_ENTRIES));
|
||||
status = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
|
@ -400,7 +397,7 @@ static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
|
|||
}
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
(void) SDL_AtomicDecRef(&queue->rwcount);
|
||||
(void)SDL_AtomicDecRef(&queue->rwcount);
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
|
@ -471,17 +468,15 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
|
|||
return status;
|
||||
}
|
||||
|
||||
static SDL_sem *writersDone;
|
||||
static SDL_sem *readersDone;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_EventQueue *queue;
|
||||
int index;
|
||||
char padding1[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int))%SDL_CACHELINE_SIZE];
|
||||
char padding1[SDL_CACHELINE_SIZE - (sizeof(SDL_EventQueue *) + sizeof(int)) % SDL_CACHELINE_SIZE];
|
||||
int waits;
|
||||
SDL_bool lock_free;
|
||||
char padding2[SDL_CACHELINE_SIZE-sizeof(int)-sizeof(SDL_bool)];
|
||||
char padding2[SDL_CACHELINE_SIZE - sizeof(int) - sizeof(SDL_bool)];
|
||||
SDL_Thread *thread;
|
||||
} WriterData;
|
||||
|
||||
typedef struct
|
||||
|
|
@ -490,10 +485,11 @@ typedef struct
|
|||
int counters[NUM_WRITERS];
|
||||
int waits;
|
||||
SDL_bool lock_free;
|
||||
char padding[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int)*NUM_WRITERS+sizeof(int)+sizeof(SDL_bool))%SDL_CACHELINE_SIZE];
|
||||
char padding[SDL_CACHELINE_SIZE - (sizeof(SDL_EventQueue *) + sizeof(int) * NUM_WRITERS + sizeof(int) + sizeof(SDL_bool)) % SDL_CACHELINE_SIZE];
|
||||
SDL_Thread *thread;
|
||||
} ReaderData;
|
||||
|
||||
static int SDLCALL FIFO_Writer(void* _data)
|
||||
static int SDLCALL FIFO_Writer(void *_data)
|
||||
{
|
||||
WriterData *data = (WriterData *)_data;
|
||||
SDL_EventQueue *queue = data->queue;
|
||||
|
|
@ -523,20 +519,19 @@ static int SDLCALL FIFO_Writer(void* _data)
|
|||
}
|
||||
}
|
||||
}
|
||||
SDL_SemPost(writersDone);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SDLCALL FIFO_Reader(void* _data)
|
||||
static int SDLCALL FIFO_Reader(void *_data)
|
||||
{
|
||||
ReaderData *data = (ReaderData *)_data;
|
||||
SDL_EventQueue *queue = data->queue;
|
||||
SDL_Event event;
|
||||
|
||||
if (data->lock_free) {
|
||||
for ( ; ; ) {
|
||||
for (;;) {
|
||||
if (DequeueEvent_LockFree(queue, &event)) {
|
||||
WriterData *writer = (WriterData*)event.user.data1;
|
||||
WriterData *writer = (WriterData *)event.user.data1;
|
||||
++data->counters[writer->index];
|
||||
} else if (SDL_AtomicGet(&queue->active)) {
|
||||
++data->waits;
|
||||
|
|
@ -547,9 +542,9 @@ static int SDLCALL FIFO_Reader(void* _data)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
for ( ; ; ) {
|
||||
for (;;) {
|
||||
if (DequeueEvent_Mutex(queue, &event)) {
|
||||
WriterData *writer = (WriterData*)event.user.data1;
|
||||
WriterData *writer = (WriterData *)event.user.data1;
|
||||
++data->counters[writer->index];
|
||||
} else if (SDL_AtomicGet(&queue->active)) {
|
||||
++data->waits;
|
||||
|
|
@ -560,13 +555,12 @@ static int SDLCALL FIFO_Reader(void* _data)
|
|||
}
|
||||
}
|
||||
}
|
||||
SDL_SemPost(readersDone);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
/* This thread periodically locks the queue for no particular reason */
|
||||
static int SDLCALL FIFO_Watcher(void* _data)
|
||||
static int SDLCALL FIFO_Watcher(void *_data)
|
||||
{
|
||||
SDL_EventQueue *queue = (SDL_EventQueue *)_data;
|
||||
|
||||
|
|
@ -577,7 +571,7 @@ static int SDLCALL FIFO_Watcher(void* _data)
|
|||
SDL_Delay(0);
|
||||
}
|
||||
/* Do queue manipulation here... */
|
||||
(void) SDL_AtomicDecRef(&queue->watcher);
|
||||
(void)SDL_AtomicDecRef(&queue->watcher);
|
||||
SDL_AtomicUnlock(&queue->lock);
|
||||
|
||||
/* Wait a bit... */
|
||||
|
|
@ -590,6 +584,7 @@ static int SDLCALL FIFO_Watcher(void* _data)
|
|||
static void RunFIFOTest(SDL_bool lock_free)
|
||||
{
|
||||
SDL_EventQueue queue;
|
||||
SDL_Thread *fifo_thread = NULL;
|
||||
WriterData writerData[NUM_WRITERS];
|
||||
ReaderData readerData[NUM_READERS];
|
||||
Uint32 start, end;
|
||||
|
|
@ -601,9 +596,6 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
SDL_Log("\nFIFO test---------------------------------------\n\n");
|
||||
SDL_Log("Mode: %s\n", lock_free ? "LockFree" : "Mutex");
|
||||
|
||||
readersDone = SDL_CreateSemaphore(0);
|
||||
writersDone = SDL_CreateSemaphore(0);
|
||||
|
||||
SDL_memset(&queue, 0xff, sizeof(queue));
|
||||
|
||||
InitEventQueue(&queue);
|
||||
|
|
@ -616,7 +608,7 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
#ifdef TEST_SPINLOCK_FIFO
|
||||
/* Start a monitoring thread */
|
||||
if (lock_free) {
|
||||
SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
|
||||
fifo_thread = SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -625,10 +617,10 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
SDL_zeroa(readerData);
|
||||
for (i = 0; i < NUM_READERS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "FIFOReader%d", i);
|
||||
(void)SDL_snprintf(name, sizeof(name), "FIFOReader%d", i);
|
||||
readerData[i].queue = &queue;
|
||||
readerData[i].lock_free = lock_free;
|
||||
SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
|
||||
readerData[i].thread = SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
|
||||
}
|
||||
|
||||
/* Start up the writers */
|
||||
|
|
@ -636,16 +628,16 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
SDL_zeroa(writerData);
|
||||
for (i = 0; i < NUM_WRITERS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "FIFOWriter%d", i);
|
||||
(void)SDL_snprintf(name, sizeof(name), "FIFOWriter%d", i);
|
||||
writerData[i].queue = &queue;
|
||||
writerData[i].index = i;
|
||||
writerData[i].lock_free = lock_free;
|
||||
SDL_CreateThread(FIFO_Writer, name, &writerData[i]);
|
||||
writerData[i].thread = SDL_CreateThread(FIFO_Writer, name, &writerData[i]);
|
||||
}
|
||||
|
||||
/* Wait for the writers */
|
||||
for (i = 0; i < NUM_WRITERS; ++i) {
|
||||
SDL_SemWait(writersDone);
|
||||
SDL_WaitThread(writerData[i].thread, NULL);
|
||||
}
|
||||
|
||||
/* Shut down the queue so readers exit */
|
||||
|
|
@ -653,13 +645,15 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
|
||||
/* Wait for the readers */
|
||||
for (i = 0; i < NUM_READERS; ++i) {
|
||||
SDL_SemWait(readersDone);
|
||||
SDL_WaitThread(readerData[i].thread, NULL);
|
||||
}
|
||||
|
||||
end = SDL_GetTicks();
|
||||
|
||||
SDL_DestroySemaphore(readersDone);
|
||||
SDL_DestroySemaphore(writersDone);
|
||||
/* Wait for the FIFO thread */
|
||||
if (fifo_thread) {
|
||||
SDL_WaitThread(fifo_thread, NULL);
|
||||
}
|
||||
|
||||
if (!lock_free) {
|
||||
SDL_DestroyMutex(queue.mutex);
|
||||
|
|
@ -671,7 +665,7 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
for (i = 0; i < NUM_WRITERS; ++i) {
|
||||
SDL_Log("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits);
|
||||
}
|
||||
SDL_Log("Writers wrote %d total events\n", NUM_WRITERS*EVENTS_PER_WRITER);
|
||||
SDL_Log("Writers wrote %d total events\n", NUM_WRITERS * EVENTS_PER_WRITER);
|
||||
|
||||
/* Print a breakdown of which readers read messages from which writer */
|
||||
SDL_Log("\n");
|
||||
|
|
@ -683,17 +677,17 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
}
|
||||
grand_total += total;
|
||||
SDL_Log("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits);
|
||||
SDL_snprintf(textBuffer, sizeof(textBuffer), " { ");
|
||||
(void)SDL_snprintf(textBuffer, sizeof(textBuffer), " { ");
|
||||
for (j = 0; j < NUM_WRITERS; ++j) {
|
||||
if (j > 0) {
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
|
||||
(void)SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
|
||||
}
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", readerData[i].counters[j]);
|
||||
(void)SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", readerData[i].counters[j]);
|
||||
}
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
|
||||
(void)SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
|
||||
SDL_Log("%s", textBuffer);
|
||||
}
|
||||
SDL_Log("Readers read %d total events\n", grand_total);
|
||||
|
|
@ -702,8 +696,7 @@ static void RunFIFOTest(SDL_bool lock_free)
|
|||
/* End FIFO test */
|
||||
/**************************************************************************/
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -67,9 +67,9 @@ loop()
|
|||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_cancel_main_loop();
|
||||
#endif
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
@ -78,16 +78,15 @@ loop()
|
|||
trying to test the API, so we use SDL_DequeueAudio() here. */
|
||||
while (SDL_TRUE) {
|
||||
Uint8 buf[1024];
|
||||
const Uint32 br = SDL_DequeueAudio(devid_in, buf, sizeof (buf));
|
||||
const Uint32 br = SDL_DequeueAudio(devid_in, buf, sizeof(buf));
|
||||
SDL_QueueAudio(devid_out, buf, br);
|
||||
if (br < sizeof (buf)) {
|
||||
if (br < sizeof(buf)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* (argv[1] == NULL means "open default device.") */
|
||||
const char *devname = argv[1];
|
||||
|
|
@ -101,7 +100,7 @@ main(int argc, char **argv)
|
|||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
window = SDL_CreateWindow("testaudiocapture", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320, 240, 0);
|
||||
|
|
@ -157,7 +156,10 @@ main(int argc, char **argv)
|
|||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (1) { loop(); SDL_Delay(16); }
|
||||
while (1) {
|
||||
loop();
|
||||
SDL_Delay(16);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -29,8 +29,8 @@
|
|||
#include "testutils.h"
|
||||
|
||||
static SDL_AudioSpec spec;
|
||||
static Uint8 *sound = NULL; /* Pointer to wave data */
|
||||
static Uint32 soundlen = 0; /* Length of wave data */
|
||||
static Uint8 *sound = NULL; /* Pointer to wave data */
|
||||
static Uint32 soundlen = 0; /* Length of wave data */
|
||||
|
||||
static int posindex = 0;
|
||||
static Uint32 positions[64];
|
||||
|
|
@ -44,9 +44,9 @@ quit(int rc)
|
|||
}
|
||||
|
||||
void SDLCALL
|
||||
fillerup(void *_pos, Uint8 * stream, int len)
|
||||
fillerup(void *_pos, Uint8 *stream, int len)
|
||||
{
|
||||
Uint32 pos = *((Uint32 *) _pos);
|
||||
Uint32 pos = *((Uint32 *)_pos);
|
||||
Uint8 *waveptr;
|
||||
int waveleft;
|
||||
|
||||
|
|
@ -65,17 +65,16 @@ fillerup(void *_pos, Uint8 * stream, int len)
|
|||
}
|
||||
SDL_memcpy(stream, waveptr, len);
|
||||
pos += len;
|
||||
*((Uint32 *) _pos) = pos;
|
||||
*((Uint32 *)_pos) = pos;
|
||||
}
|
||||
|
||||
static int done = 0;
|
||||
void
|
||||
poked(int sig)
|
||||
void poked(int sig)
|
||||
{
|
||||
done = 1;
|
||||
}
|
||||
|
||||
static const char*
|
||||
static const char *
|
||||
devtypestr(int iscapture)
|
||||
{
|
||||
return iscapture ? "capture" : "output";
|
||||
|
|
@ -90,17 +89,18 @@ iteration()
|
|||
if (e.type == SDL_QUIT) {
|
||||
done = 1;
|
||||
} else if (e.type == SDL_KEYUP) {
|
||||
if (e.key.keysym.sym == SDLK_ESCAPE)
|
||||
if (e.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
}
|
||||
} else if (e.type == SDL_AUDIODEVICEADDED) {
|
||||
int index = e.adevice.which;
|
||||
int iscapture = e.adevice.iscapture;
|
||||
const char *name = SDL_GetAudioDeviceName(index, iscapture);
|
||||
if (name != NULL)
|
||||
SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int) index, name);
|
||||
else {
|
||||
if (name != NULL) {
|
||||
SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int)index, name);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device at index %u, but failed to get the name: %s\n",
|
||||
devtypestr(iscapture), (unsigned int) index, SDL_GetError());
|
||||
devtypestr(iscapture), (unsigned int)index, SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
if (!iscapture) {
|
||||
|
|
@ -111,31 +111,29 @@ iteration()
|
|||
if (!dev) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open '%s': %s\n", name, SDL_GetError());
|
||||
} else {
|
||||
SDL_Log("Opened '%s' as %u\n", name, (unsigned int) dev);
|
||||
SDL_Log("Opened '%s' as %u\n", name, (unsigned int)dev);
|
||||
SDL_PauseAudioDevice(dev, 0);
|
||||
}
|
||||
}
|
||||
} else if (e.type == SDL_AUDIODEVICEREMOVED) {
|
||||
dev = (SDL_AudioDeviceID) e.adevice.which;
|
||||
SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.iscapture), (unsigned int) dev);
|
||||
dev = (SDL_AudioDeviceID)e.adevice.which;
|
||||
SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.iscapture), (unsigned int)dev);
|
||||
SDL_CloseAudioDevice(dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
if(done)
|
||||
if (done)
|
||||
emscripten_cancel_main_loop();
|
||||
else
|
||||
iteration();
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char *filename = NULL;
|
||||
|
|
@ -146,7 +144,7 @@ main(int argc, char *argv[])
|
|||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Some targets (Mac CoreAudio) need an event queue for audio hotplug, so make and immediately hide a window. */
|
||||
|
|
@ -168,13 +166,13 @@ main(int argc, char *argv[])
|
|||
#if HAVE_SIGNAL_H
|
||||
/* Set the signals */
|
||||
#ifdef SIGHUP
|
||||
signal(SIGHUP, poked);
|
||||
(void)signal(SIGHUP, poked);
|
||||
#endif
|
||||
signal(SIGINT, poked);
|
||||
(void)signal(SIGINT, poked);
|
||||
#ifdef SIGQUIT
|
||||
signal(SIGQUIT, poked);
|
||||
(void)signal(SIGQUIT, poked);
|
||||
#endif
|
||||
signal(SIGTERM, poked);
|
||||
(void)signal(SIGTERM, poked);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
|
||||
/* Show the list of available drivers */
|
||||
|
|
@ -201,7 +199,7 @@ main(int argc, char *argv[])
|
|||
SDL_FreeWAV(sound);
|
||||
SDL_free(filename);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -15,31 +15,40 @@
|
|||
static void
|
||||
print_devices(int iscapture)
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
const char *typestr = ((iscapture) ? "capture" : "output");
|
||||
int n = SDL_GetNumAudioDevices(iscapture);
|
||||
|
||||
SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
|
||||
|
||||
if (n == -1)
|
||||
if (n == -1) {
|
||||
SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr);
|
||||
else if (n == 0)
|
||||
} else if (n == 0) {
|
||||
SDL_Log(" No %s devices found.\n\n", typestr);
|
||||
else {
|
||||
} else {
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
const char *name = SDL_GetAudioDeviceName(i, iscapture);
|
||||
if (name != NULL)
|
||||
if (name != NULL) {
|
||||
SDL_Log(" %d: %s\n", i, name);
|
||||
else
|
||||
} else {
|
||||
SDL_Log(" %d Error: %s\n", i, SDL_GetError());
|
||||
}
|
||||
|
||||
if (SDL_GetAudioDeviceSpec(i, iscapture, &spec) == 0) {
|
||||
SDL_Log(" Sample Rate: %d\n", spec.freq);
|
||||
SDL_Log(" Channels: %d\n", spec.channels);
|
||||
SDL_Log(" SDL_AudioFormat: %X\n", spec.format);
|
||||
}
|
||||
}
|
||||
SDL_Log("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *deviceName = NULL;
|
||||
SDL_AudioSpec spec;
|
||||
int n;
|
||||
|
||||
/* Enable standard application logging */
|
||||
|
|
@ -48,7 +57,7 @@ main(int argc, char **argv)
|
|||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Print available audio drivers */
|
||||
|
|
@ -69,6 +78,26 @@ main(int argc, char **argv)
|
|||
print_devices(0);
|
||||
print_devices(1);
|
||||
|
||||
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 0) < 0) {
|
||||
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
|
||||
} else {
|
||||
SDL_Log("Default Output Name: %s\n", deviceName != NULL ? deviceName : "unknown");
|
||||
SDL_free(deviceName);
|
||||
SDL_Log("Sample Rate: %d\n", spec.freq);
|
||||
SDL_Log("Channels: %d\n", spec.channels);
|
||||
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
|
||||
}
|
||||
|
||||
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 1) < 0) {
|
||||
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
|
||||
} else {
|
||||
SDL_Log("Default Capture Name: %s\n", deviceName != NULL ? deviceName : "unknown");
|
||||
SDL_free(deviceName);
|
||||
SDL_Log("Sample Rate: %d\n", spec.freq);
|
||||
SDL_Log("Channels: %d\n", spec.channels);
|
||||
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -29,8 +29,7 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int result;
|
||||
int testIterations = 1;
|
||||
|
|
@ -42,10 +41,13 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* No need of windows (or update testautomation_mouse.c:mouse_getMouseFocus() */
|
||||
state->num_windows = 0;
|
||||
|
||||
/* Parse commandline */
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
|
@ -56,23 +58,22 @@ main(int argc, char *argv[])
|
|||
if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
testIterations = SDL_atoi(argv[i + 1]);
|
||||
if (testIterations < 1) testIterations = 1;
|
||||
if (testIterations < 1) {
|
||||
testIterations = 1;
|
||||
}
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
|
||||
} else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
SDL_sscanf(argv[i + 1], "%"SDL_PRIu64, &userExecKey);
|
||||
(void)SDL_sscanf(argv[i + 1], "%" SDL_PRIu64, &userExecKey);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
|
||||
} else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
userRunSeed = SDL_strdup(argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
|
||||
} else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
filter = SDL_strdup(argv[i + 1]);
|
||||
consumed = 2;
|
||||
|
|
@ -101,15 +102,15 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Call Harness */
|
||||
result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
|
||||
result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, filter, testIterations);
|
||||
|
||||
/* Empty event queue */
|
||||
done = 0;
|
||||
for (i=0; i<100; i++) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
SDL_Delay(10);
|
||||
for (i = 0; i < 100; i++) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
|
|
@ -118,7 +119,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Shutdown everything */
|
||||
quit(result);
|
||||
return(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -18,8 +18,7 @@
|
|||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_HasClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testHasClipboardText(void *arg)
|
||||
int clipboard_testHasClipboardText(void *arg)
|
||||
{
|
||||
SDL_HasClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
|
||||
|
|
@ -27,14 +26,27 @@ clipboard_testHasClipboardText(void *arg)
|
|||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check call to SDL_HasPrimarySelectionText
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_HasPrimarySelectionText
|
||||
*/
|
||||
int clipboard_testHasPrimarySelectionText(void *arg)
|
||||
{
|
||||
SDL_HasPrimarySelectionText();
|
||||
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check call to SDL_GetClipboardText
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_GetClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testGetClipboardText(void *arg)
|
||||
int clipboard_testGetClipboardText(void *arg)
|
||||
{
|
||||
char *charResult;
|
||||
charResult = SDL_GetClipboardText();
|
||||
|
|
@ -45,13 +57,29 @@ clipboard_testGetClipboardText(void *arg)
|
|||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check call to SDL_GetPrimarySelectionText
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_GetPrimarySelectionText
|
||||
*/
|
||||
int clipboard_testGetPrimarySelectionText(void *arg)
|
||||
{
|
||||
char *charResult;
|
||||
charResult = SDL_GetPrimarySelectionText();
|
||||
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
|
||||
|
||||
SDL_free(charResult);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check call to SDL_SetClipboardText
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_SetClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testSetClipboardText(void *arg)
|
||||
int clipboard_testSetClipboardText(void *arg)
|
||||
{
|
||||
char *textRef = SDLTest_RandomAsciiString();
|
||||
char *text = SDL_strdup(textRef);
|
||||
|
|
@ -71,7 +99,35 @@ clipboard_testSetClipboardText(void *arg)
|
|||
SDL_free(textRef);
|
||||
SDL_free(text);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Check call to SDL_SetPrimarySelectionText
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_SetPrimarySelectionText
|
||||
*/
|
||||
int clipboard_testSetPrimarySelectionText(void *arg)
|
||||
{
|
||||
char *textRef = SDLTest_RandomAsciiString();
|
||||
char *text = SDL_strdup(textRef);
|
||||
int result;
|
||||
result = SDL_SetPrimarySelectionText((const char *)text);
|
||||
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
result == 0,
|
||||
"Validate SDL_SetPrimarySelectionText result, expected 0, got %i",
|
||||
result);
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(textRef, text) == 0,
|
||||
"Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'",
|
||||
textRef, text);
|
||||
|
||||
/* Cleanup */
|
||||
SDL_free(textRef);
|
||||
SDL_free(text);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,8 +137,7 @@ clipboard_testSetClipboardText(void *arg)
|
|||
* http://wiki.libsdl.org/SDL_GetClipboardText
|
||||
* http://wiki.libsdl.org/SDL_SetClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testClipboardTextFunctions(void *arg)
|
||||
int clipboard_testClipboardTextFunctions(void *arg)
|
||||
{
|
||||
char *textRef = SDLTest_RandomAsciiString();
|
||||
char *text = SDL_strdup(textRef);
|
||||
|
|
@ -114,13 +169,13 @@ clipboard_testClipboardTextFunctions(void *arg)
|
|||
/* Empty clipboard */
|
||||
charResult = SDL_GetClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
SDLTest_Assert(
|
||||
charResult != NULL,
|
||||
"Verify SDL_GetClipboardText did not return NULL");
|
||||
SDLTest_AssertCheck(
|
||||
charResult[0] == '\0',
|
||||
charResult[0] == '\0', /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
|
||||
"Verify SDL_GetClipboardText returned string with length 0, got length %i",
|
||||
(int) SDL_strlen(charResult));
|
||||
(int)SDL_strlen(charResult));
|
||||
intResult = SDL_SetClipboardText((const char *)text);
|
||||
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
|
|
@ -150,28 +205,125 @@ clipboard_testClipboardTextFunctions(void *arg)
|
|||
SDL_free(text);
|
||||
SDL_free(charResult);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief End-to-end test of SDL_xyzPrimarySelectionText functions
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_HasPrimarySelectionText
|
||||
* http://wiki.libsdl.org/SDL_GetPrimarySelectionText
|
||||
* http://wiki.libsdl.org/SDL_SetPrimarySelectionText
|
||||
*/
|
||||
int clipboard_testPrimarySelectionTextFunctions(void *arg)
|
||||
{
|
||||
char *textRef = SDLTest_RandomAsciiString();
|
||||
char *text = SDL_strdup(textRef);
|
||||
SDL_bool boolResult;
|
||||
int intResult;
|
||||
char *charResult;
|
||||
|
||||
/* Clear primary selection text state */
|
||||
boolResult = SDL_HasPrimarySelectionText();
|
||||
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
|
||||
if (boolResult == SDL_TRUE) {
|
||||
intResult = SDL_SetPrimarySelectionText((const char *)NULL);
|
||||
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText(NULL) succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
intResult == 0,
|
||||
"Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i",
|
||||
intResult);
|
||||
charResult = SDL_GetPrimarySelectionText();
|
||||
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
|
||||
SDL_free(charResult);
|
||||
boolResult = SDL_HasPrimarySelectionText();
|
||||
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
boolResult == SDL_FALSE,
|
||||
"Verify SDL_HasPrimarySelectionText returned SDL_FALSE, got %s",
|
||||
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
|
||||
}
|
||||
|
||||
/* Empty primary selection */
|
||||
charResult = SDL_GetPrimarySelectionText();
|
||||
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
|
||||
SDLTest_Assert(
|
||||
charResult != NULL,
|
||||
"Verify SDL_GetPrimarySelectionText did not return NULL");
|
||||
SDLTest_AssertCheck(
|
||||
charResult[0] == '\0', /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
|
||||
"Verify SDL_GetPrimarySelectionText returned string with length 0, got length %i",
|
||||
(int)SDL_strlen(charResult));
|
||||
intResult = SDL_SetPrimarySelectionText((const char *)text);
|
||||
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
intResult == 0,
|
||||
"Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i",
|
||||
intResult);
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(textRef, text) == 0,
|
||||
"Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'",
|
||||
textRef, text);
|
||||
boolResult = SDL_HasPrimarySelectionText();
|
||||
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
boolResult == SDL_TRUE,
|
||||
"Verify SDL_HasPrimarySelectionText returned SDL_TRUE, got %s",
|
||||
(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
|
||||
SDL_free(charResult);
|
||||
charResult = SDL_GetPrimarySelectionText();
|
||||
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(textRef, charResult) == 0,
|
||||
"Verify SDL_GetPrimarySelectionText returned correct string, expected '%s', got '%s'",
|
||||
textRef, charResult);
|
||||
|
||||
/* Cleanup */
|
||||
SDL_free(textRef);
|
||||
SDL_free(text);
|
||||
SDL_free(charResult);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Clipboard test cases */
|
||||
static const SDLTest_TestCaseReference clipboardTest1 =
|
||||
{ (SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference clipboardTest1 = {
|
||||
(SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference clipboardTest2 =
|
||||
{ (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference clipboardTest2 = {
|
||||
(SDLTest_TestCaseFp)clipboard_testHasPrimarySelectionText, "clipboard_testHasPrimarySelectionText", "Check call to SDL_HasPrimarySelectionText", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference clipboardTest3 =
|
||||
{ (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference clipboardTest3 = {
|
||||
(SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference clipboardTest4 =
|
||||
{ (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference clipboardTest4 = {
|
||||
(SDLTest_TestCaseFp)clipboard_testGetPrimarySelectionText, "clipboard_testGetPrimarySelectionText", "Check call to SDL_GetPrimarySelectionText", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference clipboardTest5 = {
|
||||
(SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference clipboardTest6 = {
|
||||
(SDLTest_TestCaseFp)clipboard_testSetPrimarySelectionText, "clipboard_testSetPrimarySelectionText", "Check call to SDL_SetPrimarySelectionText", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference clipboardTest7 = {
|
||||
(SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference clipboardTest8 = {
|
||||
(SDLTest_TestCaseFp)clipboard_testPrimarySelectionTextFunctions, "clipboard_testPrimarySelectionTextFunctions", "End-to-end test of SDL_xyzPrimarySelectionText functions", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Clipboard test cases */
|
||||
static const SDLTest_TestCaseReference *clipboardTests[] = {
|
||||
&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, NULL
|
||||
static const SDLTest_TestCaseReference *clipboardTests[] = {
|
||||
&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, &clipboardTest5, &clipboardTest6, &clipboardTest7, &clipboardTest8, NULL
|
||||
};
|
||||
|
||||
/* Clipboard test suite (global) */
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ int _userdataValue2 = 2;
|
|||
/* Event filter that sets some flags and optionally checks userdata */
|
||||
int SDLCALL _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
|
||||
{
|
||||
_eventFilterCalled = 1;
|
||||
_eventFilterCalled = 1;
|
||||
|
||||
if (_userdataCheck != 0) {
|
||||
SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
|
||||
if (userdata != NULL) {
|
||||
SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
|
||||
}
|
||||
}
|
||||
if (_userdataCheck != 0) {
|
||||
SDLTest_AssertCheck(userdata != NULL, "Check userdata pointer, expected: non-NULL, got: %s", (userdata != NULL) ? "non-NULL" : "NULL");
|
||||
if (userdata != NULL) {
|
||||
SDLTest_AssertCheck(*(int *)userdata == _userdataValue, "Check userdata value, expected: %i, got: %i", _userdataValue, *(int *)userdata);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -45,34 +45,32 @@ int SDLCALL _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
|
|||
* @sa http://wiki.libsdl.org/SDL_PumpEvents
|
||||
* @sa http://wiki.libsdl.org/SDL_PollEvent
|
||||
*/
|
||||
int
|
||||
events_pushPumpAndPollUserevent(void *arg)
|
||||
int events_pushPumpAndPollUserevent(void *arg)
|
||||
{
|
||||
SDL_Event event1;
|
||||
SDL_Event event2;
|
||||
int result;
|
||||
SDL_Event event1;
|
||||
SDL_Event event2;
|
||||
int result;
|
||||
|
||||
/* Create user event */
|
||||
event1.type = SDL_USEREVENT;
|
||||
event1.user.code = SDLTest_RandomSint32();
|
||||
event1.user.data1 = (void *)&_userdataValue1;
|
||||
event1.user.data2 = (void *)&_userdataValue2;
|
||||
/* Create user event */
|
||||
event1.type = SDL_USEREVENT;
|
||||
event1.user.code = SDLTest_RandomSint32();
|
||||
event1.user.data1 = (void *)&_userdataValue1;
|
||||
event1.user.data2 = (void *)&_userdataValue2;
|
||||
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
SDL_PushEvent(&event1);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
SDL_PushEvent(&event1);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
|
||||
/* Poll for user event */
|
||||
result = SDL_PollEvent(&event2);
|
||||
SDLTest_AssertPass("Call to SDL_PollEvent()");
|
||||
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
|
||||
/* Poll for user event */
|
||||
result = SDL_PollEvent(&event2);
|
||||
SDLTest_AssertPass("Call to SDL_PollEvent()");
|
||||
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Adds and deletes an event watch function with NULL userdata
|
||||
*
|
||||
|
|
@ -80,47 +78,46 @@ events_pushPumpAndPollUserevent(void *arg)
|
|||
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
|
||||
*
|
||||
*/
|
||||
int
|
||||
events_addDelEventWatch(void *arg)
|
||||
int events_addDelEventWatch(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
SDL_Event event;
|
||||
|
||||
/* Create user event */
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.code = SDLTest_RandomSint32();
|
||||
event.user.data1 = (void *)&_userdataValue1;
|
||||
event.user.data2 = (void *)&_userdataValue2;
|
||||
/* Create user event */
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.code = SDLTest_RandomSint32();
|
||||
event.user.data1 = (void *)&_userdataValue1;
|
||||
event.user.data2 = (void *)&_userdataValue2;
|
||||
|
||||
/* Disable userdata check */
|
||||
_userdataCheck = 0;
|
||||
/* Disable userdata check */
|
||||
_userdataCheck = 0;
|
||||
|
||||
/* Reset event filter call tracker */
|
||||
_eventFilterCalled = 0;
|
||||
/* Reset event filter call tracker */
|
||||
_eventFilterCalled = 0;
|
||||
|
||||
/* Add watch */
|
||||
SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
|
||||
/* Add watch */
|
||||
SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
|
||||
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
|
||||
|
||||
/* Delete watch */
|
||||
SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
|
||||
/* Delete watch */
|
||||
SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
|
||||
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
_eventFilterCalled = 0;
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
_eventFilterCalled = 0;
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -130,65 +127,66 @@ events_addDelEventWatch(void *arg)
|
|||
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
|
||||
*
|
||||
*/
|
||||
int
|
||||
events_addDelEventWatchWithUserdata(void *arg)
|
||||
int events_addDelEventWatchWithUserdata(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
SDL_Event event;
|
||||
|
||||
/* Create user event */
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.code = SDLTest_RandomSint32();
|
||||
event.user.data1 = (void *)&_userdataValue1;
|
||||
event.user.data2 = (void *)&_userdataValue2;
|
||||
/* Create user event */
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.code = SDLTest_RandomSint32();
|
||||
event.user.data1 = (void *)&_userdataValue1;
|
||||
event.user.data2 = (void *)&_userdataValue2;
|
||||
|
||||
/* Enable userdata check and set a value to check */
|
||||
_userdataCheck = 1;
|
||||
_userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
|
||||
/* Enable userdata check and set a value to check */
|
||||
_userdataCheck = 1;
|
||||
_userdataValue = SDLTest_RandomIntegerInRange(-1024, 1024);
|
||||
|
||||
/* Reset event filter call tracker */
|
||||
_eventFilterCalled = 0;
|
||||
/* Reset event filter call tracker */
|
||||
_eventFilterCalled = 0;
|
||||
|
||||
/* Add watch */
|
||||
SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
|
||||
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
|
||||
/* Add watch */
|
||||
SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
|
||||
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
|
||||
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 1, "Check that event filter was called");
|
||||
|
||||
/* Delete watch */
|
||||
SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
|
||||
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
|
||||
/* Delete watch */
|
||||
SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
|
||||
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
|
||||
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
_eventFilterCalled = 0;
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
|
||||
/* Push a user event onto the queue and force queue update */
|
||||
_eventFilterCalled = 0;
|
||||
SDL_PushEvent(&event);
|
||||
SDLTest_AssertPass("Call to SDL_PushEvent()");
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
SDLTest_AssertCheck(_eventFilterCalled == 0, "Check that event filter was NOT called");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Events test cases */
|
||||
static const SDLTest_TestCaseReference eventsTest1 =
|
||||
{ (SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference eventsTest1 = {
|
||||
(SDLTest_TestCaseFp)events_pushPumpAndPollUserevent, "events_pushPumpAndPollUserevent", "Pushes, pumps and polls a user event", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference eventsTest2 =
|
||||
{ (SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference eventsTest2 = {
|
||||
(SDLTest_TestCaseFp)events_addDelEventWatch, "events_addDelEventWatch", "Adds and deletes an event watch function with NULL userdata", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference eventsTest3 =
|
||||
{ (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference eventsTest3 = {
|
||||
(SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Events test cases */
|
||||
static const SDLTest_TestCaseReference *eventsTests[] = {
|
||||
static const SDLTest_TestCaseReference *eventsTests[] = {
|
||||
&eventsTest1, &eventsTest2, &eventsTest3, NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
171
Engine/lib/sdl/test/testautomation_guid.c
Normal file
171
Engine/lib/sdl/test/testautomation_guid.c
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
/**
|
||||
* GUID test suite
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Helper functions */
|
||||
|
||||
#define NUM_TEST_GUIDS 5
|
||||
|
||||
#ifndef UINT64_C
|
||||
#ifdef _MSC_VER
|
||||
#define UINT64_C(x) x##ui64
|
||||
#elif defined(_LP64)
|
||||
#define UINT64_C(x) x##UL
|
||||
#else
|
||||
#define UINT64_C(x) x##ULL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static struct
|
||||
{
|
||||
char *str;
|
||||
Uint64 upper, lower;
|
||||
} test_guids[NUM_TEST_GUIDS] = {
|
||||
{ "0000000000000000"
|
||||
"ffffffffffffffff",
|
||||
UINT64_C(0x0000000000000000), UINT64_C(0xffffffffffffffff) },
|
||||
{ "0011223344556677"
|
||||
"8091a2b3c4d5e6f0",
|
||||
UINT64_C(0x0011223344556677), UINT64_C(0x8091a2b3c4d5e6f0) },
|
||||
{ "a011223344556677"
|
||||
"8091a2b3c4d5e6f0",
|
||||
UINT64_C(0xa011223344556677), UINT64_C(0x8091a2b3c4d5e6f0) },
|
||||
{ "a011223344556677"
|
||||
"8091a2b3c4d5e6f1",
|
||||
UINT64_C(0xa011223344556677), UINT64_C(0x8091a2b3c4d5e6f1) },
|
||||
{ "a011223344556677"
|
||||
"8191a2b3c4d5e6f0",
|
||||
UINT64_C(0xa011223344556677), UINT64_C(0x8191a2b3c4d5e6f0) },
|
||||
};
|
||||
|
||||
static void
|
||||
upper_lower_to_bytestring(Uint8 *out, Uint64 upper, Uint64 lower)
|
||||
{
|
||||
Uint64 values[2];
|
||||
int i, k;
|
||||
|
||||
values[0] = upper;
|
||||
values[1] = lower;
|
||||
|
||||
for (i = 0; i < 2; ++i) {
|
||||
Uint64 v = values[i];
|
||||
|
||||
for (k = 0; k < 8; ++k) {
|
||||
*out++ = v >> 56;
|
||||
v <<= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Check String-to-GUID conversion
|
||||
*
|
||||
* @sa SDL_GUIDFromString
|
||||
*/
|
||||
static int
|
||||
TestGuidFromString(void *arg)
|
||||
{
|
||||
int i;
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_GUIDFromString");
|
||||
for (i = 0; i < NUM_TEST_GUIDS; ++i) {
|
||||
Uint8 expected[16];
|
||||
SDL_GUID guid;
|
||||
|
||||
upper_lower_to_bytestring(expected,
|
||||
test_guids[i].upper, test_guids[i].lower);
|
||||
|
||||
guid = SDL_GUIDFromString(test_guids[i].str);
|
||||
SDLTest_AssertCheck(SDL_memcmp(expected, guid.data, 16) == 0, "GUID from string, GUID was: '%s'", test_guids[i].str);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check GUID-to-String conversion
|
||||
*
|
||||
* @sa SDL_GUIDToString
|
||||
*/
|
||||
static int
|
||||
TestGuidToString(void *arg)
|
||||
{
|
||||
int i;
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_GUIDToString");
|
||||
for (i = 0; i < NUM_TEST_GUIDS; ++i) {
|
||||
const int guid_str_offset = 4;
|
||||
char guid_str_buf[64];
|
||||
char *guid_str = guid_str_buf + guid_str_offset;
|
||||
SDL_GUID guid;
|
||||
int size;
|
||||
|
||||
upper_lower_to_bytestring(guid.data,
|
||||
test_guids[i].upper, test_guids[i].lower);
|
||||
|
||||
/* Serialise to limited-length buffers */
|
||||
for (size = 0; size <= 36; ++size) {
|
||||
const Uint8 fill_char = size + 0xa0;
|
||||
Uint32 expected_prefix;
|
||||
Uint32 actual_prefix;
|
||||
int written_size;
|
||||
|
||||
SDL_memset(guid_str_buf, fill_char, sizeof(guid_str_buf));
|
||||
SDL_GUIDToString(guid, guid_str, size);
|
||||
|
||||
/* Check bytes before guid_str_buf */
|
||||
expected_prefix = fill_char | (fill_char << 8) | (fill_char << 16) | (fill_char << 24);
|
||||
SDL_memcpy(&actual_prefix, guid_str_buf, 4);
|
||||
SDLTest_AssertCheck(expected_prefix == actual_prefix, "String buffer memory before output untouched, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32 ", at size=%d", expected_prefix, actual_prefix, size);
|
||||
|
||||
/* Check that we did not overwrite too much */
|
||||
written_size = 0;
|
||||
while ((guid_str[written_size] & 0xff) != fill_char && written_size < 256) {
|
||||
++written_size;
|
||||
}
|
||||
SDLTest_AssertCheck(written_size <= size, "Output length is within expected bounds, with length %d: wrote %d of %d permitted bytes", size, written_size, size);
|
||||
if (size >= 33) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(guid_str, test_guids[i].str) == 0, "GUID string equality, from string: %s", test_guids[i].str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* GUID routine test cases */
|
||||
static const SDLTest_TestCaseReference guidTest1 = {
|
||||
(SDLTest_TestCaseFp)TestGuidFromString, "TestGuidFromString", "Call to SDL_GUIDFromString", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference guidTest2 = {
|
||||
(SDLTest_TestCaseFp)TestGuidToString, "TestGuidToString", "Call to SDL_GUIDToString", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of GUID routine test cases */
|
||||
static const SDLTest_TestCaseReference *guidTests[] = {
|
||||
&guidTest1,
|
||||
&guidTest2,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* GUID routine test suite (global) */
|
||||
SDLTest_TestSuiteReference guidTestSuite = {
|
||||
"GUID",
|
||||
NULL,
|
||||
guidTests,
|
||||
NULL
|
||||
};
|
||||
|
|
@ -7,9 +7,7 @@
|
|||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
|
||||
const char* _HintsEnum[] =
|
||||
{
|
||||
const char *_HintsEnum[] = {
|
||||
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
|
||||
SDL_HINT_FRAMEBUFFER_ACCELERATION,
|
||||
SDL_HINT_GAMECONTROLLERCONFIG,
|
||||
|
|
@ -33,9 +31,8 @@ const char* _HintsEnum[] =
|
|||
SDL_HINT_VIDEO_WIN_D3DCOMPILER,
|
||||
SDL_HINT_VIDEO_X11_XRANDR,
|
||||
SDL_HINT_XINPUT_ENABLED,
|
||||
};
|
||||
const char* _HintsVerbose[] =
|
||||
{
|
||||
};
|
||||
const char *_HintsVerbose[] = {
|
||||
"SDL_ACCELEROMETER_AS_JOYSTICK",
|
||||
"SDL_FRAMEBUFFER_ACCELERATION",
|
||||
"SDL_GAMECONTROLLERCONFIG",
|
||||
|
|
@ -59,7 +56,7 @@ const char* _HintsVerbose[] =
|
|||
"SDL_VIDEO_WIN_D3DCOMPILER",
|
||||
"SDL_VIDEO_X11_XRANDR",
|
||||
"SDL_XINPUT_ENABLED"
|
||||
};
|
||||
};
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(HintsEnum, SDL_arraysize(_HintsEnum) == SDL_arraysize(_HintsVerbose));
|
||||
|
||||
|
|
@ -70,94 +67,193 @@ const int _numHintsEnum = SDL_arraysize(_HintsEnum);
|
|||
/**
|
||||
* @brief Call to SDL_GetHint
|
||||
*/
|
||||
int
|
||||
hints_getHint(void *arg)
|
||||
int hints_getHint(void *arg)
|
||||
{
|
||||
const char *result1;
|
||||
const char *result2;
|
||||
int i;
|
||||
const char *result1;
|
||||
const char *result2;
|
||||
int i;
|
||||
|
||||
for (i=0; i<_numHintsEnum; i++) {
|
||||
result1 = SDL_GetHint(_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
|
||||
result2 = SDL_GetHint(_HintsVerbose[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
|
||||
SDLTest_AssertCheck(
|
||||
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
|
||||
"Verify returned values are equal; got: result1='%s' result2='%s",
|
||||
(result1 == NULL) ? "null" : result1,
|
||||
(result2 == NULL) ? "null" : result2);
|
||||
}
|
||||
for (i = 0; i < _numHintsEnum; i++) {
|
||||
result1 = SDL_GetHint(_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char *)_HintsEnum[i]);
|
||||
result2 = SDL_GetHint(_HintsVerbose[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char *)_HintsVerbose[i]);
|
||||
SDLTest_AssertCheck(
|
||||
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
|
||||
"Verify returned values are equal; got: result1='%s' result2='%s",
|
||||
(result1 == NULL) ? "null" : result1,
|
||||
(result2 == NULL) ? "null" : result2);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
static void SDLCALL hints_testHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
*(char **)userdata = hint ? SDL_strdup(hint) : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_SetHint
|
||||
*/
|
||||
int
|
||||
hints_setHint(void *arg)
|
||||
int hints_setHint(void *arg)
|
||||
{
|
||||
const char *originalValue;
|
||||
const char *value;
|
||||
const char *testValue;
|
||||
SDL_bool result;
|
||||
int i, j;
|
||||
const char *testHint = "SDL_AUTOMATED_TEST_HINT";
|
||||
const char *originalValue;
|
||||
char *value;
|
||||
const char *testValue;
|
||||
char *callbackValue;
|
||||
SDL_bool result;
|
||||
int i, j;
|
||||
|
||||
/* Create random values to set */
|
||||
value = SDLTest_RandomAsciiStringOfSize(10);
|
||||
/* Create random values to set */
|
||||
value = SDLTest_RandomAsciiStringOfSize(10);
|
||||
|
||||
for (i=0; i<_numHintsEnum; i++) {
|
||||
/* Capture current value */
|
||||
originalValue = SDL_GetHint(_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
|
||||
for (i = 0; i < _numHintsEnum; i++) {
|
||||
/* Capture current value */
|
||||
originalValue = SDL_GetHint(_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
|
||||
|
||||
/* Copy the original value, since it will be freed when we set it again */
|
||||
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
|
||||
/* Copy the original value, since it will be freed when we set it again */
|
||||
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
|
||||
|
||||
/* Set value (twice) */
|
||||
for (j=1; j<=2; j++) {
|
||||
result = SDL_SetHint(_HintsEnum[i], value);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
testValue = SDL_GetHint(_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
|
||||
SDLTest_AssertCheck(
|
||||
(SDL_strcmp(value, testValue) == 0),
|
||||
"Verify returned value equals set value; got: testValue='%s' value='%s",
|
||||
(testValue == NULL) ? "null" : testValue,
|
||||
value);
|
||||
/* Set value (twice) */
|
||||
for (j = 1; j <= 2; j++) {
|
||||
result = SDL_SetHint(_HintsEnum[i], value);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
testValue = SDL_GetHint(_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
|
||||
SDLTest_AssertCheck(
|
||||
(SDL_strcmp(value, testValue) == 0),
|
||||
"Verify returned value equals set value; got: testValue='%s' value='%s",
|
||||
(testValue == NULL) ? "null" : testValue,
|
||||
value);
|
||||
}
|
||||
|
||||
/* Reset original value */
|
||||
result = SDL_SetHint(_HintsEnum[i], originalValue);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
SDL_free((void *)originalValue);
|
||||
}
|
||||
|
||||
/* Reset original value */
|
||||
result = SDL_SetHint(_HintsEnum[i], originalValue);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
|
||||
SDL_free(value);
|
||||
|
||||
/* Set default value in environment */
|
||||
SDL_setenv(testHint, "original", 1);
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_GetHint() after saving and restoring hint");
|
||||
originalValue = SDL_GetHint(testHint);
|
||||
value = (originalValue == NULL) ? NULL : SDL_strdup(originalValue);
|
||||
SDL_SetHint(testHint, "temp");
|
||||
SDL_SetHint(testHint, value);
|
||||
SDL_free(value);
|
||||
testValue = SDL_GetHint(testHint);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
SDL_free((void *)originalValue);
|
||||
}
|
||||
testValue && SDL_strcmp(testValue, "original") == 0,
|
||||
"testValue = %s, expected \"original\"",
|
||||
testValue);
|
||||
|
||||
SDL_free((void *)value);
|
||||
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_DEFAULT)");
|
||||
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_DEFAULT);
|
||||
testValue = SDL_GetHint(testHint);
|
||||
SDLTest_AssertCheck(
|
||||
testValue && SDL_strcmp(testValue, "original") == 0,
|
||||
"testValue = %s, expected \"original\"",
|
||||
testValue);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE)");
|
||||
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
|
||||
testValue = SDL_GetHint(testHint);
|
||||
SDLTest_AssertCheck(
|
||||
testValue && SDL_strcmp(testValue, "temp") == 0,
|
||||
"testValue = %s, expected \"temp\"",
|
||||
testValue);
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_OVERRIDE)");
|
||||
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_OVERRIDE);
|
||||
testValue = SDL_GetHint(testHint);
|
||||
SDLTest_AssertCheck(
|
||||
testValue == NULL,
|
||||
"testValue = %s, expected NULL",
|
||||
testValue);
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_ResetHint()");
|
||||
SDL_ResetHint(testHint);
|
||||
testValue = SDL_GetHint(testHint);
|
||||
SDLTest_AssertCheck(
|
||||
testValue && SDL_strcmp(testValue, "original") == 0,
|
||||
"testValue = %s, expected \"original\"",
|
||||
testValue);
|
||||
|
||||
/* Make sure callback functionality works past a reset */
|
||||
SDLTest_AssertPass("Call to SDL_AddHintCallback()");
|
||||
callbackValue = NULL;
|
||||
SDL_AddHintCallback(testHint, hints_testHintChanged, &callbackValue);
|
||||
SDLTest_AssertCheck(
|
||||
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
|
||||
"callbackValue = %s, expected \"original\"",
|
||||
callbackValue);
|
||||
SDL_free(callbackValue);
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback");
|
||||
callbackValue = NULL;
|
||||
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
|
||||
SDLTest_AssertCheck(
|
||||
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
|
||||
"callbackValue = %s, expected \"temp\"",
|
||||
callbackValue);
|
||||
SDL_free(callbackValue);
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_ResetHint(), using callback");
|
||||
callbackValue = NULL;
|
||||
SDL_ResetHint(testHint);
|
||||
SDLTest_AssertCheck(
|
||||
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
|
||||
"callbackValue = %s, expected \"original\"",
|
||||
callbackValue);
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback after reset");
|
||||
callbackValue = NULL;
|
||||
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
|
||||
SDLTest_AssertCheck(
|
||||
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
|
||||
"callbackValue = %s, expected \"temp\"",
|
||||
callbackValue);
|
||||
SDL_free(callbackValue);
|
||||
|
||||
SDLTest_AssertPass("Call to SDL_ResetHint(), after clearing callback");
|
||||
callbackValue = NULL;
|
||||
SDL_DelHintCallback(testHint, hints_testHintChanged, &callbackValue);
|
||||
SDL_ResetHint(testHint);
|
||||
SDLTest_AssertCheck(
|
||||
callbackValue == NULL,
|
||||
"callbackValue = %s, expected \"(null)\"",
|
||||
callbackValue);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Hints test cases */
|
||||
static const SDLTest_TestCaseReference hintsTest1 =
|
||||
{ (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference hintsTest1 = {
|
||||
(SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference hintsTest2 =
|
||||
{ (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference hintsTest2 = {
|
||||
(SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Hints test cases */
|
||||
static const SDLTest_TestCaseReference *hintsTests[] = {
|
||||
static const SDLTest_TestCaseReference *hintsTests[] = {
|
||||
&hintsTest1, &hintsTest2, NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
91
Engine/lib/sdl/test/testautomation_joystick.c
Normal file
91
Engine/lib/sdl/test/testautomation_joystick.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/**
|
||||
* Joystick test suite
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
#include "../src/joystick/usb_ids.h"
|
||||
|
||||
/* ================= Test Case Implementation ================== */
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Check virtual joystick creation
|
||||
*
|
||||
* @sa SDL_JoystickAttachVirtualEx
|
||||
*/
|
||||
static int
|
||||
TestVirtualJoystick(void *arg)
|
||||
{
|
||||
SDL_VirtualJoystickDesc desc;
|
||||
SDL_Joystick *joystick = NULL;
|
||||
int device_index;
|
||||
|
||||
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)");
|
||||
|
||||
SDL_zero(desc);
|
||||
desc.version = SDL_VIRTUAL_JOYSTICK_DESC_VERSION;
|
||||
desc.type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
|
||||
desc.naxes = SDL_CONTROLLER_AXIS_MAX;
|
||||
desc.nbuttons = SDL_CONTROLLER_BUTTON_MAX;
|
||||
desc.vendor_id = USB_VENDOR_NVIDIA;
|
||||
desc.product_id = USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V104;
|
||||
desc.name = "Virtual NVIDIA SHIELD Controller";
|
||||
device_index = SDL_JoystickAttachVirtualEx(&desc);
|
||||
SDLTest_AssertCheck(device_index >= 0, "SDL_JoystickAttachVirtualEx()");
|
||||
SDLTest_AssertCheck(SDL_JoystickIsVirtual(device_index), "SDL_JoystickIsVirtual()");
|
||||
if (device_index >= 0) {
|
||||
joystick = SDL_JoystickOpen(device_index);
|
||||
SDLTest_AssertCheck(joystick != NULL, "SDL_JoystickOpen()");
|
||||
if (joystick) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_JoystickName(joystick), desc.name) == 0, "SDL_JoystickName()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetVendor(joystick) == desc.vendor_id, "SDL_JoystickGetVendor()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetProduct(joystick) == desc.product_id, "SDL_JoystickGetProduct()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetProductVersion(joystick) == 0, "SDL_JoystickGetProductVersion()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetFirmwareVersion(joystick) == 0, "SDL_JoystickGetFirmwareVersion()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetSerial(joystick) == NULL, "SDL_JoystickGetSerial()");
|
||||
SDLTest_AssertCheck(SDL_JoystickGetType(joystick) == desc.type, "SDL_JoystickGetType()");
|
||||
SDLTest_AssertCheck(SDL_JoystickNumAxes(joystick) == desc.naxes, "SDL_JoystickNumAxes()");
|
||||
SDLTest_AssertCheck(SDL_JoystickNumBalls(joystick) == 0, "SDL_JoystickNumBalls()");
|
||||
SDLTest_AssertCheck(SDL_JoystickNumHats(joystick) == desc.nhats, "SDL_JoystickNumHats()");
|
||||
SDLTest_AssertCheck(SDL_JoystickNumButtons(joystick) == desc.nbuttons, "SDL_JoystickNumButtons()");
|
||||
|
||||
SDLTest_AssertCheck(SDL_JoystickSetVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_PRESSED) == 0, "SDL_JoystickSetVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_PRESSED)");
|
||||
SDL_JoystickUpdate();
|
||||
SDLTest_AssertCheck(SDL_JoystickGetButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED, "SDL_JoystickGetButton(SDL_CONTROLLER_BUTTON_A) == SDL_PRESSED");
|
||||
SDLTest_AssertCheck(SDL_JoystickSetVirtualButton(joystick, SDL_CONTROLLER_BUTTON_A, SDL_RELEASED) == 0, "SDL_JoystickSetVirtualButton(SDL_CONTROLLER_BUTTON_A, SDL_RELEASED)");
|
||||
SDL_JoystickUpdate();
|
||||
SDLTest_AssertCheck(SDL_JoystickGetButton(joystick, SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED, "SDL_JoystickGetButton(SDL_CONTROLLER_BUTTON_A) == SDL_RELEASED");
|
||||
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
SDLTest_AssertCheck(SDL_JoystickDetachVirtual(device_index) == 0, "SDL_JoystickDetachVirtual()");
|
||||
}
|
||||
SDLTest_AssertCheck(!SDL_JoystickIsVirtual(device_index), "!SDL_JoystickIsVirtual()");
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Joystick routine test cases */
|
||||
static const SDLTest_TestCaseReference joystickTest1 = {
|
||||
(SDLTest_TestCaseFp)TestVirtualJoystick, "TestVirtualJoystick", "Test virtual joystick functionality", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Joystick routine test cases */
|
||||
static const SDLTest_TestCaseReference *joystickTests[] = {
|
||||
&joystickTest1,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* Joystick routine test suite (global) */
|
||||
SDLTest_TestSuiteReference joystickTestSuite = {
|
||||
"Joystick",
|
||||
NULL,
|
||||
joystickTests,
|
||||
NULL
|
||||
};
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -9,14 +9,13 @@
|
|||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_Init
|
||||
* http://wiki.libsdl.org/SDL_Quit
|
||||
*/
|
||||
static int main_testInitQuitJoystickHaptic (void *arg)
|
||||
static int main_testInitQuitJoystickHaptic(void *arg)
|
||||
{
|
||||
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED
|
||||
return TEST_SKIPPED;
|
||||
|
|
@ -24,15 +23,15 @@ static int main_testInitQuitJoystickHaptic (void *arg)
|
|||
int enabled_subsystems;
|
||||
int initialized_subsystems = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC;
|
||||
|
||||
SDLTest_AssertCheck( SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems." );
|
||||
SDLTest_AssertCheck(SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems.");
|
||||
|
||||
enabled_subsystems = SDL_WasInit(initialized_subsystems);
|
||||
SDLTest_AssertCheck( enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems );
|
||||
SDLTest_AssertCheck(enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems);
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
enabled_subsystems = SDL_WasInit(initialized_subsystems);
|
||||
SDLTest_AssertCheck( enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems );
|
||||
SDLTest_AssertCheck(enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
#endif
|
||||
|
|
@ -44,7 +43,7 @@ static int main_testInitQuitJoystickHaptic (void *arg)
|
|||
* http://wiki.libsdl.org/SDL_Init
|
||||
* http://wiki.libsdl.org/SDL_Quit
|
||||
*/
|
||||
static int main_testInitQuitSubSystem (void *arg)
|
||||
static int main_testInitQuitSubSystem(void *arg)
|
||||
{
|
||||
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
|
||||
return TEST_SKIPPED;
|
||||
|
|
@ -56,15 +55,15 @@ static int main_testInitQuitSubSystem (void *arg)
|
|||
int initialized_system;
|
||||
int subsystem = subsystems[i];
|
||||
|
||||
SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem );
|
||||
SDLTest_AssertCheck( SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem );
|
||||
SDLTest_AssertCheck((SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem);
|
||||
SDLTest_AssertCheck(SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem);
|
||||
|
||||
initialized_system = SDL_WasInit(subsystem);
|
||||
SDLTest_AssertCheck( (initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system );
|
||||
SDLTest_AssertCheck((initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system);
|
||||
|
||||
SDL_QuitSubSystem(subsystem);
|
||||
|
||||
SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem );
|
||||
SDLTest_AssertCheck((SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
|
|
@ -72,7 +71,7 @@ static int main_testInitQuitSubSystem (void *arg)
|
|||
}
|
||||
|
||||
const int joy_and_controller = SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER;
|
||||
static int main_testImpliedJoystickInit (void *arg)
|
||||
static int main_testImpliedJoystickInit(void *arg)
|
||||
{
|
||||
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
|
||||
return TEST_SKIPPED;
|
||||
|
|
@ -80,24 +79,24 @@ static int main_testImpliedJoystickInit (void *arg)
|
|||
int initialized_system;
|
||||
|
||||
/* First initialize the controller */
|
||||
SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
|
||||
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
|
||||
SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller");
|
||||
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)");
|
||||
|
||||
/* Then make sure this implicitly initialized the joystick subsystem */
|
||||
initialized_system = SDL_WasInit(joy_and_controller);
|
||||
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
|
||||
SDLTest_AssertCheck((initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system);
|
||||
|
||||
/* Then quit the controller, and make sure that implicitly also quits the */
|
||||
/* joystick subsystem */
|
||||
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
initialized_system = SDL_WasInit(joy_and_controller);
|
||||
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
|
||||
SDLTest_AssertCheck((initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int main_testImpliedJoystickQuit (void *arg)
|
||||
static int main_testImpliedJoystickQuit(void *arg)
|
||||
{
|
||||
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
|
||||
return TEST_SKIPPED;
|
||||
|
|
@ -105,19 +104,19 @@ static int main_testImpliedJoystickQuit (void *arg)
|
|||
int initialized_system;
|
||||
|
||||
/* First initialize the controller and the joystick (explicitly) */
|
||||
SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
|
||||
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)" );
|
||||
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
|
||||
SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller");
|
||||
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)");
|
||||
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)");
|
||||
|
||||
/* Then make sure they're both initialized properly */
|
||||
initialized_system = SDL_WasInit(joy_and_controller);
|
||||
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
|
||||
SDLTest_AssertCheck((initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system);
|
||||
|
||||
/* Then quit the controller, and make sure that it does NOT quit the */
|
||||
/* explicitly initialized joystick subsystem. */
|
||||
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
initialized_system = SDL_WasInit(joy_and_controller);
|
||||
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
|
||||
SDLTest_AssertCheck((initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system);
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
||||
|
||||
|
|
@ -125,24 +124,62 @@ static int main_testImpliedJoystickQuit (void *arg)
|
|||
#endif
|
||||
}
|
||||
|
||||
static const SDLTest_TestCaseReference mainTest1 =
|
||||
{ (SDLTest_TestCaseFp)main_testInitQuitJoystickHaptic, "main_testInitQuitJoystickHaptic", "Tests SDL_Init/Quit of Joystick and Haptic subsystem", TEST_ENABLED};
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-zero-length"
|
||||
#endif
|
||||
|
||||
static const SDLTest_TestCaseReference mainTest2 =
|
||||
{ (SDLTest_TestCaseFp)main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED};
|
||||
static int
|
||||
main_testSetError(void *arg)
|
||||
{
|
||||
size_t i;
|
||||
char error[1024];
|
||||
|
||||
static const SDLTest_TestCaseReference mainTest3 =
|
||||
{ (SDLTest_TestCaseFp)main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED};
|
||||
error[0] = '\0';
|
||||
SDL_SetError("");
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, SDL_GetError()) == 0, "SDL_SetError(\"\")");
|
||||
|
||||
static const SDLTest_TestCaseReference mainTest4 =
|
||||
{ (SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED};
|
||||
for (i = 0; i < (sizeof(error) - 1); ++i) {
|
||||
error[i] = 'a' + (i % 26);
|
||||
}
|
||||
error[i] = '\0';
|
||||
SDL_SetError("%s", error);
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, SDL_GetError()) == 0, "SDL_SetError(\"abc...1023\")");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
static const SDLTest_TestCaseReference mainTest1 = {
|
||||
(SDLTest_TestCaseFp)main_testInitQuitJoystickHaptic, "main_testInitQuitJoystickHaptic", "Tests SDL_Init/Quit of Joystick and Haptic subsystem", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mainTest2 = {
|
||||
(SDLTest_TestCaseFp)main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mainTest3 = {
|
||||
(SDLTest_TestCaseFp)main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mainTest4 = {
|
||||
(SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mainTest5 = {
|
||||
(SDLTest_TestCaseFp)main_testSetError, "main_testSetError", "Tests that SDL_SetError() handles arbitrarily large strings", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Main test cases */
|
||||
static const SDLTest_TestCaseReference *mainTests[] = {
|
||||
static const SDLTest_TestCaseReference *mainTests[] = {
|
||||
&mainTest1,
|
||||
&mainTest2,
|
||||
&mainTest3,
|
||||
&mainTest4,
|
||||
&mainTest5,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
3354
Engine/lib/sdl/test/testautomation_math.c
Normal file
3354
Engine/lib/sdl/test/testautomation_math.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -15,178 +15,175 @@
|
|||
/* Helper to evaluate state returned from SDL_GetMouseState */
|
||||
int _mouseStateCheck(Uint32 state)
|
||||
{
|
||||
return (state == 0) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_LEFT)) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_RIGHT)) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_X1)) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_X2));
|
||||
return (state == 0) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_LEFT)) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_MIDDLE)) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_RIGHT)) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_X1)) ||
|
||||
(state == SDL_BUTTON(SDL_BUTTON_X2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetMouseState
|
||||
*
|
||||
*/
|
||||
int
|
||||
mouse_getMouseState(void *arg)
|
||||
int mouse_getMouseState(void *arg)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
Uint32 state;
|
||||
int x;
|
||||
int y;
|
||||
Uint32 state;
|
||||
|
||||
/* Pump some events to update mouse state */
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
/* Pump some events to update mouse state */
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
|
||||
/* Case where x, y pointer is NULL */
|
||||
state = SDL_GetMouseState(NULL, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, NULL)");
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
|
||||
/* Case where x, y pointer is NULL */
|
||||
state = SDL_GetMouseState(NULL, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, NULL)");
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
|
||||
|
||||
/* Case where x pointer is not NULL */
|
||||
x = INT_MIN;
|
||||
state = SDL_GetMouseState(&x, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, NULL)");
|
||||
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
|
||||
/* Case where x pointer is not NULL */
|
||||
x = INT_MIN;
|
||||
state = SDL_GetMouseState(&x, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, NULL)");
|
||||
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
|
||||
|
||||
/* Case where y pointer is not NULL */
|
||||
y = INT_MIN;
|
||||
state = SDL_GetMouseState(NULL, &y);
|
||||
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, &y)");
|
||||
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
|
||||
/* Case where y pointer is not NULL */
|
||||
y = INT_MIN;
|
||||
state = SDL_GetMouseState(NULL, &y);
|
||||
SDLTest_AssertPass("Call to SDL_GetMouseState(NULL, &y)");
|
||||
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
|
||||
|
||||
/* Case where x and y pointer is not NULL */
|
||||
x = INT_MIN;
|
||||
y = INT_MIN;
|
||||
state = SDL_GetMouseState(&x, &y);
|
||||
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, &y)");
|
||||
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
|
||||
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
|
||||
/* Case where x and y pointer is not NULL */
|
||||
x = INT_MIN;
|
||||
y = INT_MIN;
|
||||
state = SDL_GetMouseState(&x, &y);
|
||||
SDLTest_AssertPass("Call to SDL_GetMouseState(&x, &y)");
|
||||
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
|
||||
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check call to SDL_GetRelativeMouseState
|
||||
*
|
||||
*/
|
||||
int
|
||||
mouse_getRelativeMouseState(void *arg)
|
||||
int mouse_getRelativeMouseState(void *arg)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
Uint32 state;
|
||||
int x;
|
||||
int y;
|
||||
Uint32 state;
|
||||
|
||||
/* Pump some events to update mouse state */
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
/* Pump some events to update mouse state */
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("Call to SDL_PumpEvents()");
|
||||
|
||||
/* Case where x, y pointer is NULL */
|
||||
state = SDL_GetRelativeMouseState(NULL, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, NULL)");
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
|
||||
/* Case where x, y pointer is NULL */
|
||||
state = SDL_GetRelativeMouseState(NULL, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, NULL)");
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
|
||||
|
||||
/* Case where x pointer is not NULL */
|
||||
x = INT_MIN;
|
||||
state = SDL_GetRelativeMouseState(&x, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, NULL)");
|
||||
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
|
||||
/* Case where x pointer is not NULL */
|
||||
x = INT_MIN;
|
||||
state = SDL_GetRelativeMouseState(&x, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, NULL)");
|
||||
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
|
||||
|
||||
/* Case where y pointer is not NULL */
|
||||
y = INT_MIN;
|
||||
state = SDL_GetRelativeMouseState(NULL, &y);
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, &y)");
|
||||
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
|
||||
/* Case where y pointer is not NULL */
|
||||
y = INT_MIN;
|
||||
state = SDL_GetRelativeMouseState(NULL, &y);
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(NULL, &y)");
|
||||
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
|
||||
|
||||
/* Case where x and y pointer is not NULL */
|
||||
x = INT_MIN;
|
||||
y = INT_MIN;
|
||||
state = SDL_GetRelativeMouseState(&x, &y);
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, &y)");
|
||||
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
|
||||
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %i", state);
|
||||
/* Case where x and y pointer is not NULL */
|
||||
x = INT_MIN;
|
||||
y = INT_MIN;
|
||||
state = SDL_GetRelativeMouseState(&x, &y);
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseState(&x, &y)");
|
||||
SDLTest_AssertCheck(x > INT_MIN, "Validate that value of x is > INT_MIN, got: %i", x);
|
||||
SDLTest_AssertCheck(y > INT_MIN, "Validate that value of y is > INT_MIN, got: %i", y);
|
||||
SDLTest_AssertCheck(_mouseStateCheck(state), "Validate state returned from function, got: %" SDL_PRIu32, state);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/* XPM definition of mouse Cursor */
|
||||
static const char *_mouseArrowData[] = {
|
||||
/* pixels */
|
||||
"X ",
|
||||
"XX ",
|
||||
"X.X ",
|
||||
"X..X ",
|
||||
"X...X ",
|
||||
"X....X ",
|
||||
"X.....X ",
|
||||
"X......X ",
|
||||
"X.......X ",
|
||||
"X........X ",
|
||||
"X.....XXXXX ",
|
||||
"X..X..X ",
|
||||
"X.X X..X ",
|
||||
"XX X..X ",
|
||||
"X X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "
|
||||
/* pixels */
|
||||
"X ",
|
||||
"XX ",
|
||||
"X.X ",
|
||||
"X..X ",
|
||||
"X...X ",
|
||||
"X....X ",
|
||||
"X.....X ",
|
||||
"X......X ",
|
||||
"X.......X ",
|
||||
"X........X ",
|
||||
"X.....XXXXX ",
|
||||
"X..X..X ",
|
||||
"X.X X..X ",
|
||||
"XX X..X ",
|
||||
"X X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" "
|
||||
};
|
||||
|
||||
/* Helper that creates a new mouse cursor from an XPM */
|
||||
static SDL_Cursor *_initArrowCursor(const char *image[])
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
int i, row, col;
|
||||
Uint8 data[4*32];
|
||||
Uint8 mask[4*32];
|
||||
SDL_Cursor *cursor;
|
||||
int i, row, col;
|
||||
Uint8 data[4 * 32];
|
||||
Uint8 mask[4 * 32];
|
||||
|
||||
i = -1;
|
||||
for ( row=0; row<32; ++row ) {
|
||||
for ( col=0; col<32; ++col ) {
|
||||
if ( col % 8 ) {
|
||||
data[i] <<= 1;
|
||||
mask[i] <<= 1;
|
||||
} else {
|
||||
++i;
|
||||
data[i] = mask[i] = 0;
|
||||
}
|
||||
switch (image[row][col]) {
|
||||
case 'X':
|
||||
data[i] |= 0x01;
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case '.':
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
i = -1;
|
||||
for (row = 0; row < 32; ++row) {
|
||||
for (col = 0; col < 32; ++col) {
|
||||
if (col % 8) {
|
||||
data[i] <<= 1;
|
||||
mask[i] <<= 1;
|
||||
} else {
|
||||
++i;
|
||||
data[i] = mask[i] = 0;
|
||||
}
|
||||
switch (image[row][col]) {
|
||||
case 'X':
|
||||
data[i] |= 0x01;
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case '.':
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0);
|
||||
return cursor;
|
||||
cursor = SDL_CreateCursor(data, mask, 32, 32, 0, 0);
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -195,15 +192,14 @@ static SDL_Cursor *_initArrowCursor(const char *image[])
|
|||
* @sa http://wiki.libsdl.org/SDL_CreateCursor
|
||||
* @sa http://wiki.libsdl.org/SDL_FreeCursor
|
||||
*/
|
||||
int
|
||||
mouse_createFreeCursor(void *arg)
|
||||
int mouse_createFreeCursor(void *arg)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
/* Create a cursor */
|
||||
cursor = _initArrowCursor(_mouseArrowData);
|
||||
SDLTest_AssertPass("Call to SDL_CreateCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
|
||||
SDLTest_AssertPass("Call to SDL_CreateCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
|
||||
if (cursor == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
|
@ -221,8 +217,7 @@ mouse_createFreeCursor(void *arg)
|
|||
* @sa http://wiki.libsdl.org/SDL_CreateColorCursor
|
||||
* @sa http://wiki.libsdl.org/SDL_FreeCursor
|
||||
*/
|
||||
int
|
||||
mouse_createFreeColorCursor(void *arg)
|
||||
int mouse_createFreeColorCursor(void *arg)
|
||||
{
|
||||
SDL_Surface *face;
|
||||
SDL_Cursor *cursor;
|
||||
|
|
@ -230,12 +225,14 @@ mouse_createFreeColorCursor(void *arg)
|
|||
/* Get sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Validate sample input image is not NULL");
|
||||
if (face == NULL) return TEST_ABORTED;
|
||||
if (face == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Create a color cursor from surface */
|
||||
cursor = SDL_CreateColorCursor(face, 0, 0);
|
||||
SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
|
||||
SDLTest_AssertPass("Call to SDL_CreateColorCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateColorCursor() is not NULL");
|
||||
if (cursor == NULL) {
|
||||
SDL_FreeSurface(face);
|
||||
return TEST_ABORTED;
|
||||
|
|
@ -258,18 +255,18 @@ void _changeCursorVisibility(int state)
|
|||
int newState;
|
||||
int result;
|
||||
|
||||
oldState = SDL_ShowCursor(SDL_QUERY);
|
||||
oldState = SDL_ShowCursor(SDL_QUERY);
|
||||
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
|
||||
|
||||
result = SDL_ShowCursor(state);
|
||||
result = SDL_ShowCursor(state);
|
||||
SDLTest_AssertPass("Call to SDL_ShowCursor(%s)", (state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE");
|
||||
SDLTest_AssertCheck(result == oldState, "Validate result from SDL_ShowCursor(%s), expected: %i, got: %i",
|
||||
(state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result);
|
||||
(state == SDL_ENABLE) ? "SDL_ENABLE" : "SDL_DISABLE", oldState, result);
|
||||
|
||||
newState = SDL_ShowCursor(SDL_QUERY);
|
||||
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
|
||||
SDLTest_AssertCheck(state == newState, "Validate new state, expected: %i, got: %i",
|
||||
state, newState);
|
||||
state, newState);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -277,8 +274,7 @@ void _changeCursorVisibility(int state)
|
|||
*
|
||||
* @sa http://wiki.libsdl.org/SDL_ShowCursor
|
||||
*/
|
||||
int
|
||||
mouse_showCursor(void *arg)
|
||||
int mouse_showCursor(void *arg)
|
||||
{
|
||||
int currentState;
|
||||
|
||||
|
|
@ -286,7 +282,7 @@ mouse_showCursor(void *arg)
|
|||
currentState = SDL_ShowCursor(SDL_QUERY);
|
||||
SDLTest_AssertPass("Call to SDL_ShowCursor(SDL_QUERY)");
|
||||
SDLTest_AssertCheck(currentState == SDL_DISABLE || currentState == SDL_ENABLE,
|
||||
"Validate result is %i or %i, got: %i", SDL_DISABLE, SDL_ENABLE, currentState);
|
||||
"Validate result is %i or %i, got: %i", SDL_DISABLE, SDL_ENABLE, currentState);
|
||||
if (currentState == SDL_DISABLE) {
|
||||
/* Show the cursor, then hide it again */
|
||||
_changeCursorVisibility(SDL_ENABLE);
|
||||
|
|
@ -307,15 +303,14 @@ mouse_showCursor(void *arg)
|
|||
*
|
||||
* @sa http://wiki.libsdl.org/SDL_SetCursor
|
||||
*/
|
||||
int
|
||||
mouse_setCursor(void *arg)
|
||||
int mouse_setCursor(void *arg)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
/* Create a cursor */
|
||||
cursor = _initArrowCursor(_mouseArrowData);
|
||||
SDLTest_AssertPass("Call to SDL_CreateCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
|
||||
SDLTest_AssertPass("Call to SDL_CreateCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_CreateCursor() is not NULL");
|
||||
if (cursor == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
|
@ -340,15 +335,14 @@ mouse_setCursor(void *arg)
|
|||
*
|
||||
* @sa http://wiki.libsdl.org/SDL_GetCursor
|
||||
*/
|
||||
int
|
||||
mouse_getCursor(void *arg)
|
||||
int mouse_getCursor(void *arg)
|
||||
{
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
/* Get current cursor */
|
||||
cursor = SDL_GetCursor();
|
||||
SDLTest_AssertPass("Call to SDL_GetCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL");
|
||||
SDLTest_AssertPass("Call to SDL_GetCursor()");
|
||||
SDLTest_AssertCheck(cursor != NULL, "Validate result from SDL_GetCursor() is not NULL");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
|
@ -359,52 +353,51 @@ mouse_getCursor(void *arg)
|
|||
* @sa http://wiki.libsdl.org/SDL_GetRelativeMouseMode
|
||||
* @sa http://wiki.libsdl.org/SDL_SetRelativeMouseMode
|
||||
*/
|
||||
int
|
||||
mouse_getSetRelativeMouseMode(void *arg)
|
||||
int mouse_getSetRelativeMouseMode(void *arg)
|
||||
{
|
||||
int result;
|
||||
int i;
|
||||
int i;
|
||||
SDL_bool initialState;
|
||||
SDL_bool currentState;
|
||||
|
||||
/* Capture original state so we can revert back to it later */
|
||||
initialState = SDL_GetRelativeMouseMode();
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
|
||||
|
||||
/* Repeat twice to check D->D transition */
|
||||
for (i=0; i<2; i++) {
|
||||
/* Disable - should always be supported */
|
||||
result = SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
|
||||
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
|
||||
currentState = SDL_GetRelativeMouseMode();
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
|
||||
SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
|
||||
}
|
||||
|
||||
/* Repeat twice to check D->E->E transition */
|
||||
for (i=0; i<2; i++) {
|
||||
/* Enable - may not be supported */
|
||||
result = SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)");
|
||||
if (result != -1) {
|
||||
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
|
||||
currentState = SDL_GetRelativeMouseMode();
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
|
||||
SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState);
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable to check E->D transition */
|
||||
/* Repeat twice to check D->D transition */
|
||||
for (i = 0; i < 2; i++) {
|
||||
/* Disable - should always be supported */
|
||||
result = SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
|
||||
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
|
||||
currentState = SDL_GetRelativeMouseMode();
|
||||
currentState = SDL_GetRelativeMouseMode();
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
|
||||
SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
|
||||
}
|
||||
|
||||
/* Revert to original state - ignore result */
|
||||
result = SDL_SetRelativeMouseMode(initialState);
|
||||
/* Repeat twice to check D->E->E transition */
|
||||
for (i = 0; i < 2; i++) {
|
||||
/* Enable - may not be supported */
|
||||
result = SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(TRUE)");
|
||||
if (result != -1) {
|
||||
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
|
||||
currentState = SDL_GetRelativeMouseMode();
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
|
||||
SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState);
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable to check E->D transition */
|
||||
result = SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDL_SetRelativeMouseMode(FALSE)");
|
||||
SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetRelativeMouseMode, expected: 0, got: %i", result);
|
||||
currentState = SDL_GetRelativeMouseMode();
|
||||
SDLTest_AssertPass("Call to SDL_GetRelativeMouseMode()");
|
||||
SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState);
|
||||
|
||||
/* Revert to original state - ignore result */
|
||||
result = SDL_SetRelativeMouseMode(initialState);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
|
@ -417,12 +410,12 @@ mouse_getSetRelativeMouseMode(void *arg)
|
|||
*/
|
||||
SDL_Window *_createMouseSuiteTestWindow()
|
||||
{
|
||||
int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
|
||||
SDL_Window *window;
|
||||
window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0);
|
||||
SDLTest_AssertPass("SDL_CreateWindow()");
|
||||
SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
|
||||
return window;
|
||||
int posX = 100, posY = 100, width = MOUSE_TESTWINDOW_WIDTH, height = MOUSE_TESTWINDOW_HEIGHT;
|
||||
SDL_Window *window;
|
||||
window = SDL_CreateWindow("mouse_createMouseSuiteTestWindow", posX, posY, width, height, 0);
|
||||
SDLTest_AssertPass("SDL_CreateWindow()");
|
||||
SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
|
||||
return window;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -430,11 +423,11 @@ SDL_Window *_createMouseSuiteTestWindow()
|
|||
*/
|
||||
void _destroyMouseSuiteTestWindow(SDL_Window *window)
|
||||
{
|
||||
if (window != NULL) {
|
||||
SDL_DestroyWindow(window);
|
||||
window = NULL;
|
||||
SDLTest_AssertPass("SDL_DestroyWindow()");
|
||||
}
|
||||
if (window != NULL) {
|
||||
SDL_DestroyWindow(window);
|
||||
window = NULL;
|
||||
SDLTest_AssertPass("SDL_DestroyWindow()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -442,8 +435,7 @@ void _destroyMouseSuiteTestWindow(SDL_Window *window)
|
|||
*
|
||||
* @sa http://wiki.libsdl.org/SDL_WarpMouseInWindow
|
||||
*/
|
||||
int
|
||||
mouse_warpMouseInWindow(void *arg)
|
||||
int mouse_warpMouseInWindow(void *arg)
|
||||
{
|
||||
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
|
||||
int numPositions = 6;
|
||||
|
|
@ -455,45 +447,46 @@ mouse_warpMouseInWindow(void *arg)
|
|||
xPositions[0] = -1;
|
||||
xPositions[1] = 0;
|
||||
xPositions[2] = 1;
|
||||
xPositions[3] = w-1;
|
||||
xPositions[3] = w - 1;
|
||||
xPositions[4] = w;
|
||||
xPositions[5] = w+1;
|
||||
xPositions[5] = w + 1;
|
||||
yPositions[0] = -1;
|
||||
yPositions[1] = 0;
|
||||
yPositions[2] = 1;
|
||||
yPositions[3] = h-1;
|
||||
yPositions[3] = h - 1;
|
||||
yPositions[4] = h;
|
||||
yPositions[5] = h+1;
|
||||
yPositions[5] = h + 1;
|
||||
/* Create test window */
|
||||
window = _createMouseSuiteTestWindow();
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Mouse to random position inside window */
|
||||
x = SDLTest_RandomIntegerInRange(1, w-1);
|
||||
y = SDLTest_RandomIntegerInRange(1, h-1);
|
||||
x = SDLTest_RandomIntegerInRange(1, w - 1);
|
||||
y = SDLTest_RandomIntegerInRange(1, h - 1);
|
||||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
|
||||
/* Same position again */
|
||||
/* Same position again */
|
||||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
|
||||
/* Mouse to various boundary positions */
|
||||
for (i=0; i<numPositions; i++) {
|
||||
for (j=0; j<numPositions; j++) {
|
||||
x = xPositions[i];
|
||||
y = yPositions[j];
|
||||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
for (i = 0; i < numPositions; i++) {
|
||||
for (j = 0; j < numPositions; j++) {
|
||||
x = xPositions[i];
|
||||
y = yPositions[j];
|
||||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
|
||||
/* TODO: add tracking of events and check that each call generates a mouse motion event */
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("SDL_PumpEvents()");
|
||||
}
|
||||
/* TODO: add tracking of events and check that each call generates a mouse motion event */
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("SDL_PumpEvents()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Clean up test window */
|
||||
/* Clean up test window */
|
||||
_destroyMouseSuiteTestWindow(window);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
|
|
@ -504,8 +497,7 @@ mouse_warpMouseInWindow(void *arg)
|
|||
*
|
||||
* @sa http://wiki.libsdl.org/SDL_GetMouseFocus
|
||||
*/
|
||||
int
|
||||
mouse_getMouseFocus(void *arg)
|
||||
int mouse_getMouseFocus(void *arg)
|
||||
{
|
||||
const int w = MOUSE_TESTWINDOW_WIDTH, h = MOUSE_TESTWINDOW_HEIGHT;
|
||||
int x, y;
|
||||
|
|
@ -516,13 +508,15 @@ mouse_getMouseFocus(void *arg)
|
|||
focusWindow = SDL_GetMouseFocus();
|
||||
SDLTest_AssertPass("SDL_GetMouseFocus()");
|
||||
|
||||
/* Create test window */
|
||||
/* Create test window */
|
||||
window = _createMouseSuiteTestWindow();
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Mouse to random position inside window */
|
||||
x = SDLTest_RandomIntegerInRange(1, w-1);
|
||||
y = SDLTest_RandomIntegerInRange(1, h-1);
|
||||
x = SDLTest_RandomIntegerInRange(1, w - 1);
|
||||
y = SDLTest_RandomIntegerInRange(1, h - 1);
|
||||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
|
||||
|
|
@ -531,11 +525,11 @@ mouse_getMouseFocus(void *arg)
|
|||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("SDL_PumpEvents()");
|
||||
|
||||
/* Get focus with explicit window setup - focus deterministic */
|
||||
/* Get focus with explicit window setup - focus deterministic */
|
||||
focusWindow = SDL_GetMouseFocus();
|
||||
SDLTest_AssertPass("SDL_GetMouseFocus()");
|
||||
SDLTest_AssertCheck (focusWindow != NULL, "Check returned window value is not NULL");
|
||||
SDLTest_AssertCheck (focusWindow == window, "Check returned window value is test window");
|
||||
SDLTest_AssertCheck(focusWindow != NULL, "Check returned window value is not NULL");
|
||||
SDLTest_AssertCheck(focusWindow == window, "Check returned window value is test window");
|
||||
|
||||
/* Mouse to random position outside window */
|
||||
x = SDLTest_RandomIntegerInRange(-9, -1);
|
||||
|
|
@ -543,18 +537,17 @@ mouse_getMouseFocus(void *arg)
|
|||
SDL_WarpMouseInWindow(window, x, y);
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
|
||||
/* Clean up test window */
|
||||
/* Clean up test window */
|
||||
_destroyMouseSuiteTestWindow(window);
|
||||
|
||||
/* Pump events to update focus state */
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("SDL_PumpEvents()");
|
||||
|
||||
/* Get focus for non-existing window */
|
||||
/* Get focus for non-existing window */
|
||||
focusWindow = SDL_GetMouseFocus();
|
||||
SDLTest_AssertPass("SDL_GetMouseFocus()");
|
||||
SDLTest_AssertCheck (focusWindow == NULL, "Check returned window value is NULL");
|
||||
|
||||
SDLTest_AssertCheck(focusWindow == NULL, "Check returned window value is NULL");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
|
@ -562,35 +555,45 @@ mouse_getMouseFocus(void *arg)
|
|||
/* ================= Test References ================== */
|
||||
|
||||
/* Mouse test cases */
|
||||
static const SDLTest_TestCaseReference mouseTest1 =
|
||||
{ (SDLTest_TestCaseFp)mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest1 = {
|
||||
(SDLTest_TestCaseFp)mouse_getMouseState, "mouse_getMouseState", "Check call to SDL_GetMouseState", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mouseTest2 =
|
||||
{ (SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest2 = {
|
||||
(SDLTest_TestCaseFp)mouse_getRelativeMouseState, "mouse_getRelativeMouseState", "Check call to SDL_GetRelativeMouseState", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mouseTest3 =
|
||||
{ (SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest3 = {
|
||||
(SDLTest_TestCaseFp)mouse_createFreeCursor, "mouse_createFreeCursor", "Check call to SDL_CreateCursor and SDL_FreeCursor", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mouseTest4 =
|
||||
{ (SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest4 = {
|
||||
(SDLTest_TestCaseFp)mouse_showCursor, "mouse_showCursor", "Check call to SDL_ShowCursor", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mouseTest5 =
|
||||
{ (SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest5 = {
|
||||
(SDLTest_TestCaseFp)mouse_setCursor, "mouse_setCursor", "Check call to SDL_SetCursor", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mouseTest6 =
|
||||
{ (SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest6 = {
|
||||
(SDLTest_TestCaseFp)mouse_getCursor, "mouse_getCursor", "Check call to SDL_GetCursor", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mouseTest7 =
|
||||
{ (SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest7 = {
|
||||
(SDLTest_TestCaseFp)mouse_warpMouseInWindow, "mouse_warpMouseInWindow", "Check call to SDL_WarpMouseInWindow", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mouseTest8 =
|
||||
{ (SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest8 = {
|
||||
(SDLTest_TestCaseFp)mouse_getMouseFocus, "mouse_getMouseFocus", "Check call to SDL_getMouseFocus", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mouseTest9 =
|
||||
{ (SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest9 = {
|
||||
(SDLTest_TestCaseFp)mouse_createFreeColorCursor, "mouse_createFreeColorCursor", "Check call to SDL_CreateColorCursor and SDL_FreeCursor", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference mouseTest10 =
|
||||
{ (SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference mouseTest10 = {
|
||||
(SDLTest_TestCaseFp)mouse_getSetRelativeMouseMode, "mouse_getSetRelativeMouseMode", "Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Mouse test cases */
|
||||
static const SDLTest_TestCaseReference *mouseTests[] = {
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@
|
|||
|
||||
/* Definition of all RGB formats used to test pixel conversions */
|
||||
const int _numRGBPixelFormats = 31;
|
||||
Uint32 _RGBPixelFormats[] =
|
||||
{
|
||||
Uint32 _RGBPixelFormats[] = {
|
||||
SDL_PIXELFORMAT_INDEX1LSB,
|
||||
SDL_PIXELFORMAT_INDEX1MSB,
|
||||
SDL_PIXELFORMAT_INDEX4LSB,
|
||||
|
|
@ -44,9 +43,8 @@ Uint32 _RGBPixelFormats[] =
|
|||
SDL_PIXELFORMAT_ABGR8888,
|
||||
SDL_PIXELFORMAT_BGRA8888,
|
||||
SDL_PIXELFORMAT_ARGB2101010
|
||||
};
|
||||
const char* _RGBPixelFormatsVerbose[] =
|
||||
{
|
||||
};
|
||||
const char *_RGBPixelFormatsVerbose[] = {
|
||||
"SDL_PIXELFORMAT_INDEX1LSB",
|
||||
"SDL_PIXELFORMAT_INDEX1MSB",
|
||||
"SDL_PIXELFORMAT_INDEX4LSB",
|
||||
|
|
@ -78,12 +76,11 @@ const char* _RGBPixelFormatsVerbose[] =
|
|||
"SDL_PIXELFORMAT_ABGR8888",
|
||||
"SDL_PIXELFORMAT_BGRA8888",
|
||||
"SDL_PIXELFORMAT_ARGB2101010"
|
||||
};
|
||||
};
|
||||
|
||||
/* Definition of all Non-RGB formats used to test pixel conversions */
|
||||
const int _numNonRGBPixelFormats = 7;
|
||||
Uint32 _nonRGBPixelFormats[] =
|
||||
{
|
||||
Uint32 _nonRGBPixelFormats[] = {
|
||||
SDL_PIXELFORMAT_YV12,
|
||||
SDL_PIXELFORMAT_IYUV,
|
||||
SDL_PIXELFORMAT_YUY2,
|
||||
|
|
@ -91,9 +88,8 @@ Uint32 _nonRGBPixelFormats[] =
|
|||
SDL_PIXELFORMAT_YVYU,
|
||||
SDL_PIXELFORMAT_NV12,
|
||||
SDL_PIXELFORMAT_NV21
|
||||
};
|
||||
const char* _nonRGBPixelFormatsVerbose[] =
|
||||
{
|
||||
};
|
||||
const char *_nonRGBPixelFormatsVerbose[] = {
|
||||
"SDL_PIXELFORMAT_YV12",
|
||||
"SDL_PIXELFORMAT_IYUV",
|
||||
"SDL_PIXELFORMAT_YUY2",
|
||||
|
|
@ -101,20 +97,18 @@ const char* _nonRGBPixelFormatsVerbose[] =
|
|||
"SDL_PIXELFORMAT_YVYU",
|
||||
"SDL_PIXELFORMAT_NV12",
|
||||
"SDL_PIXELFORMAT_NV21"
|
||||
};
|
||||
};
|
||||
|
||||
/* Definition of some invalid formats for negative tests */
|
||||
const int _numInvalidPixelFormats = 2;
|
||||
Uint32 _invalidPixelFormats[] =
|
||||
{
|
||||
Uint32 _invalidPixelFormats[] = {
|
||||
0xfffffffe,
|
||||
0xffffffff
|
||||
};
|
||||
const char* _invalidPixelFormatsVerbose[] =
|
||||
{
|
||||
};
|
||||
const char *_invalidPixelFormatsVerbose[] = {
|
||||
"SDL_PIXELFORMAT_UNKNOWN",
|
||||
"SDL_PIXELFORMAT_UNKNOWN"
|
||||
};
|
||||
};
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
|
|
@ -124,105 +118,104 @@ const char* _invalidPixelFormatsVerbose[] =
|
|||
* @sa http://wiki.libsdl.org/SDL_AllocFormat
|
||||
* @sa http://wiki.libsdl.org/SDL_FreeFormat
|
||||
*/
|
||||
int
|
||||
pixels_allocFreeFormat(void *arg)
|
||||
int pixels_allocFreeFormat(void *arg)
|
||||
{
|
||||
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
|
||||
const char *expectedError = "Parameter 'format' is invalid";
|
||||
const char *error;
|
||||
int i;
|
||||
Uint32 format;
|
||||
Uint32 masks;
|
||||
SDL_PixelFormat* result;
|
||||
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
|
||||
const char *expectedError = "Parameter 'format' is invalid";
|
||||
const char *error;
|
||||
int i;
|
||||
Uint32 format;
|
||||
Uint32 masks;
|
||||
SDL_PixelFormat *result;
|
||||
|
||||
/* Blank/unknown format */
|
||||
format = 0;
|
||||
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
|
||||
|
||||
/* Allocate format */
|
||||
result = SDL_AllocFormat(format);
|
||||
SDLTest_AssertPass("Call to SDL_AllocFormat()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %u, got %u", format, result->format);
|
||||
SDLTest_AssertCheck(result->BitsPerPixel == 0, "Verify value of result.BitsPerPixel; expected: 0, got %u", result->BitsPerPixel);
|
||||
SDLTest_AssertCheck(result->BytesPerPixel == 0, "Verify value of result.BytesPerPixel; expected: 0, got %u", result->BytesPerPixel);
|
||||
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
|
||||
SDLTest_AssertCheck(masks == 0, "Verify value of result.[RGBA]mask combined; expected: 0, got %u", masks);
|
||||
|
||||
/* Deallocate again */
|
||||
SDL_FreeFormat(result);
|
||||
SDLTest_AssertPass("Call to SDL_FreeFormat()");
|
||||
}
|
||||
|
||||
/* RGB formats */
|
||||
for (i = 0; i < _numRGBPixelFormats; i++) {
|
||||
format = _RGBPixelFormats[i];
|
||||
SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
|
||||
/* Blank/unknown format */
|
||||
format = 0;
|
||||
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", unknownFormat, format);
|
||||
|
||||
/* Allocate format */
|
||||
result = SDL_AllocFormat(format);
|
||||
SDLTest_AssertPass("Call to SDL_AllocFormat()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %u, got %u", format, result->format);
|
||||
SDLTest_AssertCheck(result->BitsPerPixel > 0, "Verify value of result.BitsPerPixel; expected: >0, got %u", result->BitsPerPixel);
|
||||
SDLTest_AssertCheck(result->BytesPerPixel > 0, "Verify value of result.BytesPerPixel; expected: >0, got %u", result->BytesPerPixel);
|
||||
if (result->palette != NULL) {
|
||||
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
|
||||
SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %u", masks);
|
||||
}
|
||||
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %" SDL_PRIu32 ", got %" SDL_PRIu32, format, result->format);
|
||||
SDLTest_AssertCheck(result->BitsPerPixel == 0, "Verify value of result.BitsPerPixel; expected: 0, got %u", result->BitsPerPixel);
|
||||
SDLTest_AssertCheck(result->BytesPerPixel == 0, "Verify value of result.BytesPerPixel; expected: 0, got %u", result->BytesPerPixel);
|
||||
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
|
||||
SDLTest_AssertCheck(masks == 0, "Verify value of result.[RGBA]mask combined; expected: 0, got %" SDL_PRIu32, masks);
|
||||
|
||||
/* Deallocate again */
|
||||
SDL_FreeFormat(result);
|
||||
SDLTest_AssertPass("Call to SDL_FreeFormat()");
|
||||
/* Deallocate again */
|
||||
SDL_FreeFormat(result);
|
||||
SDLTest_AssertPass("Call to SDL_FreeFormat()");
|
||||
}
|
||||
}
|
||||
|
||||
/* Non-RGB formats */
|
||||
for (i = 0; i < _numNonRGBPixelFormats; i++) {
|
||||
format = _nonRGBPixelFormats[i];
|
||||
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
|
||||
/* RGB formats */
|
||||
for (i = 0; i < _numRGBPixelFormats; i++) {
|
||||
format = _RGBPixelFormats[i];
|
||||
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", _RGBPixelFormatsVerbose[i], format);
|
||||
|
||||
/* Try to allocate format */
|
||||
result = SDL_AllocFormat(format);
|
||||
SDLTest_AssertPass("Call to SDL_AllocFormat()");
|
||||
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
|
||||
}
|
||||
/* Allocate format */
|
||||
result = SDL_AllocFormat(format);
|
||||
SDLTest_AssertPass("Call to SDL_AllocFormat()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result->format == format, "Verify value of result.format; expected: %" SDL_PRIu32 ", got %" SDL_PRIu32, format, result->format);
|
||||
SDLTest_AssertCheck(result->BitsPerPixel > 0, "Verify value of result.BitsPerPixel; expected: >0, got %u", result->BitsPerPixel);
|
||||
SDLTest_AssertCheck(result->BytesPerPixel > 0, "Verify value of result.BytesPerPixel; expected: >0, got %u", result->BytesPerPixel);
|
||||
if (result->palette != NULL) {
|
||||
masks = result->Rmask | result->Gmask | result->Bmask | result->Amask;
|
||||
SDLTest_AssertCheck(masks > 0, "Verify value of result.[RGBA]mask combined; expected: >0, got %" SDL_PRIu32, masks);
|
||||
}
|
||||
|
||||
/* Negative cases */
|
||||
/* Deallocate again */
|
||||
SDL_FreeFormat(result);
|
||||
SDLTest_AssertPass("Call to SDL_FreeFormat()");
|
||||
}
|
||||
}
|
||||
|
||||
/* Invalid Formats */
|
||||
for (i = 0; i < _numInvalidPixelFormats; i++) {
|
||||
/* Non-RGB formats */
|
||||
for (i = 0; i < _numNonRGBPixelFormats; i++) {
|
||||
format = _nonRGBPixelFormats[i];
|
||||
SDLTest_Log("non-RGB Format: %s (%" SDL_PRIu32 ")", _nonRGBPixelFormatsVerbose[i], format);
|
||||
|
||||
/* Try to allocate format */
|
||||
result = SDL_AllocFormat(format);
|
||||
SDLTest_AssertPass("Call to SDL_AllocFormat()");
|
||||
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
|
||||
}
|
||||
|
||||
/* Negative cases */
|
||||
|
||||
/* Invalid Formats */
|
||||
for (i = 0; i < _numInvalidPixelFormats; i++) {
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
format = _invalidPixelFormats[i];
|
||||
result = SDL_AllocFormat(format);
|
||||
SDLTest_AssertPass("Call to SDL_AllocFormat(%" SDL_PRIu32 ")", format);
|
||||
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||
if (error != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||
}
|
||||
}
|
||||
|
||||
/* Invalid free pointer */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
format = _invalidPixelFormats[i];
|
||||
result = SDL_AllocFormat(format);
|
||||
SDLTest_AssertPass("Call to SDL_AllocFormat(%u)", format);
|
||||
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
|
||||
SDL_FreeFormat(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_FreeFormat(NULL)");
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||
if (error != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||
}
|
||||
}
|
||||
|
||||
/* Invalid free pointer */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
SDL_FreeFormat(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_FreeFormat(NULL)");
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||
if (error != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -230,83 +223,82 @@ pixels_allocFreeFormat(void *arg)
|
|||
*
|
||||
* @sa http://wiki.libsdl.org/SDL_GetPixelFormatName
|
||||
*/
|
||||
int
|
||||
pixels_getPixelFormatName(void *arg)
|
||||
int pixels_getPixelFormatName(void *arg)
|
||||
{
|
||||
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
|
||||
const char *error;
|
||||
int i;
|
||||
Uint32 format;
|
||||
const char *result;
|
||||
const char *unknownFormat = "SDL_PIXELFORMAT_UNKNOWN";
|
||||
const char *error;
|
||||
int i;
|
||||
Uint32 format;
|
||||
const char *result;
|
||||
|
||||
/* Blank/undefined format */
|
||||
format = 0;
|
||||
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
|
||||
|
||||
/* Get name of format */
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, unknownFormat) == 0,
|
||||
"Verify result text; expected: %s, got %s", unknownFormat, result);
|
||||
}
|
||||
|
||||
/* RGB formats */
|
||||
for (i = 0; i < _numRGBPixelFormats; i++) {
|
||||
format = _RGBPixelFormats[i];
|
||||
SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
|
||||
/* Blank/undefined format */
|
||||
format = 0;
|
||||
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", unknownFormat, format);
|
||||
|
||||
/* Get name of format */
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, _RGBPixelFormatsVerbose[i]) == 0,
|
||||
"Verify result text; expected: %s, got %s", _RGBPixelFormatsVerbose[i], result);
|
||||
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, unknownFormat) == 0,
|
||||
"Verify result text; expected: %s, got %s", unknownFormat, result);
|
||||
}
|
||||
}
|
||||
|
||||
/* Non-RGB formats */
|
||||
for (i = 0; i < _numNonRGBPixelFormats; i++) {
|
||||
format = _nonRGBPixelFormats[i];
|
||||
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
|
||||
/* RGB formats */
|
||||
for (i = 0; i < _numRGBPixelFormats; i++) {
|
||||
format = _RGBPixelFormats[i];
|
||||
SDLTest_Log("RGB Format: %s (%" SDL_PRIu32 ")", _RGBPixelFormatsVerbose[i], format);
|
||||
|
||||
/* Get name of format */
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, _nonRGBPixelFormatsVerbose[i]) == 0,
|
||||
"Verify result text; expected: %s, got %s", _nonRGBPixelFormatsVerbose[i], result);
|
||||
/* Get name of format */
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, _RGBPixelFormatsVerbose[i]) == 0,
|
||||
"Verify result text; expected: %s, got %s", _RGBPixelFormatsVerbose[i], result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Negative cases */
|
||||
/* Non-RGB formats */
|
||||
for (i = 0; i < _numNonRGBPixelFormats; i++) {
|
||||
format = _nonRGBPixelFormats[i];
|
||||
SDLTest_Log("non-RGB Format: %s (%" SDL_PRIu32 ")", _nonRGBPixelFormatsVerbose[i], format);
|
||||
|
||||
/* Invalid Formats */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
for (i = 0; i < _numInvalidPixelFormats; i++) {
|
||||
format = _invalidPixelFormats[i];
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%u)", format);
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result[0] != '\0',
|
||||
"Verify result is non-empty; got: %s", result);
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, _invalidPixelFormatsVerbose[i]) == 0,
|
||||
"Validate name is UNKNOWN, expected: '%s', got: '%s'", _invalidPixelFormatsVerbose[i], result);
|
||||
/* Get name of format */
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, _nonRGBPixelFormatsVerbose[i]) == 0,
|
||||
"Verify result text; expected: %s, got %s", _nonRGBPixelFormatsVerbose[i], result);
|
||||
}
|
||||
}
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error == NULL || error[0] == '\0', "Validate that error message is empty");
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
/* Negative cases */
|
||||
|
||||
/* Invalid Formats */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
for (i = 0; i < _numInvalidPixelFormats; i++) {
|
||||
format = _invalidPixelFormats[i];
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%" SDL_PRIu32 ")", format);
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result[0] != '\0',
|
||||
"Verify result is non-empty; got: %s", result);
|
||||
SDLTest_AssertCheck(SDL_strcmp(result, _invalidPixelFormatsVerbose[i]) == 0,
|
||||
"Validate name is UNKNOWN, expected: '%s', got: '%s'", _invalidPixelFormatsVerbose[i], result);
|
||||
}
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error == NULL || error[0] == '\0', "Validate that error message is empty");
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -315,88 +307,88 @@ pixels_getPixelFormatName(void *arg)
|
|||
* @sa http://wiki.libsdl.org/SDL_AllocPalette
|
||||
* @sa http://wiki.libsdl.org/SDL_FreePalette
|
||||
*/
|
||||
int
|
||||
pixels_allocFreePalette(void *arg)
|
||||
int pixels_allocFreePalette(void *arg)
|
||||
{
|
||||
const char *expectedError1 = "Parameter 'ncolors' is invalid";
|
||||
const char *expectedError2 = "Parameter 'palette' is invalid";
|
||||
const char *error;
|
||||
int variation;
|
||||
int i;
|
||||
int ncolors;
|
||||
SDL_Palette* result;
|
||||
const char *expectedError1 = "Parameter 'ncolors' is invalid";
|
||||
const char *expectedError2 = "Parameter 'palette' is invalid";
|
||||
const char *error;
|
||||
int variation;
|
||||
int i;
|
||||
int ncolors;
|
||||
SDL_Palette *result;
|
||||
|
||||
/* Allocate palette */
|
||||
for (variation = 1; variation <= 3; variation++) {
|
||||
switch (variation) {
|
||||
/* Just one color */
|
||||
case 1:
|
||||
ncolors = 1;
|
||||
break;
|
||||
/* Two colors */
|
||||
case 2:
|
||||
ncolors = 2;
|
||||
break;
|
||||
/* More than two colors */
|
||||
case 3:
|
||||
ncolors = SDLTest_RandomIntegerInRange(8, 16);
|
||||
break;
|
||||
/* Allocate palette */
|
||||
for (variation = 1; variation <= 3; variation++) {
|
||||
switch (variation) {
|
||||
/* Just one color */
|
||||
default:
|
||||
case 1:
|
||||
ncolors = 1;
|
||||
break;
|
||||
/* Two colors */
|
||||
case 2:
|
||||
ncolors = 2;
|
||||
break;
|
||||
/* More than two colors */
|
||||
case 3:
|
||||
ncolors = SDLTest_RandomIntegerInRange(8, 16);
|
||||
break;
|
||||
}
|
||||
|
||||
result = SDL_AllocPalette(ncolors);
|
||||
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result->ncolors == ncolors, "Verify value of result.ncolors; expected: %u, got %u", ncolors, result->ncolors);
|
||||
if (result->ncolors > 0) {
|
||||
SDLTest_AssertCheck(result->colors != NULL, "Verify value of result.colors is not NULL");
|
||||
if (result->colors != NULL) {
|
||||
for (i = 0; i < result->ncolors; i++) {
|
||||
SDLTest_AssertCheck(result->colors[i].r == 255, "Verify value of result.colors[%d].r; expected: 255, got %u", i, result->colors[i].r);
|
||||
SDLTest_AssertCheck(result->colors[i].g == 255, "Verify value of result.colors[%d].g; expected: 255, got %u", i, result->colors[i].g);
|
||||
SDLTest_AssertCheck(result->colors[i].b == 255, "Verify value of result.colors[%d].b; expected: 255, got %u", i, result->colors[i].b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Deallocate again */
|
||||
SDL_FreePalette(result);
|
||||
SDLTest_AssertPass("Call to SDL_FreePalette()");
|
||||
}
|
||||
}
|
||||
|
||||
result = SDL_AllocPalette(ncolors);
|
||||
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
SDLTest_AssertCheck(result->ncolors == ncolors, "Verify value of result.ncolors; expected: %u, got %u", ncolors, result->ncolors);
|
||||
if (result->ncolors > 0) {
|
||||
SDLTest_AssertCheck(result->colors != NULL, "Verify value of result.colors is not NULL");
|
||||
if (result->colors != NULL) {
|
||||
for(i = 0; i < result->ncolors; i++) {
|
||||
SDLTest_AssertCheck(result->colors[i].r == 255, "Verify value of result.colors[%d].r; expected: 255, got %u", i, result->colors[i].r);
|
||||
SDLTest_AssertCheck(result->colors[i].g == 255, "Verify value of result.colors[%d].g; expected: 255, got %u", i, result->colors[i].g);
|
||||
SDLTest_AssertCheck(result->colors[i].b == 255, "Verify value of result.colors[%d].b; expected: 255, got %u", i, result->colors[i].b);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Negative cases */
|
||||
|
||||
/* Deallocate again */
|
||||
SDL_FreePalette(result);
|
||||
SDLTest_AssertPass("Call to SDL_FreePalette()");
|
||||
/* Invalid number of colors */
|
||||
for (ncolors = 0; ncolors > -3; ncolors--) {
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
result = SDL_AllocPalette(ncolors);
|
||||
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
|
||||
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||
if (error != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError1, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Negative cases */
|
||||
|
||||
/* Invalid number of colors */
|
||||
for (ncolors = 0; ncolors > -3; ncolors--) {
|
||||
/* Invalid free pointer */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
result = SDL_AllocPalette(ncolors);
|
||||
SDLTest_AssertPass("Call to SDL_AllocPalette(%d)", ncolors);
|
||||
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
|
||||
SDL_FreePalette(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_FreePalette(NULL)");
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||
if (error != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError1) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError1, error);
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError2, error);
|
||||
}
|
||||
}
|
||||
|
||||
/* Invalid free pointer */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
SDL_FreePalette(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_FreePalette(NULL)");
|
||||
error = SDL_GetError();
|
||||
SDLTest_AssertPass("Call to SDL_GetError()");
|
||||
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
|
||||
if (error != NULL) {
|
||||
SDLTest_AssertCheck(SDL_strcmp(error, expectedError2) == 0,
|
||||
"Validate error message, expected: '%s', got: '%s'", expectedError2, error);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -426,6 +418,7 @@ pixels_calcGammaRamp(void *arg)
|
|||
for (variation = 0; variation < 4; variation++) {
|
||||
switch (variation) {
|
||||
/* gamma = 0 all black */
|
||||
default:
|
||||
case 0:
|
||||
gamma = 0.0f;
|
||||
break;
|
||||
|
|
@ -505,11 +498,13 @@ pixels_calcGammaRamp(void *arg)
|
|||
/* ================= Test References ================== */
|
||||
|
||||
/* Pixels test cases */
|
||||
static const SDLTest_TestCaseReference pixelsTest1 =
|
||||
{ (SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference pixelsTest1 = {
|
||||
(SDLTest_TestCaseFp)pixels_allocFreeFormat, "pixels_allocFreeFormat", "Call to SDL_AllocFormat and SDL_FreeFormat", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference pixelsTest2 =
|
||||
{ (SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference pixelsTest2 = {
|
||||
(SDLTest_TestCaseFp)pixels_allocFreePalette, "pixels_allocFreePalette", "Call to SDL_AllocPalette and SDL_FreePalette", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference pixelsTest3 =
|
||||
{ (SDLTest_TestCaseFp)pixels_calcGammaRamp, "pixels_calcGammaRamp", "Call to SDL_CalculateGammaRamp", TEST_ENABLED };
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
* compare them directly, so we push it through a function to keep the
|
||||
* compiler quiet. --ryan.
|
||||
*/
|
||||
static int _compareSizeOfType( size_t sizeoftype, size_t hardcodetype )
|
||||
static int _compareSizeOfType(size_t sizeoftype, size_t hardcodetype)
|
||||
{
|
||||
return sizeoftype != hardcodetype;
|
||||
}
|
||||
|
|
@ -31,21 +31,21 @@ static int _compareSizeOfType( size_t sizeoftype, size_t hardcodetype )
|
|||
*/
|
||||
int platform_testTypes(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
ret = _compareSizeOfType( sizeof(Uint8), 1 );
|
||||
SDLTest_AssertCheck( ret == 0, "sizeof(Uint8) = %lu, expected 1", (unsigned long)sizeof(Uint8) );
|
||||
ret = _compareSizeOfType(sizeof(Uint8), 1);
|
||||
SDLTest_AssertCheck(ret == 0, "sizeof(Uint8) = %u, expected 1", (unsigned int)sizeof(Uint8));
|
||||
|
||||
ret = _compareSizeOfType( sizeof(Uint16), 2 );
|
||||
SDLTest_AssertCheck( ret == 0, "sizeof(Uint16) = %lu, expected 2", (unsigned long)sizeof(Uint16) );
|
||||
ret = _compareSizeOfType(sizeof(Uint16), 2);
|
||||
SDLTest_AssertCheck(ret == 0, "sizeof(Uint16) = %u, expected 2", (unsigned int)sizeof(Uint16));
|
||||
|
||||
ret = _compareSizeOfType( sizeof(Uint32), 4 );
|
||||
SDLTest_AssertCheck( ret == 0, "sizeof(Uint32) = %lu, expected 4", (unsigned long)sizeof(Uint32) );
|
||||
ret = _compareSizeOfType(sizeof(Uint32), 4);
|
||||
SDLTest_AssertCheck(ret == 0, "sizeof(Uint32) = %u, expected 4", (unsigned int)sizeof(Uint32));
|
||||
|
||||
ret = _compareSizeOfType( sizeof(Uint64), 8 );
|
||||
SDLTest_AssertCheck( ret == 0, "sizeof(Uint64) = %lu, expected 8", (unsigned long)sizeof(Uint64) );
|
||||
ret = _compareSizeOfType(sizeof(Uint64), 8);
|
||||
SDLTest_AssertCheck(ret == 0, "sizeof(Uint64) = %u, expected 8", (unsigned int)sizeof(Uint64));
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,9 +61,10 @@ int platform_testEndianessAndSwap(void *arg)
|
|||
Uint32 value32 = 0xEFBEADDE;
|
||||
Uint32 swapped32 = 0xDEADBEEF;
|
||||
|
||||
union {
|
||||
double d;
|
||||
Uint32 ui32[2];
|
||||
union
|
||||
{
|
||||
double d;
|
||||
Uint32 ui32[2];
|
||||
} value_double;
|
||||
|
||||
Uint64 value64, swapped64;
|
||||
|
|
@ -75,17 +76,17 @@ int platform_testEndianessAndSwap(void *arg)
|
|||
swapped64 |= 0xDEADBEEF;
|
||||
value_double.d = 3.141593;
|
||||
|
||||
if ((*((char *) &value) >> 4) == 0x1) {
|
||||
if ((*((char *)&value) >> 4) == 0x1) {
|
||||
real_byteorder = SDL_BIG_ENDIAN;
|
||||
} else {
|
||||
real_byteorder = SDL_LIL_ENDIAN;
|
||||
}
|
||||
|
||||
/* Test endianness. */
|
||||
SDLTest_AssertCheck( real_byteorder == SDL_BYTEORDER,
|
||||
"Machine detected as %s endian, appears to be %s endian.",
|
||||
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
|
||||
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" );
|
||||
SDLTest_AssertCheck(real_byteorder == SDL_BYTEORDER,
|
||||
"Machine detected as %s endian, appears to be %s endian.",
|
||||
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
|
||||
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
|
||||
|
||||
if (value_double.ui32[0] == 0x82c2bd7f && value_double.ui32[1] == 0x400921fb) {
|
||||
real_floatwordorder = SDL_LIL_ENDIAN;
|
||||
|
|
@ -94,27 +95,28 @@ int platform_testEndianessAndSwap(void *arg)
|
|||
}
|
||||
|
||||
/* Test endianness. */
|
||||
SDLTest_AssertCheck( real_floatwordorder == SDL_FLOATWORDORDER,
|
||||
"Machine detected as having %s endian float word order, appears to be %s endian.",
|
||||
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big",
|
||||
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big" : "unknown" );
|
||||
SDLTest_AssertCheck(real_floatwordorder == SDL_FLOATWORDORDER,
|
||||
"Machine detected as having %s endian float word order, appears to be %s endian.",
|
||||
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big",
|
||||
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big"
|
||||
: "unknown");
|
||||
|
||||
/* Test 16 swap. */
|
||||
SDLTest_AssertCheck( SDL_Swap16(value16) == swapped16,
|
||||
"SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
|
||||
value16, SDL_Swap16(value16) );
|
||||
SDLTest_AssertCheck(SDL_Swap16(value16) == swapped16,
|
||||
"SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
|
||||
value16, SDL_Swap16(value16));
|
||||
|
||||
/* Test 32 swap. */
|
||||
SDLTest_AssertCheck( SDL_Swap32(value32) == swapped32,
|
||||
"SDL_Swap32(): 32 bit swapped: 0x%X => 0x%X",
|
||||
value32, SDL_Swap32(value32) );
|
||||
SDLTest_AssertCheck(SDL_Swap32(value32) == swapped32,
|
||||
"SDL_Swap32(): 32 bit swapped: 0x%" SDL_PRIX32 " => 0x%" SDL_PRIX32,
|
||||
value32, SDL_Swap32(value32));
|
||||
|
||||
/* Test 64 swap. */
|
||||
SDLTest_AssertCheck( SDL_Swap64(value64) == swapped64,
|
||||
"SDL_Swap64(): 64 bit swapped: 0x%"SDL_PRIX64" => 0x%"SDL_PRIX64,
|
||||
value64, SDL_Swap64(value64) );
|
||||
SDLTest_AssertCheck(SDL_Swap64(value64) == swapped64,
|
||||
"SDL_Swap64(): 64 bit swapped: 0x%" SDL_PRIX64 " => 0x%" SDL_PRIX64,
|
||||
value64, SDL_Swap64(value64));
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
|
|
@ -126,41 +128,41 @@ int platform_testEndianessAndSwap(void *arg)
|
|||
* http://wiki.libsdl.org/SDL_GetRevision
|
||||
* http://wiki.libsdl.org/SDL_GetRevisionNumber
|
||||
*/
|
||||
int platform_testGetFunctions (void *arg)
|
||||
int platform_testGetFunctions(void *arg)
|
||||
{
|
||||
char *platform;
|
||||
char *revision;
|
||||
int ret;
|
||||
size_t len;
|
||||
char *platform;
|
||||
char *revision;
|
||||
int ret;
|
||||
size_t len;
|
||||
|
||||
platform = (char *)SDL_GetPlatform();
|
||||
SDLTest_AssertPass("SDL_GetPlatform()");
|
||||
SDLTest_AssertCheck(platform != NULL, "SDL_GetPlatform() != NULL");
|
||||
if (platform != NULL) {
|
||||
len = SDL_strlen(platform);
|
||||
SDLTest_AssertCheck(len > 0,
|
||||
"SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i",
|
||||
platform,
|
||||
(int) len);
|
||||
}
|
||||
platform = (char *)SDL_GetPlatform();
|
||||
SDLTest_AssertPass("SDL_GetPlatform()");
|
||||
SDLTest_AssertCheck(platform != NULL, "SDL_GetPlatform() != NULL");
|
||||
if (platform != NULL) {
|
||||
len = SDL_strlen(platform);
|
||||
SDLTest_AssertCheck(len > 0,
|
||||
"SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i",
|
||||
platform,
|
||||
(int)len);
|
||||
}
|
||||
|
||||
ret = SDL_GetCPUCount();
|
||||
SDLTest_AssertPass("SDL_GetCPUCount()");
|
||||
SDLTest_AssertCheck(ret > 0,
|
||||
"SDL_GetCPUCount(): expected count > 0, was: %i",
|
||||
ret);
|
||||
ret = SDL_GetCPUCount();
|
||||
SDLTest_AssertPass("SDL_GetCPUCount()");
|
||||
SDLTest_AssertCheck(ret > 0,
|
||||
"SDL_GetCPUCount(): expected count > 0, was: %i",
|
||||
ret);
|
||||
|
||||
ret = SDL_GetCPUCacheLineSize();
|
||||
SDLTest_AssertPass("SDL_GetCPUCacheLineSize()");
|
||||
SDLTest_AssertCheck(ret >= 0,
|
||||
"SDL_GetCPUCacheLineSize(): expected size >= 0, was: %i",
|
||||
ret);
|
||||
ret = SDL_GetCPUCacheLineSize();
|
||||
SDLTest_AssertPass("SDL_GetCPUCacheLineSize()");
|
||||
SDLTest_AssertCheck(ret >= 0,
|
||||
"SDL_GetCPUCacheLineSize(): expected size >= 0, was: %i",
|
||||
ret);
|
||||
|
||||
revision = (char *)SDL_GetRevision();
|
||||
SDLTest_AssertPass("SDL_GetRevision()");
|
||||
SDLTest_AssertCheck(revision != NULL, "SDL_GetRevision() != NULL");
|
||||
revision = (char *)SDL_GetRevision();
|
||||
SDLTest_AssertPass("SDL_GetRevision()");
|
||||
SDLTest_AssertCheck(revision != NULL, "SDL_GetRevision() != NULL");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
|
|
@ -177,41 +179,41 @@ int platform_testGetFunctions (void *arg)
|
|||
* http://wiki.libsdl.org/SDL_HasSSE42
|
||||
* http://wiki.libsdl.org/SDL_HasAVX
|
||||
*/
|
||||
int platform_testHasFunctions (void *arg)
|
||||
int platform_testHasFunctions(void *arg)
|
||||
{
|
||||
/* TODO: independently determine and compare values as well */
|
||||
/* TODO: independently determine and compare values as well */
|
||||
|
||||
SDL_HasRDTSC();
|
||||
SDLTest_AssertPass("SDL_HasRDTSC()");
|
||||
SDL_HasRDTSC();
|
||||
SDLTest_AssertPass("SDL_HasRDTSC()");
|
||||
|
||||
SDL_HasAltiVec();
|
||||
SDLTest_AssertPass("SDL_HasAltiVec()");
|
||||
SDL_HasAltiVec();
|
||||
SDLTest_AssertPass("SDL_HasAltiVec()");
|
||||
|
||||
SDL_HasMMX();
|
||||
SDLTest_AssertPass("SDL_HasMMX()");
|
||||
SDL_HasMMX();
|
||||
SDLTest_AssertPass("SDL_HasMMX()");
|
||||
|
||||
SDL_Has3DNow();
|
||||
SDLTest_AssertPass("SDL_Has3DNow()");
|
||||
SDL_Has3DNow();
|
||||
SDLTest_AssertPass("SDL_Has3DNow()");
|
||||
|
||||
SDL_HasSSE();
|
||||
SDLTest_AssertPass("SDL_HasSSE()");
|
||||
SDL_HasSSE();
|
||||
SDLTest_AssertPass("SDL_HasSSE()");
|
||||
|
||||
SDL_HasSSE2();
|
||||
SDLTest_AssertPass("SDL_HasSSE2()");
|
||||
SDL_HasSSE2();
|
||||
SDLTest_AssertPass("SDL_HasSSE2()");
|
||||
|
||||
SDL_HasSSE3();
|
||||
SDLTest_AssertPass("SDL_HasSSE3()");
|
||||
SDL_HasSSE3();
|
||||
SDLTest_AssertPass("SDL_HasSSE3()");
|
||||
|
||||
SDL_HasSSE41();
|
||||
SDLTest_AssertPass("SDL_HasSSE41()");
|
||||
SDL_HasSSE41();
|
||||
SDLTest_AssertPass("SDL_HasSSE41()");
|
||||
|
||||
SDL_HasSSE42();
|
||||
SDLTest_AssertPass("SDL_HasSSE42()");
|
||||
SDL_HasSSE42();
|
||||
SDLTest_AssertPass("SDL_HasSSE42()");
|
||||
|
||||
SDL_HasAVX();
|
||||
SDLTest_AssertPass("SDL_HasAVX()");
|
||||
SDL_HasAVX();
|
||||
SDLTest_AssertPass("SDL_HasAVX()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
|
|
@ -221,67 +223,65 @@ int platform_testHasFunctions (void *arg)
|
|||
*/
|
||||
int platform_testGetVersion(void *arg)
|
||||
{
|
||||
SDL_version linked;
|
||||
int major = SDL_MAJOR_VERSION;
|
||||
int minor = SDL_MINOR_VERSION;
|
||||
SDL_version linked;
|
||||
int major = SDL_MAJOR_VERSION;
|
||||
int minor = SDL_MINOR_VERSION;
|
||||
|
||||
SDL_GetVersion(&linked);
|
||||
SDLTest_AssertCheck( linked.major >= major,
|
||||
"SDL_GetVersion(): returned major %i (>= %i)",
|
||||
linked.major,
|
||||
major);
|
||||
SDLTest_AssertCheck( linked.minor >= minor,
|
||||
"SDL_GetVersion(): returned minor %i (>= %i)",
|
||||
linked.minor,
|
||||
minor);
|
||||
SDL_GetVersion(&linked);
|
||||
SDLTest_AssertCheck(linked.major >= major,
|
||||
"SDL_GetVersion(): returned major %i (>= %i)",
|
||||
linked.major,
|
||||
major);
|
||||
SDLTest_AssertCheck(linked.minor >= minor,
|
||||
"SDL_GetVersion(): returned minor %i (>= %i)",
|
||||
linked.minor,
|
||||
minor);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_VERSION macro
|
||||
*/
|
||||
int platform_testSDLVersion(void *arg)
|
||||
{
|
||||
SDL_version compiled;
|
||||
int major = SDL_MAJOR_VERSION;
|
||||
int minor = SDL_MINOR_VERSION;
|
||||
SDL_version compiled;
|
||||
int major = SDL_MAJOR_VERSION;
|
||||
int minor = SDL_MINOR_VERSION;
|
||||
|
||||
SDL_VERSION(&compiled);
|
||||
SDLTest_AssertCheck( compiled.major >= major,
|
||||
"SDL_VERSION() returned major %i (>= %i)",
|
||||
compiled.major,
|
||||
major);
|
||||
SDLTest_AssertCheck( compiled.minor >= minor,
|
||||
"SDL_VERSION() returned minor %i (>= %i)",
|
||||
compiled.minor,
|
||||
minor);
|
||||
SDL_VERSION(&compiled);
|
||||
SDLTest_AssertCheck(compiled.major >= major,
|
||||
"SDL_VERSION() returned major %i (>= %i)",
|
||||
compiled.major,
|
||||
major);
|
||||
SDLTest_AssertCheck(compiled.minor >= minor,
|
||||
"SDL_VERSION() returned minor %i (>= %i)",
|
||||
compiled.minor,
|
||||
minor);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/* !
|
||||
* \brief Tests default SDL_Init
|
||||
*/
|
||||
int platform_testDefaultInit(void *arg)
|
||||
{
|
||||
int ret;
|
||||
int subsystem;
|
||||
int ret;
|
||||
int subsystem;
|
||||
|
||||
subsystem = SDL_WasInit(SDL_INIT_EVERYTHING);
|
||||
SDLTest_AssertCheck( subsystem != 0,
|
||||
"SDL_WasInit(0): returned %i, expected != 0",
|
||||
subsystem);
|
||||
subsystem = SDL_WasInit(SDL_INIT_EVERYTHING);
|
||||
SDLTest_AssertCheck(subsystem != 0,
|
||||
"SDL_WasInit(0): returned %i, expected != 0",
|
||||
subsystem);
|
||||
|
||||
ret = SDL_Init(SDL_WasInit(SDL_INIT_EVERYTHING));
|
||||
SDLTest_AssertCheck( ret == 0,
|
||||
"SDL_Init(0): returned %i, expected 0, error: %s",
|
||||
ret,
|
||||
SDL_GetError());
|
||||
ret = SDL_Init(SDL_WasInit(SDL_INIT_EVERYTHING));
|
||||
SDLTest_AssertCheck(ret == 0,
|
||||
"SDL_Init(0): returned %i, expected 0, error: %s",
|
||||
ret,
|
||||
SDL_GetError());
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
|
|
@ -293,49 +293,47 @@ int platform_testDefaultInit(void *arg)
|
|||
*/
|
||||
int platform_testGetSetClearError(void *arg)
|
||||
{
|
||||
int result;
|
||||
const char *testError = "Testing";
|
||||
char *lastError;
|
||||
size_t len;
|
||||
int result;
|
||||
const char *testError = "Testing";
|
||||
char *lastError;
|
||||
size_t len;
|
||||
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
"SDL_GetError(): no message expected, len: %i", (int) len);
|
||||
}
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertPass("SDL_GetError()");
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
"SDL_GetError(): no message expected, len: %i", (int)len);
|
||||
}
|
||||
|
||||
result = SDL_SetError("%s", testError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
(int) SDL_strlen(testError),
|
||||
(int) len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
|
||||
"SDL_GetError(): expected message %s, was message: %s",
|
||||
testError,
|
||||
lastError);
|
||||
}
|
||||
result = SDL_SetError("%s", testError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
(int)SDL_strlen(testError),
|
||||
(int)len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
|
||||
"SDL_GetError(): expected message %s, was message: %s",
|
||||
testError,
|
||||
lastError);
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
/* Clean up */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
|
|
@ -345,37 +343,41 @@ int platform_testGetSetClearError(void *arg)
|
|||
*/
|
||||
int platform_testSetErrorEmptyInput(void *arg)
|
||||
{
|
||||
int result;
|
||||
const char *testError = "";
|
||||
char *lastError;
|
||||
size_t len;
|
||||
int result;
|
||||
const char *testError = "";
|
||||
char *lastError;
|
||||
size_t len;
|
||||
|
||||
result = SDL_SetError("%s", testError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
(int) SDL_strlen(testError),
|
||||
(int) len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
testError,
|
||||
lastError);
|
||||
}
|
||||
result = SDL_SetError("%s", testError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(testError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
(int)SDL_strlen(testError),
|
||||
(int)len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, testError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
testError,
|
||||
lastError);
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
/* Clean up */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
#if defined(HAVE_WFORMAT_OVERFLOW)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-overflow"
|
||||
#endif
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_SetError with invalid input
|
||||
* \sa
|
||||
|
|
@ -383,82 +385,83 @@ int platform_testSetErrorEmptyInput(void *arg)
|
|||
*/
|
||||
int platform_testSetErrorInvalidInput(void *arg)
|
||||
{
|
||||
int result;
|
||||
const char *invalidError = NULL;
|
||||
const char *probeError = "Testing";
|
||||
char *lastError;
|
||||
size_t len;
|
||||
int result;
|
||||
const char *invalidError = NULL;
|
||||
const char *probeError = "Testing";
|
||||
char *lastError;
|
||||
size_t len;
|
||||
|
||||
/* Reset */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
/* Reset */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
/* Check for no-op */
|
||||
result = SDL_SetError("%s", invalidError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0 || SDL_strcmp(lastError, "(null)") == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
(int) len);
|
||||
}
|
||||
/* Check for no-op */
|
||||
result = SDL_SetError("%s", invalidError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0 || SDL_strcmp(lastError, "(null)") == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
(int)len);
|
||||
}
|
||||
|
||||
/* Set */
|
||||
result = SDL_SetError("%s", probeError);
|
||||
SDLTest_AssertPass("SDL_SetError('%s')", probeError);
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
/* Set */
|
||||
result = SDL_SetError("%s", probeError);
|
||||
SDLTest_AssertPass("SDL_SetError('%s')", probeError);
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
|
||||
/* Check for no-op */
|
||||
result = SDL_SetError("%s", invalidError);
|
||||
SDLTest_AssertPass("SDL_SetError(NULL)");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0 || SDL_strcmp( lastError, "(null)" ) == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
(int) len);
|
||||
}
|
||||
/* Check for no-op */
|
||||
result = SDL_SetError("%s", invalidError);
|
||||
SDLTest_AssertPass("SDL_SetError(NULL)");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0 || SDL_strcmp(lastError, "(null)") == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
(int)len);
|
||||
}
|
||||
|
||||
/* Reset */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
/* Reset */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
/* Set and check */
|
||||
result = SDL_SetError("%s", probeError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(probeError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
(int) SDL_strlen(probeError),
|
||||
(int) len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, probeError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
probeError,
|
||||
lastError);
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
/* Set and check */
|
||||
result = SDL_SetError("%s", probeError);
|
||||
SDLTest_AssertPass("SDL_SetError()");
|
||||
SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
|
||||
lastError = (char *)SDL_GetError();
|
||||
SDLTest_AssertCheck(lastError != NULL,
|
||||
"SDL_GetError() != NULL");
|
||||
if (lastError != NULL) {
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == SDL_strlen(probeError),
|
||||
"SDL_GetError(): expected message len %i, was len: %i",
|
||||
(int)SDL_strlen(probeError),
|
||||
(int)len);
|
||||
SDLTest_AssertCheck(SDL_strcmp(lastError, probeError) == 0,
|
||||
"SDL_GetError(): expected message '%s', was message: '%s'",
|
||||
probeError,
|
||||
lastError);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
/* Clean up */
|
||||
SDL_ClearError();
|
||||
SDLTest_AssertPass("SDL_ClearError()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
#if defined(HAVE_WFORMAT_OVERFLOW)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_GetPowerInfo
|
||||
* \sa
|
||||
|
|
@ -466,115 +469,124 @@ int platform_testSetErrorInvalidInput(void *arg)
|
|||
*/
|
||||
int platform_testGetPowerInfo(void *arg)
|
||||
{
|
||||
SDL_PowerState state;
|
||||
SDL_PowerState stateAgain;
|
||||
int secs;
|
||||
int secsAgain;
|
||||
int pct;
|
||||
int pctAgain;
|
||||
SDL_PowerState state;
|
||||
SDL_PowerState stateAgain;
|
||||
int secs;
|
||||
int secsAgain;
|
||||
int pct;
|
||||
int pctAgain;
|
||||
|
||||
state = SDL_GetPowerInfo(&secs, &pct);
|
||||
SDLTest_AssertPass("SDL_GetPowerInfo()");
|
||||
SDLTest_AssertCheck(
|
||||
state==SDL_POWERSTATE_UNKNOWN ||
|
||||
state==SDL_POWERSTATE_ON_BATTERY ||
|
||||
state==SDL_POWERSTATE_NO_BATTERY ||
|
||||
state==SDL_POWERSTATE_CHARGING ||
|
||||
state==SDL_POWERSTATE_CHARGED,
|
||||
"SDL_GetPowerInfo(): state %i is one of the expected values",
|
||||
(int)state);
|
||||
state = SDL_GetPowerInfo(&secs, &pct);
|
||||
SDLTest_AssertPass("SDL_GetPowerInfo()");
|
||||
SDLTest_AssertCheck(
|
||||
state == SDL_POWERSTATE_UNKNOWN ||
|
||||
state == SDL_POWERSTATE_ON_BATTERY ||
|
||||
state == SDL_POWERSTATE_NO_BATTERY ||
|
||||
state == SDL_POWERSTATE_CHARGING ||
|
||||
state == SDL_POWERSTATE_CHARGED,
|
||||
"SDL_GetPowerInfo(): state %i is one of the expected values",
|
||||
(int)state);
|
||||
|
||||
if (state==SDL_POWERSTATE_ON_BATTERY)
|
||||
{
|
||||
SDLTest_AssertCheck(
|
||||
secs >= 0,
|
||||
"SDL_GetPowerInfo(): on battery, secs >= 0, was: %i",
|
||||
secs);
|
||||
SDLTest_AssertCheck(
|
||||
(pct >= 0) && (pct <= 100),
|
||||
"SDL_GetPowerInfo(): on battery, pct=[0,100], was: %i",
|
||||
pct);
|
||||
}
|
||||
if (state == SDL_POWERSTATE_ON_BATTERY) {
|
||||
SDLTest_AssertCheck(
|
||||
secs >= 0,
|
||||
"SDL_GetPowerInfo(): on battery, secs >= 0, was: %i",
|
||||
secs);
|
||||
SDLTest_AssertCheck(
|
||||
(pct >= 0) && (pct <= 100),
|
||||
"SDL_GetPowerInfo(): on battery, pct=[0,100], was: %i",
|
||||
pct);
|
||||
}
|
||||
|
||||
if (state==SDL_POWERSTATE_UNKNOWN ||
|
||||
state==SDL_POWERSTATE_NO_BATTERY)
|
||||
{
|
||||
SDLTest_AssertCheck(
|
||||
secs == -1,
|
||||
"SDL_GetPowerInfo(): no battery, secs == -1, was: %i",
|
||||
secs);
|
||||
SDLTest_AssertCheck(
|
||||
pct == -1,
|
||||
"SDL_GetPowerInfo(): no battery, pct == -1, was: %i",
|
||||
pct);
|
||||
}
|
||||
if (state == SDL_POWERSTATE_UNKNOWN ||
|
||||
state == SDL_POWERSTATE_NO_BATTERY) {
|
||||
SDLTest_AssertCheck(
|
||||
secs == -1,
|
||||
"SDL_GetPowerInfo(): no battery, secs == -1, was: %i",
|
||||
secs);
|
||||
SDLTest_AssertCheck(
|
||||
pct == -1,
|
||||
"SDL_GetPowerInfo(): no battery, pct == -1, was: %i",
|
||||
pct);
|
||||
}
|
||||
|
||||
/* Partial return value variations */
|
||||
stateAgain = SDL_GetPowerInfo(&secsAgain, NULL);
|
||||
SDLTest_AssertCheck(
|
||||
state==stateAgain,
|
||||
/* Partial return value variations */
|
||||
stateAgain = SDL_GetPowerInfo(&secsAgain, NULL);
|
||||
SDLTest_AssertCheck(
|
||||
state == stateAgain,
|
||||
"State %i returned when only 'secs' requested",
|
||||
stateAgain);
|
||||
SDLTest_AssertCheck(
|
||||
secs==secsAgain,
|
||||
SDLTest_AssertCheck(
|
||||
secs == secsAgain,
|
||||
"Value %i matches when only 'secs' requested",
|
||||
secsAgain);
|
||||
stateAgain = SDL_GetPowerInfo(NULL, &pctAgain);
|
||||
SDLTest_AssertCheck(
|
||||
state==stateAgain,
|
||||
stateAgain = SDL_GetPowerInfo(NULL, &pctAgain);
|
||||
SDLTest_AssertCheck(
|
||||
state == stateAgain,
|
||||
"State %i returned when only 'pct' requested",
|
||||
stateAgain);
|
||||
SDLTest_AssertCheck(
|
||||
pct==pctAgain,
|
||||
SDLTest_AssertCheck(
|
||||
pct == pctAgain,
|
||||
"Value %i matches when only 'pct' requested",
|
||||
pctAgain);
|
||||
stateAgain = SDL_GetPowerInfo(NULL, NULL);
|
||||
SDLTest_AssertCheck(
|
||||
state==stateAgain,
|
||||
stateAgain = SDL_GetPowerInfo(NULL, NULL);
|
||||
SDLTest_AssertCheck(
|
||||
state == stateAgain,
|
||||
"State %i returned when no value requested",
|
||||
stateAgain);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Platform test cases */
|
||||
static const SDLTest_TestCaseReference platformTest1 =
|
||||
{ (SDLTest_TestCaseFp)platform_testTypes, "platform_testTypes", "Tests predefined types", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest1 = {
|
||||
(SDLTest_TestCaseFp)platform_testTypes, "platform_testTypes", "Tests predefined types", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest2 =
|
||||
{ (SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianess and swap functions", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest2 = {
|
||||
(SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianness and swap functions", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest3 =
|
||||
{ (SDLTest_TestCaseFp)platform_testGetFunctions, "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest3 = {
|
||||
(SDLTest_TestCaseFp)platform_testGetFunctions, "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest4 =
|
||||
{ (SDLTest_TestCaseFp)platform_testHasFunctions, "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest4 = {
|
||||
(SDLTest_TestCaseFp)platform_testHasFunctions, "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest5 =
|
||||
{ (SDLTest_TestCaseFp)platform_testGetVersion, "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest5 = {
|
||||
(SDLTest_TestCaseFp)platform_testGetVersion, "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest6 =
|
||||
{ (SDLTest_TestCaseFp)platform_testSDLVersion, "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest6 = {
|
||||
(SDLTest_TestCaseFp)platform_testSDLVersion, "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest7 =
|
||||
{ (SDLTest_TestCaseFp)platform_testDefaultInit, "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest7 = {
|
||||
(SDLTest_TestCaseFp)platform_testDefaultInit, "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest8 =
|
||||
{ (SDLTest_TestCaseFp)platform_testGetSetClearError, "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest8 = {
|
||||
(SDLTest_TestCaseFp)platform_testGetSetClearError, "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest9 =
|
||||
{ (SDLTest_TestCaseFp)platform_testSetErrorEmptyInput, "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest9 = {
|
||||
(SDLTest_TestCaseFp)platform_testSetErrorEmptyInput, "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest10 =
|
||||
{ (SDLTest_TestCaseFp)platform_testSetErrorInvalidInput, "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference platformTest10 = {
|
||||
(SDLTest_TestCaseFp)platform_testSetErrorInvalidInput, "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference platformTest11 =
|
||||
{ (SDLTest_TestCaseFp)platform_testGetPowerInfo, "platform_testGetPowerInfo", "Tests SDL_GetPowerInfo function", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference platformTest11 = {
|
||||
(SDLTest_TestCaseFp)platform_testGetPowerInfo, "platform_testGetPowerInfo", "Tests SDL_GetPowerInfo function", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Platform test cases */
|
||||
static const SDLTest_TestCaseReference *platformTests[] = {
|
||||
static const SDLTest_TestCaseReference *platformTests[] = {
|
||||
&platformTest1,
|
||||
&platformTest2,
|
||||
&platformTest3,
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -7,327 +7,415 @@
|
|||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_strlcpy
|
||||
*/
|
||||
#undef SDL_strlcpy
|
||||
int
|
||||
stdlib_strlcpy(void *arg)
|
||||
int stdlib_strlcpy(void *arg)
|
||||
{
|
||||
size_t result;
|
||||
char text[1024];
|
||||
const char *expected;
|
||||
size_t result;
|
||||
char text[1024];
|
||||
const char *expected;
|
||||
|
||||
result = SDL_strlcpy(text, "foo", sizeof(text));
|
||||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), (int) result);
|
||||
result = SDL_strlcpy(text, "foo", sizeof(text));
|
||||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), (int)result);
|
||||
|
||||
result = SDL_strlcpy(text, "foo", 2);
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", (int) result);
|
||||
result = SDL_strlcpy(text, "foo", 2);
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", (int)result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
|
||||
#pragma GCC diagnostic push
|
||||
#if defined(HAVE_WFORMAT)
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#endif
|
||||
#if defined(HAVE_WFORMAT_EXTRA_ARGS)
|
||||
#pragma GCC diagnostic ignored "-Wformat-extra-args"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_snprintf
|
||||
*/
|
||||
#undef SDL_snprintf
|
||||
int
|
||||
stdlib_snprintf(void *arg)
|
||||
int stdlib_snprintf(void *arg)
|
||||
{
|
||||
int result;
|
||||
int predicted;
|
||||
char text[1024];
|
||||
const char *expected;
|
||||
int result;
|
||||
int predicted;
|
||||
char text[1024];
|
||||
const char *expected;
|
||||
size_t size;
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%s", "foo");
|
||||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
result = SDL_snprintf(text, sizeof(text), "%s", "foo");
|
||||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, 2, "%s", "foo");
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
result = SDL_snprintf(text, sizeof(text), "%S", L"foo");
|
||||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%S\", \"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(NULL, 0, "%s", "foo");
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(NULL, 0, \"%%s\", \"foo\")");
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
result = SDL_snprintf(text, sizeof(text), "%ls", L"foo");
|
||||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%ls\", \"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, 2, "%s\n", "foo");
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\\n\", \"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 4, "Check result value, expected: 4, got: %d", result);
|
||||
result = SDL_snprintf(text, 2, "%s", "foo");
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 0.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%f", 0.0);
|
||||
expected = "0.000000";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 0.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
result = SDL_snprintf(NULL, 0, "%s", "foo");
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(NULL, 0, \"%%s\", \"foo\")");
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%f", 1.0);
|
||||
expected = "1.000000";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
result = SDL_snprintf(text, 2, "%s\n", "foo");
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\\n\", \"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 4, "Check result value, expected: 4, got: %d", result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%.f", 1.0);
|
||||
expected = "1";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 0.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%f", 0.0);
|
||||
expected = "0.000000";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 0.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%#.f", 1.0);
|
||||
expected = "1.";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%f", 1.0);
|
||||
expected = "1.000000";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%.f", 1.0);
|
||||
expected = "1";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%+f", 1.0 + 1.0 / 3.0);
|
||||
expected = "+1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%#.f", 1.0);
|
||||
expected = "1.";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%6.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = " 1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%+f", 1.0 + 1.0 / 3.0);
|
||||
expected = "+1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == 6, "Check result value, expected: 6, got: %d", result);
|
||||
result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%6.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = " 1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == 6, "Check result value, expected: 6, got: %d", result);
|
||||
|
||||
size = 64;
|
||||
result = SDL_snprintf(text, sizeof(text), "%zu %s", size, "test");
|
||||
expected = "64 test";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"%%zu %%s\", size, \"test\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == 7, "Check result value, expected: 7, got: %d", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_getenv and SDL_setenv
|
||||
*/
|
||||
int
|
||||
stdlib_getsetenv(void *arg)
|
||||
int stdlib_getsetenv(void *arg)
|
||||
{
|
||||
const int nameLen = 16;
|
||||
char name[17];
|
||||
int counter;
|
||||
int result;
|
||||
char * value1;
|
||||
char * value2;
|
||||
char * expected;
|
||||
int overwrite;
|
||||
char * text;
|
||||
const int nameLen = 16;
|
||||
char name[17];
|
||||
int counter;
|
||||
int result;
|
||||
char *value1;
|
||||
char *value2;
|
||||
char *expected;
|
||||
int overwrite;
|
||||
char *text;
|
||||
|
||||
/* Create a random name. This tests SDL_getenv, since we need to */
|
||||
/* make sure the variable is not set yet (it shouldn't). */
|
||||
do {
|
||||
for(counter = 0; counter < nameLen; counter++) {
|
||||
name[counter] = (char)SDLTest_RandomIntegerInRange(65, 90);
|
||||
}
|
||||
name[nameLen] = '\0';
|
||||
|
||||
/* Create a random name. This tests SDL_getenv, since we need to */
|
||||
/* make sure the variable is not set yet (it shouldn't). */
|
||||
do {
|
||||
for (counter = 0; counter < nameLen; counter++) {
|
||||
name[counter] = (char)SDLTest_RandomIntegerInRange(65, 90);
|
||||
}
|
||||
name[nameLen] = '\0';
|
||||
|
||||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
if (text != NULL) {
|
||||
SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int)SDL_strlen(text));
|
||||
}
|
||||
} while (text != NULL);
|
||||
|
||||
/* Create random values to set */
|
||||
value1 = SDLTest_RandomAsciiStringOfSize(10);
|
||||
value2 = SDLTest_RandomAsciiStringOfSize(10);
|
||||
|
||||
/* Set value 1 without overwrite */
|
||||
overwrite = 0;
|
||||
expected = value1;
|
||||
result = SDL_setenv(name, value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
|
||||
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
|
||||
|
||||
/* Check value */
|
||||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
|
||||
if (text != NULL) {
|
||||
SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int) SDL_strlen(text));
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(text, expected) == 0,
|
||||
"Verify returned text, expected: %s, got: %s",
|
||||
expected,
|
||||
text);
|
||||
}
|
||||
} while (text != NULL);
|
||||
|
||||
/* Create random values to set */
|
||||
value1 = SDLTest_RandomAsciiStringOfSize(10);
|
||||
value2 = SDLTest_RandomAsciiStringOfSize(10);
|
||||
|
||||
/* Set value 1 without overwrite */
|
||||
overwrite = 0;
|
||||
expected = value1;
|
||||
result = SDL_setenv(name, value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
|
||||
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
|
||||
/* Set value 2 with overwrite */
|
||||
overwrite = 1;
|
||||
expected = value2;
|
||||
result = SDL_setenv(name, value2, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value2, overwrite);
|
||||
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
|
||||
|
||||
/* Check value */
|
||||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
|
||||
if (text != NULL) {
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(text, expected) == 0,
|
||||
"Verify returned text, expected: %s, got: %s",
|
||||
expected,
|
||||
text);
|
||||
}
|
||||
|
||||
/* Set value 2 with overwrite */
|
||||
overwrite = 1;
|
||||
expected = value2;
|
||||
result = SDL_setenv(name, value2, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value2, overwrite);
|
||||
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
|
||||
/* Check value */
|
||||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
|
||||
if (text != NULL) {
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(text, expected) == 0,
|
||||
"Verify returned text, expected: %s, got: %s",
|
||||
expected,
|
||||
text);
|
||||
}
|
||||
|
||||
/* Check value */
|
||||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
|
||||
if (text != NULL) {
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(text, expected) == 0,
|
||||
"Verify returned text, expected: %s, got: %s",
|
||||
expected,
|
||||
text);
|
||||
}
|
||||
/* Set value 1 without overwrite */
|
||||
overwrite = 0;
|
||||
expected = value2;
|
||||
result = SDL_setenv(name, value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
|
||||
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
|
||||
|
||||
/* Set value 1 without overwrite */
|
||||
overwrite = 0;
|
||||
expected = value2;
|
||||
result = SDL_setenv(name, value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
|
||||
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
|
||||
/* Check value */
|
||||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
|
||||
if (text != NULL) {
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(text, expected) == 0,
|
||||
"Verify returned text, expected: %s, got: %s",
|
||||
expected,
|
||||
text);
|
||||
}
|
||||
|
||||
/* Check value */
|
||||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
|
||||
if (text != NULL) {
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(text, expected) == 0,
|
||||
"Verify returned text, expected: %s, got: %s",
|
||||
expected,
|
||||
text);
|
||||
}
|
||||
|
||||
/* Set value 1 without overwrite */
|
||||
overwrite = 1;
|
||||
expected = value1;
|
||||
result = SDL_setenv(name, value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
|
||||
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
|
||||
/* Set value 1 without overwrite */
|
||||
overwrite = 1;
|
||||
expected = value1;
|
||||
result = SDL_setenv(name, value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s','%s', %i)", name, value1, overwrite);
|
||||
SDLTest_AssertCheck(result == 0, "Check result, expected: 0, got: %i", result);
|
||||
|
||||
/* Check value */
|
||||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
|
||||
if (text != NULL) {
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(text, expected) == 0,
|
||||
"Verify returned text, expected: %s, got: %s",
|
||||
expected,
|
||||
text);
|
||||
}
|
||||
/* Check value */
|
||||
text = SDL_getenv(name);
|
||||
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
|
||||
SDLTest_AssertCheck(text != NULL, "Verify returned text is not NULL");
|
||||
if (text != NULL) {
|
||||
SDLTest_AssertCheck(
|
||||
SDL_strcmp(text, expected) == 0,
|
||||
"Verify returned text, expected: %s, got: %s",
|
||||
expected,
|
||||
text);
|
||||
}
|
||||
|
||||
/* Negative cases */
|
||||
for (overwrite=0; overwrite <= 1; overwrite++) {
|
||||
result = SDL_setenv(NULL, value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv(NULL,'%s', %i)", value1, overwrite);
|
||||
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
|
||||
result = SDL_setenv("", value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('','%s', %i)", value1, overwrite);
|
||||
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
|
||||
result = SDL_setenv("=", value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('=','%s', %i)", value1, overwrite);
|
||||
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
|
||||
result = SDL_setenv(name, NULL, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s', NULL, %i)", name, overwrite);
|
||||
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
|
||||
}
|
||||
/* Negative cases */
|
||||
for (overwrite = 0; overwrite <= 1; overwrite++) {
|
||||
result = SDL_setenv(NULL, value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv(NULL,'%s', %i)", value1, overwrite);
|
||||
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
|
||||
result = SDL_setenv("", value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('','%s', %i)", value1, overwrite);
|
||||
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
|
||||
result = SDL_setenv("=", value1, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('=','%s', %i)", value1, overwrite);
|
||||
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
|
||||
result = SDL_setenv(name, NULL, overwrite);
|
||||
SDLTest_AssertPass("Call to SDL_setenv('%s', NULL, %i)", name, overwrite);
|
||||
SDLTest_AssertCheck(result == -1, "Check result, expected: -1, got: %i", result);
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
SDL_free(value1);
|
||||
SDL_free(value2);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
/* Clean up */
|
||||
SDL_free(value1);
|
||||
SDL_free(value2);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
|
||||
#pragma GCC diagnostic push
|
||||
#if defined(HAVE_WFORMAT)
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#endif
|
||||
#if defined(HAVE_WFORMAT_EXTRA_ARGS)
|
||||
#pragma GCC diagnostic ignored "-Wformat-extra-args"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_sscanf
|
||||
*/
|
||||
#undef SDL_sscanf
|
||||
int
|
||||
stdlib_sscanf(void *arg)
|
||||
int stdlib_sscanf(void *arg)
|
||||
{
|
||||
int output;
|
||||
int result;
|
||||
int expected_output;
|
||||
int expected_result;
|
||||
int output;
|
||||
int result;
|
||||
int expected_output;
|
||||
int expected_result;
|
||||
short short_output, expected_short_output;
|
||||
long long_output, expected_long_output;
|
||||
long long long_long_output, expected_long_long_output;
|
||||
size_t size_output, expected_size_output;
|
||||
char text[128];
|
||||
|
||||
expected_output = output = 123;
|
||||
expected_result = -1;
|
||||
result = SDL_sscanf("", "%i", &output);
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"\", \"%%i\", &output)");
|
||||
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
expected_output = output = 123;
|
||||
expected_result = -1;
|
||||
result = SDL_sscanf("", "%i", &output);
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"\", \"%%i\", &output)");
|
||||
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
|
||||
expected_output = output = 123;
|
||||
expected_result = 0;
|
||||
result = SDL_sscanf("a", "%i", &output);
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"a\", \"%%i\", &output)");
|
||||
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
expected_output = output = 123;
|
||||
expected_result = 0;
|
||||
result = SDL_sscanf("a", "%i", &output);
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"a\", \"%%i\", &output)");
|
||||
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
|
||||
output = 123;
|
||||
expected_output = 2;
|
||||
expected_result = 1;
|
||||
result = SDL_sscanf("2", "%i", &output);
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i\", &output)");
|
||||
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
output = 123;
|
||||
expected_output = 2;
|
||||
expected_result = 1;
|
||||
result = SDL_sscanf("2", "%i", &output);
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i\", &output)");
|
||||
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
output = 123;
|
||||
expected_output = 0xa;
|
||||
expected_result = 1;
|
||||
result = SDL_sscanf("aa", "%1x", &output);
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"aa\", \"%%1x\", &output)");
|
||||
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
|
||||
#define SIZED_TEST_CASE(type, var, format_specifier) \
|
||||
var##_output = 123; \
|
||||
expected_##var##_output = (type)(((unsigned type)(~0)) >> 1); \
|
||||
expected_result = 1; \
|
||||
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
|
||||
result = SDL_sscanf(text, format_specifier, &var##_output); \
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
|
||||
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
|
||||
\
|
||||
var##_output = 123; \
|
||||
expected_##var##_output = ~(type)(((unsigned type)(~0)) >> 1); \
|
||||
expected_result = 1; \
|
||||
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
|
||||
result = SDL_sscanf(text, format_specifier, &var##_output); \
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
|
||||
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
|
||||
SIZED_TEST_CASE(short, short, "%hd")
|
||||
SIZED_TEST_CASE(long, long, "%ld")
|
||||
SIZED_TEST_CASE(long long, long_long, "%lld")
|
||||
|
||||
size_output = 123;
|
||||
expected_size_output = ~((size_t)0);
|
||||
expected_result = 1;
|
||||
result = SDL_snprintf(text, sizeof(text), "%zu", expected_size_output);
|
||||
result = SDL_sscanf(text, "%zu", &size_output);
|
||||
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%%zu\", &output)", text);
|
||||
SDLTest_AssertCheck(expected_size_output == size_output, "Check output, expected: %zu, got: %zu", expected_size_output, size_output);
|
||||
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64)
|
||||
# define SIZE_FORMAT "I64u"
|
||||
#define SIZE_FORMAT "I64u"
|
||||
#elif defined(__WIN32__)
|
||||
# define SIZE_FORMAT "I32u"
|
||||
#define SIZE_FORMAT "I32u"
|
||||
#else
|
||||
# define SIZE_FORMAT "zu"
|
||||
#define SIZE_FORMAT "zu"
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
|
|
@ -338,8 +426,7 @@ typedef struct
|
|||
int status;
|
||||
} overflow_test;
|
||||
|
||||
static const overflow_test multiplications[] =
|
||||
{
|
||||
static const overflow_test multiplications[] = {
|
||||
{ 1, 1, 1, 0 },
|
||||
{ 0, 0, 0, 0 },
|
||||
{ SDL_SIZE_MAX, 0, 0, 0 },
|
||||
|
|
@ -352,8 +439,7 @@ static const overflow_test multiplications[] =
|
|||
{ SDL_SIZE_MAX, SDL_SIZE_MAX, 0, -1 },
|
||||
};
|
||||
|
||||
static const overflow_test additions[] =
|
||||
{
|
||||
static const overflow_test additions[] = {
|
||||
{ 1, 1, 2, 0 },
|
||||
{ 0, 0, 0, 0 },
|
||||
{ SDL_SIZE_MAX, 0, SDL_SIZE_MAX, 0 },
|
||||
|
|
@ -368,142 +454,147 @@ static const overflow_test additions[] =
|
|||
static int
|
||||
stdlib_overflow(void *arg)
|
||||
{
|
||||
size_t i;
|
||||
size_t useBuiltin;
|
||||
size_t i;
|
||||
size_t useBuiltin;
|
||||
|
||||
for (useBuiltin = 0; useBuiltin < 2; useBuiltin++) {
|
||||
if (useBuiltin) {
|
||||
SDLTest_Log("Using gcc/clang builtins if possible");
|
||||
} else {
|
||||
SDLTest_Log("Not using gcc/clang builtins");
|
||||
}
|
||||
for (useBuiltin = 0; useBuiltin < 2; useBuiltin++) {
|
||||
if (useBuiltin) {
|
||||
SDLTest_Log("Using gcc/clang builtins if possible");
|
||||
} else {
|
||||
SDLTest_Log("Not using gcc/clang builtins");
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_arraysize(multiplications); i++) {
|
||||
const overflow_test *t = &multiplications[i];
|
||||
int status;
|
||||
size_t result = ~t->result;
|
||||
for (i = 0; i < SDL_arraysize(multiplications); i++) {
|
||||
const overflow_test *t = &multiplications[i];
|
||||
int status;
|
||||
size_t result = ~t->result;
|
||||
|
||||
if (useBuiltin) {
|
||||
status = SDL_size_mul_overflow(t->a, t->b, &result);
|
||||
} else {
|
||||
/* This disables the macro that tries to use a gcc/clang
|
||||
* builtin, so we test the fallback implementation instead. */
|
||||
status = (SDL_size_mul_overflow)(t->a, t->b, &result);
|
||||
}
|
||||
if (useBuiltin) {
|
||||
status = SDL_size_mul_overflow(t->a, t->b, &result);
|
||||
} else {
|
||||
/* This disables the macro that tries to use a gcc/clang
|
||||
* builtin, so we test the fallback implementation instead. */
|
||||
status = (SDL_size_mul_overflow)(t->a, t->b, &result);
|
||||
}
|
||||
|
||||
if (t->status == 0) {
|
||||
SDLTest_AssertCheck(status == 0,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
|
||||
t->a, t->b);
|
||||
SDLTest_AssertCheck(result == t->result,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
|
||||
t->a, t->b, t->result, result);
|
||||
} else {
|
||||
SDLTest_AssertCheck(status == -1,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
|
||||
t->a, t->b);
|
||||
}
|
||||
if (t->status == 0) {
|
||||
SDLTest_AssertCheck(status == 0,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
|
||||
t->a, t->b);
|
||||
SDLTest_AssertCheck(result == t->result,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
|
||||
t->a, t->b, t->result, result);
|
||||
} else {
|
||||
SDLTest_AssertCheck(status == -1,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
|
||||
t->a, t->b);
|
||||
}
|
||||
|
||||
if (t->a == t->b) {
|
||||
continue;
|
||||
}
|
||||
if (t->a == t->b) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = ~t->result;
|
||||
result = ~t->result;
|
||||
|
||||
if (useBuiltin) {
|
||||
status = SDL_size_mul_overflow(t->b, t->a, &result);
|
||||
} else {
|
||||
status = (SDL_size_mul_overflow)(t->b, t->a, &result);
|
||||
}
|
||||
if (useBuiltin) {
|
||||
status = SDL_size_mul_overflow(t->b, t->a, &result);
|
||||
} else {
|
||||
status = (SDL_size_mul_overflow)(t->b, t->a, &result);
|
||||
}
|
||||
|
||||
if (t->status == 0) {
|
||||
SDLTest_AssertCheck(status == 0,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
|
||||
t->b, t->a);
|
||||
SDLTest_AssertCheck(result == t->result,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
|
||||
t->b, t->a, t->result, result);
|
||||
} else {
|
||||
SDLTest_AssertCheck(status == -1,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
|
||||
t->b, t->a);
|
||||
}
|
||||
}
|
||||
if (t->status == 0) {
|
||||
SDLTest_AssertCheck(status == 0,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
|
||||
t->b, t->a);
|
||||
SDLTest_AssertCheck(result == t->result,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
|
||||
t->b, t->a, t->result, result);
|
||||
} else {
|
||||
SDLTest_AssertCheck(status == -1,
|
||||
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
|
||||
t->b, t->a);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < SDL_arraysize(additions); i++) {
|
||||
const overflow_test *t = &additions[i];
|
||||
int status;
|
||||
size_t result = ~t->result;
|
||||
for (i = 0; i < SDL_arraysize(additions); i++) {
|
||||
const overflow_test *t = &additions[i];
|
||||
int status;
|
||||
size_t result = ~t->result;
|
||||
|
||||
if (useBuiltin) {
|
||||
status = SDL_size_add_overflow(t->a, t->b, &result);
|
||||
} else {
|
||||
status = (SDL_size_add_overflow)(t->a, t->b, &result);
|
||||
}
|
||||
if (useBuiltin) {
|
||||
status = SDL_size_add_overflow(t->a, t->b, &result);
|
||||
} else {
|
||||
status = (SDL_size_add_overflow)(t->a, t->b, &result);
|
||||
}
|
||||
|
||||
if (t->status == 0) {
|
||||
SDLTest_AssertCheck(status == 0,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
|
||||
t->a, t->b);
|
||||
SDLTest_AssertCheck(result == t->result,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
|
||||
t->a, t->b, t->result, result);
|
||||
} else {
|
||||
SDLTest_AssertCheck(status == -1,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
|
||||
t->a, t->b);
|
||||
}
|
||||
if (t->status == 0) {
|
||||
SDLTest_AssertCheck(status == 0,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
|
||||
t->a, t->b);
|
||||
SDLTest_AssertCheck(result == t->result,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
|
||||
t->a, t->b, t->result, result);
|
||||
} else {
|
||||
SDLTest_AssertCheck(status == -1,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
|
||||
t->a, t->b);
|
||||
}
|
||||
|
||||
if (t->a == t->b) {
|
||||
continue;
|
||||
}
|
||||
if (t->a == t->b) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = ~t->result;
|
||||
result = ~t->result;
|
||||
|
||||
if (useBuiltin) {
|
||||
status = SDL_size_add_overflow(t->b, t->a, &result);
|
||||
} else {
|
||||
status = (SDL_size_add_overflow)(t->b, t->a, &result);
|
||||
}
|
||||
if (useBuiltin) {
|
||||
status = SDL_size_add_overflow(t->b, t->a, &result);
|
||||
} else {
|
||||
status = (SDL_size_add_overflow)(t->b, t->a, &result);
|
||||
}
|
||||
|
||||
if (t->status == 0) {
|
||||
SDLTest_AssertCheck(status == 0,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
|
||||
t->b, t->a);
|
||||
SDLTest_AssertCheck(result == t->result,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
|
||||
t->b, t->a, t->result, result);
|
||||
} else {
|
||||
SDLTest_AssertCheck(status == -1,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
|
||||
t->b, t->a);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (t->status == 0) {
|
||||
SDLTest_AssertCheck(status == 0,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
|
||||
t->b, t->a);
|
||||
SDLTest_AssertCheck(result == t->result,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
|
||||
t->b, t->a, t->result, result);
|
||||
} else {
|
||||
SDLTest_AssertCheck(status == -1,
|
||||
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
|
||||
t->b, t->a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Standard C routine test cases */
|
||||
static const SDLTest_TestCaseReference stdlibTest1 =
|
||||
{ (SDLTest_TestCaseFp)stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference stdlibTest1 = {
|
||||
(SDLTest_TestCaseFp)stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference stdlibTest2 =
|
||||
{ (SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference stdlibTest2 = {
|
||||
(SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference stdlibTest3 =
|
||||
{ (SDLTest_TestCaseFp)stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference stdlibTest3 = {
|
||||
(SDLTest_TestCaseFp)stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference stdlibTest4 =
|
||||
{ (SDLTest_TestCaseFp)stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference stdlibTest4 = {
|
||||
(SDLTest_TestCaseFp)stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference stdlibTestOverflow =
|
||||
{ stdlib_overflow, "stdlib_overflow", "Overflow detection", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference stdlibTestOverflow = {
|
||||
stdlib_overflow, "stdlib_overflow", "Overflow detection", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Standard C routine test cases */
|
||||
static const SDLTest_TestCaseReference *stdlibTests[] = {
|
||||
static const SDLTest_TestCaseReference *stdlibTests[] = {
|
||||
&stdlibTest1,
|
||||
&stdlibTest2,
|
||||
&stdlibTest3,
|
||||
|
|
|
|||
|
|
@ -12,8 +12,12 @@
|
|||
extern SDLTest_TestSuiteReference audioTestSuite;
|
||||
extern SDLTest_TestSuiteReference clipboardTestSuite;
|
||||
extern SDLTest_TestSuiteReference eventsTestSuite;
|
||||
extern SDLTest_TestSuiteReference guidTestSuite;
|
||||
extern SDLTest_TestSuiteReference hintsTestSuite;
|
||||
extern SDLTest_TestSuiteReference joystickTestSuite;
|
||||
extern SDLTest_TestSuiteReference keyboardTestSuite;
|
||||
extern SDLTest_TestSuiteReference mainTestSuite;
|
||||
extern SDLTest_TestSuiteReference mathTestSuite;
|
||||
extern SDLTest_TestSuiteReference mouseTestSuite;
|
||||
extern SDLTest_TestSuiteReference pixelsTestSuite;
|
||||
extern SDLTest_TestSuiteReference platformTestSuite;
|
||||
|
|
@ -26,15 +30,18 @@ extern SDLTest_TestSuiteReference surfaceTestSuite;
|
|||
extern SDLTest_TestSuiteReference syswmTestSuite;
|
||||
extern SDLTest_TestSuiteReference timerTestSuite;
|
||||
extern SDLTest_TestSuiteReference videoTestSuite;
|
||||
extern SDLTest_TestSuiteReference hintsTestSuite;
|
||||
|
||||
/* All test suites */
|
||||
SDLTest_TestSuiteReference *testSuites[] = {
|
||||
SDLTest_TestSuiteReference *testSuites[] = {
|
||||
&audioTestSuite,
|
||||
&clipboardTestSuite,
|
||||
&eventsTestSuite,
|
||||
&guidTestSuite,
|
||||
&hintsTestSuite,
|
||||
&joystickTestSuite,
|
||||
&keyboardTestSuite,
|
||||
&mainTestSuite,
|
||||
&mathTestSuite,
|
||||
&mouseTestSuite,
|
||||
&pixelsTestSuite,
|
||||
&platformTestSuite,
|
||||
|
|
@ -47,7 +54,6 @@ SDLTest_TestSuiteReference *testSuites[] = {
|
|||
&syswmTestSuite,
|
||||
&timerTestSuite,
|
||||
&videoTestSuite,
|
||||
&hintsTestSuite,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,12 @@
|
|||
*/
|
||||
|
||||
/* Supress C4996 VS compiler warnings for unlink() */
|
||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
#endif
|
||||
#if defined(_MSC_VER) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#ifndef _MSC_VER
|
||||
|
|
@ -29,14 +33,13 @@ static SDL_Surface *testSurface = NULL;
|
|||
|
||||
/* Helper functions for the test cases */
|
||||
|
||||
#define TEST_SURFACE_WIDTH testSurface->w
|
||||
#define TEST_SURFACE_WIDTH testSurface->w
|
||||
#define TEST_SURFACE_HEIGHT testSurface->h
|
||||
|
||||
/* Fixture */
|
||||
|
||||
/* Create a 32-bit writable surface for blitting tests */
|
||||
void
|
||||
_surfaceSetUp(void *arg)
|
||||
void _surfaceSetUp(void *arg)
|
||||
{
|
||||
int result;
|
||||
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
|
|
@ -58,17 +61,16 @@ _surfaceSetUp(void *arg)
|
|||
testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
|
||||
SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
|
||||
if (testSurface != NULL) {
|
||||
/* Disable blend mode for target surface */
|
||||
result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
|
||||
SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
|
||||
result = SDL_GetSurfaceBlendMode(testSurface, ¤tBlendMode);
|
||||
SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
|
||||
SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);
|
||||
/* Disable blend mode for target surface */
|
||||
result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
|
||||
SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
|
||||
result = SDL_GetSurfaceBlendMode(testSurface, ¤tBlendMode);
|
||||
SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
|
||||
SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_surfaceTearDown(void *arg)
|
||||
void _surfaceTearDown(void *arg)
|
||||
{
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
|
@ -85,9 +87,9 @@ void _clearTestSurface()
|
|||
Uint32 color;
|
||||
|
||||
/* Clear surface. */
|
||||
color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
|
||||
color = SDL_MapRGBA(testSurface->format, 0, 0, 0, 0);
|
||||
SDLTest_AssertPass("Call to SDL_MapRGBA()");
|
||||
ret = SDL_FillRect( testSurface, NULL, color);
|
||||
ret = SDL_FillRect(testSurface, NULL, color);
|
||||
SDLTest_AssertPass("Call to SDL_FillRect()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
|
||||
}
|
||||
|
|
@ -110,30 +112,34 @@ void _testBlitBlendMode(int mode)
|
|||
|
||||
/* Check test surface */
|
||||
SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL");
|
||||
if (testSurface == NULL) return;
|
||||
if (testSurface == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL) return;
|
||||
if (face == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Reset alpha modulation */
|
||||
/* Reset alpha modulation */
|
||||
ret = SDL_SetSurfaceAlphaMod(face, 255);
|
||||
SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
|
||||
|
||||
/* Reset color modulation */
|
||||
/* Reset color modulation */
|
||||
ret = SDL_SetSurfaceColorMod(face, 255, 255, 255);
|
||||
SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
|
||||
|
||||
/* Reset color key */
|
||||
/* Reset color key */
|
||||
ret = SDL_SetColorKey(face, SDL_FALSE, 0);
|
||||
SDLTest_AssertPass("Call to SDL_SetColorKey()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret);
|
||||
|
||||
/* Clear the test surface */
|
||||
_clearTestSurface();
|
||||
_clearTestSurface();
|
||||
|
||||
/* Target rect size */
|
||||
rect.w = face->w;
|
||||
|
|
@ -145,7 +151,7 @@ void _testBlitBlendMode(int mode)
|
|||
|
||||
/* Optionally set blend mode. */
|
||||
if (mode >= 0) {
|
||||
ret = SDL_SetSurfaceBlendMode( face, (SDL_BlendMode)mode );
|
||||
ret = SDL_SetSurfaceBlendMode(face, (SDL_BlendMode)mode);
|
||||
SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret);
|
||||
}
|
||||
|
|
@ -155,40 +161,50 @@ void _testBlitBlendMode(int mode)
|
|||
checkFailCount2 = 0;
|
||||
checkFailCount3 = 0;
|
||||
checkFailCount4 = 0;
|
||||
for (j=0; j <= nj; j+=4) {
|
||||
for (i=0; i <= ni; i+=4) {
|
||||
if (mode == -2) {
|
||||
/* Set color mod. */
|
||||
ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
|
||||
if (ret != 0) checkFailCount2++;
|
||||
}
|
||||
else if (mode == -3) {
|
||||
/* Set alpha mod. */
|
||||
ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
|
||||
if (ret != 0) checkFailCount3++;
|
||||
}
|
||||
else if (mode == -4) {
|
||||
/* Crazy blending mode magic. */
|
||||
nmode = (i/4*j/4) % 4;
|
||||
if (nmode==0) {
|
||||
bmode = SDL_BLENDMODE_NONE;
|
||||
} else if (nmode==1) {
|
||||
bmode = SDL_BLENDMODE_BLEND;
|
||||
} else if (nmode==2) {
|
||||
bmode = SDL_BLENDMODE_ADD;
|
||||
} else if (nmode==3) {
|
||||
bmode = SDL_BLENDMODE_MOD;
|
||||
for (j = 0; j <= nj; j += 4) {
|
||||
for (i = 0; i <= ni; i += 4) {
|
||||
if (mode == -2) {
|
||||
/* Set color mod. */
|
||||
ret = SDL_SetSurfaceColorMod(face, (255 / nj) * j, (255 / ni) * i, (255 / nj) * j);
|
||||
if (ret != 0) {
|
||||
checkFailCount2++;
|
||||
}
|
||||
} else if (mode == -3) {
|
||||
/* Set alpha mod. */
|
||||
ret = SDL_SetSurfaceAlphaMod(face, (255 / ni) * i);
|
||||
if (ret != 0) {
|
||||
checkFailCount3++;
|
||||
}
|
||||
} else if (mode == -4) {
|
||||
/* Crazy blending mode magic. */
|
||||
nmode = (i / 4 * j / 4) % 4;
|
||||
if (nmode == 0) {
|
||||
bmode = SDL_BLENDMODE_NONE;
|
||||
} else if (nmode == 1) {
|
||||
bmode = SDL_BLENDMODE_BLEND;
|
||||
} else if (nmode == 2) {
|
||||
bmode = SDL_BLENDMODE_ADD;
|
||||
} else if (nmode == 3) {
|
||||
bmode = SDL_BLENDMODE_MOD;
|
||||
} else {
|
||||
/* Should be impossible, but some static checkers are too imprecise and will complain */
|
||||
SDLTest_LogError("Invalid: nmode=%d", nmode);
|
||||
return;
|
||||
}
|
||||
ret = SDL_SetSurfaceBlendMode(face, bmode);
|
||||
if (ret != 0) {
|
||||
checkFailCount4++;
|
||||
}
|
||||
}
|
||||
ret = SDL_SetSurfaceBlendMode( face, bmode );
|
||||
if (ret != 0) checkFailCount4++;
|
||||
}
|
||||
|
||||
/* Blitting. */
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_BlitSurface( face, NULL, testSurface, &rect );
|
||||
if (ret != 0) checkFailCount1++;
|
||||
}
|
||||
/* Blitting. */
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
ret = SDL_BlitSurface(face, NULL, testSurface, &rect);
|
||||
if (ret != 0) {
|
||||
checkFailCount1++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i", checkFailCount1);
|
||||
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", checkFailCount2);
|
||||
|
|
@ -201,8 +217,7 @@ void _testBlitBlendMode(int mode)
|
|||
}
|
||||
|
||||
/* Helper to check that a file exists */
|
||||
void
|
||||
_AssertFileExist(const char *filename)
|
||||
void _AssertFileExist(const char *filename)
|
||||
{
|
||||
struct stat st;
|
||||
int ret = stat(filename, &st);
|
||||
|
|
@ -210,14 +225,12 @@ _AssertFileExist(const char *filename)
|
|||
SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
|
||||
}
|
||||
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Tests sprite saving and loading
|
||||
*/
|
||||
int
|
||||
surface_testSaveLoadBitmap(void *arg)
|
||||
int surface_testSaveLoadBitmap(void *arg)
|
||||
{
|
||||
int ret;
|
||||
const char *sampleFilename = "testSaveLoadBitmap.bmp";
|
||||
|
|
@ -227,7 +240,9 @@ surface_testSaveLoadBitmap(void *arg)
|
|||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL) return TEST_ABORTED;
|
||||
if (face == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Delete test file; ignore errors */
|
||||
unlink(sampleFilename);
|
||||
|
|
@ -262,8 +277,7 @@ surface_testSaveLoadBitmap(void *arg)
|
|||
/* !
|
||||
* Tests surface conversion.
|
||||
*/
|
||||
int
|
||||
surface_testSurfaceConversion(void *arg)
|
||||
int surface_testSurfaceConversion(void *arg)
|
||||
{
|
||||
SDL_Surface *rface = NULL, *face = NULL;
|
||||
int ret = 0;
|
||||
|
|
@ -271,14 +285,15 @@ surface_testSurfaceConversion(void *arg)
|
|||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL)
|
||||
if (face == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Set transparent pixel as the pixel at (0,0) */
|
||||
if (face->format->palette) {
|
||||
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
|
||||
SDLTest_AssertPass("Call to SDL_SetColorKey()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
|
||||
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *)face->pixels);
|
||||
SDLTest_AssertPass("Call to SDL_SetColorKey()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
|
||||
}
|
||||
|
||||
/* Convert to 32 bit to compare. */
|
||||
|
|
@ -287,7 +302,7 @@ surface_testSurfaceConversion(void *arg)
|
|||
SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
|
||||
|
||||
/* Compare surface. */
|
||||
ret = SDLTest_CompareSurfaces( rface, face, 0 );
|
||||
ret = SDLTest_CompareSurfaces(rface, face, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
|
|
@ -299,12 +314,10 @@ surface_testSurfaceConversion(void *arg)
|
|||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/* !
|
||||
* Tests surface conversion across all pixel formats.
|
||||
*/
|
||||
int
|
||||
surface_testCompleteSurfaceConversion(void *arg)
|
||||
int surface_testCompleteSurfaceConversion(void *arg)
|
||||
{
|
||||
Uint32 pixel_formats[] = {
|
||||
SDL_PIXELFORMAT_INDEX8,
|
||||
|
|
@ -342,18 +355,19 @@ surface_testCompleteSurfaceConversion(void *arg)
|
|||
/* Create sample surface */
|
||||
face = SDLTest_ImageFace();
|
||||
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
|
||||
if (face == NULL)
|
||||
if (face == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Set transparent pixel as the pixel at (0,0) */
|
||||
if (face->format->palette) {
|
||||
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *) face->pixels);
|
||||
SDLTest_AssertPass("Call to SDL_SetColorKey()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
|
||||
ret = SDL_SetColorKey(face, SDL_RLEACCEL, *(Uint8 *)face->pixels);
|
||||
SDLTest_AssertPass("Call to SDL_SetColorKey()");
|
||||
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey, expected: 0, got: %i", ret);
|
||||
}
|
||||
|
||||
for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
|
||||
for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
|
||||
for (i = 0; i < SDL_arraysize(pixel_formats); ++i) {
|
||||
for (j = 0; j < SDL_arraysize(pixel_formats); ++j) {
|
||||
fmt1 = SDL_AllocFormat(pixel_formats[i]);
|
||||
SDL_assert(fmt1 != NULL);
|
||||
cvt1 = SDL_ConvertSurface(face, fmt1, 0);
|
||||
|
|
@ -372,7 +386,7 @@ surface_testCompleteSurfaceConversion(void *arg)
|
|||
SDL_assert(final != NULL);
|
||||
|
||||
/* Compare surface. */
|
||||
ret = SDLTest_CompareSurfaces( face, final, 0 );
|
||||
ret = SDLTest_CompareSurfaces(face, final, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
SDL_FreeSurface(final);
|
||||
}
|
||||
|
|
@ -385,17 +399,15 @@ surface_testCompleteSurfaceConversion(void *arg)
|
|||
}
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface( face );
|
||||
SDL_FreeSurface(face);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Tests sprite loading. A failure case.
|
||||
*/
|
||||
int
|
||||
surface_testLoadFailure(void *arg)
|
||||
int surface_testLoadFailure(void *arg)
|
||||
{
|
||||
SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
|
||||
SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
|
||||
|
|
@ -406,236 +418,412 @@ surface_testLoadFailure(void *arg)
|
|||
/**
|
||||
* @brief Tests some blitting routines.
|
||||
*/
|
||||
int
|
||||
surface_testBlit(void *arg)
|
||||
int surface_testBlit(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Basic blitting */
|
||||
_testBlitBlendMode(-1);
|
||||
/* Basic blitting */
|
||||
_testBlitBlendMode(-1);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlit();
|
||||
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlit();
|
||||
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some blitting routines with color mod
|
||||
*/
|
||||
int
|
||||
surface_testBlitColorMod(void *arg)
|
||||
int surface_testBlitColorMod(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Basic blitting with color mod */
|
||||
_testBlitBlendMode(-2);
|
||||
/* Basic blitting with color mod */
|
||||
_testBlitBlendMode(-2);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitColor();
|
||||
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitColor();
|
||||
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some blitting routines with alpha mod
|
||||
*/
|
||||
int
|
||||
surface_testBlitAlphaMod(void *arg)
|
||||
int surface_testBlitAlphaMod(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Basic blitting with alpha mod */
|
||||
_testBlitBlendMode(-3);
|
||||
/* Basic blitting with alpha mod */
|
||||
_testBlitBlendMode(-3);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitAlpha();
|
||||
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitAlpha();
|
||||
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Tests some more blitting routines.
|
||||
*/
|
||||
int
|
||||
surface_testBlitBlendNone(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Basic blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_NONE);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendNone();
|
||||
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some more blitting routines.
|
||||
*/
|
||||
int
|
||||
surface_testBlitBlendBlend(void *arg)
|
||||
int surface_testBlitBlendNone(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Blend blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_BLEND);
|
||||
/* Basic blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_NONE);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlend();
|
||||
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendNone();
|
||||
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some more blitting routines.
|
||||
*/
|
||||
int
|
||||
surface_testBlitBlendAdd(void *arg)
|
||||
int surface_testBlitBlendBlend(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Add blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_ADD);
|
||||
/* Blend blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendAdd();
|
||||
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlend();
|
||||
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some more blitting routines.
|
||||
*/
|
||||
int
|
||||
surface_testBlitBlendMod(void *arg)
|
||||
int surface_testBlitBlendAdd(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Mod blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_MOD);
|
||||
/* Add blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_ADD);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendMod();
|
||||
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendAdd();
|
||||
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some more blitting routines.
|
||||
*/
|
||||
int surface_testBlitBlendMod(void *arg)
|
||||
{
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* Mod blitting */
|
||||
_testBlitBlendMode(SDL_BLENDMODE_MOD);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendMod();
|
||||
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests some more blitting routines with loop
|
||||
*/
|
||||
int
|
||||
surface_testBlitBlendLoop(void *arg) {
|
||||
int surface_testBlitBlendLoop(void *arg)
|
||||
{
|
||||
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
int ret;
|
||||
SDL_Surface *compareSurface;
|
||||
|
||||
/* All blitting modes */
|
||||
_testBlitBlendMode(-4);
|
||||
/* All blitting modes */
|
||||
_testBlitBlendMode(-4);
|
||||
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendAll();
|
||||
ret = SDLTest_CompareSurfaces( testSurface, compareSurface, 0 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
/* Verify result by comparing surfaces */
|
||||
compareSurface = SDLTest_ImageBlitBlendAll();
|
||||
ret = SDLTest_CompareSurfaces(testSurface, compareSurface, 0);
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(compareSurface);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
int surface_testOverflow(void *arg)
|
||||
{
|
||||
char buf[1024];
|
||||
const char *expectedError;
|
||||
SDL_Surface *surface;
|
||||
|
||||
SDL_memset(buf, '\0', sizeof(buf));
|
||||
|
||||
expectedError = "Parameter 'width' is invalid";
|
||||
surface = SDL_CreateRGBSurfaceWithFormat(0, -3, 100, 8, SDL_PIXELFORMAT_INDEX8);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, -1, 1, 8, 4, SDL_PIXELFORMAT_INDEX8);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, -1, 1, 32, 4, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
||||
expectedError = "Parameter 'height' is invalid";
|
||||
surface = SDL_CreateRGBSurfaceWithFormat(0, 100, -3, 8, SDL_PIXELFORMAT_INDEX8);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 1, -1, 8, 4, SDL_PIXELFORMAT_INDEX8);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 1, -1, 32, 4, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
||||
expectedError = "Parameter 'pitch' is invalid";
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 8, -1, SDL_PIXELFORMAT_INDEX8);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 1, 1, 32, -1, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
||||
/* Less than 1 byte per pixel: the pitch can legitimately be less than
|
||||
* the width, but it must be enough to hold the appropriate number of
|
||||
* bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 4, 3, SDL_PIXELFORMAT_INDEX4LSB);
|
||||
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 6, 1, 4, 3, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, 3, SDL_PIXELFORMAT_INDEX4LSB);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 7, 1, 4, 3, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, 4, SDL_PIXELFORMAT_INDEX4LSB);
|
||||
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 7, 1, 4, 4, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
/* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 16, 1, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
|
||||
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 16, 1, 1, 2, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 17, 1, 1, 2, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 1, 3, SDL_PIXELFORMAT_INDEX1LSB);
|
||||
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 17, 1, 1, 3, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
/* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 5, 1, 8, 5, SDL_PIXELFORMAT_RGB332);
|
||||
SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 5, 1, 8, 5, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 8, 5, SDL_PIXELFORMAT_RGB332);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 6, 1, 8, 5, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
||||
/* Everything else requires more than 1 byte per pixel, and rounds up
|
||||
* each pixel to an integer number of bytes (e.g. RGB555 is really
|
||||
* XRGB1555, with 1 bit per pixel wasted). */
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 3, 1, 15, 6, SDL_PIXELFORMAT_RGB555);
|
||||
SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 3, 1, 15, 6, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface != NULL, "5px * 15 (really 16) bits per px fits in 6 bytes: %s",
|
||||
surface != NULL ? "(success)" : SDL_GetError());
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 15, 6, SDL_PIXELFORMAT_RGB555);
|
||||
SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceFrom(buf, 4, 1, 15, 6, 0, 0, 0, 0);
|
||||
SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
|
||||
if (sizeof(size_t) == 4 && sizeof(int) >= 4) {
|
||||
expectedError = "Out of memory";
|
||||
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32, 1, 8, SDL_PIXELFORMAT_INDEX8);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width + alignment");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32 / 2, 1, 32, SDL_PIXELFORMAT_ARGB8888);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 29) - 1, (1 << 29) - 1, 8, SDL_PIXELFORMAT_INDEX8);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 15) + 1, (1 << 15) + 1, 32, SDL_PIXELFORMAT_ARGB8888);
|
||||
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel");
|
||||
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
|
||||
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
|
||||
} else {
|
||||
SDLTest_Log("Can't easily overflow size_t on this platform");
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Surface test cases */
|
||||
static const SDLTest_TestCaseReference surfaceTest1 =
|
||||
{ (SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest1 = {
|
||||
(SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest2 =
|
||||
{ (SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest2 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest3 =
|
||||
{ (SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest3 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitBlendNone, "surface_testBlitBlendNone", "Tests blitting routines with none blending mode.", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest4 =
|
||||
{ (SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest4 = {
|
||||
(SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest5 =
|
||||
{ (SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest5 = {
|
||||
(SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest6 =
|
||||
{ (SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest6 = {
|
||||
(SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest7 =
|
||||
{ (SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest7 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest8 =
|
||||
{ (SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest8 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
|
||||
static const SDLTest_TestCaseReference surfaceTest9 =
|
||||
{ (SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blitting routines with various blending modes", TEST_DISABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest9 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitBlendLoop, "surface_testBlitBlendLoop", "Test blitting routines with various blending modes", TEST_DISABLED
|
||||
};
|
||||
|
||||
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
|
||||
static const SDLTest_TestCaseReference surfaceTest10 =
|
||||
{ (SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest10 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_DISABLED
|
||||
};
|
||||
|
||||
/* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
|
||||
static const SDLTest_TestCaseReference surfaceTest11 =
|
||||
{ (SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest11 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_DISABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTest12 =
|
||||
{ (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
|
||||
static const SDLTest_TestCaseReference surfaceTest12 = {
|
||||
(SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference surfaceTestOverflow = {
|
||||
surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Surface test cases */
|
||||
static const SDLTest_TestCaseReference *surfaceTests[] = {
|
||||
static const SDLTest_TestCaseReference *surfaceTests[] = {
|
||||
&surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
|
||||
&surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
|
||||
&surfaceTest11, &surfaceTest12, NULL
|
||||
&surfaceTest11, &surfaceTest12, &surfaceTestOverflow, NULL
|
||||
};
|
||||
|
||||
/* Surface test suite (global) */
|
||||
|
|
|
|||
|
|
@ -13,19 +13,18 @@
|
|||
/**
|
||||
* @brief Call to SDL_GetWindowWMInfo
|
||||
*/
|
||||
int
|
||||
syswm_getWindowWMInfo(void *arg)
|
||||
int syswm_getWindowWMInfo(void *arg)
|
||||
{
|
||||
SDL_bool result;
|
||||
SDL_Window *window;
|
||||
SDL_SysWMinfo info;
|
||||
|
||||
window = SDL_CreateWindow("", 0, 0, 0, 0, SDL_WINDOW_HIDDEN);
|
||||
SDLTest_AssertPass("Call to SDL_CreateWindow()");
|
||||
SDLTest_AssertCheck(window != NULL, "Check that value returned from SDL_CreateWindow is not NULL");
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
window = SDL_CreateWindow("", 0, 0, 0, 0, SDL_WINDOW_HIDDEN);
|
||||
SDLTest_AssertPass("Call to SDL_CreateWindow()");
|
||||
SDLTest_AssertCheck(window != NULL, "Check that value returned from SDL_CreateWindow is not NULL");
|
||||
if (window == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
/* Initialize info structure with SDL version info */
|
||||
SDL_VERSION(&info.version);
|
||||
|
|
@ -35,20 +34,21 @@ syswm_getWindowWMInfo(void *arg)
|
|||
SDLTest_AssertPass("Call to SDL_GetWindowWMInfo()");
|
||||
SDLTest_Log((result == SDL_TRUE) ? "Got window information" : "Couldn't get window information");
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
SDLTest_AssertPass("Call to SDL_DestroyWindow()");
|
||||
SDL_DestroyWindow(window);
|
||||
SDLTest_AssertPass("Call to SDL_DestroyWindow()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* SysWM test cases */
|
||||
static const SDLTest_TestCaseReference syswmTest1 =
|
||||
{ (SDLTest_TestCaseFp)syswm_getWindowWMInfo, "syswm_getWindowWMInfo", "Call to SDL_GetWindowWMInfo", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference syswmTest1 = {
|
||||
(SDLTest_TestCaseFp)syswm_getWindowWMInfo, "syswm_getWindowWMInfo", "Call to SDL_GetWindowWMInfo", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of SysWM test cases */
|
||||
static const SDLTest_TestCaseReference *syswmTests[] = {
|
||||
static const SDLTest_TestCaseReference *syswmTests[] = {
|
||||
&syswmTest1, NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,16 +18,15 @@ int _timerCallbackCalled = 0;
|
|||
|
||||
/* Fixture */
|
||||
|
||||
void
|
||||
_timerSetUp(void *arg)
|
||||
void _timerSetUp(void *arg)
|
||||
{
|
||||
/* Start SDL timer subsystem */
|
||||
int ret = SDL_InitSubSystem( SDL_INIT_TIMER );
|
||||
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_TIMER)");
|
||||
SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_TIMER)");
|
||||
int ret = SDL_InitSubSystem(SDL_INIT_TIMER);
|
||||
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_TIMER)");
|
||||
SDLTest_AssertCheck(ret == 0, "Check result from SDL_InitSubSystem(SDL_INIT_TIMER)");
|
||||
if (ret != 0) {
|
||||
SDLTest_LogError("%s", SDL_GetError());
|
||||
}
|
||||
SDLTest_LogError("%s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
/* Test case functions */
|
||||
|
|
@ -35,160 +34,160 @@ _timerSetUp(void *arg)
|
|||
/**
|
||||
* @brief Call to SDL_GetPerformanceCounter
|
||||
*/
|
||||
int
|
||||
timer_getPerformanceCounter(void *arg)
|
||||
int timer_getPerformanceCounter(void *arg)
|
||||
{
|
||||
Uint64 result;
|
||||
Uint64 result;
|
||||
|
||||
result = SDL_GetPerformanceCounter();
|
||||
SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
|
||||
result = SDL_GetPerformanceCounter();
|
||||
SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %" SDL_PRIu64, result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_GetPerformanceFrequency
|
||||
*/
|
||||
int
|
||||
timer_getPerformanceFrequency(void *arg)
|
||||
int timer_getPerformanceFrequency(void *arg)
|
||||
{
|
||||
Uint64 result;
|
||||
Uint64 result;
|
||||
|
||||
result = SDL_GetPerformanceFrequency();
|
||||
SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %"SDL_PRIu64, result);
|
||||
result = SDL_GetPerformanceFrequency();
|
||||
SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %" SDL_PRIu64, result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_Delay and SDL_GetTicks
|
||||
*/
|
||||
int
|
||||
timer_delayAndGetTicks(void *arg)
|
||||
int timer_delayAndGetTicks(void *arg)
|
||||
{
|
||||
const Uint32 testDelay = 100;
|
||||
const Uint32 marginOfError = 25;
|
||||
Uint32 result;
|
||||
Uint32 result2;
|
||||
Uint32 difference;
|
||||
const Uint32 testDelay = 100;
|
||||
const Uint32 marginOfError = 25;
|
||||
Uint32 result;
|
||||
Uint32 result2;
|
||||
Uint32 difference;
|
||||
|
||||
/* Zero delay */
|
||||
SDL_Delay(0);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(0)");
|
||||
/* Zero delay */
|
||||
SDL_Delay(0);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(0)");
|
||||
|
||||
/* Non-zero delay */
|
||||
SDL_Delay(1);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(1)");
|
||||
/* Non-zero delay */
|
||||
SDL_Delay(1);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(1)");
|
||||
|
||||
SDL_Delay(SDLTest_RandomIntegerInRange(5, 15));
|
||||
SDLTest_AssertPass("Call to SDL_Delay()");
|
||||
SDL_Delay(SDLTest_RandomIntegerInRange(5, 15));
|
||||
SDLTest_AssertPass("Call to SDL_Delay()");
|
||||
|
||||
/* Get ticks count - should be non-zero by now */
|
||||
result = SDL_GetTicks();
|
||||
SDLTest_AssertPass("Call to SDL_GetTicks()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %d", result);
|
||||
/* Get ticks count - should be non-zero by now */
|
||||
result = SDL_GetTicks();
|
||||
SDLTest_AssertPass("Call to SDL_GetTicks()");
|
||||
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, result);
|
||||
|
||||
/* Delay a bit longer and measure ticks and verify difference */
|
||||
SDL_Delay(testDelay);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(%d)", testDelay);
|
||||
result2 = SDL_GetTicks();
|
||||
SDLTest_AssertPass("Call to SDL_GetTicks()");
|
||||
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %d", result2);
|
||||
difference = result2 - result;
|
||||
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%d, got: %d", testDelay - marginOfError, difference);
|
||||
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %d", testDelay + marginOfError, difference);
|
||||
/* Delay a bit longer and measure ticks and verify difference */
|
||||
SDL_Delay(testDelay);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(%" SDL_PRIu32 ")", testDelay);
|
||||
result2 = SDL_GetTicks();
|
||||
SDLTest_AssertPass("Call to SDL_GetTicks()");
|
||||
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, result2);
|
||||
difference = result2 - result;
|
||||
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%" SDL_PRIu32 ", got: %" SDL_PRIu32, testDelay - marginOfError, difference);
|
||||
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%" SDL_PRIu32 ", got: %" SDL_PRIu32, testDelay + marginOfError, difference);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* Test callback */
|
||||
Uint32 SDLCALL _timerTestCallback(Uint32 interval, void *param)
|
||||
{
|
||||
_timerCallbackCalled = 1;
|
||||
_timerCallbackCalled = 1;
|
||||
|
||||
if (_paramCheck != 0) {
|
||||
SDLTest_AssertCheck(param != NULL, "Check param pointer, expected: non-NULL, got: %s", (param != NULL) ? "non-NULL" : "NULL");
|
||||
if (param != NULL) {
|
||||
SDLTest_AssertCheck(*(int *)param == _paramValue, "Check param value, expected: %i, got: %i", _paramValue, *(int *)param);
|
||||
}
|
||||
}
|
||||
if (_paramCheck != 0) {
|
||||
SDLTest_AssertCheck(param != NULL, "Check param pointer, expected: non-NULL, got: %s", (param != NULL) ? "non-NULL" : "NULL");
|
||||
if (param != NULL) {
|
||||
SDLTest_AssertCheck(*(int *)param == _paramValue, "Check param value, expected: %i, got: %i", _paramValue, *(int *)param);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_AddTimer and SDL_RemoveTimer
|
||||
*/
|
||||
int
|
||||
timer_addRemoveTimer(void *arg)
|
||||
int timer_addRemoveTimer(void *arg)
|
||||
{
|
||||
SDL_TimerID id;
|
||||
SDL_bool result;
|
||||
int param;
|
||||
SDL_TimerID id;
|
||||
SDL_bool result;
|
||||
int param;
|
||||
|
||||
/* Reset state */
|
||||
_paramCheck = 0;
|
||||
_timerCallbackCalled = 0;
|
||||
/* Reset state */
|
||||
_paramCheck = 0;
|
||||
_timerCallbackCalled = 0;
|
||||
|
||||
/* Set timer with a long delay */
|
||||
id = SDL_AddTimer(10000, _timerTestCallback, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
|
||||
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
|
||||
/* Set timer with a long delay */
|
||||
id = SDL_AddTimer(10000, _timerTestCallback, NULL);
|
||||
SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
|
||||
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
|
||||
|
||||
/* Remove timer again and check that callback was not called */
|
||||
result = SDL_RemoveTimer(id);
|
||||
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
|
||||
SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
|
||||
SDLTest_AssertCheck(_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", _timerCallbackCalled);
|
||||
/* Remove timer again and check that callback was not called */
|
||||
result = SDL_RemoveTimer(id);
|
||||
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
|
||||
SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: %i, got: %i", SDL_TRUE, result);
|
||||
SDLTest_AssertCheck(_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", _timerCallbackCalled);
|
||||
|
||||
/* Try to remove timer again (should be a NOOP) */
|
||||
result = SDL_RemoveTimer(id);
|
||||
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
|
||||
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
|
||||
/* Try to remove timer again (should be a NOOP) */
|
||||
result = SDL_RemoveTimer(id);
|
||||
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
|
||||
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
|
||||
|
||||
/* Reset state */
|
||||
param = SDLTest_RandomIntegerInRange(-1024, 1024);
|
||||
_paramCheck = 1;
|
||||
_paramValue = param;
|
||||
_timerCallbackCalled = 0;
|
||||
/* Reset state */
|
||||
param = SDLTest_RandomIntegerInRange(-1024, 1024);
|
||||
_paramCheck = 1;
|
||||
_paramValue = param;
|
||||
_timerCallbackCalled = 0;
|
||||
|
||||
/* Set timer with a short delay */
|
||||
id = SDL_AddTimer(10, _timerTestCallback, (void *)¶m);
|
||||
SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
|
||||
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
|
||||
/* Set timer with a short delay */
|
||||
id = SDL_AddTimer(10, _timerTestCallback, (void *)¶m);
|
||||
SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
|
||||
SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
|
||||
|
||||
/* Wait to let timer trigger callback */
|
||||
SDL_Delay(100);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(100)");
|
||||
/* Wait to let timer trigger callback */
|
||||
SDL_Delay(100);
|
||||
SDLTest_AssertPass("Call to SDL_Delay(100)");
|
||||
|
||||
/* Remove timer again and check that callback was called */
|
||||
result = SDL_RemoveTimer(id);
|
||||
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
|
||||
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
|
||||
SDLTest_AssertCheck(_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", _timerCallbackCalled);
|
||||
/* Remove timer again and check that callback was called */
|
||||
result = SDL_RemoveTimer(id);
|
||||
SDLTest_AssertPass("Call to SDL_RemoveTimer()");
|
||||
SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: %i, got: %i", SDL_FALSE, result);
|
||||
SDLTest_AssertCheck(_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", _timerCallbackCalled);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Timer test cases */
|
||||
static const SDLTest_TestCaseReference timerTest1 =
|
||||
{ (SDLTest_TestCaseFp)timer_getPerformanceCounter, "timer_getPerformanceCounter", "Call to SDL_GetPerformanceCounter", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference timerTest1 = {
|
||||
(SDLTest_TestCaseFp)timer_getPerformanceCounter, "timer_getPerformanceCounter", "Call to SDL_GetPerformanceCounter", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference timerTest2 =
|
||||
{ (SDLTest_TestCaseFp)timer_getPerformanceFrequency, "timer_getPerformanceFrequency", "Call to SDL_GetPerformanceFrequency", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference timerTest2 = {
|
||||
(SDLTest_TestCaseFp)timer_getPerformanceFrequency, "timer_getPerformanceFrequency", "Call to SDL_GetPerformanceFrequency", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference timerTest3 =
|
||||
{ (SDLTest_TestCaseFp)timer_delayAndGetTicks, "timer_delayAndGetTicks", "Call to SDL_Delay and SDL_GetTicks", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference timerTest3 = {
|
||||
(SDLTest_TestCaseFp)timer_delayAndGetTicks, "timer_delayAndGetTicks", "Call to SDL_Delay and SDL_GetTicks", TEST_ENABLED
|
||||
};
|
||||
|
||||
static const SDLTest_TestCaseReference timerTest4 =
|
||||
{ (SDLTest_TestCaseFp)timer_addRemoveTimer, "timer_addRemoveTimer", "Call to SDL_AddTimer and SDL_RemoveTimer", TEST_ENABLED };
|
||||
static const SDLTest_TestCaseReference timerTest4 = {
|
||||
(SDLTest_TestCaseFp)timer_addRemoveTimer, "timer_addRemoveTimer", "Call to SDL_AddTimer and SDL_RemoveTimer", TEST_ENABLED
|
||||
};
|
||||
|
||||
/* Sequence of Timer test cases */
|
||||
static const SDLTest_TestCaseReference *timerTests[] = {
|
||||
static const SDLTest_TestCaseReference *timerTests[] = {
|
||||
&timerTest1, &timerTest2, &timerTest3, &timerTest4, NULL
|
||||
};
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -23,7 +23,7 @@ int main(int argc, char **argv)
|
|||
|
||||
total = SDL_GetNumVideoDisplays();
|
||||
for (i = 0; i < total; i++) {
|
||||
SDL_Rect bounds = { -1,-1,-1,-1 }, usable = { -1,-1,-1,-1 };
|
||||
SDL_Rect bounds = { -1, -1, -1, -1 }, usable = { -1, -1, -1, -1 };
|
||||
SDL_GetDisplayBounds(i, &bounds);
|
||||
SDL_GetDisplayUsableBounds(i, &usable);
|
||||
SDL_Log("Display #%d ('%s'): bounds={(%d,%d),%dx%d}, usable={(%d,%d),%dx%d}",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -22,59 +22,58 @@
|
|||
/* Stolen from the mailing list */
|
||||
/* Creates a new mouse cursor from an XPM */
|
||||
|
||||
|
||||
/* XPM */
|
||||
static const char *arrow[] = {
|
||||
/* width height num_colors chars_per_pixel */
|
||||
" 32 32 3 1",
|
||||
/* colors */
|
||||
"X c #000000",
|
||||
". c #ffffff",
|
||||
" c None",
|
||||
/* pixels */
|
||||
"X ",
|
||||
"XX ",
|
||||
"X.X ",
|
||||
"X..X ",
|
||||
"X...X ",
|
||||
"X....X ",
|
||||
"X.....X ",
|
||||
"X......X ",
|
||||
"X.......X ",
|
||||
"X........X ",
|
||||
"X.....XXXXX ",
|
||||
"X..X..X ",
|
||||
"X.X X..X ",
|
||||
"XX X..X ",
|
||||
"X X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
"0,0"
|
||||
};
|
||||
/* width height num_colors chars_per_pixel */
|
||||
" 32 32 3 1",
|
||||
/* colors */
|
||||
"X c #000000",
|
||||
". c #ffffff",
|
||||
" c None",
|
||||
/* pixels */
|
||||
"X ",
|
||||
"XX ",
|
||||
"X.X ",
|
||||
"X..X ",
|
||||
"X...X ",
|
||||
"X....X ",
|
||||
"X.....X ",
|
||||
"X......X ",
|
||||
"X.......X ",
|
||||
"X........X ",
|
||||
"X.....XXXXX ",
|
||||
"X..X..X ",
|
||||
"X.X X..X ",
|
||||
"XX X..X ",
|
||||
"X X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" X..X ",
|
||||
" XX ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
"0,0"
|
||||
};
|
||||
|
||||
static SDL_Cursor*
|
||||
static SDL_Cursor *
|
||||
init_color_cursor(const char *file)
|
||||
{
|
||||
SDL_Cursor *cursor = NULL;
|
||||
SDL_Surface *surface = SDL_LoadBMP(file);
|
||||
if (surface) {
|
||||
if (surface->format->palette) {
|
||||
SDL_SetColorKey(surface, 1, *(Uint8 *) surface->pixels);
|
||||
SDL_SetColorKey(surface, 1, *(Uint8 *)surface->pixels);
|
||||
} else {
|
||||
switch (surface->format->BitsPerPixel) {
|
||||
case 15:
|
||||
|
|
@ -97,44 +96,47 @@ init_color_cursor(const char *file)
|
|||
return cursor;
|
||||
}
|
||||
|
||||
static SDL_Cursor*
|
||||
static SDL_Cursor *
|
||||
init_system_cursor(const char *image[])
|
||||
{
|
||||
int i, row, col;
|
||||
Uint8 data[4*32];
|
||||
Uint8 mask[4*32];
|
||||
int hot_x, hot_y;
|
||||
int i, row, col;
|
||||
Uint8 data[4 * 32];
|
||||
Uint8 mask[4 * 32];
|
||||
int hot_x = 0;
|
||||
int hot_y = 0;
|
||||
|
||||
i = -1;
|
||||
for (row=0; row<32; ++row) {
|
||||
for (col=0; col<32; ++col) {
|
||||
if (col % 8) {
|
||||
data[i] <<= 1;
|
||||
mask[i] <<= 1;
|
||||
} else {
|
||||
++i;
|
||||
data[i] = mask[i] = 0;
|
||||
}
|
||||
switch (image[4+row][col]) {
|
||||
case 'X':
|
||||
data[i] |= 0x01;
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case '.':
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
i = -1;
|
||||
for (row = 0; row < 32; ++row) {
|
||||
for (col = 0; col < 32; ++col) {
|
||||
if (col % 8) {
|
||||
data[i] <<= 1;
|
||||
mask[i] <<= 1;
|
||||
} else {
|
||||
++i;
|
||||
data[i] = mask[i] = 0;
|
||||
}
|
||||
switch (image[4 + row][col]) {
|
||||
case 'X':
|
||||
data[i] |= 0x01;
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case '.':
|
||||
mask[i] |= 0x01;
|
||||
break;
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
|
||||
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
|
||||
(void)SDL_sscanf(image[4 + row], "%d,%d", &hot_x, &hot_y);
|
||||
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
|
||||
}
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
int done;
|
||||
static SDL_Cursor *cursors[1+SDL_NUM_SYSTEM_CURSORS];
|
||||
static SDL_Cursor *cursors[1 + SDL_NUM_SYSTEM_CURSORS];
|
||||
static SDL_SystemCursor cursor_types[1 + SDL_NUM_SYSTEM_CURSORS];
|
||||
static int num_cursors;
|
||||
static int current_cursor;
|
||||
static int show_cursor;
|
||||
|
||||
|
|
@ -146,8 +148,7 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
|
@ -156,39 +157,69 @@ loop()
|
|||
SDLTest_CommonEvent(state, &event, &done);
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
if (num_cursors == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
++current_cursor;
|
||||
if (current_cursor == SDL_arraysize(cursors)) {
|
||||
if (current_cursor == num_cursors) {
|
||||
current_cursor = 0;
|
||||
}
|
||||
|
||||
SDL_SetCursor(cursors[current_cursor]);
|
||||
|
||||
if (current_cursor == 0) {
|
||||
switch ((int)cursor_types[current_cursor]) {
|
||||
case (SDL_SystemCursor)-1:
|
||||
SDL_Log("Custom cursor");
|
||||
} else {
|
||||
switch ((SDL_SystemCursor) (current_cursor-1)) {
|
||||
case SDL_SYSTEM_CURSOR_ARROW: SDL_Log("Arrow"); break;
|
||||
case SDL_SYSTEM_CURSOR_IBEAM: SDL_Log("I-beam"); break;
|
||||
case SDL_SYSTEM_CURSOR_WAIT: SDL_Log("Wait"); break;
|
||||
case SDL_SYSTEM_CURSOR_CROSSHAIR: SDL_Log("Crosshair"); break;
|
||||
case SDL_SYSTEM_CURSOR_WAITARROW: SDL_Log("Small wait cursor (or Wait if not available)"); break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENWSE: SDL_Log("Double arrow pointing northwest and southeast"); break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENESW: SDL_Log("Double arrow pointing northeast and southwest"); break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEWE: SDL_Log("Double arrow pointing west and east"); break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENS: SDL_Log("Double arrow pointing north and south"); break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEALL: SDL_Log("Four pointed arrow pointing north, south, east, and west"); break;
|
||||
case SDL_SYSTEM_CURSOR_NO: SDL_Log("Slashed circle or crossbones"); break;
|
||||
case SDL_SYSTEM_CURSOR_HAND: SDL_Log("Hand"); break;
|
||||
default: SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM."); break;
|
||||
}
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_ARROW:
|
||||
SDL_Log("Arrow");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_IBEAM:
|
||||
SDL_Log("I-beam");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WAIT:
|
||||
SDL_Log("Wait");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_CROSSHAIR:
|
||||
SDL_Log("Crosshair");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_WAITARROW:
|
||||
SDL_Log("Small wait cursor (or Wait if not available)");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENWSE:
|
||||
SDL_Log("Double arrow pointing northwest and southeast");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENESW:
|
||||
SDL_Log("Double arrow pointing northeast and southwest");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEWE:
|
||||
SDL_Log("Double arrow pointing west and east");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZENS:
|
||||
SDL_Log("Double arrow pointing north and south");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_SIZEALL:
|
||||
SDL_Log("Four pointed arrow pointing north, south, east, and west");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_NO:
|
||||
SDL_Log("Slashed circle or crossbones");
|
||||
break;
|
||||
case SDL_SYSTEM_CURSOR_HAND:
|
||||
SDL_Log("Hand");
|
||||
break;
|
||||
default:
|
||||
SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM.");
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
show_cursor = !show_cursor;
|
||||
SDL_ShowCursor(show_cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_RenderClear(renderer);
|
||||
|
|
@ -201,8 +232,7 @@ loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
const char *color_cursor = NULL;
|
||||
|
|
@ -212,7 +242,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
|
@ -240,23 +270,38 @@ main(int argc, char *argv[])
|
|||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
num_cursors = 0;
|
||||
|
||||
if (color_cursor) {
|
||||
cursors[0] = init_color_cursor(color_cursor);
|
||||
SDL_Cursor *cursor = init_color_cursor(color_cursor);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
|
||||
num_cursors++;
|
||||
}
|
||||
} else {
|
||||
cursors[0] = init_system_cursor(arrow);
|
||||
}
|
||||
if (!cursors[0]) {
|
||||
SDL_Log("Error, couldn't create cursor\n");
|
||||
quit(2);
|
||||
}
|
||||
for (i = 0; i < SDL_NUM_SYSTEM_CURSORS; ++i) {
|
||||
cursors[1+i] = SDL_CreateSystemCursor((SDL_SystemCursor)i);
|
||||
if (!cursors[1+i]) {
|
||||
SDL_Log("Error, couldn't create system cursor %d\n", i);
|
||||
quit(2);
|
||||
SDL_Cursor *cursor = init_system_cursor(arrow);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
|
||||
num_cursors++;
|
||||
}
|
||||
}
|
||||
SDL_SetCursor(cursors[0]);
|
||||
|
||||
for (i = 0; i < SDL_NUM_SYSTEM_CURSORS; ++i) {
|
||||
SDL_Cursor *cursor = SDL_CreateSystemCursor((SDL_SystemCursor)i);
|
||||
if (cursor) {
|
||||
cursors[num_cursors] = cursor;
|
||||
cursor_types[num_cursors] = i;
|
||||
num_cursors++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_cursors > 0) {
|
||||
SDL_SetCursor(cursors[0]);
|
||||
}
|
||||
|
||||
show_cursor = SDL_ShowCursor(SDL_QUERY);
|
||||
|
||||
/* Main render loop */
|
||||
done = 0;
|
||||
|
|
@ -268,13 +313,13 @@ main(int argc, char *argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < SDL_arraysize(cursors); ++i) {
|
||||
for (i = 0; i < num_cursors; ++i) {
|
||||
SDL_FreeCursor(cursors[i]);
|
||||
}
|
||||
quit(0);
|
||||
|
||||
/* keep the compiler happy ... */
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -20,16 +20,16 @@
|
|||
static void
|
||||
print_mode(const char *prefix, const SDL_DisplayMode *mode)
|
||||
{
|
||||
if (!mode)
|
||||
if (mode == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
|
||||
prefix, SDL_GetPixelFormatName(mode->format),
|
||||
mode->w, mode->h, mode->refresh_rate);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
int num_displays, dpy;
|
||||
|
|
@ -80,7 +80,7 @@ main(int argc, char *argv[])
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError());
|
||||
} else {
|
||||
char prefix[64];
|
||||
SDL_snprintf(prefix, sizeof (prefix), " MODE %d", m);
|
||||
(void)SDL_snprintf(prefix, sizeof(prefix), " MODE %d", m);
|
||||
print_mode(prefix, &mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -37,8 +37,7 @@ static const Uint32 fps_check_delay = 5000;
|
|||
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawPoints(SDL_Renderer * renderer)
|
||||
void DrawPoints(SDL_Renderer *renderer)
|
||||
{
|
||||
int i;
|
||||
int x, y;
|
||||
|
|
@ -71,8 +70,8 @@ DrawPoints(SDL_Renderer * renderer)
|
|||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
|
||||
(Uint8) current_color, (Uint8) current_alpha);
|
||||
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
|
||||
(Uint8)current_color, (Uint8)current_alpha);
|
||||
|
||||
x = rand() % viewport.w;
|
||||
y = rand() % viewport.h;
|
||||
|
|
@ -80,8 +79,7 @@ DrawPoints(SDL_Renderer * renderer)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
DrawLines(SDL_Renderer * renderer)
|
||||
void DrawLines(SDL_Renderer *renderer)
|
||||
{
|
||||
int i;
|
||||
int x1, y1, x2, y2;
|
||||
|
|
@ -114,8 +112,8 @@ DrawLines(SDL_Renderer * renderer)
|
|||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
|
||||
(Uint8) current_color, (Uint8) current_alpha);
|
||||
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
|
||||
(Uint8)current_color, (Uint8)current_alpha);
|
||||
|
||||
if (i == 0) {
|
||||
SDL_RenderDrawLine(renderer, 0, 0, viewport.w - 1, viewport.h - 1);
|
||||
|
|
@ -123,17 +121,16 @@ DrawLines(SDL_Renderer * renderer)
|
|||
SDL_RenderDrawLine(renderer, 0, viewport.h / 2, viewport.w - 1, viewport.h / 2);
|
||||
SDL_RenderDrawLine(renderer, viewport.w / 2, 0, viewport.w / 2, viewport.h - 1);
|
||||
} else {
|
||||
x1 = (rand() % (viewport.w*2)) - viewport.w;
|
||||
x2 = (rand() % (viewport.w*2)) - viewport.w;
|
||||
y1 = (rand() % (viewport.h*2)) - viewport.h;
|
||||
y2 = (rand() % (viewport.h*2)) - viewport.h;
|
||||
x1 = (rand() % (viewport.w * 2)) - viewport.w;
|
||||
x2 = (rand() % (viewport.w * 2)) - viewport.w;
|
||||
y1 = (rand() % (viewport.h * 2)) - viewport.h;
|
||||
y2 = (rand() % (viewport.h * 2)) - viewport.h;
|
||||
SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DrawRects(SDL_Renderer * renderer)
|
||||
void DrawRects(SDL_Renderer *renderer)
|
||||
{
|
||||
int i;
|
||||
SDL_Rect rect;
|
||||
|
|
@ -166,19 +163,18 @@ DrawRects(SDL_Renderer * renderer)
|
|||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
|
||||
(Uint8) current_color, (Uint8) current_alpha);
|
||||
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
|
||||
(Uint8)current_color, (Uint8)current_alpha);
|
||||
|
||||
rect.w = rand() % (viewport.h / 2);
|
||||
rect.h = rand() % (viewport.h / 2);
|
||||
rect.x = (rand() % (viewport.w*2) - viewport.w) - (rect.w / 2);
|
||||
rect.y = (rand() % (viewport.h*2) - viewport.h) - (rect.h / 2);
|
||||
rect.x = (rand() % (viewport.w * 2) - viewport.w) - (rect.w / 2);
|
||||
rect.y = (rand() % (viewport.h * 2) - viewport.h) - (rect.h / 2);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
Uint32 now;
|
||||
int i;
|
||||
|
|
@ -190,8 +186,9 @@ loop()
|
|||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
|
|
@ -211,16 +208,14 @@ loop()
|
|||
if (SDL_TICKS_PASSED(now, next_fps_check)) {
|
||||
/* Print out some timing information */
|
||||
const Uint32 then = next_fps_check - fps_check_delay;
|
||||
const double fps = ((double) frames * 1000) / (now - then);
|
||||
const double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
next_fps_check = now + fps_check_delay;
|
||||
frames = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -232,7 +227,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
|
@ -269,12 +264,13 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
static const char *options[] = {
|
||||
"[--blend none|blend|add|mod]",
|
||||
static const char *options[] = {
|
||||
"[--blend none|blend|add|mod]",
|
||||
"[--cyclecolor]",
|
||||
"[--cyclealpha]",
|
||||
"[num_objects]",
|
||||
NULL };
|
||||
NULL
|
||||
};
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -307,7 +303,6 @@ main(int argc, char *argv[])
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
SDLTest_CommonQuit(state);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -28,25 +28,22 @@ SDL_Renderer *renderer;
|
|||
SDL_Surface *surface;
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawChessBoard()
|
||||
void DrawChessBoard()
|
||||
{
|
||||
int row = 0,column = 0,x = 0;
|
||||
int row = 0, column = 0, x = 0;
|
||||
SDL_Rect rect, darea;
|
||||
|
||||
/* Get the Size of drawing surface */
|
||||
SDL_RenderGetViewport(renderer, &darea);
|
||||
|
||||
for( ; row < 8; row++)
|
||||
{
|
||||
column = row%2;
|
||||
for (; row < 8; row++) {
|
||||
column = row % 2;
|
||||
x = column;
|
||||
for( ; column < 4+(row%2); column++)
|
||||
{
|
||||
for (; column < 4 + (row % 2); column++) {
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
|
||||
|
||||
rect.w = darea.w/8;
|
||||
rect.h = darea.h/8;
|
||||
rect.w = darea.w / 8;
|
||||
rect.h = darea.h / 8;
|
||||
rect.x = x * rect.w;
|
||||
rect.y = row * rect.h;
|
||||
x = x + 2;
|
||||
|
|
@ -55,25 +52,24 @@ DrawChessBoard()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
SDL_Event e;
|
||||
while (SDL_PollEvent(&e)) {
|
||||
|
||||
/* Re-create when window has been resized */
|
||||
if ((e.type == SDL_WINDOWEVENT) && (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) {
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
/* Re-create when window has been resized */
|
||||
if ((e.type == SDL_WINDOWEVENT) && (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) {
|
||||
|
||||
surface = SDL_GetWindowSurface(window);
|
||||
renderer = SDL_CreateSoftwareRenderer(surface);
|
||||
/* Clear the rendering surface with the specified color */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
SDL_DestroyRenderer(renderer);
|
||||
|
||||
if (e.type == SDL_QUIT) {
|
||||
surface = SDL_GetWindowSurface(window);
|
||||
renderer = SDL_CreateSoftwareRenderer(surface);
|
||||
/* Clear the rendering surface with the specified color */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
if (e.type == SDL_QUIT) {
|
||||
done = 1;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_cancel_main_loop();
|
||||
|
|
@ -97,32 +93,27 @@ loop()
|
|||
SDL_UpdateWindowSurface(window);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL */
|
||||
if(SDL_Init(SDL_INIT_VIDEO) != 0)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Create window and renderer for given surface */
|
||||
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
|
||||
if(!window)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
surface = SDL_GetWindowSurface(window);
|
||||
renderer = SDL_CreateSoftwareRenderer(surface);
|
||||
if(!renderer)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +121,6 @@ main(int argc, char *argv[])
|
|||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
|
||||
/* Draw the Image on rendering surface */
|
||||
done = 0;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -25,8 +25,7 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
SDL_Event event;
|
||||
|
|
@ -36,7 +35,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -76,13 +75,13 @@ main(int argc, char *argv[])
|
|||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_DROPBEGIN) {
|
||||
SDL_Log("Drop beginning on window %u", (unsigned int) event.drop.windowID);
|
||||
SDL_Log("Drop beginning on window %u", (unsigned int)event.drop.windowID);
|
||||
} else if (event.type == SDL_DROPCOMPLETE) {
|
||||
SDL_Log("Drop complete on window %u", (unsigned int) event.drop.windowID);
|
||||
SDL_Log("Drop complete on window %u", (unsigned int)event.drop.windowID);
|
||||
} else if ((event.type == SDL_DROPFILE) || (event.type == SDL_DROPTEXT)) {
|
||||
const char *typestr = (event.type == SDL_DROPFILE) ? "File" : "Text";
|
||||
char *dropped_filedir = event.drop.file;
|
||||
SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int) event.drop.windowID, dropped_filedir);
|
||||
SDL_Log("%s dropped on window %u: %s", typestr, (unsigned int)event.drop.windowID, dropped_filedir);
|
||||
/* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
|
||||
/*SDL_free(dropped_filedir);*/
|
||||
}
|
||||
|
|
@ -93,7 +92,7 @@ main(int argc, char *argv[])
|
|||
|
||||
quit(0);
|
||||
/* keep the compiler happy ... */
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -32,17 +32,16 @@ ThreadFunc(void *data)
|
|||
{
|
||||
/* Set the child thread error string */
|
||||
SDL_SetError("Thread %s (%lu) had a problem: %s",
|
||||
(char *) data, SDL_ThreadID(), "nevermind");
|
||||
(char *)data, SDL_ThreadID(), "nevermind");
|
||||
while (alive) {
|
||||
SDL_Log("Thread '%s' is alive!\n", (char *) data);
|
||||
SDL_Log("Thread '%s' is alive!\n", (char *)data);
|
||||
SDL_Delay(1 * 1000);
|
||||
}
|
||||
SDL_Log("Child thread error string: %s\n", SDL_GetError());
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
|
||||
|
|
@ -52,7 +51,7 @@ main(int argc, char *argv[])
|
|||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Set the error value for the main thread */
|
||||
|
|
@ -78,5 +77,5 @@ main(int argc, char *argv[])
|
|||
SDL_Log("Main thread error string: %s\n", SDL_GetError());
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 2020 Collabora Ltd.
|
||||
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 2020-2022 Collabora Ltd.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -31,10 +31,11 @@ static const struct
|
|||
{
|
||||
int code;
|
||||
const char *name;
|
||||
} device_classes[] =
|
||||
{
|
||||
#define CLS(x) \
|
||||
{ SDL_UDEV_DEVICE_ ## x, #x }
|
||||
} device_classes[] = {
|
||||
#define CLS(x) \
|
||||
{ \
|
||||
SDL_UDEV_DEVICE_##x, #x \
|
||||
}
|
||||
CLS(MOUSE),
|
||||
CLS(KEYBOARD),
|
||||
CLS(JOYSTICK),
|
||||
|
|
@ -48,18 +49,18 @@ static const struct
|
|||
|
||||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
uint16_t bus_type;
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
uint16_t version;
|
||||
uint8_t ev[(EV_MAX + 1) / 8];
|
||||
uint8_t keys[(KEY_MAX + 1) / 8];
|
||||
uint8_t abs[(ABS_MAX + 1) / 8];
|
||||
uint8_t rel[(REL_MAX + 1) / 8];
|
||||
uint8_t ff[(FF_MAX + 1) / 8];
|
||||
uint8_t props[INPUT_PROP_MAX / 8];
|
||||
int expected;
|
||||
const char *name;
|
||||
uint16_t bus_type;
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
uint16_t version;
|
||||
uint8_t ev[(EV_MAX + 1) / 8];
|
||||
uint8_t keys[(KEY_MAX + 1) / 8];
|
||||
uint8_t abs[(ABS_MAX + 1) / 8];
|
||||
uint8_t rel[(REL_MAX + 1) / 8];
|
||||
uint8_t ff[(FF_MAX + 1) / 8];
|
||||
uint8_t props[INPUT_PROP_MAX / 8];
|
||||
int expected;
|
||||
} GuessTest;
|
||||
|
||||
/*
|
||||
|
|
@ -73,10 +74,11 @@ typedef struct
|
|||
*/
|
||||
#define ZEROx4 0, 0, 0, 0
|
||||
#define ZEROx8 ZEROx4, ZEROx4
|
||||
#define FFx4 0xff, 0xff, 0xff, 0xff
|
||||
#define FFx8 FFx4, FFx4
|
||||
#define FFx4 0xff, 0xff, 0xff, 0xff
|
||||
#define FFx8 FFx4, FFx4
|
||||
|
||||
/* Test-cases derived from real devices or from Linux kernel source */
|
||||
/* *INDENT-OFF* */ /* clang-format off */
|
||||
static const GuessTest guess_tests[] =
|
||||
{
|
||||
{
|
||||
|
|
@ -934,13 +936,24 @@ static const GuessTest guess_tests[] =
|
|||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
}
|
||||
};
|
||||
/* *INDENT-ON* */ /* clang-format on */
|
||||
|
||||
#if ULONG_MAX == 0xFFFFFFFFUL
|
||||
# define SwapLongLE(X) SDL_SwapLE32(X)
|
||||
#else
|
||||
/* assume 64-bit */
|
||||
# define SwapLongLE(X) SDL_SwapLE64(X)
|
||||
#endif
|
||||
/* The Linux kernel provides capability info in EVIOCGBIT and in /sys
|
||||
* as an array of unsigned long in native byte order, rather than an array
|
||||
* of bytes, an array of native-endian 32-bit words or an array of
|
||||
* native-endian 64-bit words like you might have reasonably expected.
|
||||
* The order of words in the array is always lowest-valued first: for
|
||||
* instance, the first unsigned long in abs[] contains the bit representing
|
||||
* absolute axis 0 (ABS_X).
|
||||
*
|
||||
* The constant arrays above provide test data in little-endian, because
|
||||
* that's the easiest representation for hard-coding into a test like this.
|
||||
* On a big-endian platform we need to byteswap it, one unsigned long at a
|
||||
* time, to match what the kernel would produce. This requires us to choose
|
||||
* an appropriate byteswapping function for the architecture's word size. */
|
||||
SDL_COMPILE_TIME_ASSERT(sizeof_long, sizeof(unsigned long) == 4 || sizeof(unsigned long) == 8);
|
||||
#define SwapLongLE(X) \
|
||||
((sizeof(unsigned long) == 4) ? SDL_SwapLE32(X) : SDL_SwapLE64(X))
|
||||
|
||||
static int
|
||||
run_test(void)
|
||||
|
|
@ -952,7 +965,8 @@ run_test(void)
|
|||
const GuessTest *t = &guess_tests[i];
|
||||
size_t j;
|
||||
int actual;
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
unsigned long ev[NBITS(EV_MAX)];
|
||||
unsigned long abs[NBITS(ABS_MAX)];
|
||||
unsigned long keys[NBITS(KEY_MAX)];
|
||||
|
|
@ -988,8 +1002,7 @@ run_test(void)
|
|||
|
||||
if (actual == t->expected) {
|
||||
printf("\tOK\n");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
printf("\tExpected 0x%08x\n", t->expected);
|
||||
|
||||
for (j = 0; device_classes[j].code != 0; j++) {
|
||||
|
|
@ -1024,8 +1037,7 @@ run_test(void)
|
|||
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
return run_test() ? 0 : 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -13,27 +13,26 @@
|
|||
/* sanity tests on SDL_rwops.c (usefull for alternative implementations of stdio rwops) */
|
||||
|
||||
/* quiet windows compiler warnings */
|
||||
#if defined(_MSC_VER) && !defined(_CRT_NONSTDC_NO_WARNINGS)
|
||||
#define _CRT_NONSTDC_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* WARNING ! those 2 files will be destroyed by this test program */
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#define FBASENAME1 "../Documents/sdldata1" /* this file will be created during tests */
|
||||
#define FBASENAME2 "../Documents/sdldata2" /* this file should not exist before starting test */
|
||||
#else
|
||||
#define FBASENAME1 "sdldata1" /* this file will be created during tests */
|
||||
#define FBASENAME2 "sdldata2" /* this file should not exist before starting test */
|
||||
#define FBASENAME1 "sdldata1" /* this file will be created during tests */
|
||||
#define FBASENAME2 "sdldata2" /* this file should not exist before starting test */
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
|
|
@ -48,22 +47,19 @@ cleanup(void)
|
|||
}
|
||||
|
||||
static void
|
||||
rwops_error_quit(unsigned line, SDL_RWops * rwops)
|
||||
rwops_error_quit(unsigned line, SDL_RWops *rwops)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
|
||||
if (rwops) {
|
||||
rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
|
||||
rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
|
||||
}
|
||||
cleanup();
|
||||
exit(1); /* quit with rwops error (test failed) */
|
||||
exit(1); /* quit with rwops error (test failed) */
|
||||
}
|
||||
|
||||
#define RWOP_ERR_QUIT(x) rwops_error_quit( __LINE__, (x) )
|
||||
#define RWOP_ERR_QUIT(x) rwops_error_quit(__LINE__, (x))
|
||||
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_RWops *rwops = NULL;
|
||||
char test_buf[30];
|
||||
|
|
@ -73,211 +69,289 @@ main(int argc, char *argv[])
|
|||
|
||||
cleanup();
|
||||
|
||||
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
|
||||
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
|
||||
|
||||
rwops = SDL_RWFromFile(NULL, NULL);
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile(NULL, "ab+");
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile("something", "");
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile("something", NULL);
|
||||
if (rwops)
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
SDL_Log("test1 OK\n");
|
||||
|
||||
/* test 2 : check that inexistent file is not successfully opened/created when required */
|
||||
/* modes : r, r+ imply that file MUST exist
|
||||
modes : a, a+, w, w+ checks that it succeeds (file may not exists)
|
||||
/* test 2 : check that inexistent file is not successfully opened/created when required */
|
||||
/* modes : r, r+ imply that file MUST exist
|
||||
modes : a, a+, w, w+ checks that it succeeds (file may not exists)
|
||||
|
||||
*/
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */
|
||||
if (rwops)
|
||||
*/
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "rb"); /* this file doesn't exist that call must fail */
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */
|
||||
if (rwops)
|
||||
}
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "rb+"); /* this file doesn't exist that call must fail */
|
||||
if (rwops) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "wb");
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "wb+");
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "ab");
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
rwops = SDL_RWFromFile(FBASENAME2, "ab+");
|
||||
if (!rwops)
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
unlink(FBASENAME2);
|
||||
SDL_Log("test2 OK\n");
|
||||
|
||||
/* test 3 : creation, writing , reading, seeking,
|
||||
test : w mode, r mode, w+ mode
|
||||
*/
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */
|
||||
if (!rwops)
|
||||
/* test 3 : creation, writing , reading, seeking,
|
||||
test : w mode, r mode, w+ mode
|
||||
*/
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
}
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* we are in write only mode */
|
||||
}
|
||||
|
||||
rwops->close(rwops);
|
||||
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */
|
||||
if (!rwops)
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
}
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3))
|
||||
}
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->write(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* readonly mode */
|
||||
}
|
||||
if (0 != rwops->write(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* readonly mode */
|
||||
}
|
||||
|
||||
rwops->close(rwops);
|
||||
|
||||
/* test 3: same with w+ mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
|
||||
if (!rwops)
|
||||
/* test 3: same with w+ mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
}
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
}
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
}
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3))
|
||||
}
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_Log("test3 OK\n");
|
||||
|
||||
/* test 4: same in r+ mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
|
||||
if (!rwops)
|
||||
/* test 4: same in r+ mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
}
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1))
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops); /* we are in read/write mode */
|
||||
}
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
}
|
||||
if (20 != rwops->seek(rwops, -7, RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3))
|
||||
}
|
||||
if (2 != rwops->read(rwops, test_buf, 10, 3)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "12345678901234567890", 20) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_Log("test4 OK\n");
|
||||
|
||||
/* test5 : append mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
|
||||
if (!rwops)
|
||||
/* test5 : append mode */
|
||||
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
|
||||
if (rwops == NULL) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1))
|
||||
}
|
||||
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10))
|
||||
}
|
||||
if (10 != rwops->write(rwops, "1234567890", 1, 10)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7))
|
||||
}
|
||||
if (7 != rwops->write(rwops, "1234567", 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1))
|
||||
if (1 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
}
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END))
|
||||
if (20 + 27 != rwops->seek(rwops, -7, RW_SEEK_END)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7))
|
||||
}
|
||||
if (7 != rwops->read(rwops, test_buf, 1, 7)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "1234567", 7))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "1234567", 7) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 1, 1)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100))
|
||||
}
|
||||
if (0 != rwops->read(rwops, test_buf, 10, 100)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR))
|
||||
if (27 != rwops->seek(rwops, -27, RW_SEEK_CUR)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET))
|
||||
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (3 != rwops->read(rwops, test_buf, 10, 3))
|
||||
}
|
||||
if (3 != rwops->read(rwops, test_buf, 10, 3)) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30))
|
||||
}
|
||||
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30) != 0) {
|
||||
RWOP_ERR_QUIT(rwops);
|
||||
}
|
||||
rwops->close(rwops);
|
||||
SDL_Log("test5 OK\n");
|
||||
cleanup();
|
||||
return 0; /* all ok */
|
||||
return 0; /* all ok */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -14,8 +14,7 @@
|
|||
#include <stdio.h>
|
||||
#include "SDL.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *base_path;
|
||||
char *pref_path;
|
||||
|
|
@ -29,27 +28,27 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
base_path = SDL_GetBasePath();
|
||||
if(base_path == NULL){
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
|
||||
SDL_GetError());
|
||||
if (base_path == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
|
||||
SDL_GetError());
|
||||
} else {
|
||||
SDL_Log("base path: '%s'\n", base_path);
|
||||
SDL_free(base_path);
|
||||
}
|
||||
|
||||
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());
|
||||
pref_path = SDL_GetPrefPath("libsdl", "test_filesystem");
|
||||
if (pref_path == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
|
||||
SDL_GetError());
|
||||
} else {
|
||||
SDL_Log("pref path: '%s'\n", pref_path);
|
||||
SDL_free(pref_path);
|
||||
}
|
||||
|
||||
pref_path = SDL_GetPrefPath(NULL, "testfilesystem");
|
||||
if(pref_path == NULL){
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
|
||||
SDL_GetError());
|
||||
pref_path = SDL_GetPrefPath(NULL, "test_filesystem");
|
||||
if (pref_path == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
|
||||
SDL_GetError());
|
||||
} else {
|
||||
SDL_Log("pref path: '%s'\n", pref_path);
|
||||
SDL_free(pref_path);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -31,51 +31,73 @@
|
|||
#define BUTTON_SIZE 50
|
||||
#define AXIS_SIZE 50
|
||||
|
||||
#define BUTTON_SIZE 50
|
||||
#define AXIS_SIZE 50
|
||||
|
||||
/* This is indexed by SDL_GameControllerButton. */
|
||||
static const struct { int x; int y; } button_positions[] = {
|
||||
{387, 167}, /* SDL_CONTROLLER_BUTTON_A */
|
||||
{431, 132}, /* SDL_CONTROLLER_BUTTON_B */
|
||||
{342, 132}, /* SDL_CONTROLLER_BUTTON_X */
|
||||
{389, 101}, /* SDL_CONTROLLER_BUTTON_Y */
|
||||
{174, 132}, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{232, 128}, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{289, 132}, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{75, 154}, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{305, 230}, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
{77, 40}, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{396, 36}, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{154, 188}, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
|
||||
{154, 249}, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{116, 217}, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
{186, 217}, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
|
||||
{232, 174}, /* SDL_CONTROLLER_BUTTON_MISC1 */
|
||||
{132, 135}, /* SDL_CONTROLLER_BUTTON_PADDLE1 */
|
||||
{330, 135}, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
|
||||
{132, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
|
||||
{330, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
|
||||
{0, 0}, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
|
||||
static const struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} button_positions[] = {
|
||||
{ 387, 167 }, /* SDL_CONTROLLER_BUTTON_A */
|
||||
{ 431, 132 }, /* SDL_CONTROLLER_BUTTON_B */
|
||||
{ 342, 132 }, /* SDL_CONTROLLER_BUTTON_X */
|
||||
{ 389, 101 }, /* SDL_CONTROLLER_BUTTON_Y */
|
||||
{ 174, 132 }, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{ 232, 128 }, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{ 289, 132 }, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{ 75, 154 }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{ 305, 230 }, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
{ 77, 40 }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{ 396, 36 }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{ 154, 188 }, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
|
||||
{ 154, 249 }, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{ 116, 217 }, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
{ 186, 217 }, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
|
||||
{ 232, 174 }, /* SDL_CONTROLLER_BUTTON_MISC1 */
|
||||
{ 132, 135 }, /* SDL_CONTROLLER_BUTTON_PADDLE1 */
|
||||
{ 330, 135 }, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
|
||||
{ 132, 175 }, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
|
||||
{ 330, 175 }, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
|
||||
{ 0, 0 }, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(button_positions, SDL_arraysize(button_positions) == SDL_CONTROLLER_BUTTON_MAX);
|
||||
|
||||
/* This is indexed by SDL_GameControllerAxis. */
|
||||
static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{74, 153, 270.0}, /* LEFTX */
|
||||
{74, 153, 0.0}, /* LEFTY */
|
||||
{306, 231, 270.0}, /* RIGHTX */
|
||||
{306, 231, 0.0}, /* RIGHTY */
|
||||
{91, -20, 0.0}, /* TRIGGERLEFT */
|
||||
{375, -20, 0.0}, /* TRIGGERRIGHT */
|
||||
static const struct
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
double angle;
|
||||
} axis_positions[] = {
|
||||
{ 74, 153, 270.0 }, /* LEFTX */
|
||||
{ 74, 153, 0.0 }, /* LEFTY */
|
||||
{ 306, 231, 270.0 }, /* RIGHTX */
|
||||
{ 306, 231, 0.0 }, /* RIGHTY */
|
||||
{ 91, -20, 0.0 }, /* TRIGGERLEFT */
|
||||
{ 375, -20, 0.0 }, /* TRIGGERRIGHT */
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(axis_positions, SDL_arraysize(axis_positions) == SDL_CONTROLLER_AXIS_MAX);
|
||||
|
||||
/* This is indexed by SDL_JoystickPowerLevel + 1. */
|
||||
static const char *power_level_strings[] = {
|
||||
"unknown", /* SDL_JOYSTICK_POWER_UNKNOWN */
|
||||
"empty", /* SDL_JOYSTICK_POWER_EMPTY */
|
||||
"low", /* SDL_JOYSTICK_POWER_LOW */
|
||||
"medium", /* SDL_JOYSTICK_POWER_MEDIUM */
|
||||
"full", /* SDL_JOYSTICK_POWER_FULL */
|
||||
"wired", /* SDL_JOYSTICK_POWER_WIRED */
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(power_level_strings, SDL_arraysize(power_level_strings) == SDL_JOYSTICK_POWER_MAX + 1);
|
||||
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_Renderer *screen = NULL;
|
||||
static SDL_bool retval = SDL_FALSE;
|
||||
static SDL_bool done = SDL_FALSE;
|
||||
static SDL_bool set_LED = SDL_FALSE;
|
||||
static int trigger_effect = 0;
|
||||
static SDL_Texture *background_front, *background_back, *button, *axis;
|
||||
static SDL_Texture *background_front, *background_back, *button_texture, *axis_texture;
|
||||
static SDL_GameController *gamecontroller;
|
||||
static SDL_GameController **gamecontrollers;
|
||||
static int num_controllers = 0;
|
||||
|
|
@ -87,7 +109,7 @@ static SDL_GameControllerButton virtual_button_active = SDL_CONTROLLER_BUTTON_IN
|
|||
|
||||
static void UpdateWindowTitle()
|
||||
{
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -95,14 +117,17 @@ static void UpdateWindowTitle()
|
|||
const char *name = SDL_GameControllerName(gamecontroller);
|
||||
const char *serial = SDL_GameControllerGetSerial(gamecontroller);
|
||||
const char *basetitle = "Game Controller Test: ";
|
||||
const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + (serial ? 3 + SDL_strlen(serial) : 0) + 1;
|
||||
const size_t titlelen = SDL_strlen(basetitle) + (name ? SDL_strlen(name) : 0) + (serial ? 3 + SDL_strlen(serial) : 0) + 1;
|
||||
char *title = (char *)SDL_malloc(titlelen);
|
||||
|
||||
retval = SDL_FALSE;
|
||||
done = SDL_FALSE;
|
||||
|
||||
if (title) {
|
||||
SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
|
||||
SDL_strlcpy(title, basetitle, titlelen);
|
||||
if (name) {
|
||||
SDL_strlcat(title, name, titlelen);
|
||||
}
|
||||
if (serial) {
|
||||
SDL_strlcat(title, " (", titlelen);
|
||||
SDL_strlcat(title, serial, titlelen);
|
||||
|
|
@ -116,6 +141,26 @@ static void UpdateWindowTitle()
|
|||
}
|
||||
}
|
||||
|
||||
static const char *GetSensorName(SDL_SensorType sensor)
|
||||
{
|
||||
switch (sensor) {
|
||||
case SDL_SENSOR_ACCEL:
|
||||
return "accelerometer";
|
||||
case SDL_SENSOR_GYRO:
|
||||
return "gyro";
|
||||
case SDL_SENSOR_ACCEL_L:
|
||||
return "accelerometer (L)";
|
||||
case SDL_SENSOR_GYRO_L:
|
||||
return "gyro (L)";
|
||||
case SDL_SENSOR_ACCEL_R:
|
||||
return "accelerometer (R)";
|
||||
case SDL_SENSOR_GYRO_R:
|
||||
return "gyro (R)";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
static int FindController(SDL_JoystickID controller_id)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -133,6 +178,16 @@ static void AddController(int device_index, SDL_bool verbose)
|
|||
SDL_JoystickID controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
SDL_GameController *controller;
|
||||
SDL_GameController **controllers;
|
||||
Uint16 firmware_version;
|
||||
SDL_SensorType sensors[] = {
|
||||
SDL_SENSOR_ACCEL,
|
||||
SDL_SENSOR_GYRO,
|
||||
SDL_SENSOR_ACCEL_L,
|
||||
SDL_SENSOR_GYRO_L,
|
||||
SDL_SENSOR_ACCEL_R,
|
||||
SDL_SENSOR_GYRO_R
|
||||
};
|
||||
unsigned int i;
|
||||
|
||||
controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
|
||||
if (controller_id < 0) {
|
||||
|
|
@ -146,13 +201,13 @@ static void AddController(int device_index, SDL_bool verbose)
|
|||
}
|
||||
|
||||
controller = SDL_GameControllerOpen(device_index);
|
||||
if (!controller) {
|
||||
if (controller == NULL) {
|
||||
SDL_Log("Couldn't open controller: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
controllers = (SDL_GameController **)SDL_realloc(gamecontrollers, (num_controllers + 1) * sizeof(*controllers));
|
||||
if (!controllers) {
|
||||
if (controllers == NULL) {
|
||||
SDL_GameControllerClose(controller);
|
||||
return;
|
||||
}
|
||||
|
|
@ -168,18 +223,22 @@ static void AddController(int device_index, SDL_bool verbose)
|
|||
SDL_Log("Opened game controller %s%s%s\n", name, path ? ", " : "", path ? path : "");
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_ACCEL)) {
|
||||
firmware_version = SDL_GameControllerGetFirmwareVersion(gamecontroller);
|
||||
if (firmware_version) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling accelerometer at %.2f Hz\n", SDL_GameControllerGetSensorDataRate(gamecontroller, SDL_SENSOR_ACCEL));
|
||||
SDL_Log("Firmware version: 0x%x (%d)\n", firmware_version, firmware_version);
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_ACCEL, SDL_TRUE);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_GYRO)) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling gyro at %.2f Hz\n", SDL_GameControllerGetSensorDataRate(gamecontroller, SDL_SENSOR_GYRO));
|
||||
for (i = 0; i < SDL_arraysize(sensors); ++i) {
|
||||
SDL_SensorType sensor = sensors[i];
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, sensor)) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling %s at %.2f Hz\n", GetSensorName(sensor), SDL_GameControllerGetSensorDataRate(gamecontroller, sensor));
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, sensor, SDL_TRUE);
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_GYRO, SDL_TRUE);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasRumble(gamecontroller)) {
|
||||
|
|
@ -219,7 +278,7 @@ static void DelController(SDL_JoystickID controller)
|
|||
|
||||
--num_controllers;
|
||||
if (i < num_controllers) {
|
||||
SDL_memcpy(&gamecontrollers[i], &gamecontrollers[i+1], (num_controllers - i) * sizeof(*gamecontrollers));
|
||||
SDL_memcpy(&gamecontrollers[i], &gamecontrollers[i + 1], (num_controllers - i) * sizeof(*gamecontrollers));
|
||||
}
|
||||
|
||||
if (num_controllers > 0) {
|
||||
|
|
@ -246,35 +305,34 @@ static Uint16 ConvertAxisToRumble(Sint16 axisval)
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
Uint8 ucEnableBits1; /* 0 */
|
||||
Uint8 ucEnableBits2; /* 1 */
|
||||
Uint8 ucRumbleRight; /* 2 */
|
||||
Uint8 ucRumbleLeft; /* 3 */
|
||||
Uint8 ucHeadphoneVolume; /* 4 */
|
||||
Uint8 ucSpeakerVolume; /* 5 */
|
||||
Uint8 ucMicrophoneVolume; /* 6 */
|
||||
Uint8 ucAudioEnableBits; /* 7 */
|
||||
Uint8 ucMicLightMode; /* 8 */
|
||||
Uint8 ucAudioMuteBits; /* 9 */
|
||||
Uint8 rgucRightTriggerEffect[11]; /* 10 */
|
||||
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
|
||||
Uint8 rgucUnknown1[6]; /* 32 */
|
||||
Uint8 ucLedFlags; /* 38 */
|
||||
Uint8 rgucUnknown2[2]; /* 39 */
|
||||
Uint8 ucLedAnim; /* 41 */
|
||||
Uint8 ucLedBrightness; /* 42 */
|
||||
Uint8 ucPadLights; /* 43 */
|
||||
Uint8 ucLedRed; /* 44 */
|
||||
Uint8 ucLedGreen; /* 45 */
|
||||
Uint8 ucLedBlue; /* 46 */
|
||||
Uint8 ucEnableBits1; /* 0 */
|
||||
Uint8 ucEnableBits2; /* 1 */
|
||||
Uint8 ucRumbleRight; /* 2 */
|
||||
Uint8 ucRumbleLeft; /* 3 */
|
||||
Uint8 ucHeadphoneVolume; /* 4 */
|
||||
Uint8 ucSpeakerVolume; /* 5 */
|
||||
Uint8 ucMicrophoneVolume; /* 6 */
|
||||
Uint8 ucAudioEnableBits; /* 7 */
|
||||
Uint8 ucMicLightMode; /* 8 */
|
||||
Uint8 ucAudioMuteBits; /* 9 */
|
||||
Uint8 rgucRightTriggerEffect[11]; /* 10 */
|
||||
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
|
||||
Uint8 rgucUnknown1[6]; /* 32 */
|
||||
Uint8 ucLedFlags; /* 38 */
|
||||
Uint8 rgucUnknown2[2]; /* 39 */
|
||||
Uint8 ucLedAnim; /* 41 */
|
||||
Uint8 ucLedBrightness; /* 42 */
|
||||
Uint8 ucPadLights; /* 43 */
|
||||
Uint8 ucLedRed; /* 44 */
|
||||
Uint8 ucLedGreen; /* 45 */
|
||||
Uint8 ucLedBlue; /* 46 */
|
||||
} DS5EffectsState_t;
|
||||
|
||||
static void CyclePS5TriggerEffect()
|
||||
{
|
||||
DS5EffectsState_t state;
|
||||
|
||||
Uint8 effects[3][11] =
|
||||
{
|
||||
Uint8 effects[3][11] = {
|
||||
/* Clear trigger effect */
|
||||
{ 0x05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
/* Constant resistance across entire trigger pull */
|
||||
|
|
@ -355,7 +413,7 @@ static void OpenVirtualController()
|
|||
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
|
||||
} else {
|
||||
virtual_joystick = SDL_JoystickOpen(virtual_index);
|
||||
if (!virtual_joystick) {
|
||||
if (virtual_joystick == NULL) {
|
||||
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
|
@ -365,7 +423,7 @@ static void CloseVirtualController()
|
|||
{
|
||||
int i;
|
||||
|
||||
for (i = SDL_NumJoysticks(); i--; ) {
|
||||
for (i = SDL_NumJoysticks(); i--;) {
|
||||
if (SDL_JoystickIsVirtual(i)) {
|
||||
SDL_JoystickDetachVirtual(i);
|
||||
}
|
||||
|
|
@ -460,7 +518,7 @@ static void VirtualControllerMouseMotion(int x, int y)
|
|||
valueY = (Sint16)(distanceY * -SDL_JOYSTICK_AXIS_MIN);
|
||||
}
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, valueX);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active+1, valueY);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active + 1, valueY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -497,14 +555,13 @@ static void VirtualControllerMouseUp(int x, int y)
|
|||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, SDL_JOYSTICK_AXIS_MIN);
|
||||
} else {
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, 0);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active+1, 0);
|
||||
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active + 1, 0);
|
||||
}
|
||||
virtual_axis_active = SDL_CONTROLLER_AXIS_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop(void *arg)
|
||||
void loop(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
|
@ -517,40 +574,38 @@ loop(void *arg)
|
|||
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1) {
|
||||
switch (event.type) {
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
SDL_Log("Game controller device %d added.\n", (int) SDL_JoystickGetDeviceInstanceID(event.cdevice.which));
|
||||
SDL_Log("Game controller device %d added.\n", (int)SDL_JoystickGetDeviceInstanceID(event.cdevice.which));
|
||||
AddController(event.cdevice.which, SDL_TRUE);
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERDEVICEREMOVED:
|
||||
SDL_Log("Game controller device %d removed.\n", (int) event.cdevice.which);
|
||||
SDL_Log("Game controller device %d removed.\n", (int)event.cdevice.which);
|
||||
DelController(event.cdevice.which);
|
||||
break;
|
||||
|
||||
case SDL_CONTROLLERTOUCHPADDOWN:
|
||||
case SDL_CONTROLLERTOUCHPADMOTION:
|
||||
case SDL_CONTROLLERTOUCHPADUP:
|
||||
SDL_Log("Controller %d touchpad %d finger %d %s %.2f, %.2f, %.2f\n",
|
||||
event.ctouchpad.which,
|
||||
event.ctouchpad.touchpad,
|
||||
event.ctouchpad.finger,
|
||||
(event.type == SDL_CONTROLLERTOUCHPADDOWN ? "pressed at" :
|
||||
(event.type == SDL_CONTROLLERTOUCHPADUP ? "released at" :
|
||||
"moved to")),
|
||||
event.ctouchpad.x,
|
||||
event.ctouchpad.y,
|
||||
event.ctouchpad.pressure);
|
||||
SDL_Log("Controller %" SDL_PRIs32 " touchpad %" SDL_PRIs32 " finger %" SDL_PRIs32 " %s %.2f, %.2f, %.2f\n",
|
||||
event.ctouchpad.which,
|
||||
event.ctouchpad.touchpad,
|
||||
event.ctouchpad.finger,
|
||||
(event.type == SDL_CONTROLLERTOUCHPADDOWN ? "pressed at" : (event.type == SDL_CONTROLLERTOUCHPADUP ? "released at" : "moved to")),
|
||||
event.ctouchpad.x,
|
||||
event.ctouchpad.y,
|
||||
event.ctouchpad.pressure);
|
||||
break;
|
||||
|
||||
#define VERBOSE_SENSORS
|
||||
#ifdef VERBOSE_SENSORS
|
||||
case SDL_CONTROLLERSENSORUPDATE:
|
||||
SDL_Log("Controller %d sensor %s: %.2f, %.2f, %.2f\n",
|
||||
event.csensor.which,
|
||||
event.csensor.sensor == SDL_SENSOR_ACCEL ? "accelerometer" :
|
||||
event.csensor.sensor == SDL_SENSOR_GYRO ? "gyro" : "unknown",
|
||||
event.csensor.data[0],
|
||||
event.csensor.data[1],
|
||||
event.csensor.data[2]);
|
||||
SDL_Log("Controller %" SDL_PRIs32 " sensor %s: %.2f, %.2f, %.2f (%" SDL_PRIu64 ")\n",
|
||||
event.csensor.which,
|
||||
GetSensorName((SDL_SensorType)event.csensor.sensor),
|
||||
event.csensor.data[0],
|
||||
event.csensor.data[1],
|
||||
event.csensor.data[2],
|
||||
event.csensor.timestamp_us);
|
||||
break;
|
||||
#endif /* VERBOSE_SENSORS */
|
||||
|
||||
|
|
@ -560,7 +615,7 @@ loop(void *arg)
|
|||
if (event.caxis.value <= (-SDL_JOYSTICK_AXIS_MAX / 2) || event.caxis.value >= (SDL_JOYSTICK_AXIS_MAX / 2)) {
|
||||
SetController(event.caxis.which);
|
||||
}
|
||||
SDL_Log("Controller %d axis %s changed to %d\n", event.caxis.which, SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
|
||||
SDL_Log("Controller %" SDL_PRIs32 " axis %s changed to %d\n", event.caxis.which, SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
|
||||
break;
|
||||
#endif /* VERBOSE_AXES */
|
||||
|
||||
|
|
@ -569,7 +624,7 @@ loop(void *arg)
|
|||
if (event.type == SDL_CONTROLLERBUTTONDOWN) {
|
||||
SetController(event.cbutton.which);
|
||||
}
|
||||
SDL_Log("Controller %d button %s %s\n", event.cbutton.which, SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
|
||||
SDL_Log("Controller %" SDL_PRIs32 " button %s %s\n", event.cbutton.which, SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
|
||||
|
||||
/* Cycle PS5 trigger effects when the microphone button is pressed */
|
||||
if (event.type == SDL_CONTROLLERBUTTONDOWN &&
|
||||
|
|
@ -579,6 +634,10 @@ loop(void *arg)
|
|||
}
|
||||
break;
|
||||
|
||||
case SDL_JOYBATTERYUPDATED:
|
||||
SDL_Log("Controller %" SDL_PRIs32 " battery state changed to %s\n", event.jbattery.which, power_level_strings[event.jbattery.level + 1]);
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (virtual_joystick) {
|
||||
VirtualControllerMouseDown(event.button.x, event.button.y);
|
||||
|
|
@ -644,14 +703,14 @@ loop(void *arg)
|
|||
dst.y = button_positions[i].y;
|
||||
dst.w = BUTTON_SIZE;
|
||||
dst.h = BUTTON_SIZE;
|
||||
SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderCopyEx(screen, button_texture, NULL, &dst, 0, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showing_front) {
|
||||
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
|
||||
if (value < -deadzone) {
|
||||
const double angle = axis_positions[i].angle;
|
||||
|
|
@ -660,7 +719,7 @@ loop(void *arg)
|
|||
dst.y = axis_positions[i].y;
|
||||
dst.w = AXIS_SIZE;
|
||||
dst.h = AXIS_SIZE;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderCopyEx(screen, axis_texture, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
} else if (value > deadzone) {
|
||||
const double angle = axis_positions[i].angle + 180.0;
|
||||
SDL_Rect dst;
|
||||
|
|
@ -668,7 +727,7 @@ loop(void *arg)
|
|||
dst.y = axis_positions[i].y;
|
||||
dst.w = AXIS_SIZE;
|
||||
dst.h = AXIS_SIZE;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderCopyEx(screen, axis_texture, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -685,14 +744,14 @@ loop(void *arg)
|
|||
Uint8 r, g, b;
|
||||
|
||||
if (x < 0) {
|
||||
r = (Uint8)(((int)(~x) * 255) / 32767);
|
||||
r = (Uint8)(((~x) * 255) / 32767);
|
||||
b = 0;
|
||||
} else {
|
||||
r = 0;
|
||||
b = (Uint8)(((int)(x) * 255) / 32767);
|
||||
b = (Uint8)(((int)(x)*255) / 32767);
|
||||
}
|
||||
if (y > 0) {
|
||||
g = (Uint8)(((int)(y) * 255) / 32767);
|
||||
g = (Uint8)(((int)(y)*255) / 32767);
|
||||
} else {
|
||||
g = 0;
|
||||
}
|
||||
|
|
@ -732,8 +791,7 @@ loop(void *arg)
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int controller_count = 0;
|
||||
|
|
@ -741,9 +799,9 @@ main(int argc, char *argv[])
|
|||
char guid[64];
|
||||
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_STEAM, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ROG_CHAKRAM, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||
SDL_SetHint(SDL_HINT_LINUX_JOYSTICK_DEADZONES, "1");
|
||||
|
|
@ -752,7 +810,7 @@ main(int argc, char *argv[])
|
|||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL (Note: video is required to start event loop) */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -779,7 +837,7 @@ main(int argc, char *argv[])
|
|||
const char *description;
|
||||
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
|
||||
guid, sizeof (guid));
|
||||
guid, sizeof(guid));
|
||||
|
||||
if (SDL_IsGameController(i)) {
|
||||
controller_count++;
|
||||
|
|
@ -792,6 +850,11 @@ main(int argc, char *argv[])
|
|||
case SDL_CONTROLLER_TYPE_GOOGLE_STADIA:
|
||||
description = "Google Stadia Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT:
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT:
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR:
|
||||
description = "Nintendo Switch Joy-Con";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
|
||||
description = "Nintendo Switch Pro Controller";
|
||||
break;
|
||||
|
|
@ -824,8 +887,8 @@ main(int argc, char *argv[])
|
|||
description = "Joystick";
|
||||
}
|
||||
SDL_Log("%s %d: %s%s%s (guid %s, VID 0x%.4x, PID 0x%.4x, player index = %d)\n",
|
||||
description, i, name ? name : "Unknown", path ? ", " : "", path ? path : "", guid,
|
||||
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i), SDL_JoystickGetDevicePlayerIndex(i));
|
||||
description, i, name ? name : "Unknown", path ? ", " : "", path ? path : "", guid,
|
||||
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i), SDL_JoystickGetDevicePlayerIndex(i));
|
||||
}
|
||||
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", controller_count, SDL_NumJoysticks());
|
||||
|
||||
|
|
@ -854,16 +917,16 @@ main(int argc, char *argv[])
|
|||
|
||||
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE, NULL, NULL);
|
||||
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE, NULL, NULL);
|
||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE, NULL, NULL);
|
||||
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE, NULL, NULL);
|
||||
button_texture = LoadTexture(screen, "button.bmp", SDL_TRUE, NULL, NULL);
|
||||
axis_texture = LoadTexture(screen, "axis.bmp", SDL_TRUE, NULL, NULL);
|
||||
|
||||
if (!background_front || !background_back || !button || !axis) {
|
||||
if (background_front == NULL || background_back == NULL || button_texture == NULL || axis_texture == NULL) {
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return 2;
|
||||
}
|
||||
SDL_SetTextureColorMod(button, 10, 255, 21);
|
||||
SDL_SetTextureColorMod(axis, 10, 255, 21);
|
||||
SDL_SetTextureColorMod(button_texture, 10, 255, 21);
|
||||
SDL_SetTextureColorMod(axis_texture, 10, 255, 21);
|
||||
|
||||
/* !!! FIXME: */
|
||||
/*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -27,7 +27,7 @@ static SDLTest_CommonState *state;
|
|||
static SDL_bool use_texture = SDL_FALSE;
|
||||
static SDL_Texture **sprites;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
static double angle = 0.0;
|
||||
static float angle = 0.0f;
|
||||
static int sprite_w, sprite_h;
|
||||
|
||||
int done;
|
||||
|
|
@ -41,8 +41,7 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
int
|
||||
LoadSprite(const char *file)
|
||||
int LoadSprite(const char *file)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -50,22 +49,20 @@ LoadSprite(const char *file)
|
|||
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
|
||||
sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
|
||||
if (!sprites[i]) {
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
|
||||
SDL_DestroyTexture(sprites[i]);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* We're ready to roll. :) */
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
|
@ -99,16 +96,17 @@ loop()
|
|||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_Vertex verts[3];
|
||||
double a;
|
||||
double d;
|
||||
float a;
|
||||
float d;
|
||||
int cx, cy;
|
||||
|
||||
/* Query the sizes */
|
||||
|
|
@ -116,39 +114,39 @@ loop()
|
|||
SDL_zeroa(verts);
|
||||
cx = viewport.x + viewport.w / 2;
|
||||
cy = viewport.y + viewport.h / 2;
|
||||
d = (viewport.w + viewport.h) / 5;
|
||||
d = (viewport.w + viewport.h) / 5.f;
|
||||
|
||||
a = (angle * 3.1415) / 180.0;
|
||||
verts[0].position.x = cx + d * SDL_cos(a);
|
||||
verts[0].position.y = cy + d * SDL_sin(a);
|
||||
a = (angle * 3.1415f) / 180.0f;
|
||||
verts[0].position.x = cx + d * SDL_cosf(a);
|
||||
verts[0].position.y = cy + d * SDL_sinf(a);
|
||||
verts[0].color.r = 0xFF;
|
||||
verts[0].color.g = 0;
|
||||
verts[0].color.b = 0;
|
||||
verts[0].color.a = 0xFF;
|
||||
|
||||
a = ((angle + 120) * 3.1415) / 180.0;
|
||||
verts[1].position.x = cx + d * SDL_cos(a);
|
||||
verts[1].position.y = cy + d * SDL_sin(a);
|
||||
a = ((angle + 120) * 3.1415f) / 180.0f;
|
||||
verts[1].position.x = cx + d * SDL_cosf(a);
|
||||
verts[1].position.y = cy + d * SDL_sinf(a);
|
||||
verts[1].color.r = 0;
|
||||
verts[1].color.g = 0xFF;
|
||||
verts[1].color.b = 0;
|
||||
verts[1].color.a = 0xFF;
|
||||
|
||||
a = ((angle + 240) * 3.1415) / 180.0;
|
||||
verts[2].position.x = cx + d * SDL_cos(a);
|
||||
verts[2].position.y = cy + d * SDL_sin(a);
|
||||
a = ((angle + 240) * 3.1415f) / 180.0f;
|
||||
verts[2].position.x = cx + d * SDL_cosf(a);
|
||||
verts[2].position.y = cy + d * SDL_sinf(a);
|
||||
verts[2].color.r = 0;
|
||||
verts[2].color.g = 0;
|
||||
verts[2].color.b = 0xFF;
|
||||
verts[2].color.a = 0xFF;
|
||||
|
||||
if (use_texture) {
|
||||
verts[0].tex_coord.x = 0.5;
|
||||
verts[0].tex_coord.y = 0.0;
|
||||
verts[1].tex_coord.x = 1.0;
|
||||
verts[1].tex_coord.y = 1.0;
|
||||
verts[2].tex_coord.x = 0.0;
|
||||
verts[2].tex_coord.y = 1.0;
|
||||
verts[0].tex_coord.x = 0.5f;
|
||||
verts[0].tex_coord.y = 0.0f;
|
||||
verts[1].tex_coord.x = 1.0f;
|
||||
verts[1].tex_coord.y = 1.0f;
|
||||
verts[2].tex_coord.x = 0.0f;
|
||||
verts[2].tex_coord.y = 1.0f;
|
||||
}
|
||||
|
||||
SDL_RenderGeometry(renderer, sprites[i], verts, 3, NULL, 0);
|
||||
|
|
@ -163,8 +161,7 @@ loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
const char *icon = "icon.bmp";
|
||||
|
|
@ -175,7 +172,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
|
@ -218,8 +215,8 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Create the windows, initialize the renderers, and load the textures */
|
||||
sprites =
|
||||
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
|
||||
if (!sprites) {
|
||||
(SDL_Texture **)SDL_malloc(state->num_windows * sizeof(*sprites));
|
||||
if (sprites == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
|
@ -237,7 +234,6 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
/* Main render loop */
|
||||
|
|
@ -251,16 +247,16 @@ main(int argc, char *argv[])
|
|||
while (!done) {
|
||||
++frames;
|
||||
loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
}
|
||||
|
||||
|
||||
quit(0);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -26,9 +26,9 @@
|
|||
#include "SDL_test.h"
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#define WIDTH 640
|
||||
#define WIDTH 640
|
||||
#define HEIGHT 480
|
||||
#define BPP 4
|
||||
#define BPP 4
|
||||
|
||||
/* MUST BE A POWER OF 2! */
|
||||
#define EVENT_BUF_SIZE 256
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
static SDLTest_CommonState *state;
|
||||
static SDL_Event events[EVENT_BUF_SIZE];
|
||||
static int eventWrite;
|
||||
static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF};
|
||||
static int colors[7] = { 0xFF, 0xFF00, 0xFF0000, 0xFFFF00, 0x00FFFF, 0xFF00FF, 0xFFFFFF };
|
||||
static int quitting = 0;
|
||||
|
||||
typedef struct
|
||||
|
|
@ -54,7 +54,6 @@ typedef struct
|
|||
|
||||
static Knob knob = { 0.0f, 0.1f, { 0.0f, 0.0f } };
|
||||
|
||||
|
||||
static void
|
||||
setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
|
||||
{
|
||||
|
|
@ -65,26 +64,26 @@ setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
|
|||
const int y = (int)_y;
|
||||
float a;
|
||||
|
||||
if ( (x < 0) || (x >= screen->w) || (y < 0) || (y >= screen->h) ) {
|
||||
if ((x < 0) || (x >= screen->w) || (y < 0) || (y >= screen->h)) {
|
||||
return;
|
||||
}
|
||||
|
||||
pixmem32 = (Uint32 *) screen->pixels + y * screen->pitch / BPP + x;
|
||||
pixmem32 = (Uint32 *)screen->pixels + y * screen->pitch / BPP + x;
|
||||
|
||||
SDL_memcpy(&colour, pixmem32, screen->format->BytesPerPixel);
|
||||
|
||||
SDL_GetRGB(colour,screen->format,&r,&g,&b);
|
||||
SDL_GetRGB(colour, screen->format, &r, &g, &b);
|
||||
|
||||
/* r = 0;g = 0; b = 0; */
|
||||
a = (float) ((col >> 24) & 0xFF);
|
||||
a = (float)((col >> 24) & 0xFF);
|
||||
if (a == 0) {
|
||||
a = 0xFF; /* Hack, to make things easier. */
|
||||
}
|
||||
|
||||
a = (a == 0.0f) ? 1 : (a / 255.0f);
|
||||
r = (Uint8) (r * (1 - a) + ((col >> 16) & 0xFF) * a);
|
||||
g = (Uint8) (g * (1 - a) + ((col >> 8) & 0xFF) * a);
|
||||
b = (Uint8) (b * (1 - a) + ((col >> 0) & 0xFF) * a);
|
||||
r = (Uint8)(r * (1 - a) + ((col >> 16) & 0xFF) * a);
|
||||
g = (Uint8)(g * (1 - a) + ((col >> 8) & 0xFF) * a);
|
||||
b = (Uint8)(b * (1 - a) + ((col >> 0) & 0xFF) * a);
|
||||
colour = SDL_MapRGB(screen->format, r, g, b);
|
||||
|
||||
*pixmem32 = colour;
|
||||
|
|
@ -104,11 +103,11 @@ drawLine(SDL_Surface *screen, float x0, float y0, float x1, float y1, unsigned i
|
|||
static void
|
||||
drawCircle(SDL_Surface *screen, float x, float y, float r, unsigned int c)
|
||||
{
|
||||
float tx,ty, xr;
|
||||
for (ty = (float) -SDL_fabs(r); ty <= (float) SDL_fabs((int) r); ty++) {
|
||||
xr = (float) SDL_sqrt(r * r - ty * ty);
|
||||
float tx, ty, xr;
|
||||
for (ty = (float)-SDL_fabs(r); ty <= (float)SDL_fabs((int)r); ty++) {
|
||||
xr = (float)SDL_sqrt(r * r - ty * ty);
|
||||
if (r > 0) { /* r > 0 ==> filled circle */
|
||||
for(tx = -xr + 0.5f; tx <= xr - 0.5f; tx++) {
|
||||
for (tx = -xr + 0.5f; tx <= xr - 0.5f; tx++) {
|
||||
setpix(screen, x + tx, y + ty, c);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -132,7 +131,7 @@ DrawScreen(SDL_Window *window)
|
|||
SDL_Surface *screen = SDL_GetWindowSurface(window);
|
||||
int i;
|
||||
|
||||
if (!screen) {
|
||||
if (screen == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -145,15 +144,15 @@ DrawScreen(SDL_Window *window)
|
|||
float x, y;
|
||||
unsigned int c, col;
|
||||
|
||||
if ( (event->type == SDL_FINGERMOTION) ||
|
||||
(event->type == SDL_FINGERDOWN) ||
|
||||
(event->type == SDL_FINGERUP) ) {
|
||||
if ((event->type == SDL_FINGERMOTION) ||
|
||||
(event->type == SDL_FINGERDOWN) ||
|
||||
(event->type == SDL_FINGERUP)) {
|
||||
x = event->tfinger.x;
|
||||
y = event->tfinger.y;
|
||||
|
||||
/* draw the touch: */
|
||||
c = colors[event->tfinger.fingerId % 7];
|
||||
col = ((unsigned int) (c * (0.1f + 0.85f))) | (unsigned int) (0xFF * age) << 24;
|
||||
col = ((unsigned int)(c * (0.1f + 0.85f))) | (unsigned int)(0xFF * age) << 24;
|
||||
|
||||
if (event->type == SDL_FINGERMOTION) {
|
||||
drawCircle(screen, x * screen->w, y * screen->h, 5, col);
|
||||
|
|
@ -181,78 +180,79 @@ loop(void)
|
|||
SDLTest_CommonEvent(state, &event, &quitting);
|
||||
|
||||
/* Record _all_ events */
|
||||
events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
|
||||
events[eventWrite & (EVENT_BUF_SIZE - 1)] = event;
|
||||
eventWrite++;
|
||||
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_i: {
|
||||
for (i = 0; i < SDL_GetNumTouchDevices(); ++i) {
|
||||
const SDL_TouchID id = SDL_GetTouchDevice(i);
|
||||
const char *name = SDL_GetTouchName(i);
|
||||
SDL_Log("Fingers Down on device %"SDL_PRIs64" (%s): %d", id, name, SDL_GetNumTouchFingers(id));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_SPACE:
|
||||
SDL_RecordGesture(-1);
|
||||
break;
|
||||
|
||||
case SDLK_s:
|
||||
stream = SDL_RWFromFile("gestureSave", "w");
|
||||
SDL_Log("Wrote %i templates", SDL_SaveAllDollarTemplates(stream));
|
||||
SDL_RWclose(stream);
|
||||
break;
|
||||
|
||||
case SDLK_l:
|
||||
stream = SDL_RWFromFile("gestureSave", "r");
|
||||
SDL_Log("Loaded: %i", SDL_LoadDollarTemplates(-1, stream));
|
||||
SDL_RWclose(stream);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_i:
|
||||
{
|
||||
for (i = 0; i < SDL_GetNumTouchDevices(); ++i) {
|
||||
const SDL_TouchID id = SDL_GetTouchDevice(i);
|
||||
const char *name = SDL_GetTouchName(i);
|
||||
SDL_Log("Fingers Down on device %" SDL_PRIs64 " (%s): %d", id, name, SDL_GetNumTouchFingers(id));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDLK_SPACE:
|
||||
SDL_RecordGesture(-1);
|
||||
break;
|
||||
|
||||
case SDLK_s:
|
||||
stream = SDL_RWFromFile("gestureSave", "w");
|
||||
SDL_Log("Wrote %i templates", SDL_SaveAllDollarTemplates(stream));
|
||||
SDL_RWclose(stream);
|
||||
break;
|
||||
|
||||
case SDLK_l:
|
||||
stream = SDL_RWFromFile("gestureSave", "r");
|
||||
SDL_Log("Loaded: %i", SDL_LoadDollarTemplates(-1, stream));
|
||||
SDL_RWclose(stream);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
#if VERBOSE
|
||||
case SDL_FINGERMOTION:
|
||||
SDL_Log("Finger: %"SDL_PRIs64", x: %f, y: %f",event.tfinger.fingerId,
|
||||
event.tfinger.x,event.tfinger.y);
|
||||
break;
|
||||
case SDL_FINGERMOTION:
|
||||
SDL_Log("Finger: %" SDL_PRIs64 ", x: %f, y: %f", event.tfinger.fingerId,
|
||||
event.tfinger.x, event.tfinger.y);
|
||||
break;
|
||||
|
||||
case SDL_FINGERDOWN:
|
||||
SDL_Log("Finger: %"SDL_PRIs64" down - x: %f, y: %f",
|
||||
event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
SDL_Log("Finger: %" SDL_PRIs64 " down - x: %f, y: %f",
|
||||
event.tfinger.fingerId, event.tfinger.x, event.tfinger.y);
|
||||
break;
|
||||
|
||||
case SDL_FINGERUP:
|
||||
SDL_Log("Finger: %"SDL_PRIs64" up - x: %f, y: %f",
|
||||
event.tfinger.fingerId,event.tfinger.x,event.tfinger.y);
|
||||
break;
|
||||
case SDL_FINGERUP:
|
||||
SDL_Log("Finger: %" SDL_PRIs64 " up - x: %f, y: %f",
|
||||
event.tfinger.fingerId, event.tfinger.x, event.tfinger.y);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SDL_MULTIGESTURE:
|
||||
case SDL_MULTIGESTURE:
|
||||
#if VERBOSE
|
||||
SDL_Log("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f",
|
||||
event.mgesture.x, event.mgesture.y,
|
||||
event.mgesture.dTheta, event.mgesture.dDist);
|
||||
SDL_Log("MG: numDownTouch = %i",event.mgesture.numFingers);
|
||||
SDL_Log("Multi Gesture: x = %f, y = %f, dAng = %f, dR = %f",
|
||||
event.mgesture.x, event.mgesture.y,
|
||||
event.mgesture.dTheta, event.mgesture.dDist);
|
||||
SDL_Log("MG: numDownTouch = %i", event.mgesture.numFingers);
|
||||
#endif
|
||||
|
||||
knob.p.x = event.mgesture.x;
|
||||
knob.p.y = event.mgesture.y;
|
||||
knob.ang += event.mgesture.dTheta;
|
||||
knob.r += event.mgesture.dDist;
|
||||
break;
|
||||
knob.p.x = event.mgesture.x;
|
||||
knob.p.y = event.mgesture.y;
|
||||
knob.ang += event.mgesture.dTheta;
|
||||
knob.r += event.mgesture.dDist;
|
||||
break;
|
||||
|
||||
case SDL_DOLLARGESTURE:
|
||||
SDL_Log("Gesture %"SDL_PRIs64" performed, error: %f",
|
||||
event.dgesture.gestureId, event.dgesture.error);
|
||||
break;
|
||||
case SDL_DOLLARGESTURE:
|
||||
SDL_Log("Gesture %" SDL_PRIs64 " performed, error: %f",
|
||||
event.dgesture.gestureId, event.dgesture.error);
|
||||
break;
|
||||
|
||||
case SDL_DOLLARRECORD:
|
||||
SDL_Log("Recorded gesture: %"SDL_PRIs64"",event.dgesture.gestureId);
|
||||
break;
|
||||
case SDL_DOLLARRECORD:
|
||||
SDL_Log("Recorded gesture: %" SDL_PRIs64 "", event.dgesture.gestureId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -269,10 +269,10 @@ loop(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -26,12 +26,11 @@
|
|||
|
||||
typedef struct GL_Context
|
||||
{
|
||||
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
|
||||
#define SDL_PROC(ret, func, params) ret (APIENTRY *func) params;
|
||||
#include "../src/render/opengl/SDL_glfuncs.h"
|
||||
#undef SDL_PROC
|
||||
} GL_Context;
|
||||
|
||||
|
||||
/* Undefine this if you want a flat cube instead of a rainbow cube */
|
||||
#define SHADED_CUBE
|
||||
|
||||
|
|
@ -39,7 +38,7 @@ static SDLTest_CommonState *state;
|
|||
static SDL_GLContext context;
|
||||
static GL_Context ctx;
|
||||
|
||||
static int LoadContext(GL_Context * data)
|
||||
static int LoadContext(GL_Context *data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
|
|
@ -50,15 +49,15 @@ static int LoadContext(GL_Context * data)
|
|||
#endif
|
||||
|
||||
#if defined __SDL_NOGETPROCADDR__
|
||||
#define SDL_PROC(ret,func,params) data->func=func;
|
||||
#define SDL_PROC(ret, func, params) data->func = func;
|
||||
#else
|
||||
#define SDL_PROC(ret,func,params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if ( ! data->func ) { \
|
||||
#define SDL_PROC(ret, func, params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if (!data->func) { \
|
||||
return SDL_SetError("Couldn't load GL function %s: %s", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
} \
|
||||
} while (0);
|
||||
#endif /* __SDL_NOGETPROCADDR__ */
|
||||
|
||||
#include "../src/render/opengl/SDL_glfuncs.h"
|
||||
|
|
@ -66,13 +65,12 @@ static int LoadContext(GL_Context * data)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
if (context) {
|
||||
/* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
|
||||
/* SDL_GL_MakeCurrent(0, NULL); */ /* doesn't do anything */
|
||||
SDL_GL_DeleteContext(context);
|
||||
}
|
||||
SDLTest_CommonQuit(state);
|
||||
|
|
@ -83,24 +81,24 @@ static void
|
|||
Render()
|
||||
{
|
||||
static float color[8][3] = {
|
||||
{1.0, 1.0, 0.0},
|
||||
{1.0, 0.0, 0.0},
|
||||
{0.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.0},
|
||||
{0.0, 1.0, 1.0},
|
||||
{1.0, 1.0, 1.0},
|
||||
{1.0, 0.0, 1.0},
|
||||
{0.0, 0.0, 1.0}
|
||||
{ 1.0, 1.0, 0.0 },
|
||||
{ 1.0, 0.0, 0.0 },
|
||||
{ 0.0, 0.0, 0.0 },
|
||||
{ 0.0, 1.0, 0.0 },
|
||||
{ 0.0, 1.0, 1.0 },
|
||||
{ 1.0, 1.0, 1.0 },
|
||||
{ 1.0, 0.0, 1.0 },
|
||||
{ 0.0, 0.0, 1.0 }
|
||||
};
|
||||
static float cube[8][3] = {
|
||||
{0.5, 0.5, -0.5},
|
||||
{0.5, -0.5, -0.5},
|
||||
{-0.5, -0.5, -0.5},
|
||||
{-0.5, 0.5, -0.5},
|
||||
{-0.5, 0.5, 0.5},
|
||||
{0.5, 0.5, 0.5},
|
||||
{0.5, -0.5, 0.5},
|
||||
{-0.5, -0.5, 0.5}
|
||||
{ 0.5, 0.5, -0.5 },
|
||||
{ 0.5, -0.5, -0.5 },
|
||||
{ -0.5, -0.5, -0.5 },
|
||||
{ -0.5, 0.5, -0.5 },
|
||||
{ -0.5, 0.5, 0.5 },
|
||||
{ 0.5, 0.5, 0.5 },
|
||||
{ 0.5, -0.5, 0.5 },
|
||||
{ -0.5, -0.5, 0.5 }
|
||||
};
|
||||
|
||||
/* Do our drawing, too. */
|
||||
|
|
@ -163,7 +161,7 @@ Render()
|
|||
ctx.glVertex3fv(cube[2]);
|
||||
ctx.glColor3fv(color[7]);
|
||||
ctx.glVertex3fv(cube[7]);
|
||||
#else /* flat cube */
|
||||
#else /* flat cube */
|
||||
ctx.glColor3f(1.0, 0.0, 0.0);
|
||||
ctx.glVertex3fv(cube[0]);
|
||||
ctx.glVertex3fv(cube[1]);
|
||||
|
|
@ -207,8 +205,7 @@ Render()
|
|||
ctx.glRotatef(5.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
|
|
@ -229,7 +226,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
|
@ -237,11 +234,11 @@ main(int argc, char *argv[])
|
|||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i+1 < argc) {
|
||||
fsaa = SDL_atoi(argv[i+1]);
|
||||
if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i + 1 < argc) {
|
||||
fsaa = SDL_atoi(argv[i + 1]);
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
|
||||
accel = SDL_atoi(argv[i+1]);
|
||||
} else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i + 1 < argc) {
|
||||
accel = SDL_atoi(argv[i + 1]);
|
||||
consumed = 2;
|
||||
} else {
|
||||
consumed = -1;
|
||||
|
|
@ -280,7 +277,7 @@ main(int argc, char *argv[])
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
|
||||
/* Important: call this *after* creating the context */
|
||||
if (LoadContext(&ctx) < 0) {
|
||||
SDL_Log("Could not load GL functions\n");
|
||||
|
|
@ -297,12 +294,12 @@ main(int argc, char *argv[])
|
|||
swap_interval = 1;
|
||||
}
|
||||
} else {
|
||||
SDL_GL_SetSwapInterval(0); /* disable vsync. */
|
||||
SDL_GL_SetSwapInterval(0); /* disable vsync. */
|
||||
swap_interval = 0;
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(0, &mode);
|
||||
SDL_Log("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format));
|
||||
SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
|
||||
SDL_GetWindowSize(state->windows[0], &dw, &dh);
|
||||
SDL_Log("Window Size : %d,%d\n", dw, dh);
|
||||
|
|
@ -345,25 +342,25 @@ main(int argc, char *argv[])
|
|||
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
|
||||
value);
|
||||
value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
if (accel >= 0) {
|
||||
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
|
||||
value);
|
||||
value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -376,7 +373,7 @@ main(int argc, char *argv[])
|
|||
ctx.glEnable(GL_DEPTH_TEST);
|
||||
ctx.glDepthFunc(GL_LESS);
|
||||
ctx.glShadeModel(GL_SMOOTH);
|
||||
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
|
|
@ -405,8 +402,9 @@ main(int argc, char *argv[])
|
|||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
int w, h;
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_GL_MakeCurrent(state->windows[i], context);
|
||||
if (update_swap_interval) {
|
||||
SDL_GL_SetSwapInterval(swap_interval);
|
||||
|
|
@ -422,7 +420,7 @@ main(int argc, char *argv[])
|
|||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
SDL_Log("%2.2f frames per second\n",
|
||||
((double) frames * 1000) / (now - then));
|
||||
((double)frames * 1000) / (now - then));
|
||||
}
|
||||
quit(0);
|
||||
return 0;
|
||||
|
|
@ -430,8 +428,7 @@ main(int argc, char *argv[])
|
|||
|
||||
#else /* HAVE_OPENGL */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -51,38 +51,34 @@ quit(int rc)
|
|||
static void
|
||||
Render()
|
||||
{
|
||||
static GLubyte color[8][4] = { {255, 0, 0, 0},
|
||||
{255, 0, 0, 255},
|
||||
{0, 255, 0, 255},
|
||||
{0, 255, 0, 255},
|
||||
{0, 255, 0, 255},
|
||||
{255, 255, 255, 255},
|
||||
{255, 0, 255, 255},
|
||||
{0, 0, 255, 255}
|
||||
};
|
||||
static GLfloat cube[8][3] = { {0.5, 0.5, -0.5},
|
||||
{0.5f, -0.5f, -0.5f},
|
||||
{-0.5f, -0.5f, -0.5f},
|
||||
{-0.5f, 0.5f, -0.5f},
|
||||
{-0.5f, 0.5f, 0.5f},
|
||||
{0.5f, 0.5f, 0.5f},
|
||||
{0.5f, -0.5f, 0.5f},
|
||||
{-0.5f, -0.5f, 0.5f}
|
||||
};
|
||||
static GLubyte color[8][4] = { { 255, 0, 0, 0 },
|
||||
{ 255, 0, 0, 255 },
|
||||
{ 0, 255, 0, 255 },
|
||||
{ 0, 255, 0, 255 },
|
||||
{ 0, 255, 0, 255 },
|
||||
{ 255, 255, 255, 255 },
|
||||
{ 255, 0, 255, 255 },
|
||||
{ 0, 0, 255, 255 } };
|
||||
static GLfloat cube[8][3] = { { 0.5, 0.5, -0.5 },
|
||||
{ 0.5f, -0.5f, -0.5f },
|
||||
{ -0.5f, -0.5f, -0.5f },
|
||||
{ -0.5f, 0.5f, -0.5f },
|
||||
{ -0.5f, 0.5f, 0.5f },
|
||||
{ 0.5f, 0.5f, 0.5f },
|
||||
{ 0.5f, -0.5f, 0.5f },
|
||||
{ -0.5f, -0.5f, 0.5f } };
|
||||
static GLubyte indices[36] = { 0, 3, 4,
|
||||
4, 5, 0,
|
||||
0, 5, 6,
|
||||
6, 1, 0,
|
||||
6, 7, 2,
|
||||
2, 1, 6,
|
||||
7, 4, 3,
|
||||
3, 2, 7,
|
||||
5, 4, 7,
|
||||
7, 6, 5,
|
||||
2, 3, 1,
|
||||
3, 0, 1
|
||||
};
|
||||
|
||||
4, 5, 0,
|
||||
0, 5, 6,
|
||||
6, 1, 0,
|
||||
6, 7, 2,
|
||||
2, 1, 6,
|
||||
7, 4, 3,
|
||||
3, 2, 7,
|
||||
5, 4, 7,
|
||||
7, 6, 5,
|
||||
2, 3, 1,
|
||||
3, 0, 1 };
|
||||
|
||||
/* Do our drawing, too. */
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
||||
|
|
@ -99,8 +95,7 @@ Render()
|
|||
glRotatef(5.0, 1.0, 1.0, 1.0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
|
|
@ -119,7 +114,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
|
@ -163,17 +158,17 @@ main(int argc, char *argv[])
|
|||
state->gl_minor_version = 1;
|
||||
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
|
||||
if (fsaa) {
|
||||
state->gl_multisamplebuffers=1;
|
||||
state->gl_multisamplesamples=fsaa;
|
||||
state->gl_multisamplebuffers = 1;
|
||||
state->gl_multisamplesamples = fsaa;
|
||||
}
|
||||
if (accel) {
|
||||
state->gl_accelerated=1;
|
||||
state->gl_accelerated = 1;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
}
|
||||
|
||||
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(context));
|
||||
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(*context));
|
||||
if (context == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
|
|
@ -208,28 +203,28 @@ main(int argc, char *argv[])
|
|||
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
if (fsaa) {
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
|
||||
|
|
@ -237,15 +232,15 @@ main(int argc, char *argv[])
|
|||
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
|
||||
value);
|
||||
value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
if (accel) {
|
||||
|
|
@ -254,7 +249,7 @@ main(int argc, char *argv[])
|
|||
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -293,30 +288,31 @@ main(int argc, char *argv[])
|
|||
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 */
|
||||
glViewport(0, 0, event.window.data1, event.window.data2);
|
||||
/* Update window content */
|
||||
Render();
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
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 */
|
||||
glViewport(0, 0, event.window.data1, event.window.data2);
|
||||
/* Update window content */
|
||||
Render();
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
|
@ -333,18 +329,17 @@ main(int argc, char *argv[])
|
|||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
SDL_Log("%2.2f frames per second\n",
|
||||
((double) frames * 1000) / (now - then));
|
||||
((double)frames * 1000) / (now - then));
|
||||
}
|
||||
#if !defined(__ANDROID__)
|
||||
quit(0);
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* HAVE_OPENGLES */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL ES support on this system\n");
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
typedef struct GLES2_Context
|
||||
{
|
||||
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
|
||||
#define SDL_PROC(ret, func, params) ret (APIENTRY *func) params;
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
#undef SDL_PROC
|
||||
} GLES2_Context;
|
||||
|
|
@ -51,12 +51,19 @@ typedef struct shader_data
|
|||
GLuint color_buffer;
|
||||
} shader_data;
|
||||
|
||||
typedef struct thread_data
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
int done;
|
||||
int index;
|
||||
} thread_data;
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_GLContext *context = NULL;
|
||||
static int depth = 16;
|
||||
static GLES2_Context ctx;
|
||||
|
||||
static int LoadContext(GLES2_Context * data)
|
||||
static int LoadContext(GLES2_Context *data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
|
|
@ -67,15 +74,15 @@ static int LoadContext(GLES2_Context * data)
|
|||
#endif
|
||||
|
||||
#if defined __SDL_NOGETPROCADDR__
|
||||
#define SDL_PROC(ret,func,params) data->func=func;
|
||||
#define SDL_PROC(ret, func, params) data->func = func;
|
||||
#else
|
||||
#define SDL_PROC(ret,func,params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if ( ! data->func ) { \
|
||||
#define SDL_PROC(ret, func, params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if (!data->func) { \
|
||||
return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
} \
|
||||
} while (0);
|
||||
#endif /* __SDL_NOGETPROCADDR__ */
|
||||
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
|
|
@ -103,19 +110,19 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
#define GL_CHECK(x) \
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if(glError != GL_NO_ERROR) { \
|
||||
#define GL_CHECK(x) \
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if (glError != GL_NO_ERROR) { \
|
||||
SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
|
||||
quit(1); \
|
||||
} \
|
||||
}
|
||||
quit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Simulates desktop's glRotatef. The matrix is returned in column-major
|
||||
* order.
|
||||
/*
|
||||
* Simulates desktop's glRotatef. The matrix is returned in column-major
|
||||
* order.
|
||||
*/
|
||||
static void
|
||||
rotate_matrix(float angle, float x, float y, float z, float *r)
|
||||
|
|
@ -154,16 +161,16 @@ rotate_matrix(float angle, float x, float y, float z, float *r)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Simulates gluPerspectiveMatrix
|
||||
/*
|
||||
* Simulates gluPerspectiveMatrix
|
||||
*/
|
||||
static void
|
||||
static void
|
||||
perspective_matrix(float fovy, float aspect, float znear, float zfar, float *r)
|
||||
{
|
||||
int i;
|
||||
float f;
|
||||
|
||||
f = 1.0f/SDL_tanf(fovy * 0.5f);
|
||||
f = 1.0f / SDL_tanf(fovy * 0.5f);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
r[i] = 0.0;
|
||||
|
|
@ -177,12 +184,12 @@ perspective_matrix(float fovy, float aspect, float znear, float zfar, float *r)
|
|||
r[15] = 0.0f;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Multiplies lhs by rhs and writes out to r. All matrices are 4x4 and column
|
||||
* major. In-place multiplication is supported.
|
||||
*/
|
||||
static void
|
||||
multiply_matrix(float *lhs, float *rhs, float *r)
|
||||
multiply_matrix(const float *lhs, const float *rhs, float *r)
|
||||
{
|
||||
int i, j, k;
|
||||
float tmp[16];
|
||||
|
|
@ -202,7 +209,7 @@ multiply_matrix(float *lhs, float *rhs, float *r)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Create shader, load in source, compile, dump debug as necessary.
|
||||
*
|
||||
* shader: Pointer to return created shader ID.
|
||||
|
|
@ -210,7 +217,7 @@ multiply_matrix(float *lhs, float *rhs, float *r)
|
|||
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
|
||||
*/
|
||||
static void
|
||||
process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||
process_shader(GLuint *shader, const char *source, GLint shader_type)
|
||||
{
|
||||
GLint status = GL_FALSE;
|
||||
const char *shaders[1] = { NULL };
|
||||
|
|
@ -232,7 +239,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
|
|||
GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status));
|
||||
|
||||
/* Dump debug info (source and log) if compilation failed. */
|
||||
if(status != GL_TRUE) {
|
||||
if (status != GL_TRUE) {
|
||||
ctx.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
||||
buffer[length] = '\0';
|
||||
SDL_Log("Shader compilation failed: %s", buffer);
|
||||
|
|
@ -253,7 +260,7 @@ link_program(struct shader_data *data)
|
|||
GL_CHECK(ctx.glLinkProgram(data->shader_program));
|
||||
GL_CHECK(ctx.glGetProgramiv(data->shader_program, GL_LINK_STATUS, &status));
|
||||
|
||||
if(status != GL_TRUE) {
|
||||
if (status != GL_TRUE) {
|
||||
ctx.glGetProgramInfoLog(data->shader_program, sizeof(buffer), &length, &buffer[0]);
|
||||
buffer[length] = '\0';
|
||||
SDL_Log("Program linking failed: %s", buffer);
|
||||
|
|
@ -263,67 +270,137 @@ link_program(struct shader_data *data)
|
|||
}
|
||||
|
||||
/* 3D data. Vertex range -0.5..0.5 in all axes.
|
||||
* Z -0.5 is near, 0.5 is far. */
|
||||
const float _vertices[] =
|
||||
{
|
||||
* Z -0.5 is near, 0.5 is far. */
|
||||
const float _vertices[] = {
|
||||
/* Front face. */
|
||||
/* Bottom left */
|
||||
-0.5, 0.5, -0.5,
|
||||
0.5, -0.5, -0.5,
|
||||
-0.5, -0.5, -0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
/* Top right */
|
||||
-0.5, 0.5, -0.5,
|
||||
0.5, 0.5, -0.5,
|
||||
0.5, -0.5, -0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
/* Left face */
|
||||
/* Bottom left */
|
||||
-0.5, 0.5, 0.5,
|
||||
-0.5, -0.5, -0.5,
|
||||
-0.5, -0.5, 0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
/* Top right */
|
||||
-0.5, 0.5, 0.5,
|
||||
-0.5, 0.5, -0.5,
|
||||
-0.5, -0.5, -0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
/* Top face */
|
||||
/* Bottom left */
|
||||
-0.5, 0.5, 0.5,
|
||||
0.5, 0.5, -0.5,
|
||||
-0.5, 0.5, -0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
/* Top right */
|
||||
-0.5, 0.5, 0.5,
|
||||
0.5, 0.5, 0.5,
|
||||
0.5, 0.5, -0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
/* Right face */
|
||||
/* Bottom left */
|
||||
0.5, 0.5, -0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
0.5, -0.5, -0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
/* Top right */
|
||||
0.5, 0.5, -0.5,
|
||||
0.5, 0.5, 0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
/* Back face */
|
||||
/* Bottom left */
|
||||
0.5, 0.5, 0.5,
|
||||
-0.5, -0.5, 0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
/* Top right */
|
||||
0.5, 0.5, 0.5,
|
||||
-0.5, 0.5, 0.5,
|
||||
-0.5, -0.5, 0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
/* Bottom face */
|
||||
/* Bottom left */
|
||||
-0.5, -0.5, -0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
-0.5, -0.5, 0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
/* Top right */
|
||||
-0.5, -0.5, -0.5,
|
||||
0.5, -0.5, -0.5,
|
||||
0.5, -0.5, 0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
-0.5,
|
||||
0.5,
|
||||
};
|
||||
|
||||
const float _colors[] =
|
||||
{
|
||||
const float _colors[] = {
|
||||
/* Front face */
|
||||
/* Bottom left */
|
||||
1.0, 0.0, 0.0, /* red */
|
||||
|
|
@ -380,32 +457,32 @@ const float _colors[] =
|
|||
1.0, 0.0, 1.0, /* magenta */
|
||||
};
|
||||
|
||||
const char* _shader_vert_src =
|
||||
" attribute vec4 av4position; "
|
||||
" attribute vec3 av3color; "
|
||||
" uniform mat4 mvp; "
|
||||
" varying vec3 vv3color; "
|
||||
" void main() { "
|
||||
" vv3color = av3color; "
|
||||
" gl_Position = mvp * av4position; "
|
||||
" } ";
|
||||
const char *_shader_vert_src =
|
||||
" attribute vec4 av4position; "
|
||||
" attribute vec3 av3color; "
|
||||
" uniform mat4 mvp; "
|
||||
" varying vec3 vv3color; "
|
||||
" void main() { "
|
||||
" vv3color = av3color; "
|
||||
" gl_Position = mvp * av4position; "
|
||||
" } ";
|
||||
|
||||
const char* _shader_frag_src =
|
||||
" precision lowp float; "
|
||||
" varying vec3 vv3color; "
|
||||
" void main() { "
|
||||
" gl_FragColor = vec4(vv3color, 1.0); "
|
||||
" } ";
|
||||
const char *_shader_frag_src =
|
||||
" precision lowp float; "
|
||||
" varying vec3 vv3color; "
|
||||
" void main() { "
|
||||
" gl_FragColor = vec4(vv3color, 1.0); "
|
||||
" } ";
|
||||
|
||||
static void
|
||||
Render(unsigned int width, unsigned int height, shader_data* data)
|
||||
Render(unsigned int width, unsigned int height, shader_data *data)
|
||||
{
|
||||
float matrix_rotate[16], matrix_modelview[16], matrix_perspective[16], matrix_mvp[16];
|
||||
|
||||
/*
|
||||
* Do some rotation with Euler angles. It is not a fixed axis as
|
||||
* quaterions would be, but the effect is cool.
|
||||
*/
|
||||
/*
|
||||
* Do some rotation with Euler angles. It is not a fixed axis as
|
||||
* quaterions would be, but the effect is cool.
|
||||
*/
|
||||
rotate_matrix((float)data->angle_x, 1.0f, 0.0f, 0.0f, matrix_modelview);
|
||||
rotate_matrix((float)data->angle_y, 0.0f, 1.0f, 0.0f, matrix_rotate);
|
||||
|
||||
|
|
@ -418,7 +495,7 @@ Render(unsigned int width, unsigned int height, shader_data* data)
|
|||
/* Pull the camera back from the cube */
|
||||
matrix_modelview[14] -= 2.5;
|
||||
|
||||
perspective_matrix(45.0f, (float)width/height, 0.01f, 100.0f, matrix_perspective);
|
||||
perspective_matrix(45.0f, (float)width / height, 0.01f, 100.0f, matrix_perspective);
|
||||
multiply_matrix(matrix_perspective, matrix_modelview, matrix_mvp);
|
||||
|
||||
GL_CHECK(ctx.glUniformMatrix4fv(data->attr_mvp, 1, GL_FALSE, matrix_mvp));
|
||||
|
|
@ -427,13 +504,26 @@ Render(unsigned int width, unsigned int height, shader_data* data)
|
|||
data->angle_y += 2;
|
||||
data->angle_z += 1;
|
||||
|
||||
if(data->angle_x >= 360) data->angle_x -= 360;
|
||||
if(data->angle_x < 0) data->angle_x += 360;
|
||||
if(data->angle_y >= 360) data->angle_y -= 360;
|
||||
if(data->angle_y < 0) data->angle_y += 360;
|
||||
if(data->angle_z >= 360) data->angle_z -= 360;
|
||||
if(data->angle_z < 0) data->angle_z += 360;
|
||||
if (data->angle_x >= 360) {
|
||||
data->angle_x -= 360;
|
||||
}
|
||||
if (data->angle_x < 0) {
|
||||
data->angle_x += 360;
|
||||
}
|
||||
if (data->angle_y >= 360) {
|
||||
data->angle_y -= 360;
|
||||
}
|
||||
if (data->angle_y < 0) {
|
||||
data->angle_y += 360;
|
||||
}
|
||||
if (data->angle_z >= 360) {
|
||||
data->angle_z -= 360;
|
||||
}
|
||||
if (data->angle_z < 0) {
|
||||
data->angle_z += 360;
|
||||
}
|
||||
|
||||
GL_CHECK(ctx.glViewport(0, 0, width, height));
|
||||
GL_CHECK(ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
|
||||
GL_CHECK(ctx.glDrawArrays(GL_TRIANGLES, 0, 36));
|
||||
}
|
||||
|
|
@ -441,56 +531,86 @@ Render(unsigned int width, unsigned int height, shader_data* data)
|
|||
int done;
|
||||
Uint32 frames;
|
||||
shader_data *datas;
|
||||
thread_data *threads;
|
||||
|
||||
void loop()
|
||||
static void
|
||||
render_window(int index)
|
||||
{
|
||||
int w, h, status;
|
||||
|
||||
if (!state->windows[index]) {
|
||||
return;
|
||||
}
|
||||
|
||||
status = SDL_GL_MakeCurrent(state->windows[index], context[index]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_GL_GetDrawableSize(state->windows[index], &w, &h);
|
||||
Render(w, h, &datas[index]);
|
||||
SDL_GL_SwapWindow(state->windows[index]);
|
||||
++frames;
|
||||
}
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
static int SDLCALL
|
||||
render_thread_fn(void *render_ctx)
|
||||
{
|
||||
thread_data *thread = render_ctx;
|
||||
|
||||
while (!done && !thread->done && state->windows[thread->index]) {
|
||||
render_window(thread->index);
|
||||
}
|
||||
|
||||
SDL_GL_MakeCurrent(state->windows[thread->index], NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
loop_threaded()
|
||||
{
|
||||
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;
|
||||
/* Wait for events */
|
||||
while (SDL_WaitEvent(&event) && !done) {
|
||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE) {
|
||||
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
|
||||
if (window) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (window == state->windows[i]) {
|
||||
/* Stop the render thread when the window is closed */
|
||||
threads[i].done = 1;
|
||||
if (threads[i].thread) {
|
||||
SDL_WaitThread(threads[i].thread, NULL);
|
||||
threads[i].thread = NULL;
|
||||
}
|
||||
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());
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
static void
|
||||
loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event) && !done) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
if (!done) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
render_window(i);
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
else {
|
||||
|
|
@ -499,10 +619,9 @@ void loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int fsaa, accel, threaded;
|
||||
int value;
|
||||
int i;
|
||||
SDL_DisplayMode mode;
|
||||
|
|
@ -513,10 +632,11 @@ main(int argc, char *argv[])
|
|||
/* Initialize parameters */
|
||||
fsaa = 0;
|
||||
accel = 0;
|
||||
threaded = 0;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
|
@ -530,6 +650,9 @@ main(int argc, char *argv[])
|
|||
} else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
|
||||
++accel;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--threaded") == 0) {
|
||||
++threaded;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
|
||||
i++;
|
||||
if (!argv[i]) {
|
||||
|
|
@ -543,7 +666,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", NULL };
|
||||
static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", "[--threaded]", NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
quit(1);
|
||||
}
|
||||
|
|
@ -551,7 +674,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Set OpenGL parameters */
|
||||
state->window_flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS;
|
||||
state->window_flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
|
||||
state->gl_red_size = 5;
|
||||
state->gl_green_size = 5;
|
||||
state->gl_blue_size = 5;
|
||||
|
|
@ -561,23 +684,23 @@ main(int argc, char *argv[])
|
|||
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
|
||||
|
||||
if (fsaa) {
|
||||
state->gl_multisamplebuffers=1;
|
||||
state->gl_multisamplesamples=fsaa;
|
||||
state->gl_multisamplebuffers = 1;
|
||||
state->gl_multisamplesamples = fsaa;
|
||||
}
|
||||
if (accel) {
|
||||
state->gl_accelerated=1;
|
||||
state->gl_accelerated = 1;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(context));
|
||||
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(*context));
|
||||
if (context == NULL) {
|
||||
SDL_Log("Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
||||
|
||||
/* Create OpenGL ES contexts */
|
||||
for (i = 0; i < state->num_windows; i++) {
|
||||
context[i] = SDL_GL_CreateContext(state->windows[i]);
|
||||
|
|
@ -594,8 +717,6 @@ main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
} else {
|
||||
|
|
@ -603,6 +724,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(0, &mode);
|
||||
SDL_Log("Threaded : %s\n", threaded ? "yes" : "no");
|
||||
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
SDL_Log("\n");
|
||||
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
|
||||
|
|
@ -615,28 +737,28 @@ main(int argc, char *argv[])
|
|||
if (!status) {
|
||||
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_RED_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_RED_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_GREEN_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_GREEN_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_BLUE_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_BLUE_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
if (fsaa) {
|
||||
|
|
@ -644,15 +766,15 @@ main(int argc, char *argv[])
|
|||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
|
||||
value);
|
||||
value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
|
@ -661,7 +783,7 @@ main(int argc, char *argv[])
|
|||
if (!status) {
|
||||
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
|
@ -683,7 +805,9 @@ main(int argc, char *argv[])
|
|||
ctx.glViewport(0, 0, w, h);
|
||||
|
||||
data = &datas[i];
|
||||
data->angle_x = 0; data->angle_y = 0; data->angle_z = 0;
|
||||
data->angle_x = 0;
|
||||
data->angle_y = 0;
|
||||
data->angle_z = 0;
|
||||
|
||||
/* Shader Initialization */
|
||||
process_shader(&data->shader_vert, _shader_vert_src, GL_VERTEX_SHADER);
|
||||
|
|
@ -724,6 +848,8 @@ main(int argc, char *argv[])
|
|||
|
||||
GL_CHECK(ctx.glEnable(GL_CULL_FACE));
|
||||
GL_CHECK(ctx.glEnable(GL_DEPTH_TEST));
|
||||
|
||||
SDL_GL_MakeCurrent(state->windows[i], NULL);
|
||||
}
|
||||
|
||||
/* Main render loop */
|
||||
|
|
@ -734,8 +860,30 @@ main(int argc, char *argv[])
|
|||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
if (threaded) {
|
||||
threads = (thread_data *)SDL_calloc(state->num_windows, sizeof(thread_data));
|
||||
|
||||
/* Start a render thread for each window */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
threads[i].index = i;
|
||||
threads[i].thread = SDL_CreateThread(render_thread_fn, "RenderThread", &threads[i]);
|
||||
}
|
||||
|
||||
while (!done) {
|
||||
loop_threaded();
|
||||
}
|
||||
|
||||
/* Join the remaining render threads (if any) */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
threads[i].done = 1;
|
||||
if (threads[i].thread) {
|
||||
SDL_WaitThread(threads[i].thread, NULL);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -743,7 +891,7 @@ main(int argc, char *argv[])
|
|||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
SDL_Log("%2.2f frames per second\n",
|
||||
((double) frames * 1000) / (now - then));
|
||||
((double)frames * 1000) / (now - then));
|
||||
}
|
||||
#if !defined(__ANDROID__) && !defined(__NACL__)
|
||||
quit(0);
|
||||
|
|
@ -753,8 +901,7 @@ main(int argc, char *argv[])
|
|||
|
||||
#else /* HAVE_OPENGLES2 */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Log("No OpenGL ES support on this system\n");
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -10,15 +10,13 @@
|
|||
freely.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
#include "testutils.h"
|
||||
|
||||
#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__) \
|
||||
|| defined(__WINDOWS__) || defined(__LINUX__)
|
||||
|
|
@ -31,12 +29,11 @@
|
|||
|
||||
typedef struct GLES2_Context
|
||||
{
|
||||
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
|
||||
#define SDL_PROC(ret, func, params) ret (APIENTRY *func) params;
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
#undef SDL_PROC
|
||||
} GLES2_Context;
|
||||
|
||||
|
||||
static SDL_Surface *g_surf_sdf = NULL;
|
||||
GLenum g_texture;
|
||||
GLenum g_texture_type = GL_TEXTURE_2D;
|
||||
|
|
@ -57,16 +54,14 @@ typedef enum
|
|||
} GLES2_Uniform;
|
||||
|
||||
|
||||
GLuint g_uniform_locations[16];
|
||||
|
||||
|
||||
GLint g_uniform_locations[16];
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_GLContext *context = NULL;
|
||||
static int depth = 16;
|
||||
static GLES2_Context ctx;
|
||||
|
||||
static int LoadContext(GLES2_Context * data)
|
||||
static int LoadContext(GLES2_Context *data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
|
|
@ -77,15 +72,15 @@ static int LoadContext(GLES2_Context * data)
|
|||
#endif
|
||||
|
||||
#if defined __SDL_NOGETPROCADDR__
|
||||
#define SDL_PROC(ret,func,params) data->func=func;
|
||||
#define SDL_PROC(ret, func, params) data->func = func;
|
||||
#else
|
||||
#define SDL_PROC(ret,func,params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if ( ! data->func ) { \
|
||||
#define SDL_PROC(ret, func, params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if (!data->func) { \
|
||||
return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
} \
|
||||
} while (0);
|
||||
#endif /* __SDL_NOGETPROCADDR__ */
|
||||
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
|
|
@ -113,26 +108,25 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
#define GL_CHECK(x) \
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if(glError != GL_NO_ERROR) { \
|
||||
#define GL_CHECK(x) \
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if (glError != GL_NO_ERROR) { \
|
||||
SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
|
||||
quit(1); \
|
||||
} \
|
||||
}
|
||||
quit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* Create shader, load in source, compile, dump debug as necessary.
|
||||
*
|
||||
* shader: Pointer to return created shader ID.
|
||||
* source: Passed-in shader source code.
|
||||
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
|
||||
*/
|
||||
void
|
||||
process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||
void
|
||||
process_shader(GLenum *shader, const char *source, GLenum shader_type)
|
||||
{
|
||||
GLint status = GL_FALSE;
|
||||
const char *shaders[1] = { NULL };
|
||||
|
|
@ -154,10 +148,10 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
|
|||
GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status));
|
||||
|
||||
/* Dump debug info (source and log) if compilation failed. */
|
||||
if(status != GL_TRUE) {
|
||||
ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
||||
if (status != GL_TRUE) {
|
||||
ctx.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
||||
buffer[length] = '\0';
|
||||
SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
|
||||
SDL_Log("Shader compilation failed: %s", buffer);
|
||||
quit(-1);
|
||||
}
|
||||
}
|
||||
|
|
@ -167,7 +161,7 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
|
|||
* To get correct rotation for most cases when a_angle is disabled cosine
|
||||
* value is decremented by 1.0 to get proper output with 0.0 which is default value
|
||||
*/
|
||||
static const Uint8 GLES2_VertexSrc_Default_[] = " \
|
||||
static const char GLES2_VertexSrc_Default_[] = " \
|
||||
uniform mat4 u_projection; \
|
||||
attribute vec2 a_position; \
|
||||
attribute vec2 a_texCoord; \
|
||||
|
|
@ -187,7 +181,7 @@ static const Uint8 GLES2_VertexSrc_Default_[] = " \
|
|||
} \
|
||||
";
|
||||
|
||||
static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
|
||||
static const char GLES2_FragmentSrc_TextureABGRSrc_[] = " \
|
||||
precision mediump float; \
|
||||
uniform sampler2D u_texture; \
|
||||
uniform vec4 u_color; \
|
||||
|
|
@ -201,7 +195,7 @@ static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
|
|||
";
|
||||
|
||||
/* RGB to ABGR conversion */
|
||||
static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_SDF[] = " \
|
||||
static const char GLES2_FragmentSrc_TextureABGRSrc_SDF[] = " \
|
||||
#extension GL_OES_standard_derivatives : enable\n\
|
||||
\
|
||||
precision mediump float; \
|
||||
|
|
@ -242,19 +236,16 @@ static const char *GLES2_FragmentSrc_TextureABGRSrc_SDF_dbg = " \
|
|||
} \
|
||||
";
|
||||
|
||||
|
||||
static float g_val = 1.0f;
|
||||
static int g_use_SDF = 1;
|
||||
static int g_use_SDF_debug = 0;
|
||||
static int g_use_SDF = 1;
|
||||
static int g_use_SDF_debug = 0;
|
||||
static float g_angle = 0.0f;
|
||||
static float matrix_mvp[4][4];
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct shader_data
|
||||
{
|
||||
GLuint shader_program, shader_frag, shader_vert;
|
||||
GLint shader_program;
|
||||
GLenum shader_frag, shader_vert;
|
||||
|
||||
GLint attr_position;
|
||||
GLint attr_color, attr_mvp;
|
||||
|
|
@ -262,7 +253,7 @@ typedef struct shader_data
|
|||
} shader_data;
|
||||
|
||||
static void
|
||||
Render(unsigned int width, unsigned int height, shader_data* data)
|
||||
Render(int width, int height, shader_data* data)
|
||||
{
|
||||
float *verts = g_verts;
|
||||
ctx.glViewport(0, 0, 640, 480);
|
||||
|
|
@ -272,17 +263,16 @@ Render(unsigned int width, unsigned int height, shader_data* data)
|
|||
GL_CHECK(ctx.glUniformMatrix4fv(g_uniform_locations[GLES2_UNIFORM_PROJECTION], 1, GL_FALSE, (const float *)matrix_mvp));
|
||||
GL_CHECK(ctx.glUniform4f(g_uniform_locations[GLES2_UNIFORM_COLOR], 1.0f, 1.0f, 1.0f, 1.0f));
|
||||
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) (verts + 16)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) (verts + 8)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) verts));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)(verts + 16)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)(verts + 8)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *)verts));
|
||||
|
||||
GL_CHECK(ctx.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
|
||||
|
||||
void renderCopy_angle(float degree_angle)
|
||||
void renderCopy_angle(float degree_angle)
|
||||
{
|
||||
const float radian_angle = (float)(3.141592 * degree_angle) / 180.0;
|
||||
const float radian_angle = (float)(3.141592 * degree_angle) / 180.0f;
|
||||
const GLfloat s = (GLfloat) SDL_sin(radian_angle);
|
||||
const GLfloat c = (GLfloat) SDL_cos(radian_angle) - 1.0f;
|
||||
GLfloat *verts = g_verts + 16;
|
||||
|
|
@ -296,22 +286,21 @@ void renderCopy_angle(float degree_angle)
|
|||
*(verts++) = c;
|
||||
}
|
||||
|
||||
|
||||
void renderCopy_position(SDL_Rect *srcrect, SDL_Rect *dstrect)
|
||||
void renderCopy_position(SDL_Rect *srcrect, SDL_Rect *dstrect)
|
||||
{
|
||||
GLfloat minx, miny, maxx, maxy;
|
||||
GLfloat minu, maxu, minv, maxv;
|
||||
GLfloat *verts = g_verts;
|
||||
|
||||
minx = dstrect->x;
|
||||
miny = dstrect->y;
|
||||
maxx = dstrect->x + dstrect->w;
|
||||
maxy = dstrect->y + dstrect->h;
|
||||
minx = (GLfloat)dstrect->x;
|
||||
miny = (GLfloat)dstrect->y;
|
||||
maxx = (GLfloat)(dstrect->x + dstrect->w);
|
||||
maxy = (GLfloat)(dstrect->y + dstrect->h);
|
||||
|
||||
minu = (GLfloat) srcrect->x / g_surf_sdf->w;
|
||||
maxu = (GLfloat) (srcrect->x + srcrect->w) / g_surf_sdf->w;
|
||||
minv = (GLfloat) srcrect->y / g_surf_sdf->h;
|
||||
maxv = (GLfloat) (srcrect->y + srcrect->h) / g_surf_sdf->h;
|
||||
minu = (GLfloat) srcrect->x / (GLfloat)g_surf_sdf->w;
|
||||
maxu = (GLfloat) (srcrect->x + srcrect->w) / (GLfloat)g_surf_sdf->w;
|
||||
minv = (GLfloat) srcrect->y / (GLfloat)g_surf_sdf->h;
|
||||
maxv = (GLfloat) (srcrect->y + srcrect->h) / (GLfloat)g_surf_sdf->h;
|
||||
|
||||
*(verts++) = minx;
|
||||
*(verts++) = miny;
|
||||
|
|
@ -347,71 +336,63 @@ void loop()
|
|||
while (SDL_PollEvent(&event) && !done) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
{
|
||||
const int sym = event.key.keysym.sym;
|
||||
{
|
||||
const int sym = event.key.keysym.sym;
|
||||
|
||||
if (sym == SDLK_TAB) {
|
||||
SDL_Log("Tab");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (sym == SDLK_LEFT) g_val -= 0.05;
|
||||
if (sym == SDLK_RIGHT) g_val += 0.05;
|
||||
if (sym == SDLK_UP) g_angle -= 1;
|
||||
if (sym == SDLK_DOWN) g_angle += 1;
|
||||
|
||||
|
||||
break;
|
||||
if (sym == SDLK_TAB) {
|
||||
SDL_Log("Tab");
|
||||
}
|
||||
|
||||
if (sym == SDLK_LEFT) {
|
||||
g_val -= 0.05f;
|
||||
}
|
||||
if (sym == SDLK_RIGHT) {
|
||||
g_val += 0.05f;
|
||||
}
|
||||
if (sym == SDLK_UP) {
|
||||
g_angle -= 1.0f;
|
||||
}
|
||||
if (sym == SDLK_DOWN) {
|
||||
g_angle += 1.0f;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
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]);
|
||||
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;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
|
||||
|
||||
matrix_mvp[3][0] = -1.0f;
|
||||
matrix_mvp[3][3] = 1.0f;
|
||||
|
||||
matrix_mvp[0][0] = 2.0f / 640.0;
|
||||
matrix_mvp[1][1] = -2.0f / 480.0;
|
||||
matrix_mvp[0][0] = 2.0f / 640.0f;
|
||||
matrix_mvp[1][1] = -2.0f / 480.0f;
|
||||
matrix_mvp[3][1] = 1.0f;
|
||||
|
||||
if (0)
|
||||
{
|
||||
float *f = (float *) matrix_mvp;
|
||||
SDL_Log("-----------------------------------");
|
||||
SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
|
||||
SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
|
||||
SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
|
||||
SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
|
||||
SDL_Log("-----------------------------------");
|
||||
}
|
||||
|
||||
renderCopy_angle(g_angle);
|
||||
|
||||
|
|
@ -422,24 +403,23 @@ void loop()
|
|||
SDL_GL_GetDrawableSize(state->windows[0], &w, &h);
|
||||
|
||||
rs.x = 0; rs.y = 0; rs.w = g_surf_sdf->w; rs.h = g_surf_sdf->h;
|
||||
rd.w = g_surf_sdf->w * g_val; rd.h = g_surf_sdf->h * g_val;
|
||||
rd.w = (int)((float)g_surf_sdf->w * g_val); rd.h = (int)((float)g_surf_sdf->h * g_val);
|
||||
rd.x = (w - rd.w) / 2; rd.y = (h - rd.h) / 2;
|
||||
renderCopy_position(&rs, &rd);
|
||||
}
|
||||
|
||||
|
||||
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());
|
||||
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]);
|
||||
}
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
else {
|
||||
|
|
@ -448,8 +428,7 @@ void loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
|
|
@ -466,7 +445,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
|
@ -511,23 +490,23 @@ main(int argc, char *argv[])
|
|||
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
|
||||
|
||||
if (fsaa) {
|
||||
state->gl_multisamplebuffers=1;
|
||||
state->gl_multisamplesamples=fsaa;
|
||||
state->gl_multisamplebuffers = 1;
|
||||
state->gl_multisamplesamples = fsaa;
|
||||
}
|
||||
if (accel) {
|
||||
state->gl_accelerated=1;
|
||||
state->gl_accelerated = 1;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(context));
|
||||
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(*context));
|
||||
if (context == NULL) {
|
||||
SDL_Log("Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
||||
|
||||
/* Create OpenGL ES contexts */
|
||||
for (i = 0; i < state->num_windows; i++) {
|
||||
context[i] = SDL_GL_CreateContext(state->windows[i]);
|
||||
|
|
@ -544,8 +523,8 @@ main(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
SDL_memset(matrix_mvp, 0, sizeof (matrix_mvp));
|
||||
|
||||
SDL_memset(matrix_mvp, 0, sizeof(matrix_mvp));
|
||||
|
||||
{
|
||||
SDL_Surface *tmp;
|
||||
char *f;
|
||||
|
|
@ -557,15 +536,16 @@ main(int argc, char *argv[])
|
|||
} else {
|
||||
f = "testgles2_sdf_img_normal.bmp";
|
||||
}
|
||||
|
||||
|
||||
SDL_Log("SDF is %s", g_use_SDF ? "enabled" : "disabled");
|
||||
|
||||
/* Load SDF BMP image */
|
||||
#if 1
|
||||
path = GetNearbyFilename(f);
|
||||
|
||||
if (path == NULL)
|
||||
if (path == NULL) {
|
||||
path = SDL_strdup(f);
|
||||
}
|
||||
|
||||
if (path == NULL) {
|
||||
SDL_Log("out of memory\n");
|
||||
|
|
@ -573,7 +553,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
tmp = SDL_LoadBMP(path);
|
||||
if (tmp == NULL) {
|
||||
if (tmp == NULL) {
|
||||
SDL_Log("missing image file: %s", path);
|
||||
exit(-1);
|
||||
} else {
|
||||
|
|
@ -584,10 +564,10 @@ main(int argc, char *argv[])
|
|||
#else
|
||||
/* Generate SDF image using SDL_ttf */
|
||||
|
||||
#include "SDL_ttf.h"
|
||||
#include "SDL_ttf.h"
|
||||
char *font_file = "./font/DroidSansFallback.ttf";
|
||||
char *str = "Abcde";
|
||||
SDL_Color color = { 0, 0,0, 255};
|
||||
SDL_Color color = { 0, 0, 0, 255 };
|
||||
|
||||
TTF_Init();
|
||||
TTF_Font *font = TTF_OpenFont(font_file, 72);
|
||||
|
|
@ -615,7 +595,6 @@ main(int argc, char *argv[])
|
|||
SDL_SetSurfaceBlendMode(g_surf_sdf, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
|
||||
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
} else {
|
||||
|
|
@ -635,28 +614,28 @@ main(int argc, char *argv[])
|
|||
if (!status) {
|
||||
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_RED_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_RED_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_GREEN_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_GREEN_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_BLUE_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_BLUE_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
if (fsaa) {
|
||||
|
|
@ -664,15 +643,15 @@ main(int argc, char *argv[])
|
|||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
|
||||
value);
|
||||
value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
|
@ -681,7 +660,7 @@ main(int argc, char *argv[])
|
|||
if (!status) {
|
||||
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_Log("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
|
@ -720,7 +699,6 @@ main(int argc, char *argv[])
|
|||
GL_CHECK(ctx.glTexSubImage2D(g_texture_type, 0, 0 /* xoffset */, 0 /* yoffset */, g_surf_sdf->w, g_surf_sdf->h, format, type, g_surf_sdf->pixels));
|
||||
}
|
||||
|
||||
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
|
||||
|
|
@ -759,23 +737,20 @@ main(int argc, char *argv[])
|
|||
|
||||
GL_CHECK(ctx.glUseProgram(data->shader_program));
|
||||
|
||||
ctx.glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_ANGLE);
|
||||
ctx.glDisableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_CENTER);
|
||||
ctx.glEnableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_ANGLE);
|
||||
ctx.glDisableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_CENTER);
|
||||
ctx.glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
|
||||
ctx.glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
|
||||
|
||||
|
||||
ctx.glUniform1i(g_uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */
|
||||
ctx.glActiveTexture(GL_TEXTURE0);
|
||||
ctx.glBindTexture(g_texture_type, g_texture);
|
||||
GL_CHECK(ctx.glClearColor(1, 1, 1, 1));
|
||||
|
||||
// SDL_BLENDMODE_BLEND
|
||||
GL_CHECK(ctx.glEnable(GL_BLEND));
|
||||
ctx.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
ctx.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
ctx.glEnableVertexAttribArray((GLenum)GLES2_ATTRIBUTE_TEXCOORD);
|
||||
|
||||
ctx.glUniform1i(g_uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */
|
||||
ctx.glActiveTexture(GL_TEXTURE0);
|
||||
ctx.glBindTexture(g_texture_type, g_texture);
|
||||
GL_CHECK(ctx.glClearColor(1, 1, 1, 1));
|
||||
|
||||
// SDL_BLENDMODE_BLEND
|
||||
GL_CHECK(ctx.glEnable(GL_BLEND));
|
||||
ctx.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
ctx.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
}
|
||||
|
||||
/* Main render loop */
|
||||
|
|
@ -795,18 +770,17 @@ main(int argc, char *argv[])
|
|||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
SDL_Log("%2.2f frames per second\n",
|
||||
((double) frames * 1000) / (now - then));
|
||||
((double)frames * 1000) / (now - then));
|
||||
}
|
||||
#if !defined(__ANDROID__) && !defined(__NACL__)
|
||||
#if !defined(__ANDROID__) && !defined(__NACL__)
|
||||
quit(0);
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* HAVE_OPENGLES2 */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Log("No OpenGL ES support on this system\n");
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -20,21 +20,18 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||
|
||||
static SDL_Haptic *haptic;
|
||||
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
static void abort_execution(void);
|
||||
static void HapticPrintSupported(SDL_Haptic *);
|
||||
|
||||
|
||||
/**
|
||||
* @brief The entry point of this force feedback demo.
|
||||
* @param[in] argc Number of arguments.
|
||||
* @param[in] argv Array of argc arguments.
|
||||
*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char *name;
|
||||
|
|
@ -53,13 +50,13 @@ main(int argc, char **argv)
|
|||
name = argv[1];
|
||||
if ((SDL_strcmp(name, "--help") == 0) || (SDL_strcmp(name, "-h") == 0)) {
|
||||
SDL_Log("USAGE: %s [device]\n"
|
||||
"If device is a two-digit number it'll use it as an index, otherwise\n"
|
||||
"it'll use it as if it were part of the device's name.\n",
|
||||
argv[0]);
|
||||
"If device is a two-digit number it'll use it as an index, otherwise\n"
|
||||
"it'll use it as if it were part of the device's name.\n",
|
||||
argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
i = SDL_strlen(name);
|
||||
i = (int)SDL_strlen(name);
|
||||
if ((i < 3) && SDL_isdigit(name[0]) && ((i == 1) || SDL_isdigit(name[1]))) {
|
||||
index = SDL_atoi(name);
|
||||
name = NULL;
|
||||
|
|
@ -78,13 +75,14 @@ main(int argc, char **argv)
|
|||
/* Try to find matching device */
|
||||
else {
|
||||
for (i = 0; i < SDL_NumHaptics(); i++) {
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL)
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= SDL_NumHaptics()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
|
||||
name);
|
||||
name);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -92,7 +90,7 @@ main(int argc, char **argv)
|
|||
haptic = SDL_HapticOpen(i);
|
||||
if (haptic == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_Log("Device: %s\n", SDL_HapticName(i));
|
||||
|
|
@ -106,7 +104,7 @@ main(int argc, char **argv)
|
|||
SDL_ClearError();
|
||||
|
||||
/* Create effects. */
|
||||
SDL_memset(&efx, 0, sizeof(efx));
|
||||
SDL_memset(efx, 0, sizeof(efx));
|
||||
nefx = 0;
|
||||
supported = SDL_HapticQuery(haptic);
|
||||
|
||||
|
|
@ -116,8 +114,8 @@ main(int argc, char **argv)
|
|||
SDL_Log(" effect %d: Sine Wave\n", nefx);
|
||||
efx[nefx].type = SDL_HAPTIC_SINE;
|
||||
efx[nefx].periodic.period = 1000;
|
||||
efx[nefx].periodic.magnitude = -0x2000; /* Negative magnitude and ... */
|
||||
efx[nefx].periodic.phase = 18000; /* ... 180 degrees phase shift => cancel eachother */
|
||||
efx[nefx].periodic.magnitude = -0x2000; /* Negative magnitude and ... */
|
||||
efx[nefx].periodic.phase = 18000; /* ... 180 degrees phase shift => cancel eachother */
|
||||
efx[nefx].periodic.length = 5000;
|
||||
efx[nefx].periodic.attack_length = 1000;
|
||||
efx[nefx].periodic.fade_length = 1000;
|
||||
|
|
@ -144,13 +142,13 @@ main(int argc, char **argv)
|
|||
}
|
||||
nefx++;
|
||||
}
|
||||
|
||||
|
||||
/* Now the classical constant effect. */
|
||||
if (supported & SDL_HAPTIC_CONSTANT) {
|
||||
SDL_Log(" effect %d: Constant Force\n", nefx);
|
||||
efx[nefx].type = SDL_HAPTIC_CONSTANT;
|
||||
efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR;
|
||||
efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
|
||||
efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
|
||||
efx[nefx].constant.length = 5000;
|
||||
efx[nefx].constant.level = 0x6000;
|
||||
efx[nefx].constant.attack_length = 1000;
|
||||
|
|
@ -162,7 +160,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
nefx++;
|
||||
}
|
||||
|
||||
|
||||
/* The cute spring effect. */
|
||||
if (supported & SDL_HAPTIC_SPRING) {
|
||||
SDL_Log(" effect %d: Condition Spring\n", nefx);
|
||||
|
|
@ -173,7 +171,7 @@ main(int argc, char **argv)
|
|||
efx[nefx].condition.left_sat[i] = 0xFFFF;
|
||||
efx[nefx].condition.right_coeff[i] = 0x2000;
|
||||
efx[nefx].condition.left_coeff[i] = 0x2000;
|
||||
efx[nefx].condition.center[i] = 0x1000; /* Displace the center for it to move. */
|
||||
efx[nefx].condition.center[i] = 0x1000; /* Displace the center for it to move. */
|
||||
}
|
||||
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
||||
if (id[nefx] < 0) {
|
||||
|
|
@ -210,7 +208,7 @@ main(int argc, char **argv)
|
|||
efx[nefx].condition.left_sat[i] = 0xFFFF;
|
||||
efx[nefx].condition.right_coeff[i] = 0x2000;
|
||||
efx[nefx].condition.left_coeff[i] = 0x2000;
|
||||
efx[nefx].condition.deadband[i] = 0x1000; /* 1/16th of axis-range around the center is 'dead'. */
|
||||
efx[nefx].condition.deadband[i] = 0x1000; /* 1/16th of axis-range around the center is 'dead'. */
|
||||
}
|
||||
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
|
||||
if (id[nefx] < 0) {
|
||||
|
|
@ -237,14 +235,14 @@ main(int argc, char **argv)
|
|||
}
|
||||
nefx++;
|
||||
}
|
||||
|
||||
|
||||
/* Now we'll try a ramp effect */
|
||||
if (supported & SDL_HAPTIC_RAMP) {
|
||||
SDL_Log(" effect %d: Ramp\n", nefx);
|
||||
efx[nefx].type = SDL_HAPTIC_RAMP;
|
||||
efx[nefx].ramp.direction.type = SDL_HAPTIC_CARTESIAN;
|
||||
efx[nefx].ramp.direction.dir[0] = 1; /* Force comes from */
|
||||
efx[nefx].ramp.direction.dir[1] = -1; /* the north-east. */
|
||||
efx[nefx].ramp.direction.dir[0] = 1; /* Force comes from */
|
||||
efx[nefx].ramp.direction.dir[1] = -1; /* the north-east. */
|
||||
efx[nefx].ramp.length = 5000;
|
||||
efx[nefx].ramp.start = 0x4000;
|
||||
efx[nefx].ramp.end = -0x4000;
|
||||
|
|
@ -273,24 +271,22 @@ main(int argc, char **argv)
|
|||
nefx++;
|
||||
}
|
||||
|
||||
|
||||
SDL_Log
|
||||
("\nNow playing effects for 5 seconds each with 1 second delay between\n");
|
||||
SDL_Log("\nNow playing effects for 5 seconds each with 1 second delay between\n");
|
||||
for (i = 0; i < nefx; i++) {
|
||||
SDL_Log(" Playing effect %d\n", i);
|
||||
SDL_HapticRunEffect(haptic, id[i], 1);
|
||||
SDL_Delay(6000); /* Effects only have length 5000 */
|
||||
SDL_Delay(6000); /* Effects only have length 5000 */
|
||||
}
|
||||
|
||||
/* Quit */
|
||||
if (haptic != NULL)
|
||||
if (haptic != NULL) {
|
||||
SDL_HapticClose(haptic);
|
||||
}
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Cleans up a bit.
|
||||
*/
|
||||
|
|
@ -305,52 +301,66 @@ abort_execution(void)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Displays information about the haptic device.
|
||||
*/
|
||||
static void
|
||||
HapticPrintSupported(SDL_Haptic * ptr)
|
||||
HapticPrintSupported(SDL_Haptic *ptr)
|
||||
{
|
||||
unsigned int supported;
|
||||
|
||||
supported = SDL_HapticQuery(ptr);
|
||||
SDL_Log(" Supported effects [%d effects, %d playing]:\n",
|
||||
SDL_HapticNumEffects(ptr), SDL_HapticNumEffectsPlaying(ptr));
|
||||
if (supported & SDL_HAPTIC_CONSTANT)
|
||||
SDL_HapticNumEffects(ptr), SDL_HapticNumEffectsPlaying(ptr));
|
||||
if (supported & SDL_HAPTIC_CONSTANT) {
|
||||
SDL_Log(" constant\n");
|
||||
if (supported & SDL_HAPTIC_SINE)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_SINE) {
|
||||
SDL_Log(" sine\n");
|
||||
}
|
||||
/* !!! FIXME: put this back when we have more bits in 2.1 */
|
||||
/* if (supported & SDL_HAPTIC_SQUARE)
|
||||
SDL_Log(" square\n"); */
|
||||
if (supported & SDL_HAPTIC_TRIANGLE)
|
||||
if (supported & SDL_HAPTIC_TRIANGLE) {
|
||||
SDL_Log(" triangle\n");
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHUP)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHUP) {
|
||||
SDL_Log(" sawtoothup\n");
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHDOWN)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_SAWTOOTHDOWN) {
|
||||
SDL_Log(" sawtoothdown\n");
|
||||
if (supported & SDL_HAPTIC_RAMP)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_RAMP) {
|
||||
SDL_Log(" ramp\n");
|
||||
if (supported & SDL_HAPTIC_FRICTION)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_FRICTION) {
|
||||
SDL_Log(" friction\n");
|
||||
if (supported & SDL_HAPTIC_SPRING)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_SPRING) {
|
||||
SDL_Log(" spring\n");
|
||||
if (supported & SDL_HAPTIC_DAMPER)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_DAMPER) {
|
||||
SDL_Log(" damper\n");
|
||||
if (supported & SDL_HAPTIC_INERTIA)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_INERTIA) {
|
||||
SDL_Log(" inertia\n");
|
||||
if (supported & SDL_HAPTIC_CUSTOM)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_CUSTOM) {
|
||||
SDL_Log(" custom\n");
|
||||
if (supported & SDL_HAPTIC_LEFTRIGHT)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_LEFTRIGHT) {
|
||||
SDL_Log(" left/right\n");
|
||||
}
|
||||
SDL_Log(" Supported capabilities:\n");
|
||||
if (supported & SDL_HAPTIC_GAIN)
|
||||
if (supported & SDL_HAPTIC_GAIN) {
|
||||
SDL_Log(" gain\n");
|
||||
if (supported & SDL_HAPTIC_AUTOCENTER)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_AUTOCENTER) {
|
||||
SDL_Log(" autocenter\n");
|
||||
if (supported & SDL_HAPTIC_STATUS)
|
||||
}
|
||||
if (supported & SDL_HAPTIC_STATUS) {
|
||||
SDL_Log(" status\n");
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -29,9 +29,10 @@ hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
|
|||
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
|
||||
#define REPORT_RESIZE_HIT(name) { \
|
||||
#define REPORT_RESIZE_HIT(name) \
|
||||
{ \
|
||||
SDL_Log("HIT-TEST: RESIZE_" #name "\n"); \
|
||||
return SDL_HITTEST_RESIZE_##name; \
|
||||
return SDL_HITTEST_RESIZE_##name; \
|
||||
}
|
||||
|
||||
if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) {
|
||||
|
|
@ -56,7 +57,6 @@ hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
|
|||
return SDL_HITTEST_NORMAL;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int done = 0;
|
||||
|
|
@ -74,8 +74,7 @@ int main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
while (!done)
|
||||
{
|
||||
while (!done) {
|
||||
SDL_Event e;
|
||||
int nothing_to_do = 1;
|
||||
|
||||
|
|
@ -88,39 +87,38 @@ int main(int argc, char **argv)
|
|||
while (SDL_PollEvent(&e)) {
|
||||
nothing_to_do = 0;
|
||||
|
||||
switch (e.type)
|
||||
{
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
SDL_Log("button down!\n");
|
||||
break;
|
||||
switch (e.type) {
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
SDL_Log("button down!\n");
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
SDL_Log("button up!\n");
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
SDL_Log("button up!\n");
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
if (e.window.event == SDL_WINDOWEVENT_MOVED) {
|
||||
SDL_Log("Window event moved to (%d, %d)!\n", (int) e.window.data1, (int) e.window.data2);
|
||||
}
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
if (e.window.event == SDL_WINDOWEVENT_MOVED) {
|
||||
SDL_Log("Window event moved to (%d, %d)!\n", (int)e.window.data1, (int)e.window.data2);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
if (e.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
} else if (e.key.keysym.sym == SDLK_x) {
|
||||
if (!areas) {
|
||||
areas = drag_areas;
|
||||
numareas = SDL_arraysize(drag_areas);
|
||||
} else {
|
||||
areas = NULL;
|
||||
numareas = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
case SDL_KEYDOWN:
|
||||
if (e.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
break;
|
||||
} else if (e.key.keysym.sym == SDLK_x) {
|
||||
if (areas == NULL) {
|
||||
areas = drag_areas;
|
||||
numareas = SDL_arraysize(drag_areas);
|
||||
} else {
|
||||
areas = NULL;
|
||||
numareas = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -20,8 +20,7 @@
|
|||
|
||||
#if !defined SDL_JOYSTICK_DISABLED && !defined SDL_HAPTIC_DISABLED
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Joystick *joystick = NULL;
|
||||
SDL_Haptic *haptic = NULL;
|
||||
|
|
@ -30,17 +29,17 @@ main(int argc, char *argv[])
|
|||
int i;
|
||||
SDL_bool enable_haptic = SDL_TRUE;
|
||||
Uint32 init_subsystems = SDL_INIT_VIDEO | SDL_INIT_JOYSTICK;
|
||||
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (SDL_strcasecmp(argv[i], "--nohaptic") == 0) {
|
||||
enable_haptic = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if(enable_haptic) {
|
||||
if (enable_haptic) {
|
||||
init_subsystems |= SDL_INIT_HAPTIC;
|
||||
}
|
||||
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
|
|
@ -57,91 +56,78 @@ main(int argc, char *argv[])
|
|||
*/
|
||||
|
||||
SDL_Log("There are %d joysticks at startup\n", SDL_NumJoysticks());
|
||||
if (enable_haptic)
|
||||
if (enable_haptic) {
|
||||
SDL_Log("There are %d haptic devices at startup\n", SDL_NumHaptics());
|
||||
}
|
||||
|
||||
while(keepGoing)
|
||||
{
|
||||
while (keepGoing) {
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
keepGoing = SDL_FALSE;
|
||||
break;
|
||||
case SDL_JOYDEVICEADDED:
|
||||
if (joystick != NULL)
|
||||
{
|
||||
SDL_Log("Only one joystick supported by this test\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
joystick = SDL_JoystickOpen(event.jdevice.which);
|
||||
instance = SDL_JoystickInstanceID(joystick);
|
||||
SDL_Log("Joy Added : %d : %s\n", event.jdevice.which, SDL_JoystickName(joystick));
|
||||
if (enable_haptic)
|
||||
{
|
||||
if (SDL_JoystickIsHaptic(joystick))
|
||||
{
|
||||
haptic = SDL_HapticOpenFromJoystick(joystick);
|
||||
if (haptic)
|
||||
{
|
||||
SDL_Log("Joy Haptic Opened\n");
|
||||
if (SDL_HapticRumbleInit( haptic ) != 0)
|
||||
{
|
||||
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
|
||||
SDL_HapticClose(haptic);
|
||||
haptic = NULL;
|
||||
}
|
||||
} else {
|
||||
SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
keepGoing = SDL_FALSE;
|
||||
break;
|
||||
case SDL_JOYDEVICEADDED:
|
||||
if (joystick != NULL) {
|
||||
SDL_Log("Only one joystick supported by this test\n");
|
||||
} else {
|
||||
joystick = SDL_JoystickOpen(event.jdevice.which);
|
||||
instance = SDL_JoystickInstanceID(joystick);
|
||||
SDL_Log("Joy Added : %" SDL_PRIs32 " : %s\n", event.jdevice.which, SDL_JoystickName(joystick));
|
||||
if (enable_haptic) {
|
||||
if (SDL_JoystickIsHaptic(joystick)) {
|
||||
haptic = SDL_HapticOpenFromJoystick(joystick);
|
||||
if (haptic) {
|
||||
SDL_Log("Joy Haptic Opened\n");
|
||||
if (SDL_HapticRumbleInit(haptic) != 0) {
|
||||
SDL_Log("Could not init Rumble!: %s\n", SDL_GetError());
|
||||
SDL_HapticClose(haptic);
|
||||
haptic = NULL;
|
||||
}
|
||||
} else {
|
||||
SDL_Log("Joy haptic open FAILED!: %s\n", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_Log("No haptic found\n");
|
||||
}
|
||||
} else {
|
||||
SDL_Log("No haptic found\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
if (instance == event.jdevice.which)
|
||||
{
|
||||
SDL_Log("Joy Removed: %d\n", event.jdevice.which);
|
||||
instance = -1;
|
||||
if(enable_haptic && haptic)
|
||||
{
|
||||
SDL_HapticClose(haptic);
|
||||
haptic = NULL;
|
||||
}
|
||||
SDL_JoystickClose(joystick);
|
||||
joystick = NULL;
|
||||
} else {
|
||||
SDL_Log("Unknown joystick diconnected\n");
|
||||
}
|
||||
break;
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
if (instance == event.jdevice.which) {
|
||||
SDL_Log("Joy Removed: %" SDL_PRIs32 "\n", event.jdevice.which);
|
||||
instance = -1;
|
||||
if (enable_haptic && haptic) {
|
||||
SDL_HapticClose(haptic);
|
||||
haptic = NULL;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
/*
|
||||
// SDL_Log("Axis Move: %d\n", event.jaxis.axis);
|
||||
*/
|
||||
if (enable_haptic)
|
||||
SDL_HapticRumblePlay(haptic, 0.25, 250);
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
SDL_Log("Button Press: %d\n", event.jbutton.button);
|
||||
if(enable_haptic && haptic)
|
||||
{
|
||||
SDL_HapticRumblePlay(haptic, 0.25, 250);
|
||||
}
|
||||
if (event.jbutton.button == 0) {
|
||||
SDL_Log("Exiting due to button press of button 0\n");
|
||||
keepGoing = SDL_FALSE;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
SDL_Log("Button Release: %d\n", event.jbutton.button);
|
||||
break;
|
||||
SDL_JoystickClose(joystick);
|
||||
joystick = NULL;
|
||||
} else {
|
||||
SDL_Log("Unknown joystick diconnected\n");
|
||||
}
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
/*
|
||||
// SDL_Log("Axis Move: %d\n", event.jaxis.axis);
|
||||
*/
|
||||
if (enable_haptic) {
|
||||
SDL_HapticRumblePlay(haptic, 0.25, 250);
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
SDL_Log("Button Press: %d\n", event.jbutton.button);
|
||||
if (enable_haptic && haptic) {
|
||||
SDL_HapticRumblePlay(haptic, 0.25, 250);
|
||||
}
|
||||
if (event.jbutton.button == 0) {
|
||||
SDL_Log("Exiting due to button press of button 0\n");
|
||||
keepGoing = SDL_FALSE;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
SDL_Log("Button Release: %d\n", event.jbutton.button);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -10,6 +10,11 @@
|
|||
freely.
|
||||
*/
|
||||
|
||||
/* quiet windows compiler warnings */
|
||||
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
|
|
@ -19,15 +24,14 @@ static size_t
|
|||
widelen(char *data)
|
||||
{
|
||||
size_t len = 0;
|
||||
Uint32 *p = (Uint32 *) data;
|
||||
Uint32 *p = (Uint32 *)data;
|
||||
while (*p++) {
|
||||
++len;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *formats[] = {
|
||||
"UTF8",
|
||||
|
|
@ -44,7 +48,7 @@ main(int argc, char *argv[])
|
|||
"UCS-4",
|
||||
};
|
||||
|
||||
char * fname;
|
||||
char *fname;
|
||||
char buffer[BUFSIZ];
|
||||
char *ucs4;
|
||||
char *test[2];
|
||||
|
|
@ -57,9 +61,9 @@ main(int argc, char *argv[])
|
|||
|
||||
fname = GetResourceFilename(argc > 1 ? argv[1] : NULL, "utf8.txt");
|
||||
file = fopen(fname, "rb");
|
||||
if (!file) {
|
||||
if (file == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", fname);
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
SDL_free(fname);
|
||||
|
||||
|
|
@ -82,9 +86,11 @@ main(int argc, char *argv[])
|
|||
}
|
||||
test[0] = SDL_iconv_string("UTF-8", "UCS-4", ucs4, len);
|
||||
SDL_free(ucs4);
|
||||
fputs(test[0], stdout);
|
||||
(void)fputs(test[0], stdout);
|
||||
SDL_free(test[0]);
|
||||
}
|
||||
fclose(file);
|
||||
return (errors ? errors + 1 : 0);
|
||||
(void)fclose(file);
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Total errors: %d\n", errors);
|
||||
return errors ? errors + 1 : 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -42,41 +42,43 @@
|
|||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_Rect textRect, markedRect;
|
||||
static SDL_Color lineColor = {0,0,0,255};
|
||||
static SDL_Color backColor = {255,255,255,255};
|
||||
static SDL_Color textColor = {0,0,0,255};
|
||||
static SDL_Color lineColor = { 0, 0, 0, 255 };
|
||||
static SDL_Color backColor = { 255, 255, 255, 255 };
|
||||
static SDL_Color textColor = { 0, 0, 0, 255 };
|
||||
static char text[MAX_TEXT_LENGTH], markedText[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
|
||||
static int cursor = 0;
|
||||
#ifdef HAVE_SDL_TTF
|
||||
static TTF_Font *font;
|
||||
#else
|
||||
#define UNIFONT_MAX_CODEPOINT 0x1ffff
|
||||
#define UNIFONT_NUM_GLYPHS 0x20000
|
||||
#define UNIFONT_MAX_CODEPOINT 0x1ffff
|
||||
#define UNIFONT_NUM_GLYPHS 0x20000
|
||||
/* Using 512x512 textures that are supported everywhere. */
|
||||
#define UNIFONT_TEXTURE_WIDTH 512
|
||||
#define UNIFONT_GLYPHS_IN_ROW (UNIFONT_TEXTURE_WIDTH / 16)
|
||||
#define UNIFONT_TEXTURE_WIDTH 512
|
||||
#define UNIFONT_GLYPHS_IN_ROW (UNIFONT_TEXTURE_WIDTH / 16)
|
||||
#define UNIFONT_GLYPHS_IN_TEXTURE (UNIFONT_GLYPHS_IN_ROW * UNIFONT_GLYPHS_IN_ROW)
|
||||
#define UNIFONT_NUM_TEXTURES ((UNIFONT_NUM_GLYPHS + UNIFONT_GLYPHS_IN_TEXTURE - 1) / UNIFONT_GLYPHS_IN_TEXTURE)
|
||||
#define UNIFONT_TEXTURE_SIZE (UNIFONT_TEXTURE_WIDTH * UNIFONT_TEXTURE_WIDTH * 4)
|
||||
#define UNIFONT_TEXTURE_PITCH (UNIFONT_TEXTURE_WIDTH * 4)
|
||||
#define UNIFONT_DRAW_SCALE 2
|
||||
struct UnifontGlyph {
|
||||
#define UNIFONT_NUM_TEXTURES ((UNIFONT_NUM_GLYPHS + UNIFONT_GLYPHS_IN_TEXTURE - 1) / UNIFONT_GLYPHS_IN_TEXTURE)
|
||||
#define UNIFONT_TEXTURE_SIZE (UNIFONT_TEXTURE_WIDTH * UNIFONT_TEXTURE_WIDTH * 4)
|
||||
#define UNIFONT_TEXTURE_PITCH (UNIFONT_TEXTURE_WIDTH * 4)
|
||||
#define UNIFONT_DRAW_SCALE 2
|
||||
struct UnifontGlyph
|
||||
{
|
||||
Uint8 width;
|
||||
Uint8 data[32];
|
||||
} *unifontGlyph;
|
||||
} * unifontGlyph;
|
||||
static SDL_Texture **unifontTexture;
|
||||
static Uint8 unifontTextureLoaded[UNIFONT_NUM_TEXTURES] = {0};
|
||||
static Uint8 unifontTextureLoaded[UNIFONT_NUM_TEXTURES] = { 0 };
|
||||
|
||||
/* Unifont loading code start */
|
||||
|
||||
static Uint8 dehex(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
} else if (c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
return 255;
|
||||
}
|
||||
|
||||
|
|
@ -88,15 +90,16 @@ static Uint8 dehex2(char c1, char c2)
|
|||
static Uint8 validate_hex(const char *cp, size_t len, Uint32 *np)
|
||||
{
|
||||
Uint32 n = 0;
|
||||
for (; len > 0; cp++, len--)
|
||||
{
|
||||
for (; len > 0; cp++, len--) {
|
||||
Uint8 c = dehex(*cp);
|
||||
if (c == 255)
|
||||
if (c == 255) {
|
||||
return 0;
|
||||
}
|
||||
n = (n << 4) | c;
|
||||
}
|
||||
if (np != NULL)
|
||||
if (np != NULL) {
|
||||
*np = n;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -113,8 +116,7 @@ static int unifont_init(const char *fontname)
|
|||
|
||||
/* Allocate memory for the glyph data so the file can be closed after initialization. */
|
||||
unifontGlyph = (struct UnifontGlyph *)SDL_malloc(unifontGlyphSize);
|
||||
if (unifontGlyph == NULL)
|
||||
{
|
||||
if (unifontGlyph == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for glyph data.\n", (int)(unifontGlyphSize + 1023) / 1024);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -122,8 +124,7 @@ static int unifont_init(const char *fontname)
|
|||
|
||||
/* Allocate memory for texture pointers for all renderers. */
|
||||
unifontTexture = (SDL_Texture **)SDL_malloc(unifontTextureSize);
|
||||
if (unifontTexture == NULL)
|
||||
{
|
||||
if (unifontTexture == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for texture pointer data.\n", (int)(unifontTextureSize + 1023) / 1024);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -136,8 +137,7 @@ static int unifont_init(const char *fontname)
|
|||
}
|
||||
hexFile = SDL_RWFromFile(filename, "rb");
|
||||
SDL_free(filename);
|
||||
if (hexFile == NULL)
|
||||
{
|
||||
if (hexFile == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to open font file: %s\n", fontname);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -150,76 +150,71 @@ static int unifont_init(const char *fontname)
|
|||
Uint32 codepoint;
|
||||
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer, 1, 9);
|
||||
if (numGlyphs > 0 && bytesRead == 0)
|
||||
if (numGlyphs > 0 && bytesRead == 0) {
|
||||
break; /* EOF */
|
||||
if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9))
|
||||
{
|
||||
}
|
||||
if ((numGlyphs == 0 && bytesRead == 0) || (numGlyphs > 0 && bytesRead < 9)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Looking for the colon that separates the codepoint and glyph data at position 2, 4, 6 and 8. */
|
||||
if (hexBuffer[2] == ':')
|
||||
if (hexBuffer[2] == ':') {
|
||||
codepointHexSize = 2;
|
||||
else if (hexBuffer[4] == ':')
|
||||
} else if (hexBuffer[4] == ':') {
|
||||
codepointHexSize = 4;
|
||||
else if (hexBuffer[6] == ':')
|
||||
} else if (hexBuffer[6] == ':') {
|
||||
codepointHexSize = 6;
|
||||
else if (hexBuffer[8] == ':')
|
||||
} else if (hexBuffer[8] == ':') {
|
||||
codepointHexSize = 8;
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Could not find codepoint and glyph data separator symbol in hex file on line %d.\n", lineNumber);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!validate_hex((const char *)hexBuffer, codepointHexSize, &codepoint))
|
||||
{
|
||||
if (!validate_hex((const char *)hexBuffer, codepointHexSize, &codepoint)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal number in hex file on line %d.\n", lineNumber);
|
||||
return -1;
|
||||
}
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT)
|
||||
if (codepoint > UNIFONT_MAX_CODEPOINT) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Codepoint on line %d exceeded limit of 0x%x.\n", lineNumber, UNIFONT_MAX_CODEPOINT);
|
||||
}
|
||||
|
||||
/* If there was glyph data read in the last file read, move it to the front of the buffer. */
|
||||
bytesOverread = 8 - codepointHexSize;
|
||||
if (codepointHexSize < 8)
|
||||
if (codepointHexSize < 8) {
|
||||
SDL_memmove(hexBuffer, hexBuffer + codepointHexSize + 1, bytesOverread);
|
||||
}
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + bytesOverread, 1, 33 - bytesOverread);
|
||||
if (bytesRead < (33 - bytesOverread))
|
||||
{
|
||||
if (bytesRead < (33 - bytesOverread)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
if (hexBuffer[32] == '\n')
|
||||
if (hexBuffer[32] == '\n') {
|
||||
glyphWidth = 8;
|
||||
else
|
||||
{
|
||||
} else {
|
||||
glyphWidth = 16;
|
||||
bytesRead = SDL_RWread(hexFile, hexBuffer + 33, 1, 32);
|
||||
if (bytesRead < 32)
|
||||
{
|
||||
if (bytesRead < 32) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Unexpected end of hex file.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!validate_hex((const char *)hexBuffer, glyphWidth * 4, NULL))
|
||||
{
|
||||
if (!validate_hex((const char *)hexBuffer, glyphWidth * 4, NULL)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Malformed hexadecimal glyph data in hex file on line %d.\n", lineNumber);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (codepoint <= UNIFONT_MAX_CODEPOINT)
|
||||
{
|
||||
if (unifontGlyph[codepoint].width > 0)
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Ignoring duplicate codepoint 0x%08x in hex file on line %d.\n", codepoint, lineNumber);
|
||||
else
|
||||
{
|
||||
if (codepoint <= UNIFONT_MAX_CODEPOINT) {
|
||||
if (unifontGlyph[codepoint].width > 0) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "unifont: Ignoring duplicate codepoint 0x%08" SDL_PRIx32 " in hex file on line %d.\n", codepoint, lineNumber);
|
||||
} else {
|
||||
unifontGlyph[codepoint].width = glyphWidth;
|
||||
/* Pack the hex data into a more compact form. */
|
||||
for (i = 0; i < glyphWidth * 2; i++)
|
||||
for (i = 0; i < glyphWidth * 2; i++) {
|
||||
unifontGlyph[codepoint].data[i] = dehex2(hexBuffer[i * 2], hexBuffer[i * 2 + 1]);
|
||||
}
|
||||
numGlyphs++;
|
||||
}
|
||||
}
|
||||
|
|
@ -228,29 +223,25 @@ static int unifont_init(const char *fontname)
|
|||
} while (bytesRead > 0);
|
||||
|
||||
SDL_RWclose(hexFile);
|
||||
SDL_Log("unifont: Loaded %u glyphs.\n", numGlyphs);
|
||||
SDL_Log("unifont: Loaded %" SDL_PRIu32 " glyphs.\n", numGlyphs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
|
||||
static void
|
||||
unifont_make_rgba(const Uint8 *src, Uint8 *dst, Uint8 width)
|
||||
{
|
||||
int i, j;
|
||||
Uint8 *row = dst;
|
||||
|
||||
for (i = 0; i < width * 2; i++)
|
||||
{
|
||||
for (i = 0; i < width * 2; i++) {
|
||||
Uint8 data = src[i];
|
||||
for (j = 0; j < 8; j++)
|
||||
{
|
||||
if (data & 0x80)
|
||||
{
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (data & 0x80) {
|
||||
row[0] = textColor.r;
|
||||
row[1] = textColor.g;
|
||||
row[2] = textColor.b;
|
||||
row[3] = textColor.a;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
row[0] = 0;
|
||||
row[1] = 0;
|
||||
row[2] = 0;
|
||||
|
|
@ -260,8 +251,7 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
|
|||
row += 4;
|
||||
}
|
||||
|
||||
if (width == 8 || (width == 16 && i % 2 == 1))
|
||||
{
|
||||
if (width == 8 || (width == 16 && i % 2 == 1)) {
|
||||
dst += UNIFONT_TEXTURE_PITCH;
|
||||
row = dst;
|
||||
}
|
||||
|
|
@ -271,52 +261,46 @@ static void unifont_make_rgba(Uint8 *src, Uint8 *dst, Uint8 width)
|
|||
static int unifont_load_texture(Uint32 textureID)
|
||||
{
|
||||
int i;
|
||||
Uint8 * textureRGBA;
|
||||
Uint8 *textureRGBA;
|
||||
|
||||
if (textureID >= UNIFONT_NUM_TEXTURES)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Tried to load out of range texture %u.\n", textureID);
|
||||
if (textureID >= UNIFONT_NUM_TEXTURES) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Tried to load out of range texture %" SDL_PRIu32 "\n", textureID);
|
||||
return -1;
|
||||
}
|
||||
|
||||
textureRGBA = (Uint8 *)SDL_malloc(UNIFONT_TEXTURE_SIZE);
|
||||
if (textureRGBA == NULL)
|
||||
{
|
||||
if (textureRGBA == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d MiB for a texture.\n", UNIFONT_TEXTURE_SIZE / 1024 / 1024);
|
||||
return -1;
|
||||
}
|
||||
SDL_memset(textureRGBA, 0, UNIFONT_TEXTURE_SIZE);
|
||||
|
||||
/* Copy the glyphs into memory in RGBA format. */
|
||||
for (i = 0; i < UNIFONT_GLYPHS_IN_TEXTURE; i++)
|
||||
{
|
||||
for (i = 0; i < UNIFONT_GLYPHS_IN_TEXTURE; i++) {
|
||||
Uint32 codepoint = UNIFONT_GLYPHS_IN_TEXTURE * textureID + i;
|
||||
if (unifontGlyph[codepoint].width > 0)
|
||||
{
|
||||
if (unifontGlyph[codepoint].width > 0) {
|
||||
const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE;
|
||||
const size_t offset = (cInTex / UNIFONT_GLYPHS_IN_ROW) * UNIFONT_TEXTURE_PITCH * 16 + (cInTex % UNIFONT_GLYPHS_IN_ROW) * 16 * 4;
|
||||
const size_t offset = ((size_t)cInTex / UNIFONT_GLYPHS_IN_ROW) * UNIFONT_TEXTURE_PITCH * 16 + (cInTex % UNIFONT_GLYPHS_IN_ROW) * 16 * 4;
|
||||
unifont_make_rgba(unifontGlyph[codepoint].data, textureRGBA + offset, unifontGlyph[codepoint].width);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create textures and upload the RGBA data from above. */
|
||||
for (i = 0; i < state->num_windows; ++i)
|
||||
{
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_Texture *tex = unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID];
|
||||
if (state->windows[i] == NULL || renderer == NULL || tex != NULL)
|
||||
if (state->windows[i] == NULL || renderer == NULL || tex != NULL) {
|
||||
continue;
|
||||
}
|
||||
tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, UNIFONT_TEXTURE_WIDTH, UNIFONT_TEXTURE_WIDTH);
|
||||
if (tex == NULL)
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to create texture %u for renderer %d.\n", textureID, i);
|
||||
if (tex == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to create texture %" SDL_PRIu32 " for renderer %d.\n", textureID, i);
|
||||
return -1;
|
||||
}
|
||||
unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID] = tex;
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
if (SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH) != 0)
|
||||
{
|
||||
SDL_Log("unifont error: Failed to update texture %u data for renderer %d.\n", textureID, i);
|
||||
if (SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH) != 0) {
|
||||
SDL_Log("unifont error: Failed to update texture %" SDL_PRIu32 " data for renderer %d.\n", textureID, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -340,8 +324,7 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst
|
|||
}
|
||||
}
|
||||
texture = unifontTexture[UNIFONT_NUM_TEXTURES * rendererID + textureID];
|
||||
if (texture != NULL)
|
||||
{
|
||||
if (texture != NULL) {
|
||||
const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE;
|
||||
srcrect.x = cInTex % UNIFONT_GLYPHS_IN_ROW * 16;
|
||||
srcrect.y = cInTex / UNIFONT_GLYPHS_IN_ROW * 16;
|
||||
|
|
@ -353,21 +336,22 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst
|
|||
static void unifont_cleanup()
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < state->num_windows; ++i)
|
||||
{
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL || renderer == NULL)
|
||||
if (state->windows[i] == NULL || renderer == NULL) {
|
||||
continue;
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++)
|
||||
{
|
||||
}
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) {
|
||||
SDL_Texture *tex = unifontTexture[UNIFONT_NUM_TEXTURES * i + j];
|
||||
if (tex != NULL)
|
||||
if (tex != NULL) {
|
||||
SDL_DestroyTexture(tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++)
|
||||
unifontTextureLoaded[j] = 0;
|
||||
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) {
|
||||
unifontTextureLoaded[j] = 0;
|
||||
}
|
||||
|
||||
SDL_free(unifontTexture);
|
||||
SDL_free(unifontGlyph);
|
||||
|
|
@ -379,30 +363,31 @@ static void unifont_cleanup()
|
|||
size_t utf8_length(unsigned char c)
|
||||
{
|
||||
c = (unsigned char)(0xff & c);
|
||||
if (c < 0x80)
|
||||
if (c < 0x80) {
|
||||
return 1;
|
||||
else if ((c >> 5) ==0x6)
|
||||
} else if ((c >> 5) == 0x6) {
|
||||
return 2;
|
||||
else if ((c >> 4) == 0xe)
|
||||
} else if ((c >> 4) == 0xe) {
|
||||
return 3;
|
||||
else if ((c >> 3) == 0x1e)
|
||||
} else if ((c >> 3) == 0x1e) {
|
||||
return 4;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *utf8_next(char *p)
|
||||
{
|
||||
size_t len = utf8_length(*p);
|
||||
size_t i = 0;
|
||||
if (!len)
|
||||
if (!len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (; i < len; ++i)
|
||||
{
|
||||
for (; i < len; ++i) {
|
||||
++p;
|
||||
if (!*p)
|
||||
if (!*p) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
|
@ -410,8 +395,7 @@ char *utf8_next(char *p)
|
|||
char *utf8_advance(char *p, size_t distance)
|
||||
{
|
||||
size_t i = 0;
|
||||
for (; i < distance && p; ++i)
|
||||
{
|
||||
for (; i < distance && p; ++i) {
|
||||
p = utf8_next(p);
|
||||
}
|
||||
return p;
|
||||
|
|
@ -421,20 +405,20 @@ Uint32 utf8_decode(char *p, size_t len)
|
|||
{
|
||||
Uint32 codepoint = 0;
|
||||
size_t i = 0;
|
||||
if (!len)
|
||||
if (!len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (; i < len; ++i)
|
||||
{
|
||||
if (i == 0)
|
||||
for (; i < len; ++i) {
|
||||
if (i == 0) {
|
||||
codepoint = (0xff >> len) & *p;
|
||||
else
|
||||
{
|
||||
} else {
|
||||
codepoint <<= 6;
|
||||
codepoint |= 0x3f & *p;
|
||||
}
|
||||
if (!*p)
|
||||
if (!*p) {
|
||||
return 0;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
|
|
@ -473,16 +457,15 @@ void CleanupVideo()
|
|||
|
||||
void _Redraw(int rendererID)
|
||||
{
|
||||
SDL_Renderer * renderer = state->renderers[rendererID];
|
||||
SDL_Renderer *renderer = state->renderers[rendererID];
|
||||
SDL_Rect drawnTextRect, cursorRect, underlineRect;
|
||||
drawnTextRect = textRect;
|
||||
drawnTextRect.w = 0;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a);
|
||||
SDL_RenderFillRect(renderer,&textRect);
|
||||
SDL_RenderFillRect(renderer, &textRect);
|
||||
|
||||
if (*text)
|
||||
{
|
||||
if (*text) {
|
||||
#ifdef HAVE_SDL_TTF
|
||||
SDL_Surface *textSur = TTF_RenderUTF8_Blended(font, text, textColor);
|
||||
SDL_Texture *texture;
|
||||
|
|
@ -492,10 +475,10 @@ void _Redraw(int rendererID)
|
|||
drawnTextRect.w = textSur->w;
|
||||
drawnTextRect.h = textSur->h;
|
||||
|
||||
texture = SDL_CreateTextureFromSurface(renderer,textSur);
|
||||
texture = SDL_CreateTextureFromSurface(renderer, textSur);
|
||||
SDL_FreeSurface(textSur);
|
||||
|
||||
SDL_RenderCopy(renderer,texture,NULL,&drawnTextRect);
|
||||
SDL_RenderCopy(renderer, texture, NULL, &drawnTextRect);
|
||||
SDL_DestroyTexture(texture);
|
||||
#else
|
||||
char *utext = text;
|
||||
|
|
@ -510,8 +493,7 @@ void _Redraw(int rendererID)
|
|||
drawnTextRect.y = dstrect.y;
|
||||
drawnTextRect.h = dstrect.h;
|
||||
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext))))
|
||||
{
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) {
|
||||
Sint32 advance = unifont_draw_glyph(codepoint, rendererID, &dstrect) * UNIFONT_DRAW_SCALE;
|
||||
dstrect.x += advance;
|
||||
drawnTextRect.w += advance;
|
||||
|
|
@ -522,14 +504,11 @@ void _Redraw(int rendererID)
|
|||
|
||||
markedRect.x = textRect.x + drawnTextRect.w;
|
||||
markedRect.w = textRect.w - drawnTextRect.w;
|
||||
if (markedRect.w < 0)
|
||||
{
|
||||
if (markedRect.w < 0) {
|
||||
/* Stop text input because we cannot hold any more characters */
|
||||
SDL_StopTextInput();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
|
||||
|
|
@ -542,19 +521,18 @@ void _Redraw(int rendererID)
|
|||
drawnTextRect.w = 0;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, backColor.r, backColor.g, backColor.b, backColor.a);
|
||||
SDL_RenderFillRect(renderer,&markedRect);
|
||||
SDL_RenderFillRect(renderer, &markedRect);
|
||||
|
||||
if (markedText[0])
|
||||
{
|
||||
if (markedText[0]) {
|
||||
#ifdef HAVE_SDL_TTF
|
||||
SDL_Surface *textSur;
|
||||
SDL_Texture *texture;
|
||||
if (cursor)
|
||||
{
|
||||
if (cursor) {
|
||||
char *p = utf8_advance(markedText, cursor);
|
||||
char c = 0;
|
||||
if (!p)
|
||||
if (p == NULL) {
|
||||
p = &markedText[SDL_strlen(markedText)];
|
||||
}
|
||||
|
||||
c = *p;
|
||||
*p = 0;
|
||||
|
|
@ -568,10 +546,10 @@ void _Redraw(int rendererID)
|
|||
drawnTextRect.w = textSur->w;
|
||||
drawnTextRect.h = textSur->h;
|
||||
|
||||
texture = SDL_CreateTextureFromSurface(renderer,textSur);
|
||||
texture = SDL_CreateTextureFromSurface(renderer, textSur);
|
||||
SDL_FreeSurface(textSur);
|
||||
|
||||
SDL_RenderCopy(renderer,texture,NULL,&drawnTextRect);
|
||||
SDL_RenderCopy(renderer, texture, NULL, &drawnTextRect);
|
||||
SDL_DestroyTexture(texture);
|
||||
#else
|
||||
int i = 0;
|
||||
|
|
@ -587,20 +565,19 @@ void _Redraw(int rendererID)
|
|||
drawnTextRect.y = dstrect.y;
|
||||
drawnTextRect.h = dstrect.h;
|
||||
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext))))
|
||||
{
|
||||
while ((codepoint = utf8_decode(utext, len = utf8_length(*utext)))) {
|
||||
Sint32 advance = unifont_draw_glyph(codepoint, rendererID, &dstrect) * UNIFONT_DRAW_SCALE;
|
||||
dstrect.x += advance;
|
||||
drawnTextRect.w += advance;
|
||||
if (i < cursor)
|
||||
if (i < cursor) {
|
||||
cursorRect.x += advance;
|
||||
}
|
||||
i++;
|
||||
utext += len;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cursor > 0)
|
||||
{
|
||||
if (cursor > 0) {
|
||||
cursorRect.y = drawnTextRect.y;
|
||||
cursorRect.h = drawnTextRect.h;
|
||||
}
|
||||
|
|
@ -615,7 +592,7 @@ void _Redraw(int rendererID)
|
|||
}
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, lineColor.r, lineColor.g, lineColor.b, lineColor.a);
|
||||
SDL_RenderFillRect(renderer,&cursorRect);
|
||||
SDL_RenderFillRect(renderer, &cursorRect);
|
||||
|
||||
SDL_SetTextInputRect(&markedRect);
|
||||
}
|
||||
|
|
@ -625,8 +602,9 @@ void Redraw()
|
|||
int i;
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
|
|
@ -648,27 +626,25 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;i++) {
|
||||
for (i = 1; i < argc; i++) {
|
||||
SDLTest_CommonArg(state, i);
|
||||
}
|
||||
for (argc--, argv++; argc > 0; argc--, argv++)
|
||||
{
|
||||
for (argc--, argv++; argc > 0; argc--, argv++) {
|
||||
if (SDL_strcmp(argv[0], "--help") == 0) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (SDL_strcmp(argv[0], "--font") == 0)
|
||||
{
|
||||
else if (SDL_strcmp(argv[0], "--font") == 0) {
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (argc > 0)
|
||||
if (argc > 0) {
|
||||
fontname = argv[0];
|
||||
else {
|
||||
} else {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -679,14 +655,12 @@ int main(int argc, char *argv[])
|
|||
return 2;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_SDL_TTF
|
||||
/* Initialize fonts */
|
||||
TTF_Init();
|
||||
|
||||
font = TTF_OpenFont(fontname, DEFAULT_PTSIZE);
|
||||
if (! font)
|
||||
{
|
||||
if (font == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to find font: %s\n", TTF_GetError());
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -713,90 +687,82 @@ int main(int argc, char *argv[])
|
|||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
switch(event.type) {
|
||||
case SDL_KEYDOWN: {
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_RETURN:
|
||||
text[0]=0x00;
|
||||
Redraw();
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
/* Only delete text if not in editing mode. */
|
||||
if (!markedText[0])
|
||||
{
|
||||
size_t textlen = SDL_strlen(text);
|
||||
|
||||
do {
|
||||
if (textlen==0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if ((text[textlen-1] & 0x80) == 0x00)
|
||||
{
|
||||
/* One byte */
|
||||
text[textlen-1]=0x00;
|
||||
break;
|
||||
}
|
||||
if ((text[textlen-1] & 0xC0) == 0x80)
|
||||
{
|
||||
/* Byte from the multibyte sequence */
|
||||
text[textlen-1]=0x00;
|
||||
textlen--;
|
||||
}
|
||||
if ((text[textlen-1] & 0xC0) == 0xC0)
|
||||
{
|
||||
/* First byte of multibyte sequence */
|
||||
text[textlen-1]=0x00;
|
||||
break;
|
||||
}
|
||||
} while(1);
|
||||
|
||||
Redraw();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (done)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Log("Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
|
||||
event.key.keysym.scancode,
|
||||
SDL_GetScancodeName(event.key.keysym.scancode),
|
||||
event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym));
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
if (event.text.text[0] == '\0' || event.text.text[0] == '\n' ||
|
||||
markedRect.w < 0)
|
||||
break;
|
||||
|
||||
SDL_Log("Keyboard: text input \"%s\"\n", event.text.text);
|
||||
|
||||
if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
|
||||
SDL_strlcat(text, event.text.text, sizeof(text));
|
||||
|
||||
SDL_Log("text inputed: %s\n", text);
|
||||
|
||||
/* After text inputed, we can clear up markedText because it */
|
||||
/* is committed */
|
||||
markedText[0] = 0;
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_RETURN:
|
||||
text[0] = 0x00;
|
||||
Redraw();
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
/* Only delete text if not in editing mode. */
|
||||
if (!markedText[0]) {
|
||||
size_t textlen = SDL_strlen(text);
|
||||
|
||||
case SDL_TEXTEDITING:
|
||||
SDL_Log("text editing \"%s\", selected range (%d, %d)\n",
|
||||
event.edit.text, event.edit.start, event.edit.length);
|
||||
do {
|
||||
if (textlen == 0) {
|
||||
break;
|
||||
}
|
||||
if (!(text[textlen - 1] & 0x80)) {
|
||||
/* One byte */
|
||||
text[textlen - 1] = 0x00;
|
||||
break;
|
||||
}
|
||||
if ((text[textlen - 1] & 0xC0) == 0x80) {
|
||||
/* Byte from the multibyte sequence */
|
||||
text[textlen - 1] = 0x00;
|
||||
textlen--;
|
||||
}
|
||||
if ((text[textlen - 1] & 0xC0) == 0xC0) {
|
||||
/* First byte of multibyte sequence */
|
||||
text[textlen - 1] = 0x00;
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
|
||||
SDL_strlcpy(markedText, event.edit.text, SDL_TEXTEDITINGEVENT_TEXT_SIZE);
|
||||
cursor = event.edit.start;
|
||||
Redraw();
|
||||
Redraw();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Log("Keyboard: scancode 0x%08X = %s, keycode 0x%08" SDL_PRIX32 " = %s\n",
|
||||
event.key.keysym.scancode,
|
||||
SDL_GetScancodeName(event.key.keysym.scancode),
|
||||
SDL_static_cast(Uint32, event.key.keysym.sym),
|
||||
SDL_GetKeyName(event.key.keysym.sym));
|
||||
break;
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
if (event.text.text[0] == '\0' || event.text.text[0] == '\n' || markedRect.w < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_Log("Keyboard: text input \"%s\"\n", event.text.text);
|
||||
|
||||
if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text)) {
|
||||
SDL_strlcat(text, event.text.text, sizeof(text));
|
||||
}
|
||||
|
||||
SDL_Log("text inputed: %s\n", text);
|
||||
|
||||
/* After text inputed, we can clear up markedText because it */
|
||||
/* is committed */
|
||||
markedText[0] = 0;
|
||||
Redraw();
|
||||
break;
|
||||
|
||||
case SDL_TEXTEDITING:
|
||||
SDL_Log("text editing \"%s\", selected range (%" SDL_PRIs32 ", %" SDL_PRIs32 ")\n",
|
||||
event.edit.text, event.edit.start, event.edit.length);
|
||||
|
||||
SDL_strlcpy(markedText, event.edit.text, SDL_TEXTEDITINGEVENT_TEXT_SIZE);
|
||||
cursor = event.edit.start;
|
||||
Redraw();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -22,7 +22,12 @@
|
|||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#define SWAP(typ,a,b) do{typ t=a;a=b;b=t;}while(0)
|
||||
#define SWAP(typ, a, b) \
|
||||
do { \
|
||||
typ t = a; \
|
||||
a = b; \
|
||||
b = t; \
|
||||
} while (0)
|
||||
#define NUM_OBJECTS 100
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
|
|
@ -37,8 +42,7 @@ static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
|||
int mouse_begin_x = -1, mouse_begin_y = -1;
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawPoints(SDL_Renderer * renderer)
|
||||
void DrawPoints(SDL_Renderer *renderer)
|
||||
{
|
||||
int i;
|
||||
int x, y;
|
||||
|
|
@ -71,8 +75,8 @@ DrawPoints(SDL_Renderer * renderer)
|
|||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
|
||||
(Uint8) current_color, (Uint8) current_alpha);
|
||||
SDL_SetRenderDrawColor(renderer, 255, (Uint8)current_color,
|
||||
(Uint8)current_color, (Uint8)current_alpha);
|
||||
|
||||
x = rand() % viewport.w;
|
||||
y = rand() % viewport.h;
|
||||
|
|
@ -86,10 +90,12 @@ SDL_Rect lines[MAX_LINES];
|
|||
static int
|
||||
add_line(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if (num_lines >= MAX_LINES)
|
||||
if (num_lines >= MAX_LINES) {
|
||||
return 0;
|
||||
if ((x1 == x2) && (y1 == y2))
|
||||
}
|
||||
if ((x1 == x2) && (y1 == y2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Log("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2);
|
||||
lines[num_lines].x = x1;
|
||||
|
|
@ -100,9 +106,7 @@ add_line(int x1, int y1, int x2, int y2)
|
|||
return ++num_lines;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DrawLines(SDL_Renderer * renderer)
|
||||
void DrawLines(SDL_Renderer *renderer)
|
||||
{
|
||||
int i;
|
||||
SDL_Rect viewport;
|
||||
|
|
@ -130,18 +134,22 @@ SDL_Rect rects[MAX_RECTS];
|
|||
static int
|
||||
add_rect(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
if (num_rects >= MAX_RECTS)
|
||||
if (num_rects >= MAX_RECTS) {
|
||||
return 0;
|
||||
if ((x1 == x2) || (y1 == y2))
|
||||
}
|
||||
if ((x1 == x2) || (y1 == y2)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (x1 > x2)
|
||||
if (x1 > x2) {
|
||||
SWAP(int, x1, x2);
|
||||
if (y1 > y2)
|
||||
}
|
||||
if (y1 > y2) {
|
||||
SWAP(int, y1, y2);
|
||||
}
|
||||
|
||||
SDL_Log("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2,
|
||||
x2 - x1, y2 - y1);
|
||||
x2 - x1, y2 - y1);
|
||||
|
||||
rects[num_rects].x = x1;
|
||||
rects[num_rects].y = y1;
|
||||
|
|
@ -152,20 +160,20 @@ add_rect(int x1, int y1, int x2, int y2)
|
|||
}
|
||||
|
||||
static void
|
||||
DrawRects(SDL_Renderer * renderer)
|
||||
DrawRects(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
|
||||
SDL_RenderFillRects(renderer, rects, num_rects);
|
||||
}
|
||||
|
||||
static void
|
||||
DrawRectLineIntersections(SDL_Renderer * renderer)
|
||||
DrawRectLineIntersections(SDL_Renderer *renderer)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 55, 255);
|
||||
|
||||
for (i = 0; i < num_rects; i++)
|
||||
for (i = 0; i < num_rects; i++) {
|
||||
for (j = 0; j < num_lines; j++) {
|
||||
int x1, y1, x2, y2;
|
||||
SDL_Rect r;
|
||||
|
|
@ -180,26 +188,27 @@ DrawRectLineIntersections(SDL_Renderer * renderer)
|
|||
SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
DrawRectRectIntersections(SDL_Renderer * renderer)
|
||||
DrawRectRectIntersections(SDL_Renderer *renderer)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 200, 0, 255);
|
||||
|
||||
for (i = 0; i < num_rects; i++)
|
||||
for (i = 0; i < num_rects; i++) {
|
||||
for (j = i + 1; j < num_rects; j++) {
|
||||
SDL_Rect r;
|
||||
if (SDL_IntersectRect(&rects[i], &rects[j], &r)) {
|
||||
SDL_RenderFillRect(renderer, &r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
|
@ -213,28 +222,30 @@ loop()
|
|||
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);
|
||||
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)
|
||||
if (event.key.keysym.mod & KMOD_SHIFT) {
|
||||
num_lines = 0;
|
||||
else
|
||||
} else {
|
||||
add_line(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
if (event.key.keysym.mod & KMOD_SHIFT)
|
||||
if (event.key.keysym.mod & KMOD_SHIFT) {
|
||||
num_rects = 0;
|
||||
else
|
||||
} else {
|
||||
add_rect(rand() % 640, rand() % 480, rand() % 640,
|
||||
rand() % 480);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
@ -244,8 +255,9 @@ loop()
|
|||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
|
|
@ -264,8 +276,7 @@ loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
Uint32 then, now, frames;
|
||||
|
|
@ -278,7 +289,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
|
@ -333,7 +344,7 @@ main(int argc, char *argv[])
|
|||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
srand(time(NULL));
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
|
|
@ -354,7 +365,7 @@ main(int argc, char *argv[])
|
|||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -28,8 +28,8 @@
|
|||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 480
|
||||
#else
|
||||
#define SCREEN_WIDTH 640
|
||||
#define SCREEN_HEIGHT 480
|
||||
#define SCREEN_WIDTH 640
|
||||
#define SCREEN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
static SDL_Window *window = NULL;
|
||||
|
|
@ -44,7 +44,7 @@ PrintJoystick(SDL_Joystick *joy)
|
|||
char guid[64];
|
||||
|
||||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joy)) == joy);
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, sizeof (guid));
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, sizeof(guid));
|
||||
switch (SDL_JoystickGetType(joy)) {
|
||||
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
|
||||
type = "Game Controller";
|
||||
|
|
@ -87,7 +87,7 @@ PrintJoystick(SDL_Joystick *joy)
|
|||
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joy));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joy));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joy));
|
||||
SDL_Log(" instance id: %d\n", SDL_JoystickInstanceID(joy));
|
||||
SDL_Log(" instance id: %" SDL_PRIs32 "\n", SDL_JoystickInstanceID(joy));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joy), SDL_JoystickGetProduct(joy));
|
||||
}
|
||||
|
|
@ -103,8 +103,7 @@ DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
|
|||
SDL_RenderFillRect(r, &area);
|
||||
}
|
||||
|
||||
void
|
||||
loop(void *arg)
|
||||
void loop(void *arg)
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
|
@ -117,8 +116,8 @@ loop(void *arg)
|
|||
switch (event.type) {
|
||||
|
||||
case SDL_JOYDEVICEADDED:
|
||||
SDL_Log("Joystick device %d added.\n", (int) event.jdevice.which);
|
||||
if (!joystick) {
|
||||
SDL_Log("Joystick device %d added.\n", (int)event.jdevice.which);
|
||||
if (joystick == NULL) {
|
||||
joystick = SDL_JoystickOpen(event.jdevice.which);
|
||||
if (joystick) {
|
||||
PrintJoystick(joystick);
|
||||
|
|
@ -129,7 +128,7 @@ loop(void *arg)
|
|||
break;
|
||||
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
SDL_Log("Joystick device %d removed.\n", (int) event.jdevice.which);
|
||||
SDL_Log("Joystick device %d removed.\n", (int)event.jdevice.which);
|
||||
if (event.jdevice.which == SDL_JoystickInstanceID(joystick)) {
|
||||
SDL_JoystickClose(joystick);
|
||||
joystick = SDL_JoystickOpen(0);
|
||||
|
|
@ -137,41 +136,46 @@ loop(void *arg)
|
|||
break;
|
||||
|
||||
case SDL_JOYAXISMOTION:
|
||||
SDL_Log("Joystick %d axis %d value: %d\n",
|
||||
event.jaxis.which,
|
||||
event.jaxis.axis, event.jaxis.value);
|
||||
SDL_Log("Joystick %" SDL_PRIs32 " axis %d value: %d\n",
|
||||
event.jaxis.which,
|
||||
event.jaxis.axis, event.jaxis.value);
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
SDL_Log("Joystick %d hat %d value:",
|
||||
event.jhat.which, event.jhat.hat);
|
||||
if (event.jhat.value == SDL_HAT_CENTERED)
|
||||
SDL_Log("Joystick %" SDL_PRIs32 " hat %d value:",
|
||||
event.jhat.which, event.jhat.hat);
|
||||
if (event.jhat.value == SDL_HAT_CENTERED) {
|
||||
SDL_Log(" centered");
|
||||
if (event.jhat.value & SDL_HAT_UP)
|
||||
}
|
||||
if (event.jhat.value & SDL_HAT_UP) {
|
||||
SDL_Log(" up");
|
||||
if (event.jhat.value & SDL_HAT_RIGHT)
|
||||
}
|
||||
if (event.jhat.value & SDL_HAT_RIGHT) {
|
||||
SDL_Log(" right");
|
||||
if (event.jhat.value & SDL_HAT_DOWN)
|
||||
}
|
||||
if (event.jhat.value & SDL_HAT_DOWN) {
|
||||
SDL_Log(" down");
|
||||
if (event.jhat.value & SDL_HAT_LEFT)
|
||||
}
|
||||
if (event.jhat.value & SDL_HAT_LEFT) {
|
||||
SDL_Log(" left");
|
||||
}
|
||||
SDL_Log("\n");
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
SDL_Log("Joystick %d ball %d delta: (%d,%d)\n",
|
||||
event.jball.which,
|
||||
event.jball.ball, event.jball.xrel, event.jball.yrel);
|
||||
SDL_Log("Joystick %" SDL_PRIs32 " ball %d delta: (%d,%d)\n",
|
||||
event.jball.which,
|
||||
event.jball.ball, event.jball.xrel, event.jball.yrel);
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
SDL_Log("Joystick %d button %d down\n",
|
||||
event.jbutton.which, event.jbutton.button);
|
||||
SDL_Log("Joystick %" SDL_PRIs32 " button %d down\n",
|
||||
event.jbutton.which, event.jbutton.button);
|
||||
/* First button triggers a 0.5 second full strength rumble */
|
||||
if (event.jbutton.button == 0) {
|
||||
SDL_JoystickRumble(joystick, 0xFFFF, 0xFFFF, 500);
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
SDL_Log("Joystick %d button %d up\n",
|
||||
event.jbutton.which, event.jbutton.button);
|
||||
SDL_Log("Joystick %" SDL_PRIs32 " button %d up\n",
|
||||
event.jbutton.which, event.jbutton.button);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
/* Press the L key to lag for 3 seconds, to see what happens
|
||||
|
|
@ -198,20 +202,26 @@ loop(void *arg)
|
|||
}
|
||||
|
||||
if (joystick) {
|
||||
const int BUTTONS_PER_LINE = ((SCREEN_WIDTH - 4) / 34);
|
||||
int x, y;
|
||||
|
||||
/* Update visual joystick state */
|
||||
SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
|
||||
y = SCREEN_HEIGHT - ((((SDL_JoystickNumButtons(joystick) + (BUTTONS_PER_LINE - 1)) / BUTTONS_PER_LINE) + 1) * 34);
|
||||
for (i = 0; i < SDL_JoystickNumButtons(joystick); ++i) {
|
||||
if ((i % BUTTONS_PER_LINE) == 0) {
|
||||
y += 34;
|
||||
}
|
||||
if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) {
|
||||
DrawRect(screen, (i%20) * 34, SCREEN_HEIGHT - 68 + (i/20) * 34, 32, 32);
|
||||
x = 2 + (i % BUTTONS_PER_LINE) * 34;
|
||||
DrawRect(screen, x, y, 32, 32);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0x00, 0x00, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumAxes(joystick); ++i) {
|
||||
/* Draw the X/Y axis */
|
||||
int x, y;
|
||||
x = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768);
|
||||
x = (((int)SDL_JoystickGetAxis(joystick, i)) + 32768);
|
||||
x *= SCREEN_WIDTH;
|
||||
x /= 65535;
|
||||
if (x < 0) {
|
||||
|
|
@ -221,7 +231,7 @@ loop(void *arg)
|
|||
}
|
||||
++i;
|
||||
if (i < SDL_JoystickNumAxes(joystick)) {
|
||||
y = (((int) SDL_JoystickGetAxis(joystick, i)) + 32768);
|
||||
y = (((int)SDL_JoystickGetAxis(joystick, i)) + 32768);
|
||||
} else {
|
||||
y = 32768;
|
||||
}
|
||||
|
|
@ -239,26 +249,27 @@ loop(void *arg)
|
|||
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
for (i = 0; i < SDL_JoystickNumHats(joystick); ++i) {
|
||||
/* Derive the new position */
|
||||
int x = SCREEN_WIDTH/2;
|
||||
int y = SCREEN_HEIGHT/2;
|
||||
const Uint8 hat_pos = SDL_JoystickGetHat(joystick, i);
|
||||
x = SCREEN_WIDTH / 2;
|
||||
y = SCREEN_HEIGHT / 2;
|
||||
|
||||
if (hat_pos & SDL_HAT_UP) {
|
||||
y = 0;
|
||||
} else if (hat_pos & SDL_HAT_DOWN) {
|
||||
y = SCREEN_HEIGHT-8;
|
||||
y = SCREEN_HEIGHT - 8;
|
||||
}
|
||||
|
||||
if (hat_pos & SDL_HAT_LEFT) {
|
||||
x = 0;
|
||||
} else if (hat_pos & SDL_HAT_RIGHT) {
|
||||
x = SCREEN_WIDTH-8;
|
||||
x = SCREEN_WIDTH - 8;
|
||||
}
|
||||
|
||||
DrawRect(screen, x, y, 8, 8);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Delay(16);
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
|
@ -268,8 +279,7 @@ loop(void *arg)
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Scancode scancode;
|
||||
|
||||
|
|
@ -33,8 +32,8 @@ main(int argc, char *argv[])
|
|||
}
|
||||
for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
|
||||
SDL_Log("Scancode #%d, \"%s\"\n", scancode,
|
||||
SDL_GetScancodeName(scancode));
|
||||
SDL_GetScancodeName(scancode));
|
||||
}
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
/* Test program to test dynamic loading with the loadso subsystem.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -19,10 +19,9 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
typedef int (*fntype) (const char *);
|
||||
typedef int (*fntype)(const char *);
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int retval = 0;
|
||||
int hello = 0;
|
||||
|
|
@ -56,23 +55,21 @@ main(int argc, char *argv[])
|
|||
lib = SDL_LoadObject(libname);
|
||||
if (lib == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s\n",
|
||||
libname, SDL_GetError());
|
||||
libname, SDL_GetError());
|
||||
retval = 3;
|
||||
} else {
|
||||
fn = (fntype) SDL_LoadFunction(lib, symname);
|
||||
fn = (fntype)SDL_LoadFunction(lib, symname);
|
||||
if (fn == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n",
|
||||
symname, SDL_GetError());
|
||||
symname, SDL_GetError());
|
||||
retval = 4;
|
||||
} else {
|
||||
SDL_Log("Found %s in %s at %p\n", symname, libname, fn);
|
||||
if (hello) {
|
||||
SDL_Log("Calling function...\n");
|
||||
fflush(stdout);
|
||||
fn(" HELLO, WORLD!\n");
|
||||
SDL_Log("...apparently, we survived. :)\n");
|
||||
SDL_Log("Unloading library...\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
SDL_UnloadObject(lib);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -61,7 +61,7 @@ int main(int argc, char **argv)
|
|||
SDL_Quit();
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -27,7 +27,7 @@ static SDL_atomic_t doterminate;
|
|||
|
||||
/*
|
||||
* SDL_Quit() shouldn't be used with atexit() directly because
|
||||
* calling conventions may differ...
|
||||
* calling conventions may differ...
|
||||
*/
|
||||
static void
|
||||
SDL_Quit_Wrapper(void)
|
||||
|
|
@ -35,28 +35,26 @@ SDL_Quit_Wrapper(void)
|
|||
SDL_Quit();
|
||||
}
|
||||
|
||||
void
|
||||
printid(void)
|
||||
void printid(void)
|
||||
{
|
||||
SDL_Log("Process %lu: exiting\n", SDL_ThreadID());
|
||||
}
|
||||
|
||||
void
|
||||
terminate(int sig)
|
||||
void terminate(int sig)
|
||||
{
|
||||
signal(SIGINT, terminate);
|
||||
(void)signal(SIGINT, terminate);
|
||||
SDL_AtomicSet(&doterminate, 1);
|
||||
}
|
||||
|
||||
void
|
||||
closemutex(int sig)
|
||||
void closemutex(int sig)
|
||||
{
|
||||
SDL_threadID id = SDL_ThreadID();
|
||||
int i;
|
||||
SDL_Log("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id);
|
||||
SDL_AtomicSet(&doterminate, 1);
|
||||
for (i = 0; i < 6; ++i)
|
||||
for (i = 0; i < 6; ++i) {
|
||||
SDL_WaitThread(threads[i], NULL);
|
||||
}
|
||||
SDL_DestroyMutex(mutex);
|
||||
exit(sig);
|
||||
}
|
||||
|
|
@ -64,8 +62,9 @@ closemutex(int sig)
|
|||
int SDLCALL
|
||||
Run(void *data)
|
||||
{
|
||||
if (SDL_ThreadID() == mainthread)
|
||||
signal(SIGTERM, closemutex);
|
||||
if (SDL_ThreadID() == mainthread) {
|
||||
(void)signal(SIGTERM, closemutex);
|
||||
}
|
||||
while (!SDL_AtomicGet(&doterminate)) {
|
||||
SDL_Log("Process %lu ready to work\n", SDL_ThreadID());
|
||||
if (SDL_LockMutex(mutex) < 0) {
|
||||
|
|
@ -84,13 +83,12 @@ Run(void *data)
|
|||
}
|
||||
if (SDL_ThreadID() == mainthread && SDL_AtomicGet(&doterminate)) {
|
||||
SDL_Log("Process %lu: raising SIGTERM\n", SDL_ThreadID());
|
||||
raise(SIGTERM);
|
||||
(void)raise(SIGTERM);
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int maxproc = 6;
|
||||
|
|
@ -103,26 +101,29 @@ main(int argc, char *argv[])
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
atexit(SDL_Quit_Wrapper);
|
||||
(void)atexit(SDL_Quit_Wrapper);
|
||||
|
||||
SDL_AtomicSet(&doterminate, 0);
|
||||
|
||||
if ((mutex = SDL_CreateMutex()) == NULL) {
|
||||
mutex = SDL_CreateMutex();
|
||||
if (mutex == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mainthread = SDL_ThreadID();
|
||||
SDL_Log("Main thread: %lu\n", mainthread);
|
||||
atexit(printid);
|
||||
(void)atexit(printid);
|
||||
for (i = 0; i < maxproc; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Worker%d", i);
|
||||
if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL)
|
||||
(void)SDL_snprintf(name, sizeof(name), "Worker%d", i);
|
||||
threads[i] = SDL_CreateThread(Run, name, NULL);
|
||||
if (threads[i] == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
|
||||
}
|
||||
}
|
||||
signal(SIGINT, terminate);
|
||||
(void)signal(SIGINT, terminate);
|
||||
Run(NULL);
|
||||
|
||||
return (0); /* Never reached */
|
||||
return 0; /* Never reached */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -29,15 +29,12 @@ static int SDLCALL
|
|||
button_messagebox(void *eventNumber)
|
||||
{
|
||||
const SDL_MessageBoxButtonData buttons[] = {
|
||||
{
|
||||
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
|
||||
0,
|
||||
"OK"
|
||||
},{
|
||||
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
|
||||
1,
|
||||
"Cancel"
|
||||
},
|
||||
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT,
|
||||
0,
|
||||
"OK" },
|
||||
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT,
|
||||
1,
|
||||
"Cancel" },
|
||||
};
|
||||
|
||||
SDL_MessageBoxData data = {
|
||||
|
|
@ -46,8 +43,8 @@ button_messagebox(void *eventNumber)
|
|||
"Custom MessageBox",
|
||||
"This is a custom messagebox",
|
||||
2,
|
||||
NULL,/* buttons */
|
||||
NULL /* Default color scheme */
|
||||
NULL, /* buttons */
|
||||
NULL /* Default color scheme */
|
||||
};
|
||||
|
||||
int button = -1;
|
||||
|
|
@ -62,26 +59,26 @@ button_messagebox(void *eventNumber)
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
if (eventNumber) {
|
||||
SDL_Event event;
|
||||
event.type = (intptr_t)eventNumber;
|
||||
event.type = (Uint32)(intptr_t)eventNumber;
|
||||
SDL_PushEvent(&event);
|
||||
return 1;
|
||||
} else {
|
||||
quit(2);
|
||||
}
|
||||
}
|
||||
SDL_Log("Pressed button: %d, %s\n", button, button == -1 ? "[closed]" : button == 1 ? "Cancel" : "OK");
|
||||
SDL_Log("Pressed button: %d, %s\n", button, button == -1 ? "[closed]" : button == 1 ? "Cancel"
|
||||
: "OK");
|
||||
|
||||
if (eventNumber) {
|
||||
SDL_Event event;
|
||||
event.type = (intptr_t)eventNumber;
|
||||
event.type = (Uint32)(intptr_t)eventNumber;
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int success;
|
||||
|
||||
|
|
@ -89,36 +86,36 @@ main(int argc, char *argv[])
|
|||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"Simple MessageBox",
|
||||
"This is a simple error MessageBox",
|
||||
NULL);
|
||||
"Simple MessageBox",
|
||||
"This is a simple error MessageBox",
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"Simple MessageBox",
|
||||
"This is a simple MessageBox with a newline:\r\nHello world!",
|
||||
NULL);
|
||||
"Simple MessageBox",
|
||||
"This is a simple MessageBox with a newline:\r\nHello world!",
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
NULL,
|
||||
"NULL Title",
|
||||
NULL);
|
||||
NULL,
|
||||
"NULL Title",
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"NULL Message",
|
||||
NULL,
|
||||
NULL);
|
||||
"NULL Message",
|
||||
NULL,
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
|
|
@ -126,9 +123,9 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Google says this is Traditional Chinese for "beef with broccoli" */
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"UTF-8 Simple MessageBox",
|
||||
"Unicode text: '牛肉西蘭花' ...",
|
||||
NULL);
|
||||
"UTF-8 Simple MessageBox",
|
||||
"Unicode text: '牛肉西蘭花' ...",
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
|
|
@ -136,9 +133,9 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Google says this is Traditional Chinese for "beef with broccoli" */
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"UTF-8 Simple MessageBox",
|
||||
"Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
|
||||
NULL);
|
||||
"UTF-8 Simple MessageBox",
|
||||
"Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
|
|
@ -146,9 +143,9 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Google says this is Traditional Chinese for "beef with broccoli" */
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"牛肉西蘭花",
|
||||
"Unicode text in the title.",
|
||||
NULL);
|
||||
"牛肉西蘭花",
|
||||
"Unicode text in the title.",
|
||||
NULL);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
|
|
@ -164,16 +161,15 @@ main(int argc, char *argv[])
|
|||
*/
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
int status = 0;
|
||||
SDL_Event event;
|
||||
intptr_t eventNumber = SDL_RegisterEvents(1);
|
||||
SDL_Thread* thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void*)eventNumber);
|
||||
SDL_Thread *thread = SDL_CreateThread(&button_messagebox, "MessageBox", (void *)eventNumber);
|
||||
|
||||
while (SDL_WaitEvent(&event))
|
||||
{
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
if (event.type == eventNumber) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -196,16 +192,15 @@ main(int argc, char *argv[])
|
|||
SDL_RenderPresent(renderer);
|
||||
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"Simple MessageBox",
|
||||
"This is a simple error MessageBox with a parent window. Press a key or close the window after dismissing this messagebox.",
|
||||
window);
|
||||
"Simple MessageBox",
|
||||
"This is a simple error MessageBox with a parent window. Press a key or close the window after dismissing this messagebox.",
|
||||
window);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
while (SDL_WaitEvent(&event))
|
||||
{
|
||||
while (SDL_WaitEvent(&event)) {
|
||||
if (event.type == SDL_QUIT || event.type == SDL_KEYUP) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -213,5 +208,5 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -22,22 +22,26 @@
|
|||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 480
|
||||
#else
|
||||
#define SCREEN_WIDTH 640
|
||||
#define SCREEN_HEIGHT 480
|
||||
#define SCREEN_WIDTH 640
|
||||
#define SCREEN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
static SDL_Window *window;
|
||||
|
||||
typedef struct _Line {
|
||||
struct _Line *next;
|
||||
typedef struct _Object
|
||||
{
|
||||
struct _Object *next;
|
||||
|
||||
int x1, y1, x2, y2;
|
||||
Uint8 r, g, b;
|
||||
} Line;
|
||||
|
||||
static Line *active = NULL;
|
||||
static Line *lines = NULL;
|
||||
SDL_bool isRect;
|
||||
} Object;
|
||||
|
||||
static Object *active = NULL;
|
||||
static Object *objects = NULL;
|
||||
static int buttons = 0;
|
||||
static SDL_bool isRect = SDL_FALSE;
|
||||
|
||||
static SDL_bool wheel_x_active = SDL_FALSE;
|
||||
static SDL_bool wheel_y_active = SDL_FALSE;
|
||||
|
|
@ -46,39 +50,59 @@ static float wheel_y = SCREEN_HEIGHT * 0.5f;
|
|||
|
||||
static SDL_bool done = SDL_FALSE;
|
||||
|
||||
void
|
||||
DrawLine(SDL_Renderer * renderer, Line * line)
|
||||
void DrawObject(SDL_Renderer *renderer, Object *object)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, line->r, line->g, line->b, 255);
|
||||
SDL_RenderDrawLine(renderer, line->x1, line->y1, line->x2, line->y2);
|
||||
SDL_SetRenderDrawColor(renderer, object->r, object->g, object->b, 255);
|
||||
|
||||
if (object->isRect) {
|
||||
SDL_Rect rect;
|
||||
|
||||
if (object->x1 > object->x2) {
|
||||
rect.x = object->x2;
|
||||
rect.w = object->x1 - object->x2;
|
||||
} else {
|
||||
rect.x = object->x1;
|
||||
rect.w = object->x2 - object->x1;
|
||||
}
|
||||
|
||||
if (object->y1 > object->y2) {
|
||||
rect.y = object->y2;
|
||||
rect.h = object->y1 - object->y2;
|
||||
} else {
|
||||
rect.y = object->y1;
|
||||
rect.h = object->y2 - object->y1;
|
||||
}
|
||||
|
||||
/* SDL_RenderDrawRect(renderer, &rect); */
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
} else {
|
||||
SDL_RenderDrawLine(renderer, object->x1, object->y1, object->x2, object->y2);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DrawLines(SDL_Renderer * renderer)
|
||||
void DrawObjects(SDL_Renderer *renderer)
|
||||
{
|
||||
Line *next = lines;
|
||||
Object *next = objects;
|
||||
while (next != NULL) {
|
||||
DrawLine(renderer, next);
|
||||
DrawObject(renderer, next);
|
||||
next = next->next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AppendLine(Line *line)
|
||||
void AppendObject(Object *object)
|
||||
{
|
||||
if (lines) {
|
||||
Line *next = lines;
|
||||
if (objects) {
|
||||
Object *next = objects;
|
||||
while (next->next != NULL) {
|
||||
next = next->next;
|
||||
}
|
||||
next->next = line;
|
||||
next->next = object;
|
||||
} else {
|
||||
lines = line;
|
||||
objects = object;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop(void *arg)
|
||||
void loop(void *arg)
|
||||
{
|
||||
SDL_Renderer *renderer = (SDL_Renderer *)arg;
|
||||
SDL_Event event;
|
||||
|
|
@ -87,65 +111,108 @@ loop(void *arg)
|
|||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
|
||||
event.wheel.preciseX *= -1.0f;
|
||||
event.wheel.preciseY *= -1.0f;
|
||||
event.wheel.x *= -1;
|
||||
event.wheel.y *= -1;
|
||||
}
|
||||
if (event.wheel.preciseX != 0.0f) {
|
||||
wheel_x_active = SDL_TRUE;
|
||||
/* "positive to the right and negative to the left" */
|
||||
wheel_x += event.wheel.preciseX * 10.0f;
|
||||
}
|
||||
if (event.wheel.preciseY != 0.0f) {
|
||||
wheel_y_active = SDL_TRUE;
|
||||
/* "positive away from the user and negative towards the user" */
|
||||
wheel_y -= event.wheel.preciseY * 10.0f;
|
||||
}
|
||||
break;
|
||||
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
|
||||
event.wheel.preciseX *= -1.0f;
|
||||
event.wheel.preciseY *= -1.0f;
|
||||
event.wheel.x *= -1;
|
||||
event.wheel.y *= -1;
|
||||
}
|
||||
if (event.wheel.preciseX != 0.0f) {
|
||||
wheel_x_active = SDL_TRUE;
|
||||
/* "positive to the right and negative to the left" */
|
||||
wheel_x += event.wheel.preciseX * 10.0f;
|
||||
}
|
||||
if (event.wheel.preciseY != 0.0f) {
|
||||
wheel_y_active = SDL_TRUE;
|
||||
/* "positive away from the user and negative towards the user" */
|
||||
wheel_y -= event.wheel.preciseY * 10.0f;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
if (!active)
|
||||
if (active == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
active->x2 = event.motion.x;
|
||||
active->y2 = event.motion.y;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (!active) {
|
||||
if (active == NULL) {
|
||||
active = SDL_calloc(1, sizeof(*active));
|
||||
active->x1 = active->x2 = event.button.x;
|
||||
active->y1 = active->y2 = event.button.y;
|
||||
active->isRect = isRect;
|
||||
}
|
||||
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT: active->r = 255; buttons |= SDL_BUTTON_LMASK; break;
|
||||
case SDL_BUTTON_MIDDLE: active->g = 255; buttons |= SDL_BUTTON_MMASK; break;
|
||||
case SDL_BUTTON_RIGHT: active->b = 255; buttons |= SDL_BUTTON_RMASK; break;
|
||||
case SDL_BUTTON_X1: active->r = 255; active->b = 255; buttons |= SDL_BUTTON_X1MASK; break;
|
||||
case SDL_BUTTON_X2: active->g = 255; active->b = 255; buttons |= SDL_BUTTON_X2MASK; break;
|
||||
case SDL_BUTTON_LEFT:
|
||||
active->r = 255;
|
||||
buttons |= SDL_BUTTON_LMASK;
|
||||
break;
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
active->g = 255;
|
||||
buttons |= SDL_BUTTON_MMASK;
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
active->b = 255;
|
||||
buttons |= SDL_BUTTON_RMASK;
|
||||
break;
|
||||
case SDL_BUTTON_X1:
|
||||
active->r = 255;
|
||||
active->b = 255;
|
||||
buttons |= SDL_BUTTON_X1MASK;
|
||||
break;
|
||||
case SDL_BUTTON_X2:
|
||||
active->g = 255;
|
||||
active->b = 255;
|
||||
buttons |= SDL_BUTTON_X2MASK;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (!active)
|
||||
if (active == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT: buttons &= ~SDL_BUTTON_LMASK; break;
|
||||
case SDL_BUTTON_MIDDLE: buttons &= ~SDL_BUTTON_MMASK; break;
|
||||
case SDL_BUTTON_RIGHT: buttons &= ~SDL_BUTTON_RMASK; break;
|
||||
case SDL_BUTTON_X1: buttons &= ~SDL_BUTTON_X1MASK; break;
|
||||
case SDL_BUTTON_X2: buttons &= ~SDL_BUTTON_X2MASK; break;
|
||||
case SDL_BUTTON_LEFT:
|
||||
buttons &= ~SDL_BUTTON_LMASK;
|
||||
break;
|
||||
case SDL_BUTTON_MIDDLE:
|
||||
buttons &= ~SDL_BUTTON_MMASK;
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
buttons &= ~SDL_BUTTON_RMASK;
|
||||
break;
|
||||
case SDL_BUTTON_X1:
|
||||
buttons &= ~SDL_BUTTON_X1MASK;
|
||||
break;
|
||||
case SDL_BUTTON_X2:
|
||||
buttons &= ~SDL_BUTTON_X2MASK;
|
||||
break;
|
||||
}
|
||||
|
||||
if (buttons == 0) {
|
||||
AppendLine(active);
|
||||
AppendObject(active);
|
||||
active = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_LSHIFT:
|
||||
isRect = (event.key.state == SDL_PRESSED);
|
||||
if (active) {
|
||||
active->isRect = isRect;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
|
|
@ -161,16 +228,17 @@ loop(void *arg)
|
|||
/* Mouse wheel */
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 128, 255);
|
||||
if (wheel_x_active) {
|
||||
SDL_RenderDrawLine(renderer, wheel_x, 0, wheel_x, SCREEN_HEIGHT);
|
||||
SDL_RenderDrawLine(renderer, (int)wheel_x, 0, (int)wheel_x, SCREEN_HEIGHT);
|
||||
}
|
||||
if (wheel_y_active) {
|
||||
SDL_RenderDrawLine(renderer, 0, wheel_y, SCREEN_WIDTH, wheel_y);
|
||||
SDL_RenderDrawLine(renderer, 0, (int)wheel_y, SCREEN_WIDTH, (int)wheel_y);
|
||||
}
|
||||
|
||||
/* Lines from mouse clicks */
|
||||
DrawLines(renderer);
|
||||
if (active)
|
||||
DrawLine(renderer, active);
|
||||
/* Objects from mouse clicks */
|
||||
DrawObjects(renderer);
|
||||
if (active) {
|
||||
DrawObject(renderer, active);
|
||||
}
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
|
|
@ -181,8 +249,7 @@ loop(void *arg)
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -20,8 +20,8 @@
|
|||
#include "testutils.h"
|
||||
|
||||
static SDL_AudioSpec spec;
|
||||
static Uint8 *sound = NULL; /* Pointer to wave data */
|
||||
static Uint32 soundlen = 0; /* Length of wave data */
|
||||
static Uint8 *sound = NULL; /* Pointer to wave data */
|
||||
static Uint32 soundlen = 0; /* Length of wave data */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
|
@ -33,14 +33,15 @@ typedef struct
|
|||
callback_data cbd[64];
|
||||
|
||||
void SDLCALL
|
||||
play_through_once(void *arg, Uint8 * stream, int len)
|
||||
play_through_once(void *arg, Uint8 *stream, int len)
|
||||
{
|
||||
callback_data *cbdata = (callback_data *) arg;
|
||||
callback_data *cbdata = (callback_data *)arg;
|
||||
Uint8 *waveptr = sound + cbdata->soundpos;
|
||||
int waveleft = soundlen - cbdata->soundpos;
|
||||
int cpy = len;
|
||||
if (cpy > waveleft)
|
||||
if (cpy > waveleft) {
|
||||
cpy = waveleft;
|
||||
}
|
||||
|
||||
SDL_memcpy(stream, waveptr, cpy);
|
||||
len -= cpy;
|
||||
|
|
@ -52,8 +53,7 @@ play_through_once(void *arg, Uint8 * stream, int len)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
if (SDL_AtomicGet(&cbd[0].done)) {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
|
@ -71,17 +71,17 @@ test_multi_audio(int devcount)
|
|||
{
|
||||
int keep_going = 1;
|
||||
int i;
|
||||
|
||||
#ifdef __ANDROID__
|
||||
|
||||
#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
|
||||
|
||||
if (devcount > 64) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Too many devices (%d), clamping to 64...\n",
|
||||
devcount);
|
||||
devcount);
|
||||
devcount = 64;
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +90,6 @@ test_multi_audio(int devcount)
|
|||
for (i = 0; i < devcount; i++) {
|
||||
const char *devname = SDL_GetAudioDeviceName(i, 0);
|
||||
SDL_Log("playing on device #%d: ('%s')...", i, devname);
|
||||
fflush(stdout);
|
||||
|
||||
SDL_memset(&cbd[0], '\0', sizeof(callback_data));
|
||||
spec.userdata = &cbd[0];
|
||||
|
|
@ -103,10 +102,11 @@ test_multi_audio(int devcount)
|
|||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!SDL_AtomicGet(&cbd[0].done)) {
|
||||
#ifdef __ANDROID__
|
||||
#ifdef __ANDROID__
|
||||
/* Empty queue, some application events would prevent pause. */
|
||||
while (SDL_PollEvent(&event)){}
|
||||
#endif
|
||||
while (SDL_PollEvent(&event)) {
|
||||
}
|
||||
#endif
|
||||
SDL_Delay(100);
|
||||
}
|
||||
SDL_PauseAudioDevice(cbd[0].dev, 1);
|
||||
|
|
@ -141,10 +141,11 @@ 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
|
||||
while (SDL_PollEvent(&event)) {
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_Delay(100);
|
||||
}
|
||||
|
|
@ -161,9 +162,7 @@ test_multi_audio(int devcount)
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int devcount = 0;
|
||||
|
||||
|
|
@ -173,11 +172,11 @@ main(int argc, char **argv)
|
|||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
|
||||
|
||||
|
||||
devcount = SDL_GetNumAudioDevices(0);
|
||||
if (devcount < 1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
|
||||
|
|
@ -187,7 +186,7 @@ main(int argc, char **argv)
|
|||
/* Load the wave file into memory */
|
||||
if (SDL_LoadWAV(file, &spec, &sound, &soundlen) == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", file,
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
} else {
|
||||
test_multi_audio(devcount);
|
||||
SDL_FreeWAV(sound);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for srand() */
|
||||
#include <time.h> /* for time() */
|
||||
#include <time.h> /* for time() */
|
||||
|
||||
#include "testnative.h"
|
||||
#include "testutils.h"
|
||||
|
|
@ -47,14 +47,13 @@ static void
|
|||
quit(int rc)
|
||||
{
|
||||
SDL_VideoQuit();
|
||||
if (native_window) {
|
||||
if (native_window != NULL && factory != NULL) {
|
||||
factory->DestroyNativeWindow(native_window);
|
||||
}
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
void
|
||||
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
||||
void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
|
||||
{
|
||||
int sprite_w, sprite_h;
|
||||
int i;
|
||||
|
|
@ -92,8 +91,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, done;
|
||||
const char *driver;
|
||||
|
|
@ -109,7 +107,7 @@ main(int argc, char *argv[])
|
|||
|
||||
if (SDL_VideoInit(NULL) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
driver = SDL_GetCurrentVideoDriver();
|
||||
|
|
@ -121,19 +119,19 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (!factory) {
|
||||
if (factory == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find native window code for %s driver\n",
|
||||
driver);
|
||||
driver);
|
||||
quit(2);
|
||||
}
|
||||
SDL_Log("Creating native window for %s driver\n", driver);
|
||||
native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H);
|
||||
if (!native_window) {
|
||||
if (native_window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create native window\n");
|
||||
quit(3);
|
||||
}
|
||||
window = SDL_CreateWindowFrom(native_window);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError());
|
||||
quit(4);
|
||||
}
|
||||
|
|
@ -141,7 +139,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Create the renderer */
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
quit(5);
|
||||
}
|
||||
|
|
@ -151,20 +149,20 @@ main(int argc, char *argv[])
|
|||
SDL_RenderClear(renderer);
|
||||
|
||||
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, NULL, NULL);
|
||||
if (!sprite) {
|
||||
if (sprite == NULL) {
|
||||
quit(6);
|
||||
}
|
||||
|
||||
/* Allocate memory for the sprite info */
|
||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||
SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h);
|
||||
positions = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
|
||||
velocities = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
|
||||
if (!positions || !velocities) {
|
||||
positions = (SDL_Rect *)SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
|
||||
velocities = (SDL_Rect *)SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
|
||||
if (positions == NULL || velocities == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
srand(time(NULL));
|
||||
srand((unsigned int)time(NULL));
|
||||
for (i = 0; i < NUM_SPRITES; ++i) {
|
||||
positions[i].x = rand() % (window_w - sprite_w);
|
||||
positions[i].y = rand() % (window_h - sprite_h);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -22,8 +22,8 @@
|
|||
typedef struct
|
||||
{
|
||||
const char *tag;
|
||||
void *(*CreateNativeWindow) (int w, int h);
|
||||
void (*DestroyNativeWindow) (void *window);
|
||||
void *(*CreateNativeWindow)(int w, int h);
|
||||
void (*DestroyNativeWindow)(void *window);
|
||||
} NativeWindowFactory;
|
||||
|
||||
#ifdef SDL_VIDEO_DRIVER_WINDOWS
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -52,7 +52,7 @@ CreateWindowNative(int w, int h)
|
|||
wc.hInstance = GetModuleHandle(NULL);
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
|
||||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszClassName = "SDL Test";
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ CreateWindowNative(int w, int h)
|
|||
static void
|
||||
DestroyWindowNative(void *window)
|
||||
{
|
||||
DestroyWindow((HWND) window);
|
||||
DestroyWindow((HWND)window);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -38,14 +38,14 @@ CreateWindowX11(int w, int h)
|
|||
XMapRaised(dpy, window);
|
||||
XSync(dpy, False);
|
||||
}
|
||||
return (void *) window;
|
||||
return (void *)window;
|
||||
}
|
||||
|
||||
static void
|
||||
DestroyWindowX11(void *window)
|
||||
{
|
||||
if (dpy) {
|
||||
XDestroyWindow(dpy, (Window) window);
|
||||
XDestroyWindow(dpy, (Window)window);
|
||||
XCloseDisplay(dpy);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -30,10 +30,9 @@ static int done = SDL_FALSE;
|
|||
static int frame_number = 0;
|
||||
static int width = 640;
|
||||
static int height = 480;
|
||||
static int max_frames = 200;
|
||||
static unsigned int max_frames = 200;
|
||||
|
||||
void
|
||||
draw()
|
||||
void draw()
|
||||
{
|
||||
SDL_Rect Rect;
|
||||
|
||||
|
|
@ -51,10 +50,9 @@ draw()
|
|||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
void
|
||||
save_surface_to_bmp()
|
||||
void save_surface_to_bmp()
|
||||
{
|
||||
SDL_Surface* surface;
|
||||
SDL_Surface *surface;
|
||||
Uint32 r_mask, g_mask, b_mask, a_mask;
|
||||
Uint32 pixel_format;
|
||||
char file[128];
|
||||
|
|
@ -66,22 +64,21 @@ save_surface_to_bmp()
|
|||
surface = SDL_CreateRGBSurface(0, width, height, bbp, r_mask, g_mask, b_mask, a_mask);
|
||||
SDL_RenderReadPixels(renderer, NULL, pixel_format, (void*)surface->pixels, surface->pitch);
|
||||
|
||||
SDL_snprintf(file, sizeof(file), "SDL_window%d-%8.8d.bmp",
|
||||
SDL_GetWindowID(window), ++frame_number);
|
||||
SDL_snprintf(file, sizeof(file), "SDL_window%" SDL_PRIs32 "-%8.8d.bmp",
|
||||
SDL_GetWindowID(window), ++frame_number);
|
||||
|
||||
SDL_SaveBMP(surface, file);
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
|
@ -97,10 +94,11 @@ loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifndef __EMSCRIPTEN__
|
||||
Uint32 then, now, frames;
|
||||
#endif
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
|
@ -108,26 +106,25 @@ main(int argc, char *argv[])
|
|||
/* Force the offscreen renderer, if it cannot be created then fail out */
|
||||
if (SDL_VideoInit("offscreen") < 0) {
|
||||
SDL_Log("Couldn't initialize the offscreen video driver: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
/* If OPENGL fails to init it will fallback to using a framebuffer for rendering */
|
||||
/* If OPENGL fails to init it will fallback to using a framebuffer for rendering */
|
||||
window = SDL_CreateWindow("Offscreen Test",
|
||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
width, height, 0);
|
||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
width, height, 0);
|
||||
|
||||
if (!window) {
|
||||
SDL_Log("Couldn't create window: %s\n",
|
||||
SDL_GetError());
|
||||
if (window == NULL) {
|
||||
SDL_Log("Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_Log("Couldn't create renderer: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -135,12 +132,14 @@ main(int argc, char *argv[])
|
|||
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
#endif
|
||||
|
||||
SDL_Log("Rendering %i frames offscreen\n", max_frames);
|
||||
SDL_Log("Rendering %u frames offscreen\n", max_frames);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
|
|
@ -153,8 +152,8 @@ main(int argc, char *argv[])
|
|||
if (frames % (max_frames / 10) == 0) {
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
SDL_Log("Frames remaining: %i rendering at %2.2f frames per second\n", max_frames - frames, fps);
|
||||
double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("Frames remaining: %" SDL_PRIu32 " rendering at %2.2f frames per second\n", max_frames - frames, fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -30,9 +30,10 @@
|
|||
#define MOOSEPIC_W 64
|
||||
#define MOOSEPIC_H 88
|
||||
|
||||
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
|
||||
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
|
||||
#define MOOSEFRAMES_COUNT 10
|
||||
|
||||
/* *INDENT-OFF* */ /* clang-format off */
|
||||
SDL_Color MooseColors[84] = {
|
||||
{49, 49, 49, SDL_ALPHA_OPAQUE}
|
||||
, {66, 24, 0, SDL_ALPHA_OPAQUE}
|
||||
|
|
@ -139,8 +140,9 @@ SDL_Color MooseColors[84] = {
|
|||
, {231, 231, 231, SDL_ALPHA_OPAQUE}
|
||||
, {239, 206, 173, SDL_ALPHA_OPAQUE}
|
||||
};
|
||||
/* *INDENT-ON* */ /* clang-format on */
|
||||
|
||||
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE*2];
|
||||
Uint8 MooseFrame[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE * 2];
|
||||
SDL_Texture *MooseTexture;
|
||||
SDL_Rect displayrect;
|
||||
int window_w;
|
||||
|
|
@ -176,8 +178,7 @@ PrintUsage(char *argv0)
|
|||
SDL_Log("\n");
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
|
|
@ -208,6 +209,7 @@ loop()
|
|||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
SDL_FALLTHROUGH;
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
|
|
@ -234,8 +236,7 @@ loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Uint8 *RawMooseData;
|
||||
SDL_RWops *handle;
|
||||
|
|
@ -260,19 +261,19 @@ main(int argc, char **argv)
|
|||
fps = SDL_atoi(argv[2]);
|
||||
if (fps == 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
|
||||
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
|
||||
quit(10);
|
||||
}
|
||||
if ((fps < 0) || (fps > 1000)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"The -fps option must be in range from 1 to 1000, default is 12.\n");
|
||||
"The -fps option must be in range from 1 to 1000, default is 12.\n");
|
||||
quit(10);
|
||||
}
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
|
||||
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
|
||||
quit(10);
|
||||
}
|
||||
} else if (SDL_strcmp(argv[1], "-nodelay") == 0) {
|
||||
|
|
@ -284,23 +285,22 @@ main(int argc, char **argv)
|
|||
scale = SDL_atoi(argv[2]);
|
||||
if (scale == 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"The -scale option requires an argument [from 1 to 50], default is 5.\n");
|
||||
"The -scale option requires an argument [from 1 to 50], default is 5.\n");
|
||||
quit(10);
|
||||
}
|
||||
if ((scale < 0) || (scale > 50)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"The -scale option must be in range from 1 to 50, default is 5.\n");
|
||||
"The -scale option must be in range from 1 to 50, default is 5.\n");
|
||||
quit(10);
|
||||
}
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
|
||||
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
|
||||
quit(10);
|
||||
}
|
||||
} else if ((SDL_strcmp(argv[1], "-help") == 0)
|
||||
|| (SDL_strcmp(argv[1], "-h") == 0)) {
|
||||
} else if ((SDL_strcmp(argv[1], "-help") == 0) || (SDL_strcmp(argv[1], "-h") == 0)) {
|
||||
PrintUsage(argv[0]);
|
||||
quit(0);
|
||||
} else {
|
||||
|
|
@ -310,7 +310,7 @@ main(int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
|
||||
RawMooseData = (Uint8 *) SDL_malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
|
||||
RawMooseData = (Uint8 *)SDL_malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
|
||||
if (RawMooseData == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
|
||||
quit(1);
|
||||
|
|
@ -320,6 +320,7 @@ main(int argc, char **argv)
|
|||
filename = GetResourceFilename(NULL, "moose.dat");
|
||||
if (filename == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
|
||||
SDL_free(RawMooseData);
|
||||
return -1;
|
||||
}
|
||||
handle = SDL_RWFromFile(filename, "rb");
|
||||
|
|
@ -342,21 +343,21 @@ main(int argc, char **argv)
|
|||
SDL_WINDOWPOS_UNDEFINED,
|
||||
window_w, window_h,
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
|
||||
SDL_free(RawMooseData);
|
||||
quit(4);
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
|
||||
SDL_free(RawMooseData);
|
||||
quit(4);
|
||||
}
|
||||
|
||||
MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
|
||||
if (!MooseTexture) {
|
||||
if (MooseTexture == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
|
||||
SDL_free(RawMooseData);
|
||||
quit(5);
|
||||
|
|
@ -365,7 +366,7 @@ main(int argc, char **argv)
|
|||
/* SDL_SetTextureColorMod(MooseTexture, 0xff, 0x80, 0x80); */
|
||||
|
||||
for (i = 0; i < MOOSEFRAMES_COUNT; i++) {
|
||||
Uint8 MooseFrameRGB[MOOSEFRAME_SIZE*3];
|
||||
Uint8 MooseFrameRGB[MOOSEFRAME_SIZE * 3];
|
||||
Uint8 *rgb;
|
||||
Uint8 *frame;
|
||||
|
||||
|
|
@ -377,9 +378,9 @@ main(int argc, char **argv)
|
|||
rgb[2] = MooseColors[frame[j]].b;
|
||||
rgb += 3;
|
||||
}
|
||||
ConvertRGBtoYUV(SDL_PIXELFORMAT_YV12, MooseFrameRGB, MOOSEPIC_W*3, MooseFrame[i], MOOSEPIC_W, MOOSEPIC_H,
|
||||
SDL_GetYUVConversionModeForResolution(MOOSEPIC_W, MOOSEPIC_H),
|
||||
0, 100);
|
||||
ConvertRGBtoYUV(SDL_PIXELFORMAT_YV12, MooseFrameRGB, MOOSEPIC_W * 3, MooseFrame[i], MOOSEPIC_W, MOOSEPIC_H,
|
||||
SDL_GetYUVConversionModeForResolution(MOOSEPIC_W, MOOSEPIC_H),
|
||||
0, 100);
|
||||
}
|
||||
|
||||
SDL_free(RawMooseData);
|
||||
|
|
@ -406,7 +407,7 @@ main(int argc, char **argv)
|
|||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -45,43 +45,42 @@ SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll)
|
|||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 0);
|
||||
|
||||
int
|
||||
TestTypes(SDL_bool verbose)
|
||||
int TestTypes(SDL_bool verbose)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
if (badsize(sizeof(Uint8), 1)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
|
||||
(unsigned int)sizeof(Uint8));
|
||||
if (verbose) {
|
||||
SDL_Log("sizeof(Uint8) != 1, instead = %u\n", (unsigned int)sizeof(Uint8));
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (badsize(sizeof(Uint16), 2)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint16) != 2, instead = %u\n",
|
||||
(unsigned int)sizeof(Uint16));
|
||||
if (verbose) {
|
||||
SDL_Log("sizeof(Uint16) != 2, instead = %u\n", (unsigned int)sizeof(Uint16));
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (badsize(sizeof(Uint32), 4)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint32) != 4, instead = %u\n",
|
||||
(unsigned int)sizeof(Uint32));
|
||||
if (verbose) {
|
||||
SDL_Log("sizeof(Uint32) != 4, instead = %u\n", (unsigned int)sizeof(Uint32));
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (badsize(sizeof(Uint64), 8)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint64) != 8, instead = %u\n",
|
||||
(unsigned int)sizeof(Uint64));
|
||||
if (verbose) {
|
||||
SDL_Log("sizeof(Uint64) != 8, instead = %u\n", (unsigned int)sizeof(Uint64));
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (verbose && !error)
|
||||
if (verbose && !error) {
|
||||
SDL_Log("All data types are the expected size.\n");
|
||||
}
|
||||
|
||||
return (error ? 1 : 0);
|
||||
return error ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
TestEndian(SDL_bool verbose)
|
||||
int TestEndian(SDL_bool verbose)
|
||||
{
|
||||
int error = 0;
|
||||
Uint16 value = 0x1234;
|
||||
|
|
@ -93,9 +92,10 @@ TestEndian(SDL_bool verbose)
|
|||
Uint32 swapped32 = 0xDEADBEEF;
|
||||
Uint64 value64, swapped64;
|
||||
|
||||
union {
|
||||
double d;
|
||||
Uint32 ui32[2];
|
||||
union
|
||||
{
|
||||
double d;
|
||||
Uint32 ui32[2];
|
||||
} value_double;
|
||||
|
||||
value64 = 0xEFBEADDE;
|
||||
|
|
@ -108,9 +108,9 @@ TestEndian(SDL_bool verbose)
|
|||
|
||||
if (verbose) {
|
||||
SDL_Log("Detected a %s endian machine.\n",
|
||||
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
|
||||
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
|
||||
}
|
||||
if ((*((char *) &value) >> 4) == 0x1) {
|
||||
if ((*((char *)&value) >> 4) == 0x1) {
|
||||
real_byteorder = SDL_BIG_ENDIAN;
|
||||
} else {
|
||||
real_byteorder = SDL_LIL_ENDIAN;
|
||||
|
|
@ -118,13 +118,13 @@ TestEndian(SDL_bool verbose)
|
|||
if (real_byteorder != SDL_BYTEORDER) {
|
||||
if (verbose) {
|
||||
SDL_Log("Actually a %s endian machine!\n",
|
||||
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
|
||||
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (verbose) {
|
||||
SDL_Log("Detected a %s endian float word order machine.\n",
|
||||
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big");
|
||||
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big");
|
||||
}
|
||||
if (value_double.ui32[0] == 0x82c2bd7f && value_double.ui32[1] == 0x400921fb) {
|
||||
real_floatwordorder = SDL_LIL_ENDIAN;
|
||||
|
|
@ -134,13 +134,14 @@ TestEndian(SDL_bool verbose)
|
|||
if (real_floatwordorder != SDL_FLOATWORDORDER) {
|
||||
if (verbose) {
|
||||
SDL_Log("Actually a %s endian float word order machine!\n",
|
||||
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big" : "unknown" );
|
||||
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big"
|
||||
: "unknown");
|
||||
}
|
||||
++error;
|
||||
}
|
||||
if (verbose) {
|
||||
SDL_Log("Value 16 = 0x%X, swapped = 0x%X\n", value16,
|
||||
SDL_Swap16(value16));
|
||||
SDL_Swap16(value16));
|
||||
}
|
||||
if (SDL_Swap16(value16) != swapped16) {
|
||||
if (verbose) {
|
||||
|
|
@ -149,8 +150,9 @@ TestEndian(SDL_bool verbose)
|
|||
++error;
|
||||
}
|
||||
if (verbose) {
|
||||
SDL_Log("Value 32 = 0x%X, swapped = 0x%X\n", value32,
|
||||
SDL_Swap32(value32));
|
||||
SDL_Log("Value 32 = 0x%" SDL_PRIX32 ", swapped = 0x%" SDL_PRIX32 "\n",
|
||||
value32,
|
||||
SDL_Swap32(value32));
|
||||
}
|
||||
if (SDL_Swap32(value32) != swapped32) {
|
||||
if (verbose) {
|
||||
|
|
@ -159,8 +161,8 @@ TestEndian(SDL_bool verbose)
|
|||
++error;
|
||||
}
|
||||
if (verbose) {
|
||||
SDL_Log("Value 64 = 0x%"SDL_PRIX64", swapped = 0x%"SDL_PRIX64"\n", value64,
|
||||
SDL_Swap64(value64));
|
||||
SDL_Log("Value 64 = 0x%" SDL_PRIX64 ", swapped = 0x%" SDL_PRIX64 "\n", value64,
|
||||
SDL_Swap64(value64));
|
||||
}
|
||||
if (SDL_Swap64(value64) != swapped64) {
|
||||
if (verbose) {
|
||||
|
|
@ -168,67 +170,67 @@ TestEndian(SDL_bool verbose)
|
|||
}
|
||||
++error;
|
||||
}
|
||||
return (error ? 1 : 0);
|
||||
return error ? 1 : 0;
|
||||
}
|
||||
|
||||
static int TST_allmul (void *a, void *b, int arg, void *result, void *expected)
|
||||
static int TST_allmul(void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = ((*(long long *)a) * (*(long long *)b));
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_alldiv (void *a, void *b, int arg, void *result, void *expected)
|
||||
static int TST_alldiv(void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = ((*(long long *)a) / (*(long long *)b));
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_allrem (void *a, void *b, int arg, void *result, void *expected)
|
||||
static int TST_allrem(void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = ((*(long long *)a) % (*(long long *)b));
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_ualldiv (void *a, void *b, int arg, void *result, void *expected)
|
||||
static int TST_ualldiv(void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(unsigned long long *)result) = ((*(unsigned long long *)a) / (*(unsigned long long *)b));
|
||||
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_uallrem (void *a, void *b, int arg, void *result, void *expected)
|
||||
static int TST_uallrem(void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(unsigned long long *)result) = ((*(unsigned long long *)a) % (*(unsigned long long *)b));
|
||||
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_allshl (void *a, void *b, int arg, void *result, void *expected)
|
||||
static int TST_allshl(void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = (*(long long *)a) << arg;
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_aullshl (void *a, void *b, int arg, void *result, void *expected)
|
||||
static int TST_aullshl(void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(unsigned long long *)result) = (*(unsigned long long *)a) << arg;
|
||||
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_allshr (void *a, void *b, int arg, void *result, void *expected)
|
||||
static int TST_allshr(void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(long long *)result) = (*(long long *)a) >> arg;
|
||||
return (*(long long *)result) == (*(long long *)expected);
|
||||
}
|
||||
|
||||
static int TST_aullshr (void *a, void *b, int arg, void *result, void *expected)
|
||||
static int TST_aullshr(void *a, void *b, int arg, void *result, void *expected)
|
||||
{
|
||||
(*(unsigned long long *)result) = (*(unsigned long long *)a) >> arg;
|
||||
return (*(unsigned long long *)result) == (*(unsigned long long *)expected);
|
||||
}
|
||||
|
||||
|
||||
typedef int (*LL_Intrinsic)(void *a, void *b, int arg, void *result, void *expected);
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
const char *operation;
|
||||
LL_Intrinsic routine;
|
||||
unsigned long long a, b;
|
||||
|
|
@ -236,133 +238,130 @@ typedef struct {
|
|||
unsigned long long expected_result;
|
||||
} LL_Test;
|
||||
|
||||
static LL_Test LL_Tests[] =
|
||||
{
|
||||
static LL_Test LL_Tests[] = {
|
||||
/* UNDEFINED {"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0x0000000000000000ll}, */
|
||||
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll},
|
||||
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll},
|
||||
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll},
|
||||
{"_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{ "_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll },
|
||||
{ "_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll },
|
||||
{ "_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll },
|
||||
{ "_allshl", &TST_allshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll },
|
||||
|
||||
{"_allshr", &TST_allshr, 0xAAAAAAAA55555555ll, 0ll, 63, 0xFFFFFFFFFFFFFFFFll},
|
||||
{ "_allshr", &TST_allshr, 0xAAAAAAAA55555555ll, 0ll, 63, 0xFFFFFFFFFFFFFFFFll },
|
||||
/* UNDEFINED {"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0xFFFFFFFFFFFFFFFFll}, */
|
||||
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{ "_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFFll },
|
||||
{ "_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFFFFFFFFFFll },
|
||||
{ "_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFFFFFFFFFFll },
|
||||
{ "_allshr", &TST_allshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll },
|
||||
/* UNDEFINED {"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 65, 0x0000000000000000ll}, */
|
||||
{"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 1, 0x2FAFAFAFAFAFAFAFll},
|
||||
{"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 32, 0x000000005F5F5F5Fll},
|
||||
{"_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 33, 0x000000002FAFAFAFll},
|
||||
{ "_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 1, 0x2FAFAFAFAFAFAFAFll },
|
||||
{ "_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 32, 0x000000005F5F5F5Fll },
|
||||
{ "_allshr", &TST_allshr, 0x5F5F5F5F5F5F5F5Fll, 0ll, 33, 0x000000002FAFAFAFll },
|
||||
|
||||
/* UNDEFINED {"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0x0000000000000000ll}, */
|
||||
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll},
|
||||
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll},
|
||||
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll},
|
||||
{"_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{ "_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0xFFFFFFFFFFFFFFFEll },
|
||||
{ "_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0xFFFFFFFF00000000ll },
|
||||
{ "_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0xFFFFFFFE00000000ll },
|
||||
{ "_aullshl", &TST_aullshl, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll },
|
||||
|
||||
/* UNDEFINED {"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 65, 0x0000000000000000ll}, */
|
||||
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0x7FFFFFFFFFFFFFFFll},
|
||||
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0x00000000FFFFFFFFll},
|
||||
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0x000000007FFFFFFFll},
|
||||
{"_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{ "_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 1, 0x7FFFFFFFFFFFFFFFll },
|
||||
{ "_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 32, 0x00000000FFFFFFFFll },
|
||||
{ "_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 33, 0x000000007FFFFFFFll },
|
||||
{ "_aullshr", &TST_aullshr, 0xFFFFFFFFFFFFFFFFll, 0ll, 0, 0xFFFFFFFFFFFFFFFFll },
|
||||
|
||||
{"_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000000ll, 0, 0x0000000000000000ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_allmul", &TST_allmul, 0x0000000000000001ll, 0x000000000FFFFFFFll, 0, 0x000000000FFFFFFFll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFF0ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000000000010ll, 0x000000000FFFFFFFll, 0, 0x00000000FFFFFFF0ll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000100ll, 0, 0x0000000FFFFFFF00ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000FFFFFFF00ll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000010000000ll, 0, 0x00FFFFFFF0000000ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000010000000ll, 0x000000000FFFFFFFll, 0, 0x00FFFFFFF0000000ll},
|
||||
{"_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000080000000ll, 0, 0x07FFFFFF80000000ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000080000000ll, 0x000000000FFFFFFFll, 0, 0x07FFFFFF80000000ll},
|
||||
{"_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFF00000000ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000080000000ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFF00000000ll},
|
||||
{"_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000008ll, 0, 0xFFFFFFFEFFFFFFF0ll},
|
||||
{"_allmul", &TST_allmul, 0x0000000080000008ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll},
|
||||
{"_allmul", &TST_allmul, 0x00000000FFFFFFFFll, 0x00000000FFFFFFFFll, 0, 0xFFFFFFFE00000001ll},
|
||||
{ "_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000000ll, 0, 0x0000000000000000ll },
|
||||
{ "_allmul", &TST_allmul, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll },
|
||||
{ "_allmul", &TST_allmul, 0x0000000000000001ll, 0x000000000FFFFFFFll, 0, 0x000000000FFFFFFFll },
|
||||
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFF0ll },
|
||||
{ "_allmul", &TST_allmul, 0x0000000000000010ll, 0x000000000FFFFFFFll, 0, 0x00000000FFFFFFF0ll },
|
||||
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000000000100ll, 0, 0x0000000FFFFFFF00ll },
|
||||
{ "_allmul", &TST_allmul, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000FFFFFFF00ll },
|
||||
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000010000000ll, 0, 0x00FFFFFFF0000000ll },
|
||||
{ "_allmul", &TST_allmul, 0x0000000010000000ll, 0x000000000FFFFFFFll, 0, 0x00FFFFFFF0000000ll },
|
||||
{ "_allmul", &TST_allmul, 0x000000000FFFFFFFll, 0x0000000080000000ll, 0, 0x07FFFFFF80000000ll },
|
||||
{ "_allmul", &TST_allmul, 0x0000000080000000ll, 0x000000000FFFFFFFll, 0, 0x07FFFFFF80000000ll },
|
||||
{ "_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFF00000000ll },
|
||||
{ "_allmul", &TST_allmul, 0x0000000080000000ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFF00000000ll },
|
||||
{ "_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000008ll, 0, 0xFFFFFFFEFFFFFFF0ll },
|
||||
{ "_allmul", &TST_allmul, 0x0000000080000008ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll },
|
||||
{ "_allmul", &TST_allmul, 0x00000000FFFFFFFFll, 0x00000000FFFFFFFFll, 0, 0xFFFFFFFE00000001ll },
|
||||
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll},
|
||||
{"_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
|
||||
{"_alldiv", &TST_alldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_alldiv", &TST_alldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x0000000000000000ll},
|
||||
{"_alldiv", &TST_alldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000080000008ll},
|
||||
{"_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xC000000080000008ll},
|
||||
{"_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll},
|
||||
{"_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll},
|
||||
{ "_alldiv", &TST_alldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_alldiv", &TST_alldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll },
|
||||
{ "_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll },
|
||||
{ "_alldiv", &TST_alldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0xFFFFFFFFFFFFFFFFll },
|
||||
{ "_alldiv", &TST_alldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll },
|
||||
{ "_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll },
|
||||
{ "_alldiv", &TST_alldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll },
|
||||
{ "_alldiv", &TST_alldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll },
|
||||
{ "_alldiv", &TST_alldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_alldiv", &TST_alldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll },
|
||||
{ "_alldiv", &TST_alldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll },
|
||||
{ "_alldiv", &TST_alldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x0000000000000000ll },
|
||||
{ "_alldiv", &TST_alldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000080000008ll },
|
||||
{ "_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xC000000080000008ll },
|
||||
{ "_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll },
|
||||
{ "_alldiv", &TST_alldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll },
|
||||
|
||||
{"_allrem", &TST_allrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll},
|
||||
{"_allrem", &TST_allrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll},
|
||||
{"_allrem", &TST_allrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFFFFFFFFFEll},
|
||||
{"_allrem", &TST_allrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
|
||||
{"_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll},
|
||||
{"_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll},
|
||||
{ "_allrem", &TST_allrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll },
|
||||
{ "_allrem", &TST_allrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll },
|
||||
{ "_allrem", &TST_allrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0xFFFFFFFFFFFFFFFEll },
|
||||
{ "_allrem", &TST_allrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll },
|
||||
{ "_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll },
|
||||
{ "_allrem", &TST_allrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll },
|
||||
|
||||
{ "_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x00000001FFFFFFFFll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll },
|
||||
{ "_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll },
|
||||
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0xFFFFFFFFFFFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000001ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x00000000FFFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x000000000FFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x00000001FFFFFFFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x0000000000000000ll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000000000007FFFll},
|
||||
{"_ualldiv", &TST_ualldiv, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000001ll},
|
||||
{ "_uallrem", &TST_uallrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll },
|
||||
{ "_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll },
|
||||
{ "_uallrem", &TST_uallrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll },
|
||||
{ "_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x000000007FFFFFFEll },
|
||||
{ "_uallrem", &TST_uallrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x7FFFFFFEFFFFFFF0ll },
|
||||
{ "_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll },
|
||||
{ "_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll },
|
||||
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
|
||||
{"_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000001ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000001ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000001ll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x000000000FFFFFFFll, 0x0000000000000001ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000FFFFFFFFFll, 0x0000000000000010ll, 0, 0x000000000000000Fll},
|
||||
{"_uallrem", &TST_uallrem, 0x0000000000000100ll, 0x000000000FFFFFFFll, 0, 0x0000000000000100ll},
|
||||
{"_uallrem", &TST_uallrem, 0x00FFFFFFF0000000ll, 0x0000000010000000ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0x07FFFFFF80000000ll, 0x0000000080000000ll, 0, 0x0000000000000000ll},
|
||||
{"_uallrem", &TST_uallrem, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000000ll, 0, 0x000000007FFFFFFEll},
|
||||
{"_uallrem", &TST_uallrem, 0xFFFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll},
|
||||
{"_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0xFFFFFFFFFFFFFFFEll, 0, 0x7FFFFFFEFFFFFFF0ll},
|
||||
{"_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x0000FFFFFFFFFFFEll, 0, 0x0000FFFF0000FFEEll},
|
||||
{"_uallrem", &TST_uallrem, 0x7FFFFFFEFFFFFFF0ll, 0x7FFFFFFEFFFFFFF0ll, 0, 0x0000000000000000ll},
|
||||
|
||||
{NULL}
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
int
|
||||
Test64Bit (SDL_bool verbose)
|
||||
int Test64Bit(SDL_bool verbose)
|
||||
{
|
||||
LL_Test *t;
|
||||
int failed = 0;
|
||||
|
|
@ -375,44 +374,46 @@ Test64Bit (SDL_bool verbose)
|
|||
unsigned int *rl = (unsigned int *)&result;
|
||||
|
||||
if (!t->routine(&t->a, &t->b, t->arg, &result, &t->expected_result)) {
|
||||
if (verbose)
|
||||
SDL_Log("%s(0x%08X%08X, 0x%08X%08X, %3d, produced: 0x%08X%08X, expected: 0x%08X%08X\n",
|
||||
t->operation, al[1], al[0], bl[1], bl[0], t->arg, rl[1], rl[0], el[1], el[0]);
|
||||
if (verbose) {
|
||||
SDL_Log("%s(0x%08X%08X, 0x%08X%08X, %3d, produced: 0x%08X%08X, expected: 0x%08X%08X\n", t->operation, al[1], al[0], bl[1], bl[0],
|
||||
t->arg, rl[1], rl[0], el[1], el[0]);
|
||||
}
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
if (verbose && (failed == 0))
|
||||
if (verbose && (failed == 0)) {
|
||||
SDL_Log("All 64bit instrinsic tests passed\n");
|
||||
return (failed ? 1 : 0);
|
||||
}
|
||||
return failed ? 1 : 0;
|
||||
}
|
||||
|
||||
int
|
||||
TestCPUInfo(SDL_bool verbose)
|
||||
int TestCPUInfo(SDL_bool verbose)
|
||||
{
|
||||
if (verbose) {
|
||||
SDL_Log("CPU count: %d\n", SDL_GetCPUCount());
|
||||
SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
|
||||
SDL_Log("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
|
||||
SDL_Log("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
|
||||
SDL_Log("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
|
||||
SDL_Log("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
|
||||
SDL_Log("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
|
||||
SDL_Log("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
|
||||
SDL_Log("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
|
||||
SDL_Log("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
|
||||
SDL_Log("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
|
||||
SDL_Log("AVX %s\n", SDL_HasAVX()? "detected" : "not detected");
|
||||
SDL_Log("AVX2 %s\n", SDL_HasAVX2()? "detected" : "not detected");
|
||||
SDL_Log("AVX-512F %s\n", SDL_HasAVX512F()? "detected" : "not detected");
|
||||
SDL_Log("ARM SIMD %s\n", SDL_HasARMSIMD()? "detected" : "not detected");
|
||||
SDL_Log("NEON %s\n", SDL_HasNEON()? "detected" : "not detected");
|
||||
SDL_Log("RDTSC %s\n", SDL_HasRDTSC() ? "detected" : "not detected");
|
||||
SDL_Log("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
|
||||
SDL_Log("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
|
||||
SDL_Log("3DNow! %s\n", SDL_Has3DNow() ? "detected" : "not detected");
|
||||
SDL_Log("SSE %s\n", SDL_HasSSE() ? "detected" : "not detected");
|
||||
SDL_Log("SSE2 %s\n", SDL_HasSSE2() ? "detected" : "not detected");
|
||||
SDL_Log("SSE3 %s\n", SDL_HasSSE3() ? "detected" : "not detected");
|
||||
SDL_Log("SSE4.1 %s\n", SDL_HasSSE41() ? "detected" : "not detected");
|
||||
SDL_Log("SSE4.2 %s\n", SDL_HasSSE42() ? "detected" : "not detected");
|
||||
SDL_Log("AVX %s\n", SDL_HasAVX() ? "detected" : "not detected");
|
||||
SDL_Log("AVX2 %s\n", SDL_HasAVX2() ? "detected" : "not detected");
|
||||
SDL_Log("AVX-512F %s\n", SDL_HasAVX512F() ? "detected" : "not detected");
|
||||
SDL_Log("ARM SIMD %s\n", SDL_HasARMSIMD() ? "detected" : "not detected");
|
||||
SDL_Log("NEON %s\n", SDL_HasNEON() ? "detected" : "not detected");
|
||||
SDL_Log("LSX %s\n", SDL_HasLSX() ? "detected" : "not detected");
|
||||
SDL_Log("LASX %s\n", SDL_HasLASX() ? "detected" : "not detected");
|
||||
SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
TestAssertions(SDL_bool verbose)
|
||||
int TestAssertions(SDL_bool verbose)
|
||||
{
|
||||
SDL_assert(1);
|
||||
SDL_assert_release(1);
|
||||
|
|
@ -421,7 +422,7 @@ TestAssertions(SDL_bool verbose)
|
|||
SDL_assert_release(0 || 1);
|
||||
SDL_assert_paranoid(0 || 1);
|
||||
|
||||
#if 0 /* enable this to test assertion failures. */
|
||||
#if 0 /* enable this to test assertion failures. */
|
||||
SDL_assert_release(1 == 2);
|
||||
SDL_assert_release(5 < 4);
|
||||
SDL_assert_release(0 && "This is a test");
|
||||
|
|
@ -431,17 +432,16 @@ TestAssertions(SDL_bool verbose)
|
|||
const SDL_AssertData *item = SDL_GetAssertionReport();
|
||||
while (item) {
|
||||
SDL_Log("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
|
||||
item->condition, item->function, item->filename,
|
||||
item->linenum, item->trigger_count,
|
||||
item->always_ignore ? "yes" : "no");
|
||||
item->condition, item->function, item->filename,
|
||||
item->linenum, item->trigger_count,
|
||||
item->always_ignore ? "yes" : "no");
|
||||
item = item->next;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_bool verbose = SDL_TRUE;
|
||||
int status = 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -54,14 +54,11 @@ report_power(void)
|
|||
if (seconds == -1) {
|
||||
SDL_Log("Time left: unknown\n");
|
||||
} else {
|
||||
SDL_Log("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
|
||||
(int) (seconds % 60));
|
||||
SDL_Log("Time left: %d minutes, %d seconds\n", seconds / 60, seconds % 60);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -15,8 +15,8 @@
|
|||
static int SDLCALL
|
||||
num_compare(const void *_a, const void *_b)
|
||||
{
|
||||
const int a = *((const int *) _a);
|
||||
const int b = *((const int *) _b);
|
||||
const int a = *((const int *)_a);
|
||||
const int b = *((const int *)_b);
|
||||
return (a < b) ? -1 : ((a > b) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ test_sort(const char *desc, int *nums, const int arraylen)
|
|||
|
||||
SDL_Log("test: %s arraylen=%d", desc, arraylen);
|
||||
|
||||
SDL_qsort(nums, arraylen, sizeof (nums[0]), num_compare);
|
||||
SDL_qsort(nums, arraylen, sizeof(nums[0]), num_compare);
|
||||
|
||||
prev = nums[0];
|
||||
for (i = 1; i < arraylen; i++) {
|
||||
|
|
@ -41,22 +41,21 @@ test_sort(const char *desc, int *nums, const int arraylen)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
static int nums[1024 * 100];
|
||||
static const int itervals[] = { SDL_arraysize(nums), 12 };
|
||||
int iteration;
|
||||
SDLTest_RandomContext rndctx;
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
if (argc > 1) {
|
||||
int success;
|
||||
Uint64 seed = 0;
|
||||
if (argv[1][0] == '0' && argv[1][1] == 'x')
|
||||
success = SDL_sscanf(argv[1] + 2, "%"SDL_PRIx64, &seed);
|
||||
else
|
||||
success = SDL_sscanf(argv[1], "%"SDL_PRIu64, &seed);
|
||||
if (argv[1][0] == '0' && argv[1][1] == 'x') {
|
||||
success = SDL_sscanf(argv[1] + 2, "%" SDL_PRIx64, &seed);
|
||||
} else {
|
||||
success = SDL_sscanf(argv[1], "%" SDL_PRIu64, &seed);
|
||||
}
|
||||
if (!success) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n");
|
||||
return 1;
|
||||
|
|
@ -66,9 +65,7 @@ main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
SDLTest_RandomInit(&rndctx, (unsigned int)(seed >> 32), (unsigned int)(seed & 0xffffffff));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SDLTest_RandomInitTime(&rndctx);
|
||||
}
|
||||
SDL_Log("Using random seed 0x%08x%08x\n", rndctx.x, rndctx.c);
|
||||
|
|
@ -85,11 +82,11 @@ main(int argc, char *argv[])
|
|||
for (i = 0; i < arraylen; i++) {
|
||||
nums[i] = i;
|
||||
}
|
||||
nums[arraylen-1] = -1;
|
||||
nums[arraylen - 1] = -1;
|
||||
test_sort("already sorted except last element", nums, arraylen);
|
||||
|
||||
for (i = 0; i < arraylen; i++) {
|
||||
nums[i] = (arraylen-1) - i;
|
||||
nums[i] = (arraylen - 1) - i;
|
||||
}
|
||||
test_sort("reverse sorted", nums, arraylen);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -28,40 +28,49 @@ SDL_Rect rect;
|
|||
SDL_Event event;
|
||||
|
||||
static void
|
||||
DrawRects(SDL_Renderer * renderer)
|
||||
DrawRects(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
|
||||
static void
|
||||
loop(){
|
||||
loop()
|
||||
{
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
switch(event.type) {
|
||||
switch (event.type) {
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
rect.x += event.motion.xrel;
|
||||
rect.y += event.motion.yrel;
|
||||
}
|
||||
break;
|
||||
{
|
||||
rect.x += event.motion.xrel;
|
||||
rect.y += event.motion.yrel;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Rect viewport;
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
/* Wrap the cursor rectangle at the screen edges to keep it visible */
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
if (rect.x < viewport.x) rect.x += viewport.w;
|
||||
if (rect.y < viewport.y) rect.y += viewport.h;
|
||||
if (rect.x > viewport.x + viewport.w) rect.x -= viewport.w;
|
||||
if (rect.y > viewport.y + viewport.h) rect.y -= viewport.h;
|
||||
if (rect.x < viewport.x) {
|
||||
rect.x += viewport.w;
|
||||
}
|
||||
if (rect.y < viewport.y) {
|
||||
rect.y += viewport.h;
|
||||
}
|
||||
if (rect.x > viewport.x + viewport.w) {
|
||||
rect.x -= viewport.w;
|
||||
}
|
||||
if (rect.y > viewport.y + viewport.h) {
|
||||
rect.y -= viewport.h;
|
||||
}
|
||||
|
||||
DrawRects(renderer);
|
||||
|
||||
|
|
@ -74,8 +83,7 @@ loop(){
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
/* Enable standard application logging */
|
||||
|
|
@ -83,7 +91,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc; ++i) {
|
||||
|
|
@ -102,9 +110,9 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
if(SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
|
||||
if (SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
|
||||
return 3;
|
||||
};
|
||||
}
|
||||
|
||||
rect.x = DEFAULT_WINDOW_WIDTH / 2;
|
||||
rect.y = DEFAULT_WINDOW_HEIGHT / 2;
|
||||
|
|
@ -117,7 +125,7 @@ main(int argc, char *argv[])
|
|||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
SDLTest_CommonQuit(state);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -24,7 +24,8 @@
|
|||
|
||||
static SDLTest_CommonState *state;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *background;
|
||||
|
|
@ -44,13 +45,12 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
void
|
||||
Draw(DrawState *s)
|
||||
void Draw(DrawState *s)
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_Texture *target;
|
||||
SDL_Point *center=NULL;
|
||||
SDL_Point origin = {0,0};
|
||||
SDL_Point *center = NULL;
|
||||
SDL_Point origin = { 0, 0 };
|
||||
|
||||
SDL_RenderGetViewport(s->renderer, &viewport);
|
||||
|
||||
|
|
@ -98,8 +98,9 @@ void loop()
|
|||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
Draw(&drawstates[i]);
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
|
@ -109,8 +110,7 @@ void loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int frames;
|
||||
|
|
@ -121,7 +121,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -157,12 +157,12 @@ main(int argc, char *argv[])
|
|||
while (!done) {
|
||||
++frames;
|
||||
loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -24,7 +24,8 @@
|
|||
|
||||
static SDLTest_CommonState *state;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *background;
|
||||
|
|
@ -72,7 +73,7 @@ DrawComposite(DrawState *s)
|
|||
SDL_RenderCopy(s->renderer, A, NULL, NULL);
|
||||
SDL_RenderReadPixels(s->renderer, NULL, SDL_PIXELFORMAT_ARGB8888, &P, sizeof(P));
|
||||
|
||||
SDL_Log("Blended pixel: 0x%8.8X\n", P);
|
||||
SDL_Log("Blended pixel: 0x%8.8" SDL_PRIX32 "\n", P);
|
||||
|
||||
SDL_DestroyTexture(A);
|
||||
SDL_DestroyTexture(B);
|
||||
|
|
@ -137,7 +138,7 @@ Draw(DrawState *s)
|
|||
SDL_RenderGetViewport(s->renderer, &viewport);
|
||||
|
||||
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h);
|
||||
if (!target) {
|
||||
if (target == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create render target texture: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
|
@ -172,8 +173,7 @@ Draw(DrawState *s)
|
|||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
|
@ -183,12 +183,17 @@ loop()
|
|||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (test_composite) {
|
||||
if (!DrawComposite(&drawstates[i])) done = 1;
|
||||
if (!DrawComposite(&drawstates[i])) {
|
||||
done = 1;
|
||||
}
|
||||
} else {
|
||||
if (!Draw(&drawstates[i])) done = 1;
|
||||
if (!Draw(&drawstates[i])) {
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
|
@ -198,8 +203,7 @@ loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int frames;
|
||||
|
|
@ -210,7 +214,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
|
|
@ -272,7 +276,7 @@ main(int argc, char *argv[])
|
|||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -12,8 +12,7 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
SDL_AudioCVT cvt;
|
||||
|
|
@ -57,7 +56,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
cvt.len = len;
|
||||
cvt.buf = (Uint8 *) SDL_malloc(len * cvt.len_mult);
|
||||
cvt.buf = (Uint8 *)SDL_malloc((size_t)len * cvt.len_mult);
|
||||
if (cvt.buf == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory.\n");
|
||||
SDL_FreeWAV(data);
|
||||
|
|
@ -88,19 +87,19 @@ main(int argc, char **argv)
|
|||
blockalign = (bitsize / 8) * cvtchans;
|
||||
avgbytes = cvtfreq * blockalign;
|
||||
|
||||
SDL_WriteLE32(io, 0x46464952); /* RIFF */
|
||||
SDL_WriteLE32(io, 0x46464952); /* RIFF */
|
||||
SDL_WriteLE32(io, cvt.len_cvt + 36);
|
||||
SDL_WriteLE32(io, 0x45564157); /* WAVE */
|
||||
SDL_WriteLE32(io, 0x20746D66); /* fmt */
|
||||
SDL_WriteLE32(io, 16); /* chunk size */
|
||||
SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
|
||||
SDL_WriteLE16(io, cvtchans); /* channels */
|
||||
SDL_WriteLE32(io, cvtfreq); /* sample rate */
|
||||
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
|
||||
SDL_WriteLE16(io, blockalign); /* block align */
|
||||
SDL_WriteLE16(io, bitsize); /* significant bits per sample */
|
||||
SDL_WriteLE32(io, 0x61746164); /* data */
|
||||
SDL_WriteLE32(io, cvt.len_cvt); /* size */
|
||||
SDL_WriteLE32(io, 0x45564157); /* WAVE */
|
||||
SDL_WriteLE32(io, 0x20746D66); /* fmt */
|
||||
SDL_WriteLE32(io, 16); /* chunk size */
|
||||
SDL_WriteLE16(io, SDL_AUDIO_ISFLOAT(spec.format) ? 3 : 1); /* uncompressed */
|
||||
SDL_WriteLE16(io, cvtchans); /* channels */
|
||||
SDL_WriteLE32(io, cvtfreq); /* sample rate */
|
||||
SDL_WriteLE32(io, avgbytes); /* average bytes per second */
|
||||
SDL_WriteLE16(io, blockalign); /* block align */
|
||||
SDL_WriteLE16(io, bitsize); /* significant bits per sample */
|
||||
SDL_WriteLE32(io, 0x61746164); /* data */
|
||||
SDL_WriteLE32(io, cvt.len_cvt); /* size */
|
||||
SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
|
||||
|
||||
if (SDL_RWclose(io) == -1) {
|
||||
|
|
@ -109,12 +108,12 @@ main(int argc, char **argv)
|
|||
SDL_FreeWAV(data);
|
||||
SDL_Quit();
|
||||
return 8;
|
||||
} /* if */
|
||||
} /* if */
|
||||
|
||||
SDL_free(cvt.buf);
|
||||
SDL_FreeWAV(data);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
} /* main */
|
||||
} /* main */
|
||||
|
||||
/* end of testresample.c ... */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -31,14 +31,12 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||
|
||||
static SDL_Haptic *haptic;
|
||||
|
||||
|
||||
/**
|
||||
* @brief The entry point of this force feedback demo.
|
||||
* @param[in] argc Number of arguments.
|
||||
* @param[in] argv Array of argc arguments.
|
||||
*/
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char *name;
|
||||
|
|
@ -54,9 +52,9 @@ main(int argc, char **argv)
|
|||
name = argv[1];
|
||||
if ((SDL_strcmp(name, "--help") == 0) || (SDL_strcmp(name, "-h") == 0)) {
|
||||
SDL_Log("USAGE: %s [device]\n"
|
||||
"If device is a two-digit number it'll use it as an index, otherwise\n"
|
||||
"it'll use it as if it were part of the device's name.\n",
|
||||
argv[0]);
|
||||
"If device is a two-digit number it'll use it as an index, otherwise\n"
|
||||
"it'll use it as if it were part of the device's name.\n",
|
||||
argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -79,13 +77,14 @@ main(int argc, char **argv)
|
|||
/* Try to find matching device */
|
||||
else {
|
||||
for (i = 0; i < SDL_NumHaptics(); i++) {
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL)
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= SDL_NumHaptics()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
|
||||
name);
|
||||
name);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +92,7 @@ main(int argc, char **argv)
|
|||
haptic = SDL_HapticOpen(i);
|
||||
if (haptic == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
|
||||
SDL_GetError());
|
||||
SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_Log("Device: %s\n", SDL_HapticName(i));
|
||||
|
|
@ -115,8 +114,8 @@ main(int argc, char **argv)
|
|||
}
|
||||
SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n");
|
||||
if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
|
||||
return 1;
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_Delay(2000);
|
||||
SDL_Log("Stopping rumble.\n");
|
||||
|
|
@ -124,14 +123,15 @@ main(int argc, char **argv)
|
|||
SDL_Delay(2000);
|
||||
SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n");
|
||||
if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
|
||||
return 1;
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
SDL_Delay(2000);
|
||||
|
||||
/* Quit */
|
||||
if (haptic != NULL)
|
||||
if (haptic != NULL) {
|
||||
SDL_HapticClose(haptic);
|
||||
}
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -22,12 +22,13 @@
|
|||
#include "SDL_test_common.h"
|
||||
#include "testutils.h"
|
||||
|
||||
#define WINDOW_WIDTH 640
|
||||
#define WINDOW_HEIGHT 480
|
||||
#define WINDOW_WIDTH 640
|
||||
#define WINDOW_HEIGHT 480
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *background;
|
||||
|
|
@ -47,8 +48,7 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
void
|
||||
Draw(DrawState *s)
|
||||
void Draw(DrawState *s)
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
|
||||
|
|
@ -78,8 +78,7 @@ Draw(DrawState *s)
|
|||
SDL_RenderPresent(s->renderer);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
|
@ -89,8 +88,9 @@ loop()
|
|||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
Draw(&drawstates[i]);
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
|
@ -100,8 +100,7 @@ loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int frames;
|
||||
|
|
@ -112,7 +111,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +153,7 @@ main(int argc, char *argv[])
|
|||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -21,14 +21,15 @@
|
|||
#define NUM_THREADS 10
|
||||
/* This value should be smaller than the maximum count of the */
|
||||
/* semaphore implementation: */
|
||||
#define NUM_OVERHEAD_OPS 10000
|
||||
#define NUM_OVERHEAD_OPS 10000
|
||||
#define NUM_OVERHEAD_OPS_MULT 10
|
||||
|
||||
static SDL_sem *sem;
|
||||
int alive;
|
||||
|
||||
typedef struct Thread_State {
|
||||
SDL_Thread * thread;
|
||||
typedef struct Thread_State
|
||||
{
|
||||
SDL_Thread *thread;
|
||||
int number;
|
||||
SDL_bool flag;
|
||||
int loop_count;
|
||||
|
|
@ -44,39 +45,40 @@ killed(int sig)
|
|||
static int SDLCALL
|
||||
ThreadFuncRealWorld(void *data)
|
||||
{
|
||||
Thread_State *state = (Thread_State *) data;
|
||||
Thread_State *state = (Thread_State *)data;
|
||||
while (alive) {
|
||||
SDL_SemWait(sem);
|
||||
SDL_Log("Thread number %d has got the semaphore (value = %d)!\n",
|
||||
SDL_Log("Thread number %d has got the semaphore (value = %" SDL_PRIu32 ")!\n",
|
||||
state->number, SDL_SemValue(sem));
|
||||
SDL_Delay(200);
|
||||
SDL_SemPost(sem);
|
||||
SDL_Log("Thread number %d has released the semaphore (value = %d)!\n",
|
||||
SDL_Log("Thread number %d has released the semaphore (value = %" SDL_PRIu32 ")!\n",
|
||||
state->number, SDL_SemValue(sem));
|
||||
++state->loop_count;
|
||||
SDL_Delay(1); /* For the scheduler */
|
||||
SDL_Delay(1); /* For the scheduler */
|
||||
}
|
||||
SDL_Log("Thread number %d exiting.\n", state->number);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
TestRealWorld(int init_sem) {
|
||||
Thread_State thread_states[NUM_THREADS] = { {0} };
|
||||
TestRealWorld(int init_sem)
|
||||
{
|
||||
Thread_State thread_states[NUM_THREADS] = { { 0 } };
|
||||
int i;
|
||||
int loop_count;
|
||||
|
||||
sem = SDL_CreateSemaphore(init_sem);
|
||||
|
||||
SDL_Log("Running %d threads, semaphore value = %d\n", NUM_THREADS,
|
||||
init_sem);
|
||||
init_sem);
|
||||
alive = 1;
|
||||
/* Create all the threads */
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
|
||||
(void)SDL_snprintf(name, sizeof(name), "Thread%u", (unsigned int)i);
|
||||
thread_states[i].number = i;
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncRealWorld, name, (void *) &thread_states[i]);
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncRealWorld, name, (void *)&thread_states[i]);
|
||||
}
|
||||
|
||||
/* Wait 10 seconds */
|
||||
|
|
@ -114,11 +116,12 @@ TestWaitTimeout(void)
|
|||
|
||||
/* Accept a little offset in the effective wait */
|
||||
SDL_assert(duration > 1900 && duration < 2050);
|
||||
SDL_Log("Wait took %d milliseconds\n\n", duration);
|
||||
SDL_Log("Wait took %" SDL_PRIu32 " milliseconds\n\n", duration);
|
||||
|
||||
/* Check to make sure the return value indicates timed out */
|
||||
if (retval != SDL_MUTEX_TIMEDOUT)
|
||||
if (retval != SDL_MUTEX_TIMEDOUT) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n\n", retval, SDL_MUTEX_TIMEDOUT);
|
||||
}
|
||||
|
||||
SDL_DestroySemaphore(sem);
|
||||
}
|
||||
|
|
@ -135,7 +138,7 @@ TestOverheadUncontended(void)
|
|||
SDL_Log("Doing %d uncontended Post/Wait operations on semaphore\n", NUM_OVERHEAD_OPS * NUM_OVERHEAD_OPS_MULT);
|
||||
|
||||
start_ticks = SDL_GetTicks();
|
||||
for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++){
|
||||
for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++) {
|
||||
for (j = 0; j < NUM_OVERHEAD_OPS; j++) {
|
||||
SDL_SemPost(sem);
|
||||
}
|
||||
|
|
@ -146,7 +149,7 @@ TestOverheadUncontended(void)
|
|||
end_ticks = SDL_GetTicks();
|
||||
|
||||
duration = end_ticks - start_ticks;
|
||||
SDL_Log("Took %d milliseconds\n\n", duration);
|
||||
SDL_Log("Took %" SDL_PRIu32 " milliseconds\n\n", duration);
|
||||
|
||||
SDL_DestroySemaphore(sem);
|
||||
}
|
||||
|
|
@ -154,17 +157,17 @@ TestOverheadUncontended(void)
|
|||
static int SDLCALL
|
||||
ThreadFuncOverheadContended(void *data)
|
||||
{
|
||||
Thread_State *state = (Thread_State *) data;
|
||||
Thread_State *state = (Thread_State *)data;
|
||||
|
||||
if (state->flag) {
|
||||
while(alive) {
|
||||
while (alive) {
|
||||
if (SDL_SemTryWait(sem) == SDL_MUTEX_TIMEDOUT) {
|
||||
++state->content_count;
|
||||
}
|
||||
++state->loop_count;
|
||||
}
|
||||
} else {
|
||||
while(alive) {
|
||||
while (alive) {
|
||||
/* Timeout needed to allow check on alive flag */
|
||||
if (SDL_SemWaitTimeout(sem, 50) == SDL_MUTEX_TIMEDOUT) {
|
||||
++state->content_count;
|
||||
|
|
@ -181,7 +184,7 @@ TestOverheadContended(SDL_bool try_wait)
|
|||
Uint32 start_ticks;
|
||||
Uint32 end_ticks;
|
||||
Uint32 duration;
|
||||
Thread_State thread_states[NUM_THREADS] = { {0} };
|
||||
Thread_State thread_states[NUM_THREADS] = { { 0 } };
|
||||
char textBuffer[1024];
|
||||
int loop_count;
|
||||
int content_count;
|
||||
|
|
@ -195,9 +198,9 @@ TestOverheadContended(SDL_bool try_wait)
|
|||
/* Create multiple threads to starve the semaphore and cause contention */
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
|
||||
(void)SDL_snprintf(name, sizeof(name), "Thread%u", (unsigned int)i);
|
||||
thread_states[i].flag = try_wait;
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncOverheadContended, name, (void *) &thread_states[i]);
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncOverheadContended, name, (void *)&thread_states[i]);
|
||||
}
|
||||
|
||||
start_ticks = SDL_GetTicks();
|
||||
|
|
@ -206,7 +209,10 @@ TestOverheadContended(SDL_bool try_wait)
|
|||
SDL_SemPost(sem);
|
||||
}
|
||||
/* Make sure threads consumed everything */
|
||||
while (SDL_SemValue(sem)) { }
|
||||
while (SDL_SemValue(sem)) {
|
||||
/* Friendlier with cooperative threading models */
|
||||
SDL_Delay(1);
|
||||
}
|
||||
}
|
||||
end_ticks = SDL_GetTicks();
|
||||
|
||||
|
|
@ -221,28 +227,27 @@ TestOverheadContended(SDL_bool try_wait)
|
|||
SDL_assert_release((loop_count - content_count) == NUM_OVERHEAD_OPS * NUM_OVERHEAD_OPS_MULT);
|
||||
|
||||
duration = end_ticks - start_ticks;
|
||||
SDL_Log("Took %d milliseconds, threads %s %d out of %d times in total (%.2f%%)\n",
|
||||
SDL_Log("Took %" SDL_PRIu32 " milliseconds, threads %s %d out of %d times in total (%.2f%%)\n",
|
||||
duration, try_wait ? "where contended" : "timed out", content_count,
|
||||
loop_count, ((float)content_count * 100) / loop_count);
|
||||
/* Print how many semaphores where consumed per thread */
|
||||
SDL_snprintf(textBuffer, sizeof(textBuffer), "{ ");
|
||||
(void)SDL_snprintf(textBuffer, sizeof(textBuffer), "{ ");
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
if (i > 0) {
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
|
||||
(void)SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
|
||||
}
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", thread_states[i].loop_count - thread_states[i].content_count);
|
||||
(void)SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", thread_states[i].loop_count - thread_states[i].content_count);
|
||||
}
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
|
||||
(void)SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
|
||||
SDL_Log("%s\n", textBuffer);
|
||||
|
||||
SDL_DestroySemaphore(sem);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int init_sem;
|
||||
|
||||
|
|
@ -251,16 +256,16 @@ main(int argc, char **argv)
|
|||
|
||||
if (argc < 2) {
|
||||
SDL_Log("Usage: %s init_value\n", argv[0]);
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
signal(SIGTERM, killed);
|
||||
signal(SIGINT, killed);
|
||||
(void)signal(SIGTERM, killed);
|
||||
(void)signal(SIGINT, killed);
|
||||
|
||||
init_sem = SDL_atoi(argv[1]);
|
||||
if (init_sem > 0) {
|
||||
|
|
@ -276,5 +281,5 @@ main(int argc, char **argv)
|
|||
TestOverheadContended(SDL_TRUE);
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -18,8 +18,7 @@ static const char *GetSensorTypeString(SDL_SensorType type)
|
|||
{
|
||||
static char unknown_type[64];
|
||||
|
||||
switch (type)
|
||||
{
|
||||
switch (type) {
|
||||
case SDL_SENSOR_INVALID:
|
||||
return "SDL_SENSOR_INVALID";
|
||||
case SDL_SENSOR_UNKNOWN:
|
||||
|
|
@ -29,7 +28,7 @@ static const char *GetSensorTypeString(SDL_SensorType type)
|
|||
case SDL_SENSOR_GYRO:
|
||||
return "SDL_SENSOR_GYRO";
|
||||
default:
|
||||
SDL_snprintf(unknown_type, sizeof(unknown_type), "UNKNOWN (%d)", type);
|
||||
(void)SDL_snprintf(unknown_type, sizeof(unknown_type), "UNKNOWN (%d)", type);
|
||||
return unknown_type;
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +36,7 @@ static const char *GetSensorTypeString(SDL_SensorType type)
|
|||
static void HandleSensorEvent(SDL_SensorEvent *event)
|
||||
{
|
||||
SDL_Sensor *sensor = SDL_SensorFromInstanceID(event->which);
|
||||
if (!sensor) {
|
||||
if (sensor == NULL) {
|
||||
SDL_Log("Couldn't get sensor for sensor event\n");
|
||||
return;
|
||||
}
|
||||
|
|
@ -55,8 +54,7 @@ static void HandleSensorEvent(SDL_SensorEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int num_sensors, num_opened;
|
||||
|
|
@ -64,7 +62,7 @@ main(int argc, char **argv)
|
|||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_SENSOR) < 0) {
|
||||
SDL_Log("Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
num_sensors = SDL_NumSensors();
|
||||
|
|
@ -72,16 +70,16 @@ main(int argc, char **argv)
|
|||
|
||||
SDL_Log("There are %d sensors available\n", num_sensors);
|
||||
for (i = 0; i < num_sensors; ++i) {
|
||||
SDL_Log("Sensor %d: %s, type %s, platform type %d\n",
|
||||
SDL_SensorGetDeviceInstanceID(i),
|
||||
SDL_SensorGetDeviceName(i),
|
||||
GetSensorTypeString(SDL_SensorGetDeviceType(i)),
|
||||
SDL_SensorGetDeviceNonPortableType(i));
|
||||
SDL_Log("Sensor %" SDL_PRIs32 ": %s, type %s, platform type %d\n",
|
||||
SDL_SensorGetDeviceInstanceID(i),
|
||||
SDL_SensorGetDeviceName(i),
|
||||
GetSensorTypeString(SDL_SensorGetDeviceType(i)),
|
||||
SDL_SensorGetDeviceNonPortableType(i));
|
||||
|
||||
if (SDL_SensorGetDeviceType(i) != SDL_SENSOR_UNKNOWN) {
|
||||
SDL_Sensor *sensor = SDL_SensorOpen(i);
|
||||
if (sensor == NULL) {
|
||||
SDL_Log("Couldn't open sensor %d: %s\n", SDL_SensorGetDeviceInstanceID(i), SDL_GetError());
|
||||
SDL_Log("Couldn't open sensor %" SDL_PRIs32 ": %s\n", SDL_SensorGetDeviceInstanceID(i), SDL_GetError());
|
||||
} else {
|
||||
++num_opened;
|
||||
}
|
||||
|
|
@ -117,5 +115,5 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -17,18 +17,19 @@
|
|||
|
||||
#include "SDL_opengl.h"
|
||||
|
||||
|
||||
static SDL_bool shaders_supported;
|
||||
static int current_shader = 0;
|
||||
static int current_shader = 0;
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
SHADER_COLOR,
|
||||
SHADER_TEXTURE,
|
||||
SHADER_TEXCOORDS,
|
||||
NUM_SHADERS
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
GLhandleARB program;
|
||||
GLhandleARB vert_shader;
|
||||
GLhandleARB frag_shader;
|
||||
|
|
@ -40,75 +41,72 @@ static ShaderData shaders[NUM_SHADERS] = {
|
|||
|
||||
/* SHADER_COLOR */
|
||||
{ 0, 0, 0,
|
||||
/* vertex shader */
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
" v_color = gl_Color;\n"
|
||||
"}",
|
||||
/* fragment shader */
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = v_color;\n"
|
||||
"}"
|
||||
},
|
||||
/* vertex shader */
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
" v_color = gl_Color;\n"
|
||||
"}",
|
||||
/* fragment shader */
|
||||
"varying vec4 v_color;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = v_color;\n"
|
||||
"}" },
|
||||
|
||||
/* SHADER_TEXTURE */
|
||||
{ 0, 0, 0,
|
||||
/* vertex shader */
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
" v_color = gl_Color;\n"
|
||||
" v_texCoord = vec2(gl_MultiTexCoord0);\n"
|
||||
"}",
|
||||
/* fragment shader */
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"uniform sampler2D tex0;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
|
||||
"}"
|
||||
},
|
||||
/* vertex shader */
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
" v_color = gl_Color;\n"
|
||||
" v_texCoord = vec2(gl_MultiTexCoord0);\n"
|
||||
"}",
|
||||
/* fragment shader */
|
||||
"varying vec4 v_color;\n"
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"uniform sampler2D tex0;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
|
||||
"}" },
|
||||
|
||||
/* SHADER_TEXCOORDS */
|
||||
{ 0, 0, 0,
|
||||
/* vertex shader */
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
" v_texCoord = vec2(gl_MultiTexCoord0);\n"
|
||||
"}",
|
||||
/* fragment shader */
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec2 delta;\n"
|
||||
" float dist;\n"
|
||||
"\n"
|
||||
" delta = vec2(0.5, 0.5) - v_texCoord;\n"
|
||||
" dist = dot(delta, delta);\n"
|
||||
"\n"
|
||||
" color.r = v_texCoord.x;\n"
|
||||
" color.g = v_texCoord.x * v_texCoord.y;\n"
|
||||
" color.b = v_texCoord.y;\n"
|
||||
" color.a = 1.0 - (dist * 4.0);\n"
|
||||
" gl_FragColor = color;\n"
|
||||
"}"
|
||||
},
|
||||
/* vertex shader */
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
|
||||
" v_texCoord = vec2(gl_MultiTexCoord0);\n"
|
||||
"}",
|
||||
/* fragment shader */
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec2 delta;\n"
|
||||
" float dist;\n"
|
||||
"\n"
|
||||
" delta = vec2(0.5, 0.5) - v_texCoord;\n"
|
||||
" dist = dot(delta, delta);\n"
|
||||
"\n"
|
||||
" color.r = v_texCoord.x;\n"
|
||||
" color.g = v_texCoord.x * v_texCoord.y;\n"
|
||||
" color.b = v_texCoord.y;\n"
|
||||
" color.a = 1.0 - (dist * 4.0);\n"
|
||||
" gl_FragColor = color;\n"
|
||||
"}" },
|
||||
};
|
||||
|
||||
static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
|
||||
|
|
@ -136,8 +134,8 @@ static SDL_bool CompileShader(GLhandleARB shader, const char *source)
|
|||
char *info;
|
||||
|
||||
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
||||
info = (char *) SDL_malloc(length + 1);
|
||||
if (!info) {
|
||||
info = (char *)SDL_malloc((size_t)length + 1);
|
||||
if (info == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
|
||||
} else {
|
||||
glGetInfoLogARB(shader, length, NULL, info);
|
||||
|
|
@ -164,8 +162,8 @@ static SDL_bool LinkProgram(ShaderData *data)
|
|||
char *info;
|
||||
|
||||
glGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
||||
info = (char *) SDL_malloc(length + 1);
|
||||
if (!info) {
|
||||
info = (char *)SDL_malloc((size_t)length + 1);
|
||||
if (info == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
|
||||
} else {
|
||||
glGetInfoLogARB(data->program, length, NULL, info);
|
||||
|
|
@ -210,7 +208,7 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
|
|||
glUseProgramObjectARB(data->program);
|
||||
for (i = 0; i < num_tmus_bound; ++i) {
|
||||
char tex_name[5];
|
||||
SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
|
||||
(void)SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
|
||||
location = glGetUniformLocationARB(data->program, tex_name);
|
||||
if (location >= 0) {
|
||||
glUniform1iARB(location, i);
|
||||
|
|
@ -240,18 +238,18 @@ static SDL_bool InitShaders()
|
|||
SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
|
||||
SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
|
||||
SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {
|
||||
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) SDL_GL_GetProcAddress("glAttachObjectARB");
|
||||
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) SDL_GL_GetProcAddress("glCompileShaderARB");
|
||||
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glCreateProgramObjectARB");
|
||||
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) SDL_GL_GetProcAddress("glCreateShaderObjectARB");
|
||||
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) SDL_GL_GetProcAddress("glDeleteObjectARB");
|
||||
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) SDL_GL_GetProcAddress("glGetInfoLogARB");
|
||||
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB");
|
||||
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) SDL_GL_GetProcAddress("glGetUniformLocationARB");
|
||||
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) SDL_GL_GetProcAddress("glLinkProgramARB");
|
||||
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) SDL_GL_GetProcAddress("glShaderSourceARB");
|
||||
glUniform1iARB = (PFNGLUNIFORM1IARBPROC) SDL_GL_GetProcAddress("glUniform1iARB");
|
||||
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) SDL_GL_GetProcAddress("glUseProgramObjectARB");
|
||||
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)SDL_GL_GetProcAddress("glAttachObjectARB");
|
||||
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)SDL_GL_GetProcAddress("glCompileShaderARB");
|
||||
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB");
|
||||
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)SDL_GL_GetProcAddress("glCreateShaderObjectARB");
|
||||
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB");
|
||||
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB");
|
||||
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)SDL_GL_GetProcAddress("glGetObjectParameterivARB");
|
||||
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB");
|
||||
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB");
|
||||
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)SDL_GL_GetProcAddress("glShaderSourceARB");
|
||||
glUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB");
|
||||
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glUseProgramObjectARB");
|
||||
if (glAttachObjectARB &&
|
||||
glCompileShaderARB &&
|
||||
glCreateProgramObjectARB &&
|
||||
|
|
@ -306,7 +304,7 @@ power_of_two(int input)
|
|||
}
|
||||
|
||||
GLuint
|
||||
SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
|
||||
SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
|
||||
{
|
||||
GLuint texture;
|
||||
int w, h;
|
||||
|
|
@ -317,10 +315,10 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
|
|||
/* Use the surface width and height expanded to powers of 2 */
|
||||
w = power_of_two(surface->w);
|
||||
h = power_of_two(surface->h);
|
||||
texcoord[0] = 0.0f; /* Min X */
|
||||
texcoord[1] = 0.0f; /* Min Y */
|
||||
texcoord[2] = (GLfloat) surface->w / w; /* Max X */
|
||||
texcoord[3] = (GLfloat) surface->h / h; /* Max Y */
|
||||
texcoord[0] = 0.0f; /* Min X */
|
||||
texcoord[1] = 0.0f; /* Min Y */
|
||||
texcoord[2] = (GLfloat)surface->w / w; /* Max X */
|
||||
texcoord[3] = (GLfloat)surface->h / h; /* Max Y */
|
||||
|
||||
image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
|
||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
|
||||
|
|
@ -330,7 +328,7 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
|
|||
0xFF000000,
|
||||
0x00FF0000, 0x0000FF00, 0x000000FF
|
||||
#endif
|
||||
);
|
||||
);
|
||||
if (image == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -357,25 +355,25 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
|
|||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
|
||||
SDL_FreeSurface(image); /* No longer needed */
|
||||
SDL_FreeSurface(image); /* No longer needed */
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
/* A general OpenGL initialization function. Sets all of the initial parameters. */
|
||||
void InitGL(int Width, int Height) /* We call this right after our OpenGL window is created. */
|
||||
void InitGL(int Width, int Height) /* We call this right after our OpenGL window is created. */
|
||||
{
|
||||
GLdouble aspect;
|
||||
|
||||
glViewport(0, 0, Width, Height);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); /* This Will Clear The Background Color To Black */
|
||||
glClearDepth(1.0); /* Enables Clearing Of The Depth Buffer */
|
||||
glDepthFunc(GL_LESS); /* The Type Of Depth Test To Do */
|
||||
glEnable(GL_DEPTH_TEST); /* Enables Depth Testing */
|
||||
glShadeModel(GL_SMOOTH); /* Enables Smooth Color Shading */
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); /* This Will Clear The Background Color To Black */
|
||||
glClearDepth(1.0); /* Enables Clearing Of The Depth Buffer */
|
||||
glDepthFunc(GL_LESS); /* The Type Of Depth Test To Do */
|
||||
glEnable(GL_DEPTH_TEST); /* Enables Depth Testing */
|
||||
glShadeModel(GL_SMOOTH); /* Enables Smooth Color Shading */
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity(); /* Reset The Projection Matrix */
|
||||
glLoadIdentity(); /* Reset The Projection Matrix */
|
||||
|
||||
aspect = (GLdouble)Width / Height;
|
||||
glOrtho(-3.0, 3.0, -3.0 / aspect, 3.0 / aspect, 0.0, 1.0);
|
||||
|
|
@ -384,32 +382,33 @@ void InitGL(int Width, int Height) /* We call this right afte
|
|||
}
|
||||
|
||||
/* The main drawing function. */
|
||||
void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat * texcoord)
|
||||
void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat *texcoord)
|
||||
{
|
||||
/* Texture coordinate lookup, to make it simple */
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
MINX,
|
||||
MINY,
|
||||
MAXX,
|
||||
MAXY
|
||||
};
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The Screen And The Depth Buffer */
|
||||
glLoadIdentity(); /* Reset The View */
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The Screen And The Depth Buffer */
|
||||
glLoadIdentity(); /* Reset The View */
|
||||
|
||||
glTranslatef(-1.5f,0.0f,0.0f); /* Move Left 1.5 Units */
|
||||
glTranslatef(-1.5f, 0.0f, 0.0f); /* Move Left 1.5 Units */
|
||||
|
||||
/* draw a triangle (in smooth coloring mode) */
|
||||
glBegin(GL_POLYGON); /* start drawing a polygon */
|
||||
glColor3f(1.0f,0.0f,0.0f); /* Set The Color To Red */
|
||||
glVertex3f( 0.0f, 1.0f, 0.0f); /* Top */
|
||||
glColor3f(0.0f,1.0f,0.0f); /* Set The Color To Green */
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f); /* Bottom Right */
|
||||
glColor3f(0.0f,0.0f,1.0f); /* Set The Color To Blue */
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f); /* Bottom Left */
|
||||
glEnd(); /* we're done with the polygon (smooth color interpolation) */
|
||||
glBegin(GL_POLYGON); /* start drawing a polygon */
|
||||
glColor3f(1.0f, 0.0f, 0.0f); /* Set The Color To Red */
|
||||
glVertex3f(0.0f, 1.0f, 0.0f); /* Top */
|
||||
glColor3f(0.0f, 1.0f, 0.0f); /* Set The Color To Green */
|
||||
glVertex3f(1.0f, -1.0f, 0.0f); /* Bottom Right */
|
||||
glColor3f(0.0f, 0.0f, 1.0f); /* Set The Color To Blue */
|
||||
glVertex3f(-1.0f, -1.0f, 0.0f); /* Bottom Left */
|
||||
glEnd(); /* we're done with the polygon (smooth color interpolation) */
|
||||
|
||||
glTranslatef(3.0f,0.0f,0.0f); /* Move Right 3 Units */
|
||||
glTranslatef(3.0f, 0.0f, 0.0f); /* Move Right 3 Units */
|
||||
|
||||
/* Enable blending */
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
|
|
@ -419,21 +418,21 @@ void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat * texcoord)
|
|||
/* draw a textured square (quadrilateral) */
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glColor3f(1.0f,1.0f,1.0f);
|
||||
glColor3f(1.0f, 1.0f, 1.0f);
|
||||
if (shaders_supported) {
|
||||
glUseProgramObjectARB(shaders[current_shader].program);
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS); /* start drawing a polygon (4 sided) */
|
||||
glBegin(GL_QUADS); /* start drawing a polygon (4 sided) */
|
||||
glTexCoord2f(texcoord[MINX], texcoord[MINY]);
|
||||
glVertex3f(-1.0f, 1.0f, 0.0f); /* Top Left */
|
||||
glVertex3f(-1.0f, 1.0f, 0.0f); /* Top Left */
|
||||
glTexCoord2f(texcoord[MAXX], texcoord[MINY]);
|
||||
glVertex3f( 1.0f, 1.0f, 0.0f); /* Top Right */
|
||||
glVertex3f(1.0f, 1.0f, 0.0f); /* Top Right */
|
||||
glTexCoord2f(texcoord[MAXX], texcoord[MAXY]);
|
||||
glVertex3f( 1.0f,-1.0f, 0.0f); /* Bottom Right */
|
||||
glVertex3f(1.0f, -1.0f, 0.0f); /* Bottom Right */
|
||||
glTexCoord2f(texcoord[MINX], texcoord[MAXY]);
|
||||
glVertex3f(-1.0f,-1.0f, 0.0f); /* Bottom Left */
|
||||
glEnd(); /* done with the polygon */
|
||||
glVertex3f(-1.0f, -1.0f, 0.0f); /* Bottom Left */
|
||||
glEnd(); /* done with the polygon */
|
||||
|
||||
if (shaders_supported) {
|
||||
glUseProgramObjectARB(0);
|
||||
|
|
@ -456,27 +455,27 @@ int main(int argc, char **argv)
|
|||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL for video output */
|
||||
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Create a 640x480 OpenGL screen */
|
||||
window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL );
|
||||
if ( !window ) {
|
||||
window = SDL_CreateWindow("Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if ( !SDL_GL_CreateContext(window)) {
|
||||
if (!SDL_GL_CreateContext(window)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL context: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
surface = SDL_LoadBMP("icon.bmp");
|
||||
if ( ! surface ) {
|
||||
if (surface == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load icon.bmp: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(3);
|
||||
|
|
@ -492,20 +491,21 @@ int main(int argc, char **argv)
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Shaders not supported!\n");
|
||||
}
|
||||
done = 0;
|
||||
while ( ! done ) {
|
||||
while (!done) {
|
||||
DrawGLScene(window, texture, texcoords);
|
||||
|
||||
/* This could go in a separate function */
|
||||
{ SDL_Event event;
|
||||
while ( SDL_PollEvent(&event) ) {
|
||||
if ( event.type == SDL_QUIT ) {
|
||||
{
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
done = 1;
|
||||
}
|
||||
if ( event.type == SDL_KEYDOWN ) {
|
||||
if ( event.key.keysym.sym == SDLK_SPACE ) {
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
current_shader = (current_shader + 1) % NUM_SHADERS;
|
||||
}
|
||||
if ( event.key.keysym.sym == SDLK_ESCAPE ) {
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -519,8 +519,7 @@ int main(int argc, char **argv)
|
|||
|
||||
#else /* HAVE_OPENGL */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -15,38 +15,39 @@
|
|||
#include "SDL.h"
|
||||
#include "SDL_shape.h"
|
||||
|
||||
#define SHAPED_WINDOW_X 150
|
||||
#define SHAPED_WINDOW_Y 150
|
||||
#define SHAPED_WINDOW_X 150
|
||||
#define SHAPED_WINDOW_Y 150
|
||||
#define SHAPED_WINDOW_DIMENSION 640
|
||||
|
||||
typedef struct LoadedPicture {
|
||||
typedef struct LoadedPicture
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
SDL_Texture *texture;
|
||||
SDL_WindowShapeMode mode;
|
||||
const char* name;
|
||||
const char *name;
|
||||
} LoadedPicture;
|
||||
|
||||
void render(SDL_Renderer *renderer,SDL_Texture *texture,SDL_Rect texture_dimensions)
|
||||
void render(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Rect texture_dimensions)
|
||||
{
|
||||
/* Clear render-target to blue. */
|
||||
SDL_SetRenderDrawColor(renderer,0x00,0x00,0xff,0xff);
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xff, 0xff);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
/* Render the texture. */
|
||||
SDL_RenderCopy(renderer,texture,&texture_dimensions,&texture_dimensions);
|
||||
SDL_RenderCopy(renderer, texture, &texture_dimensions, &texture_dimensions);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
int main(int argc,char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Uint8 num_pictures;
|
||||
LoadedPicture* pictures;
|
||||
LoadedPicture *pictures;
|
||||
int i, j;
|
||||
SDL_PixelFormat* format = NULL;
|
||||
SDL_PixelFormat *format = NULL;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Color black = {0,0,0,0xff};
|
||||
SDL_Color black = { 0, 0, 0, 0xff };
|
||||
SDL_Event event;
|
||||
int should_exit = 0;
|
||||
unsigned int current_picture;
|
||||
|
|
@ -58,81 +59,88 @@ int main(int argc,char** argv)
|
|||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
if(argc < 2) {
|
||||
if (argc < 2) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Shape requires at least one bitmap file as argument.");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if(SDL_VideoInit(NULL) == -1) {
|
||||
if (SDL_VideoInit(NULL) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL video.");
|
||||
exit(-2);
|
||||
}
|
||||
|
||||
num_pictures = argc - 1;
|
||||
pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture)*num_pictures);
|
||||
if (!pictures) {
|
||||
pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture) * num_pictures);
|
||||
if (pictures == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate memory.");
|
||||
exit(1);
|
||||
}
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
pictures[i].surface = NULL;
|
||||
for(i=0;i<num_pictures;i++) {
|
||||
pictures[i].surface = SDL_LoadBMP(argv[i+1]);
|
||||
pictures[i].name = argv[i+1];
|
||||
if(pictures[i].surface == NULL) {
|
||||
for(j=0;j<num_pictures;j++)
|
||||
}
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
pictures[i].surface = SDL_LoadBMP(argv[i + 1]);
|
||||
pictures[i].name = argv[i + 1];
|
||||
if (pictures[i].surface == NULL) {
|
||||
for (j = 0; j < num_pictures; j++) {
|
||||
SDL_FreeSurface(pictures[j].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
SDL_VideoQuit();
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file: %s", argv[i+1]);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file: %s", argv[i + 1]);
|
||||
exit(-3);
|
||||
}
|
||||
|
||||
format = pictures[i].surface->format;
|
||||
if(SDL_ISPIXELFORMAT_ALPHA(format->format)) {
|
||||
if (SDL_ISPIXELFORMAT_ALPHA(format->format)) {
|
||||
pictures[i].mode.mode = ShapeModeBinarizeAlpha;
|
||||
pictures[i].mode.parameters.binarizationCutoff = 255;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pictures[i].mode.mode = ShapeModeColorKey;
|
||||
pictures[i].mode.parameters.colorKey = black;
|
||||
}
|
||||
}
|
||||
|
||||
window = SDL_CreateShapedWindow("SDL_Shape test",
|
||||
SHAPED_WINDOW_X, SHAPED_WINDOW_Y,
|
||||
SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,
|
||||
0);
|
||||
SHAPED_WINDOW_X, SHAPED_WINDOW_Y,
|
||||
SHAPED_WINDOW_DIMENSION, SHAPED_WINDOW_DIMENSION,
|
||||
0);
|
||||
SDL_SetWindowPosition(window, SHAPED_WINDOW_X, SHAPED_WINDOW_Y);
|
||||
if(window == NULL) {
|
||||
for(i=0;i<num_pictures;i++)
|
||||
if (window == NULL) {
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_FreeSurface(pictures[i].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
SDL_VideoQuit();
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create shaped window for SDL_Shape.");
|
||||
exit(-4);
|
||||
}
|
||||
renderer = SDL_CreateRenderer(window,-1,0);
|
||||
if (!renderer) {
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (renderer == NULL) {
|
||||
SDL_DestroyWindow(window);
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_FreeSurface(pictures[i].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
SDL_VideoQuit();
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create rendering context for SDL_Shape window.");
|
||||
exit(-5);
|
||||
}
|
||||
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
pictures[i].texture = NULL;
|
||||
for(i=0;i<num_pictures;i++) {
|
||||
pictures[i].texture = SDL_CreateTextureFromSurface(renderer,pictures[i].surface);
|
||||
if(pictures[i].texture == NULL) {
|
||||
for(i=0;i<num_pictures;i++)
|
||||
if(pictures[i].texture != NULL)
|
||||
}
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
pictures[i].texture = SDL_CreateTextureFromSurface(renderer, pictures[i].surface);
|
||||
if (pictures[i].texture == NULL) {
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
if (pictures[i].texture != NULL) {
|
||||
SDL_DestroyTexture(pictures[i].texture);
|
||||
for(i=0;i<num_pictures;i++)
|
||||
}
|
||||
}
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_FreeSurface(pictures[i].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
|
|
@ -150,46 +158,49 @@ int main(int argc,char** argv)
|
|||
texture_dimensions.x = 0;
|
||||
texture_dimensions.y = 0;
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
|
||||
SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
|
||||
SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
|
||||
SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
|
||||
while(should_exit == 0) {
|
||||
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &texture_dimensions.w, &texture_dimensions.h);
|
||||
SDL_SetWindowSize(window, texture_dimensions.w, texture_dimensions.h);
|
||||
SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
|
||||
while (should_exit == 0) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if(event.type == SDL_KEYDOWN) {
|
||||
if (event.type == SDL_KEYDOWN) {
|
||||
button_down = 1;
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
should_exit = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(button_down && event.type == SDL_KEYUP) {
|
||||
if (button_down && event.type == SDL_KEYUP) {
|
||||
button_down = 0;
|
||||
current_picture += 1;
|
||||
if(current_picture >= num_pictures)
|
||||
if (current_picture >= num_pictures) {
|
||||
current_picture = 0;
|
||||
}
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Changing to shaped bmp: %s", pictures[current_picture].name);
|
||||
SDL_QueryTexture(pictures[current_picture].texture,(Uint32 *)&pixelFormat,(int *)&access,&texture_dimensions.w,&texture_dimensions.h);
|
||||
SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h);
|
||||
SDL_SetWindowShape(window,pictures[current_picture].surface,&pictures[current_picture].mode);
|
||||
SDL_QueryTexture(pictures[current_picture].texture, &pixelFormat, &access, &texture_dimensions.w, &texture_dimensions.h);
|
||||
SDL_SetWindowSize(window, texture_dimensions.w, texture_dimensions.h);
|
||||
SDL_SetWindowShape(window, pictures[current_picture].surface, &pictures[current_picture].mode);
|
||||
}
|
||||
if (event.type == SDL_QUIT) {
|
||||
should_exit = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
render(renderer,pictures[current_picture].texture,texture_dimensions);
|
||||
render(renderer, pictures[current_picture].texture, texture_dimensions);
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
/* Free the textures. */
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_DestroyTexture(pictures[i].texture);
|
||||
}
|
||||
SDL_DestroyRenderer(renderer);
|
||||
/* Destroy the window. */
|
||||
SDL_DestroyWindow(window);
|
||||
/* Free the original surfaces backing the textures. */
|
||||
for(i=0;i<num_pictures;i++)
|
||||
for (i = 0; i < num_pictures; i++) {
|
||||
SDL_FreeSurface(pictures[i].surface);
|
||||
}
|
||||
SDL_free(pictures);
|
||||
/* Call SDL_VideoQuit() before quitting. */
|
||||
SDL_VideoQuit();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -23,8 +23,8 @@
|
|||
#include "SDL_test_common.h"
|
||||
#include "testutils.h"
|
||||
|
||||
#define NUM_SPRITES 100
|
||||
#define MAX_SPEED 1
|
||||
#define NUM_SPRITES 100
|
||||
#define MAX_SPEED 1
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static int num_sprites;
|
||||
|
|
@ -56,11 +56,15 @@ quit(int rc)
|
|||
SDL_free(positions);
|
||||
SDL_free(velocities);
|
||||
SDLTest_CommonQuit(state);
|
||||
exit(rc);
|
||||
/* If rc is 0, just let main return normally rather than calling exit.
|
||||
* This allows testing of platforms where SDL_main is required and does meaningful cleanup.
|
||||
*/
|
||||
if (rc != 0) {
|
||||
exit(rc);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
LoadSprite(const char *file)
|
||||
int LoadSprite(const char *file)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -68,21 +72,20 @@ LoadSprite(const char *file)
|
|||
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
|
||||
sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
|
||||
if (!sprites[i]) {
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
|
||||
SDL_DestroyTexture(sprites[i]);
|
||||
return (-1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* We're ready to roll. :) */
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
||||
void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
|
||||
{
|
||||
int i;
|
||||
SDL_Rect viewport, temp;
|
||||
|
|
@ -102,8 +105,8 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
current_color = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
|
||||
(Uint8) current_color);
|
||||
SDL_SetTextureColorMod(sprite, 255, (Uint8)current_color,
|
||||
(Uint8)current_color);
|
||||
}
|
||||
if (cycle_alpha) {
|
||||
current_alpha += cycle_direction;
|
||||
|
|
@ -115,7 +118,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
current_alpha = 255;
|
||||
cycle_direction = -cycle_direction;
|
||||
}
|
||||
SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
|
||||
SDL_SetTextureAlphaMod(sprite, (Uint8)current_alpha);
|
||||
}
|
||||
|
||||
/* Draw a gray background */
|
||||
|
|
@ -125,16 +128,16 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
/* Test points */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
|
||||
SDL_RenderDrawPoint(renderer, 0, 0);
|
||||
SDL_RenderDrawPoint(renderer, viewport.w-1, 0);
|
||||
SDL_RenderDrawPoint(renderer, 0, viewport.h-1);
|
||||
SDL_RenderDrawPoint(renderer, viewport.w-1, viewport.h-1);
|
||||
SDL_RenderDrawPoint(renderer, viewport.w - 1, 0);
|
||||
SDL_RenderDrawPoint(renderer, 0, viewport.h - 1);
|
||||
SDL_RenderDrawPoint(renderer, viewport.w - 1, viewport.h - 1);
|
||||
|
||||
/* Test horizontal and vertical lines */
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
|
||||
SDL_RenderDrawLine(renderer, 1, 0, viewport.w-2, 0);
|
||||
SDL_RenderDrawLine(renderer, 1, viewport.h-1, viewport.w-2, viewport.h-1);
|
||||
SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
|
||||
SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);
|
||||
SDL_RenderDrawLine(renderer, 1, 0, viewport.w - 2, 0);
|
||||
SDL_RenderDrawLine(renderer, 1, viewport.h - 1, viewport.w - 2, viewport.h - 1);
|
||||
SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h - 2);
|
||||
SDL_RenderDrawLine(renderer, viewport.w - 1, 1, viewport.w - 1, viewport.h - 2);
|
||||
|
||||
/* Test fill and copy */
|
||||
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
|
|
@ -175,20 +178,20 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
SDL_RenderGeometry(renderer, NULL, verts, 3, NULL, 0);
|
||||
}
|
||||
SDL_RenderCopy(renderer, sprite, NULL, &temp);
|
||||
temp.x = viewport.w-sprite_w-1;
|
||||
temp.x = viewport.w - sprite_w - 1;
|
||||
temp.y = 1;
|
||||
temp.w = sprite_w;
|
||||
temp.h = sprite_h;
|
||||
SDL_RenderFillRect(renderer, &temp);
|
||||
SDL_RenderCopy(renderer, sprite, NULL, &temp);
|
||||
temp.x = 1;
|
||||
temp.y = viewport.h-sprite_h-1;
|
||||
temp.y = viewport.h - sprite_h - 1;
|
||||
temp.w = sprite_w;
|
||||
temp.h = sprite_h;
|
||||
SDL_RenderFillRect(renderer, &temp);
|
||||
SDL_RenderCopy(renderer, sprite, NULL, &temp);
|
||||
temp.x = viewport.w-sprite_w-1;
|
||||
temp.y = viewport.h-sprite_h-1;
|
||||
temp.x = viewport.w - sprite_w - 1;
|
||||
temp.y = viewport.h - sprite_h - 1;
|
||||
temp.w = sprite_w;
|
||||
temp.h = sprite_h;
|
||||
SDL_RenderFillRect(renderer, &temp);
|
||||
|
|
@ -197,9 +200,9 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
/* Test diagonal lines */
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
|
||||
SDL_RenderDrawLine(renderer, sprite_w, sprite_h,
|
||||
viewport.w-sprite_w-2, viewport.h-sprite_h-2);
|
||||
SDL_RenderDrawLine(renderer, viewport.w-sprite_w-2, sprite_h,
|
||||
sprite_w, viewport.h-sprite_h-2);
|
||||
viewport.w - sprite_w - 2, viewport.h - sprite_h - 2);
|
||||
SDL_RenderDrawLine(renderer, viewport.w - sprite_w - 2, sprite_h,
|
||||
sprite_w, viewport.h - sprite_h - 2);
|
||||
|
||||
/* Conditionally move the sprites, bounce at the wall */
|
||||
if (iterations == -1 || iterations > 0) {
|
||||
|
|
@ -216,7 +219,6 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
velocity->y = -velocity->y;
|
||||
position->y += velocity->y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Countdown sprite-move iterations and disable color changes at iteration end - used for visual tests. */
|
||||
|
|
@ -246,7 +248,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
*
|
||||
* Draw sprite2 as triangles that can be recombined as rect by software renderer
|
||||
*/
|
||||
SDL_Vertex *verts = (SDL_Vertex *) SDL_malloc(num_sprites * sizeof (SDL_Vertex) * 6);
|
||||
SDL_Vertex *verts = (SDL_Vertex *)SDL_malloc(num_sprites * sizeof(SDL_Vertex) * 6);
|
||||
SDL_Vertex *verts2 = verts;
|
||||
if (verts) {
|
||||
SDL_Color color;
|
||||
|
|
@ -314,9 +316,9 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
* Draw sprite2 as triangles that can *not* be recombined as rect by software renderer
|
||||
* Use an 'indices' array
|
||||
*/
|
||||
SDL_Vertex *verts = (SDL_Vertex *) SDL_malloc(num_sprites * sizeof (SDL_Vertex) * 5);
|
||||
SDL_Vertex *verts = (SDL_Vertex *)SDL_malloc(num_sprites * sizeof(SDL_Vertex) * 5);
|
||||
SDL_Vertex *verts2 = verts;
|
||||
int *indices = (int *) SDL_malloc(num_sprites * sizeof (int) * 4 * 3);
|
||||
int *indices = (int *)SDL_malloc(num_sprites * sizeof(int) * 4 * 3);
|
||||
int *indices2 = indices;
|
||||
if (verts && indices) {
|
||||
int pos = 0;
|
||||
|
|
@ -390,8 +392,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
|||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
Uint32 now;
|
||||
int i;
|
||||
|
|
@ -402,8 +403,9 @@ loop()
|
|||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->windows[i] == NULL)
|
||||
if (state->windows[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
MoveSprites(state->renderers[i], sprites[i]);
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
|
|
@ -417,16 +419,14 @@ loop()
|
|||
if (SDL_TICKS_PASSED(now, next_fps_check)) {
|
||||
/* Print out some timing information */
|
||||
const Uint32 then = next_fps_check - fps_check_delay;
|
||||
const double fps = ((double) frames * 1000) / (now - then);
|
||||
const double fps = ((double)frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
next_fps_check = now + fps_check_delay;
|
||||
frames = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
Uint64 seed;
|
||||
|
|
@ -437,7 +437,7 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -469,7 +469,9 @@ main(int argc, char *argv[])
|
|||
} else if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
iterations = SDL_atoi(argv[i + 1]);
|
||||
if (iterations < -1) iterations = -1;
|
||||
if (iterations < -1) {
|
||||
iterations = -1;
|
||||
}
|
||||
consumed = 2;
|
||||
}
|
||||
} else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
|
||||
|
|
@ -509,7 +511,8 @@ main(int argc, char *argv[])
|
|||
"[--use-rendergeometry mode1|mode2]",
|
||||
"[num_sprites]",
|
||||
"[icon.bmp]",
|
||||
NULL };
|
||||
NULL
|
||||
};
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
quit(1);
|
||||
}
|
||||
|
|
@ -521,8 +524,8 @@ main(int argc, char *argv[])
|
|||
|
||||
/* Create the windows, initialize the renderers, and load the textures */
|
||||
sprites =
|
||||
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
|
||||
if (!sprites) {
|
||||
(SDL_Texture **)SDL_malloc(state->num_windows * sizeof(*sprites));
|
||||
if (sprites == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
|
@ -536,9 +539,9 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Allocate memory for the sprite info */
|
||||
positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
|
||||
velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
|
||||
if (!positions || !velocities) {
|
||||
positions = (SDL_Rect *)SDL_malloc(num_sprites * sizeof(SDL_Rect));
|
||||
velocities = (SDL_Rect *)SDL_malloc(num_sprites * sizeof(SDL_Rect));
|
||||
if (positions == NULL || velocities == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -22,10 +22,10 @@
|
|||
#include "SDL.h"
|
||||
#include "testutils.h"
|
||||
|
||||
#define WINDOW_WIDTH 640
|
||||
#define WINDOW_HEIGHT 480
|
||||
#define NUM_SPRITES 100
|
||||
#define MAX_SPEED 1
|
||||
#define WINDOW_WIDTH 640
|
||||
#define WINDOW_HEIGHT 480
|
||||
#define NUM_SPRITES 100
|
||||
#define MAX_SPEED 1
|
||||
|
||||
static SDL_Texture *sprite;
|
||||
static SDL_Rect positions[NUM_SPRITES];
|
||||
|
|
@ -43,8 +43,7 @@ quit(int rc)
|
|||
exit(rc);
|
||||
}
|
||||
|
||||
void
|
||||
MoveSprites()
|
||||
void MoveSprites()
|
||||
{
|
||||
int i;
|
||||
int window_w = WINDOW_WIDTH;
|
||||
|
|
@ -96,13 +95,11 @@ void loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
int i;
|
||||
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
|
|
@ -117,7 +114,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Initialize the sprite positions */
|
||||
srand(time(NULL));
|
||||
srand((unsigned int)time(NULL));
|
||||
for (i = 0; i < NUM_SPRITES; ++i) {
|
||||
positions[i].x = rand() % (WINDOW_WIDTH - sprite_w);
|
||||
positions[i].y = rand() % (WINDOW_HEIGHT - sprite_h);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -28,9 +28,10 @@
|
|||
#define MOOSEPIC_W 64
|
||||
#define MOOSEPIC_H 88
|
||||
|
||||
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
|
||||
#define MOOSEFRAME_SIZE (MOOSEPIC_W * MOOSEPIC_H)
|
||||
#define MOOSEFRAMES_COUNT 10
|
||||
|
||||
/* *INDENT-OFF* */ /* clang-format off */
|
||||
SDL_Color MooseColors[84] = {
|
||||
{49, 49, 49, 255}, {66, 24, 0, 255}, {66, 33, 0, 255}, {66, 66, 66, 255},
|
||||
{66, 115, 49, 255}, {74, 33, 0, 255}, {74, 41, 16, 255}, {82, 33, 8, 255},
|
||||
|
|
@ -54,6 +55,7 @@ SDL_Color MooseColors[84] = {
|
|||
{214, 173, 140, 255}, {222, 181, 148, 255}, {222, 189, 132, 255}, {222, 189, 156, 255},
|
||||
{222, 222, 222, 255}, {231, 198, 165, 255}, {231, 231, 231, 255}, {239, 206, 173, 255}
|
||||
};
|
||||
/* *INDENT-ON* */ /* clang-format on */
|
||||
|
||||
Uint8 MooseFrames[MOOSEFRAMES_COUNT][MOOSEFRAME_SIZE];
|
||||
|
||||
|
|
@ -83,17 +85,16 @@ void UpdateTexture(SDL_Texture *texture)
|
|||
}
|
||||
src = MooseFrames[frame];
|
||||
for (row = 0; row < MOOSEPIC_H; ++row) {
|
||||
dst = (Uint32*)((Uint8*)pixels + row * pitch);
|
||||
dst = (Uint32 *)((Uint8 *)pixels + row * pitch);
|
||||
for (col = 0; col < MOOSEPIC_W; ++col) {
|
||||
color = &MooseColors[*src++];
|
||||
*dst++ = (0xFF000000|(color->r<<16)|(color->g<<8)|color->b);
|
||||
*dst++ = (0xFF000000 | (color->r << 16) | (color->g << 8) | color->b);
|
||||
}
|
||||
}
|
||||
SDL_UnlockTexture(texture);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
|
|
@ -124,8 +125,7 @@ loop()
|
|||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_RWops *handle;
|
||||
|
|
@ -154,26 +154,25 @@ main(int argc, char **argv)
|
|||
SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
|
||||
SDL_RWclose(handle);
|
||||
|
||||
|
||||
/* Create the window and renderer */
|
||||
window = SDL_CreateWindow("Happy Moose",
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
MOOSEPIC_W*4, MOOSEPIC_H*4,
|
||||
MOOSEPIC_W * 4, MOOSEPIC_H * 4,
|
||||
SDL_WINDOW_RESIZABLE);
|
||||
if (!window) {
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
|
||||
quit(3);
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (!renderer) {
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
|
||||
quit(4);
|
||||
}
|
||||
|
||||
MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
|
||||
if (!MooseTexture) {
|
||||
if (MooseTexture == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
|
||||
quit(5);
|
||||
}
|
||||
|
|
@ -186,7 +185,7 @@ main(int argc, char **argv)
|
|||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -18,16 +18,16 @@
|
|||
static int total_channels;
|
||||
static int active_channel;
|
||||
|
||||
#define SAMPLE_RATE_HZ 48000
|
||||
#define QUICK_TEST_TIME_MSEC 100
|
||||
#define SAMPLE_RATE_HZ 48000
|
||||
#define QUICK_TEST_TIME_MSEC 100
|
||||
#define CHANNEL_TEST_TIME_SEC 5
|
||||
#define MAX_AMPLITUDE SDL_MAX_SINT16
|
||||
#define MAX_AMPLITUDE SDL_MAX_SINT16
|
||||
|
||||
#define SINE_FREQ_HZ 500
|
||||
#define SINE_FREQ_HZ 500
|
||||
#define LFE_SINE_FREQ_HZ 50
|
||||
|
||||
/* The channel layout is defined in SDL_audio.h */
|
||||
const char*
|
||||
const char *
|
||||
get_channel_name(int channel_index, int channel_count)
|
||||
{
|
||||
switch (channel_index) {
|
||||
|
|
@ -38,6 +38,7 @@ get_channel_name(int channel_index, int channel_count)
|
|||
case 2:
|
||||
switch (channel_count) {
|
||||
case 3:
|
||||
case 5:
|
||||
return "Low Frequency Effects";
|
||||
case 4:
|
||||
return "Back Left";
|
||||
|
|
@ -57,27 +58,32 @@ get_channel_name(int channel_index, int channel_count)
|
|||
switch (channel_count) {
|
||||
case 5:
|
||||
return "Back Right";
|
||||
case 6:
|
||||
return "Side Left";
|
||||
case 7:
|
||||
return "Back Center";
|
||||
case 6:
|
||||
case 8:
|
||||
return "Back Left";
|
||||
}
|
||||
SDL_assert(0);
|
||||
case 5:
|
||||
switch (channel_count) {
|
||||
case 7:
|
||||
return "Back Left";
|
||||
case 6:
|
||||
return "Side Right";
|
||||
case 7:
|
||||
return "Side Left";
|
||||
case 8:
|
||||
return "Back Right";
|
||||
}
|
||||
SDL_assert(0);
|
||||
case 6:
|
||||
switch (channel_count) {
|
||||
case 7:
|
||||
return "Back Right";
|
||||
return "Side Right";
|
||||
case 8:
|
||||
return "Side Left";
|
||||
}
|
||||
SDL_assert(0);
|
||||
case 7:
|
||||
return "Side Right";
|
||||
}
|
||||
|
|
@ -92,9 +98,9 @@ is_lfe_channel(int channel_index, int channel_count)
|
|||
}
|
||||
|
||||
void SDLCALL
|
||||
fill_buffer(void* unused, Uint8* stream, int len)
|
||||
fill_buffer(void *unused, Uint8 *stream, int len)
|
||||
{
|
||||
Sint16* buffer = (Sint16*)stream;
|
||||
Sint16 *buffer = (Sint16 *)stream;
|
||||
int samples = len / sizeof(Sint16);
|
||||
static int total_samples = 0;
|
||||
int i;
|
||||
|
|
@ -132,8 +138,7 @@ fill_buffer(void* unused, Uint8* stream, int len)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -33,12 +33,15 @@ quit(int rc)
|
|||
static const char *
|
||||
getprioritystr(SDL_ThreadPriority priority)
|
||||
{
|
||||
switch(priority)
|
||||
{
|
||||
case SDL_THREAD_PRIORITY_LOW: return "SDL_THREAD_PRIORITY_LOW";
|
||||
case SDL_THREAD_PRIORITY_NORMAL: return "SDL_THREAD_PRIORITY_NORMAL";
|
||||
case SDL_THREAD_PRIORITY_HIGH: return "SDL_THREAD_PRIORITY_HIGH";
|
||||
case SDL_THREAD_PRIORITY_TIME_CRITICAL: return "SDL_THREAD_PRIORITY_TIME_CRITICAL";
|
||||
switch (priority) {
|
||||
case SDL_THREAD_PRIORITY_LOW:
|
||||
return "SDL_THREAD_PRIORITY_LOW";
|
||||
case SDL_THREAD_PRIORITY_NORMAL:
|
||||
return "SDL_THREAD_PRIORITY_NORMAL";
|
||||
case SDL_THREAD_PRIORITY_HIGH:
|
||||
return "SDL_THREAD_PRIORITY_HIGH";
|
||||
case SDL_THREAD_PRIORITY_TIME_CRITICAL:
|
||||
return "SDL_THREAD_PRIORITY_TIME_CRITICAL";
|
||||
}
|
||||
|
||||
return "???";
|
||||
|
|
@ -51,20 +54,21 @@ ThreadFunc(void *data)
|
|||
|
||||
SDL_TLSSet(tls, "baby thread", NULL);
|
||||
SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
|
||||
(char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
|
||||
(char *)data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
|
||||
while (alive) {
|
||||
SDL_Log("Thread '%s' is alive!\n", (char *) data);
|
||||
SDL_Log("Thread '%s' is alive!\n", (char *)data);
|
||||
|
||||
if (testprio) {
|
||||
SDL_Log("SDL_SetThreadPriority(%s):%d\n", getprioritystr(prio), SDL_SetThreadPriority(prio));
|
||||
if (++prio > SDL_THREAD_PRIORITY_TIME_CRITICAL)
|
||||
if (++prio > SDL_THREAD_PRIORITY_TIME_CRITICAL) {
|
||||
prio = SDL_THREAD_PRIORITY_LOW;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Delay(1 * 1000);
|
||||
}
|
||||
SDL_Log("Thread '%s' exiting!\n", (char *) data);
|
||||
return (0);
|
||||
SDL_Log("Thread '%s' exiting!\n", (char *)data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -76,8 +80,7 @@ killed(int sig)
|
|||
quit(0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int arg = 1;
|
||||
SDL_Thread *thread;
|
||||
|
|
@ -88,7 +91,7 @@ main(int argc, char *argv[])
|
|||
/* Load the SDL library */
|
||||
if (SDL_Init(0) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
|
||||
|
|
@ -123,14 +126,14 @@ main(int argc, char *argv[])
|
|||
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
|
||||
|
||||
alive = 1;
|
||||
signal(SIGTERM, killed);
|
||||
(void)signal(SIGTERM, killed);
|
||||
thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
|
||||
if (thread == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
raise(SIGTERM);
|
||||
(void)raise(SIGTERM);
|
||||
|
||||
SDL_Quit(); /* Never reached */
|
||||
return (0); /* Never reached */
|
||||
SDL_Quit(); /* Never reached */
|
||||
return 0; /* Never reached */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "SDL.h"
|
||||
|
||||
#define DEFAULT_RESOLUTION 1
|
||||
#define DEFAULT_RESOLUTION 1
|
||||
|
||||
static int ticks = 0;
|
||||
|
||||
|
|
@ -27,18 +27,17 @@ static Uint32 SDLCALL
|
|||
ticktock(Uint32 interval, void *param)
|
||||
{
|
||||
++ticks;
|
||||
return (interval);
|
||||
return interval;
|
||||
}
|
||||
|
||||
static Uint32 SDLCALL
|
||||
callback(Uint32 interval, void *param)
|
||||
{
|
||||
SDL_Log("Timer %d : param = %d\n", interval, (int) (uintptr_t) param);
|
||||
SDL_Log("Timer %" SDL_PRIu32 " : param = %d\n", interval, (int)(uintptr_t)param);
|
||||
return interval;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, desired;
|
||||
SDL_TimerID t1, t2, t3;
|
||||
|
|
@ -51,7 +50,7 @@ main(int argc, char *argv[])
|
|||
|
||||
if (SDL_Init(SDL_INIT_TIMER) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
|
||||
|
|
@ -95,20 +94,23 @@ main(int argc, char *argv[])
|
|||
/* Print the results */
|
||||
if (ticks) {
|
||||
SDL_Log("Timer resolution: desired = %d ms, actual = %f ms\n",
|
||||
desired, (double) (10 * 1000) / ticks);
|
||||
desired, (double)(10 * 1000) / ticks);
|
||||
}
|
||||
|
||||
/* Test multiple timers */
|
||||
SDL_Log("Testing multiple timers...\n");
|
||||
t1 = SDL_AddTimer(100, callback, (void *) 1);
|
||||
if (!t1)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 1: %s\n", SDL_GetError());
|
||||
t2 = SDL_AddTimer(50, callback, (void *) 2);
|
||||
if (!t2)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 2: %s\n", SDL_GetError());
|
||||
t3 = SDL_AddTimer(233, callback, (void *) 3);
|
||||
if (!t3)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 3: %s\n", SDL_GetError());
|
||||
t1 = SDL_AddTimer(100, callback, (void *)1);
|
||||
if (!t1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 1: %s\n", SDL_GetError());
|
||||
}
|
||||
t2 = SDL_AddTimer(50, callback, (void *)2);
|
||||
if (!t2) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 2: %s\n", SDL_GetError());
|
||||
}
|
||||
t3 = SDL_AddTimer(233, callback, (void *)3);
|
||||
if (!t3) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 3: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
/* Wait 10 seconds */
|
||||
SDL_Log("Waiting 10 seconds\n");
|
||||
|
|
@ -127,9 +129,9 @@ main(int argc, char *argv[])
|
|||
ticktock(0, NULL);
|
||||
}
|
||||
now = SDL_GetPerformanceCounter();
|
||||
SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
|
||||
SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start) * 1000) / SDL_GetPerformanceFrequency());
|
||||
|
||||
SDL_Log("Performance counter frequency: %"SDL_PRIu64"\n", SDL_GetPerformanceFrequency());
|
||||
SDL_Log("Performance counter frequency: %" SDL_PRIu64 "\n", SDL_GetPerformanceFrequency());
|
||||
start64 = SDL_GetTicks64();
|
||||
start32 = SDL_GetTicks();
|
||||
start = SDL_GetPerformanceCounter();
|
||||
|
|
@ -137,10 +139,10 @@ main(int argc, char *argv[])
|
|||
now = SDL_GetPerformanceCounter();
|
||||
now64 = SDL_GetTicks64();
|
||||
now32 = SDL_GetTicks();
|
||||
SDL_Log("Delay 1 second = %d ms in ticks, %d ms in ticks64, %f ms according to performance counter\n", (int) (now32-start32), (int) (now64-start64), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
|
||||
SDL_Log("Delay 1 second = %d ms in ticks, %d ms in ticks64, %f ms according to performance counter\n", (int)(now32 - start32), (int)(now64 - start64), (double)((now - start) * 1000) / SDL_GetPerformanceFrequency());
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2023 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
|
||||
|
|
@ -11,6 +11,16 @@
|
|||
*/
|
||||
#include "SDL.h"
|
||||
|
||||
static void tryOpenURL(const char *url)
|
||||
{
|
||||
SDL_Log("Opening '%s' ...", url);
|
||||
if (SDL_OpenURL(url) == 0) {
|
||||
SDL_Log(" success!");
|
||||
} else {
|
||||
SDL_Log(" failed! %s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
|
@ -19,14 +29,12 @@ int main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *url = argv[i];
|
||||
SDL_Log("Opening '%s' ...", url);
|
||||
if (SDL_OpenURL(url) == 0) {
|
||||
SDL_Log(" success!");
|
||||
} else {
|
||||
SDL_Log(" failed! %s", SDL_GetError());
|
||||
if (argc > 1) {
|
||||
for (i = 1; i < argc; i++) {
|
||||
tryOpenURL(argv[i]);
|
||||
}
|
||||
} else {
|
||||
tryOpenURL("https://libsdl.org/");
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 1997-2022 Sam Lantinga
|
||||
Copyright 1997-2023 Sam Lantinga
|
||||
Copyright 2022 Collabora Ltd.
|
||||
SPDX-License-Identifier: Zlib
|
||||
*/
|
||||
|
|
@ -33,7 +33,7 @@ GetNearbyFilename(const char *file)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SDL_snprintf(path, len, "%s%s", base, file);
|
||||
(void)SDL_snprintf(path, len, "%s%s", base, file);
|
||||
SDL_free(base);
|
||||
|
||||
rw = SDL_RWFromFile(path, "rb");
|
||||
|
|
@ -114,17 +114,17 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent,
|
|||
switch (temp->format->BitsPerPixel) {
|
||||
case 15:
|
||||
SDL_SetColorKey(temp, SDL_TRUE,
|
||||
(*(Uint16 *) temp->pixels) & 0x00007FFF);
|
||||
(*(Uint16 *)temp->pixels) & 0x00007FFF);
|
||||
break;
|
||||
case 16:
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *)temp->pixels);
|
||||
break;
|
||||
case 24:
|
||||
SDL_SetColorKey(temp, SDL_TRUE,
|
||||
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
|
||||
(*(Uint32 *)temp->pixels) & 0x00FFFFFF);
|
||||
break;
|
||||
case 32:
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *)temp->pixels);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -139,13 +139,11 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent,
|
|||
}
|
||||
|
||||
texture = SDL_CreateTextureFromSurface(renderer, temp);
|
||||
if (!texture) {
|
||||
if (texture == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
|
||||
}
|
||||
}
|
||||
if (temp) {
|
||||
SDL_FreeSurface(temp);
|
||||
}
|
||||
SDL_FreeSurface(temp);
|
||||
if (path) {
|
||||
SDL_free(path);
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue