early-access version 1988

This commit is contained in:
pineappleEA
2021-08-12 01:07:27 +02:00
parent e37f82ce96
commit 24ddfcbb39
265 changed files with 68343 additions and 5348 deletions

View File

@@ -106,11 +106,11 @@ endif()
# Need to make it an executable so we can use the TARGET_FILE_DIR generator expression.
# This is needed so they get copied to the correct Debug/Release subdirectory in Xcode.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c "int main(int argc, const char **argv){ return 1; }\n")
add_executable(SDL2_test_resoureces ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c)
add_executable(SDL2_test_resources ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c)
file(GLOB RESOURCE_FILES *.bmp *.wav moose.dat utf8.txt)
file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
foreach(RESOURCE_FILE ${RESOURCE_FILES})
add_custom_command(TARGET SDL2_test_resoureces POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:SDL2_test_resoureces>)
add_custom_command(TARGET SDL2_test_resources POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:SDL2_test_resources>)
endforeach(RESOURCE_FILE)
file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
@@ -138,7 +138,7 @@ set(NEEDS_RESOURCES
testmultiaudio
)
foreach(APP IN LISTS NEEDS_RESOURCES)
add_dependencies(${APP} SDL2_test_resoureces)
add_dependencies(${APP} SDL2_test_resources)
if(APPLE)
# Make sure resource files get installed into macOS/iOS .app bundles.
target_sources(${APP} PRIVATE "${RESOURCE_FILES}")

View File

@@ -165,6 +165,7 @@ static Uint32 s_unPendingAdvanceTime;
static SDL_bool s_bBindingComplete;
static SDL_Window *window;
static SDL_Renderer *screen;
static SDL_bool done = SDL_FALSE;
SDL_Texture *
@@ -375,7 +376,6 @@ BMergeAxisBindings(int iIndex)
static void
WatchJoystick(SDL_Joystick * joystick)
{
SDL_Renderer *screen = NULL;
SDL_Texture *background_front, *background_back, *button, *axis, *marker;
const char *name = NULL;
SDL_Event event;
@@ -384,12 +384,6 @@ WatchJoystick(SDL_Joystick * joystick)
Uint32 alpha_ticks = 0;
SDL_JoystickID nJoystickID;
screen = SDL_CreateRenderer(window, -1, 0);
if (screen == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
return;
}
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE);
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
@@ -746,7 +740,13 @@ main(int argc, char *argv[])
return 2;
}
while (SDL_NumJoysticks() == 0) {
screen = SDL_CreateRenderer(window, -1, 0);
if (screen == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
return 2;
}
while (!done && SDL_NumJoysticks() == 0) {
SDL_Event event;
while (SDL_PollEvent(&event) > 0) {
@@ -763,6 +763,7 @@ main(int argc, char *argv[])
break;
}
}
SDL_RenderPresent(screen);
}
/* Print information about the joysticks */

View File

