Made SDL_HapticEffect const in the API

Also added some additional parameter validation to haptic effect functions
This commit is contained in:
Sam Lantinga
2024-01-21 10:56:32 -08:00
parent fa5bfe577c
commit 052b958bf2
11 changed files with 61 additions and 49 deletions

View File

@@ -380,22 +380,30 @@ int SDL_GetNumHapticAxes(SDL_Haptic *haptic)
return haptic->naxes;
}
SDL_bool SDL_HapticEffectSupported(SDL_Haptic *haptic, SDL_HapticEffect *effect)
SDL_bool SDL_HapticEffectSupported(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
{
CHECK_HAPTIC_MAGIC(haptic, SDL_FALSE);
if (!effect) {
return SDL_FALSE;
}
if ((haptic->supported & effect->type) != 0) {
return SDL_TRUE;
}
return SDL_FALSE;
}
int SDL_CreateHapticEffect(SDL_Haptic *haptic, SDL_HapticEffect *effect)
int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect)
{
int i;
CHECK_HAPTIC_MAGIC(haptic, -1);
if (!effect) {
return SDL_InvalidParamError("effect");
}
/* Check to see if effect is supported */
if (SDL_HapticEffectSupported(haptic, effect) == SDL_FALSE) {
return SDL_SetError("Haptic: Effect not supported by haptic device.");
@@ -428,7 +436,7 @@ static int ValidEffect(SDL_Haptic *haptic, int effect)
return 1;
}
int SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, SDL_HapticEffect *data)
int SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data)
{
CHECK_HAPTIC_MAGIC(haptic, -1);
@@ -436,6 +444,10 @@ int SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, SDL_HapticEffect *dat
return -1;
}
if (!data) {
return SDL_InvalidParamError("data");
}
/* Can't change type dynamically. */
if (data->type != haptic->effects[effect].effect.type) {
return SDL_SetError("Haptic: Updating effect type is illegal.");