3 #include <SDL_haptic.h> 30 std::numeric_limits<effect_list::size_type>::max();
50 if (index_ != other.index_)
53 owner_ = other.owner_;
56 other.owner_ =
nullptr;
63 if (owner_ && index_ != invalid_index)
66 SDL_HapticDestroyEffect(owner_->
ptr(), my_real_id);
72 void run(uint32_t iterations = 1) { owner_->
run_effect(*
this, iterations); }
77 #pragma warning(disable : 26495) 96 operator SDL_HapticEffect*()
const 99 return (SDL_HapticEffect*)(
this);
111 "please compare the layout between SDL_HapticEffect and " 112 "sdl::Haptic::Effect");
114 sizeof(
Effect) ==
sizeof(SDL_HapticEffect),
115 "please compare the layout between SDL_HapticEffect and " 116 "sdl::Haptic::Effect");
119 SDL_memset(
this, 0,
sizeof(
Effect));
131 Haptic(
int haptic_index) : haptic_{SDL_HapticOpen(haptic_index)}
140 Haptic(SDL_Joystick* joystick) : haptic_{SDL_HapticOpenFromJoystick(joystick)}
144 throw Exception(
"SDL_HapticOpenFromJoystick");
153 SDL_HapticClose(haptic_);
167 if (haptic_ != other.haptic_)
171 other.haptic_ =
nullptr;
177 bool valid()
const {
return haptic_ !=
nullptr; }
186 const auto capabilities = SDL_HapticQuery(haptic_);
201 return (haptic_flag & caps) != 0;
212 const effect_sdlid raw_sdl_id = SDL_HapticNewEffect(haptic_, e);
214 if (raw_sdl_id < 0)
throw Exception(
"SDL_HapticNewEffect");
232 for (
size_t i = 0, nb_effects =
my_effects.size(); i < nb_effects; ++i)
242 if (e >= 0 && SDL_HapticRunEffect(haptic_,
get_effect_sdlid(h), iterations) < 0)
effect_list::size_type registered_effect_count() const
Get the number of effects installed.
SDL_HapticRamp ramp
Condition effect.
InstalledEffect(effect_list::size_type index, Haptic *owner)
SDL_HapticCondition condition
Periodic effect.
InstalledEffect & operator=(InstalledEffect const &)
Haptic & operator=(Haptic &&other) noexcept
move assign opeartor
InstalledEffect & operator=(InstalledEffect &&other) noexcept
Haptic(int haptic_index)
Open haptic device from index.
Haptic(Haptic &&other) noexcept
move ctor
void run(uint32_t iterations=1)
SDL_HapticCustom custom
Left/Right effect.
Haptic()
Uninitialized dummy haptic device.
InstalledEffect(InstalledEffect &&other) noexcept
std::vector< effect_sdlid > effect_list
Installed effect storage type.
Haptic(SDL_Joystick *joystick)
Open haptic device from joystick pointer.
SDL_HapticConstant constant
Effect type.
Effect()
Construct the effect. Fill it with zeroes.
effect_sdlid get_effect_sdlid(InstalledEffect const &h) const
Get the SDL assigned ID (an integer) to the effect.
static constexpr effect_list::size_type invalid_index
effect_list::size_type index_
Define to deactivate exception support.
void remove_effect(effect_sdlid e)
Deactiave the effect. This only set the registered id in question to -1.
bool is_effect_compatible(Effect const &e) const
Check if you can safely attemp to install the effect ont he haptic device.
SDL_Haptic * ptr() const
The the C pointer.
void run_effect(InstalledEffect const &h, uint32_t iterations=1) const
Run an effect, if said effect is valid.
InstalledEffect()=default
unsigned int get_capabilities() const
Get a bitflag that describe the device capabilities.
void move_from(InstalledEffect &other)
SDL_HapticPeriodic periodic
Constant effect.
int effect_sdlid
Type of an installed "effect" for SDL.
SDL_Haptic * haptic_
Pointer to C sdl haptic device.
effect_list my_effects
Installed effect storage.
Define to deactivate exception support.
bool valid() const
Return true if the device is correctly opened.
SDL_HapticLeftRight leftright
Ramp effect.
InstalledEffect new_effect(Effect const &e)
Install the effect.
~Haptic()
close the haptic device automatically
bool is_capable_of(int haptic_flag) const
Check the SDL_HAPTIC_ flag agianst the device capabilities.