@@ -61,15 +61,16 @@ static const struct { int x; int y; double angle; } axis_positions[] = {
{375, -20, 0.0}, /* TRIGGERRIGHT */
};
SDL_Window *window = NULL;
SDL_Renderer *screen = NULL;
SDL_bool retval = SDL_FALSE;
SDL_bool done = SDL_FALSE;
SDL_bool set_LED = SDL_FALSE;
SDL_Texture *background_front, *background_back, *button, *axis;
SDL_GameController *gamecontroller;
SDL_GameController **gamecontrollers;
int num_controllers = 0;
static 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_GameController *gamecontroller;
static SDL_GameController **gamecontrollers;
static int num_controllers = 0;
static void UpdateWindowTitle()
{
@@ -146,6 +147,7 @@ static void AddController(int device_index, SDL_bool verbose)
controllers[num_controllers++] = controller;
gamecontrollers = controllers;
gamecontroller = controller;
trigger_effect = 0;
if (verbose) {
const char *name = SDL_GameControllerName(gamecontroller);
@@ -154,14 +156,14 @@ static void AddController(int device_index, SDL_bool verbose)
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_ACCEL)) {
if (verbose) {
SDL_Log("Enabling accelerometer\n");
SDL_Log("Enabling accelerometer at %.2f Hz\n", SDL_GameControllerGetSensorDataRate(gamecontroller, SDL_SENSOR_ACCEL));
}
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_ACCEL, SDL_TRUE);
}
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_GYRO)) {
if (verbose) {
SDL_Log("Enabling gyro\n");
SDL_Log("Enabling gyro at %.2f Hz\n", SDL_GameControllerGetSensorDataRate(gamecontroller, SDL_SENSOR_GYRO));
}
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_GYRO, SDL_TRUE);
}
@@ -245,6 +247,57 @@ static Uint16 ConvertAxisToRumble(Sint16 axis)
}
}
/* PS5 trigger effect documentation:
https://controllers.fandom.com/wiki/Sony_DualSense#FFB_Trigger_Modes
*/
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 */
} DS5EffectsState_t;
static void CyclePS5TriggerEffect()
{
DS5EffectsState_t state;
Uint8 effects[3][11] =
{
/* Clear trigger effect */
{ 0x05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
/* Constant resistance across entire trigger pull */
{ 0x01, 0, 110, 0, 0, 0, 0, 0, 0, 0, 0 },
/* Resistance and vibration when trigger is pulled */
{ 0x06, 15, 63, 128, 0, 0, 0, 0, 0, 0, 0 },
};
trigger_effect = (trigger_effect + 1) % SDL_arraysize(effects);
SDL_zero(state);
state.ucEnableBits1 |= (0x04 | 0x08); /* Modify right and left trigger effect respectively */
SDL_memcpy(state.rgucRightTriggerEffect, effects[trigger_effect], sizeof(effects[trigger_effect]));
SDL_memcpy(state.rgucLeftTriggerEffect, effects[trigger_effect], sizeof(effects[trigger_effect]));
SDL_GameControllerSendEffect(gamecontroller, &state, sizeof(state));
}
void
loop(void *arg)
{
@@ -252,7 +305,11 @@ loop(void *arg)
int i;
SDL_bool showing_front = SDL_TRUE;
while (SDL_PollEvent(&event)) {
/* Update to get the current event state */
SDL_PumpEvents();
/* Process all currently pending events */
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));
@@ -279,6 +336,8 @@ loop(void *arg)
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,
@@ -288,13 +347,17 @@ loop(void *arg)
event.csensor.data[1],
event.csensor.data[2]);
break;
#endif /* VERBOSE_SENSORS */
#define VERBOSE_AXES
#ifdef VERBOSE_AXES
case SDL_CONTROLLERAXISMOTION:
if (event.caxis.value <= (-SDL_JOYSTICK_AXIS_MAX / 2) || event.caxis.value >= (SDL_JOYSTICK_AXIS_MAX / 2)) {
SetController(event.caxis.which);
}
SDL_Log("Controller %d axis %s changed to %d\n", event.caxis.which, SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
break;
#endif /* VERBOSE_AXES */
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
@@ -302,6 +365,13 @@ loop(void *arg)
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");
/* Cycle PS5 trigger effects when the microphone button is pressed */
if (event.type == SDL_CONTROLLERBUTTONDOWN &&
event.cbutton.button == SDL_CONTROLLER_BUTTON_MISC1 &&
SDL_GameControllerGetType(gamecontroller) == SDL_CONTROLLER_TYPE_PS5) {
CyclePS5TriggerEffect();
}
break;
case SDL_KEYDOWN:
@@ -408,23 +478,25 @@ loop(void *arg)
}
}
/* Update rumble based on trigger state */
{
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
Uint16 low_frequency_rumble = ConvertAxisToRumble(left);
Uint16 high_frequency_rumble = ConvertAxisToRumble(right);
SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
}
if (trigger_effect == 0) {
/* Update rumble based on trigger state */
{
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
Uint16 low_frequency_rumble = ConvertAxisToRumble(left);
Uint16 high_frequency_rumble = ConvertAxisToRumble(right);
SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
}
/* Update trigger rumble based on thumbstick state */
{
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTY);
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY);
Uint16 left_rumble = ConvertAxisToRumble(~left);
Uint16 right_rumble = ConvertAxisToRumble(~right);
/* Update trigger rumble based on thumbstick state */
{
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTY);
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY);
Uint16 left_rumble = ConvertAxisToRumble(~left);
Uint16 right_rumble = ConvertAxisToRumble(~right);
SDL_GameControllerRumbleTriggers(gamecontroller, left_rumble, right_rumble, 250);
SDL_GameControllerRumbleTriggers(gamecontroller, left_rumble, right_rumble, 250);
}
}
}
@@ -446,6 +518,7 @@ 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_ALLOW_BACKGROUND_EVENTS, "1");
@@ -486,11 +559,14 @@ main(int argc, char *argv[])
controller_count++;
name = SDL_GameControllerNameForIndex(i);
switch (SDL_GameControllerTypeForIndex(i)) {
case SDL_CONTROLLER_TYPE_XBOX360:
description = "XBox 360 Controller";
case SDL_CONTROLLER_TYPE_AMAZON_LUNA:
description = "Amazon Luna Controller";
break;
case SDL_CONTROLLER_TYPE_XBOXONE:
description = "XBox One Controller";
case SDL_CONTROLLER_TYPE_GOOGLE_STADIA:
description = "Google Stadia Controller";
break;
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
description = "Nintendo Switch Pro Controller";
break;
case SDL_CONTROLLER_TYPE_PS3:
description = "PS3 Controller";
@@ -498,8 +574,14 @@ main(int argc, char *argv[])
case SDL_CONTROLLER_TYPE_PS4:
description = "PS4 Controller";
break;
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
description = "Nintendo Switch Pro Controller";
case SDL_CONTROLLER_TYPE_PS5:
description = "PS5 Controller";
break;
case SDL_CONTROLLER_TYPE_XBOX360:
description = "XBox 360 Controller";
break;
case SDL_CONTROLLER_TYPE_XBOXONE:
description = "XBox One Controller";
break;
case SDL_CONTROLLER_TYPE_VIRTUAL:
description = "Virtual Game Controller";
@@ -577,6 +659,12 @@ main(int argc, char *argv[])
}
#endif
/* Reset trigger state */
if (trigger_effect != 0) {
trigger_effect = -1;
CyclePS5TriggerEffect();
}
SDL_DestroyRenderer(screen);
SDL_DestroyWindow(window);
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);

View File

@@ -35,7 +35,7 @@
#define DEFAULT_FONT "NoDefaultFont.ttf"
#endif
#else
#define DEFAULT_FONT "unifont-9.0.02.hex"
#define DEFAULT_FONT "unifont-13.0.06.hex"
#endif
#define MAX_TEXT_LENGTH 256

View File

@@ -197,7 +197,7 @@ main(int argc, char *argv[])
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Simple MessageBox",
"This is a simple error MessageBox with a parent window",
"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());

View File

@@ -95,7 +95,11 @@ main(int argc, char **argv)
SDL_CreateWindow("Sensor Test", 0, 0, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP);
while (!done) {
while (SDL_PollEvent(&event) > 0) {
/* Update to get the current event state */
SDL_PumpEvents();
/* Process all currently pending events */
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1) {
switch (event.type) {
case SDL_SENSORUPDATE:
HandleSensorEvent(&event.sensor);

View File

@@ -719,8 +719,17 @@ static SDL_bool createSwapchain(void)
// get size
SDL_Vulkan_GetDrawableSize(state->windows[0], &w, &h);
vulkanContext.swapchainSize.width = w;
vulkanContext.swapchainSize.height = h;
// Clamp the size to the allowable image extent.
// SDL_Vulkan_GetDrawableSize()'s result it not always in this range (bug #3287)
vulkanContext.swapchainSize.width = SDL_max(vulkanContext.surfaceCapabilities.minImageExtent.width,
SDL_min(w,
vulkanContext.surfaceCapabilities.maxImageExtent.width));
vulkanContext.swapchainSize.height = SDL_max(vulkanContext.surfaceCapabilities.minImageExtent.height,
SDL_min(h,
vulkanContext.surfaceCapabilities.maxImageExtent.height));
if(w == 0 || h == 0)
return SDL_FALSE;

View File

@@ -38,6 +38,7 @@ static const char *cursorNames[] = {
};
int system_cursor = -1;
SDL_Cursor *cursor = NULL;
SDL_bool relative_mode = SDL_FALSE;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
@@ -76,6 +77,17 @@ loop()
SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
}
}
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
relative_mode = SDL_GetRelativeMouseMode();
if (relative_mode) {
SDL_SetRelativeMouseMode(SDL_FALSE);
}
}
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
if (relative_mode) {
SDL_SetRelativeMouseMode(SDL_TRUE);
}
}
}
if (event.type == SDL_KEYUP) {
SDL_bool updateCursor = SDL_FALSE;

View File

@@ -0,0 +1,90 @@
The SIL Open Font License version 1.1 is copied below, and is also
available with a FAQ at http://scripts.sil.org/OFL.
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

57086
externals/SDL/test/unifont-13.0.06.hex vendored Executable file

File diff suppressed because it is too large Load Diff