mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
SDL: Refactor the SDL haptic effects a little.
This commit is contained in:
parent
17ad68ff86
commit
f47cce2210
@ -208,42 +208,39 @@ std::string Joystick::LeftRightEffect::GetName() const
|
|||||||
void Joystick::HapticEffect::SetState(ControlState state)
|
void Joystick::HapticEffect::SetState(ControlState state)
|
||||||
{
|
{
|
||||||
memset(&m_effect, 0, sizeof(m_effect));
|
memset(&m_effect, 0, sizeof(m_effect));
|
||||||
_SetState(state);
|
SetSDLHapticEffect(state);
|
||||||
|
Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::ConstantEffect::_SetState(ControlState state)
|
void Joystick::ConstantEffect::SetSDLHapticEffect(ControlState state)
|
||||||
{
|
{
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
m_effect.type = SDL_HAPTIC_CONSTANT;
|
m_effect.type = SDL_HAPTIC_CONSTANT;
|
||||||
m_effect.constant.length = SDL_HAPTIC_INFINITY;
|
m_effect.constant.length = SDL_HAPTIC_INFINITY;
|
||||||
|
m_effect.constant.level = (Sint16)(state * 0x7FFF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_effect.type = 0;
|
m_effect.type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_effect.constant.level = (Sint16)(state * 0x7FFF);
|
|
||||||
Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::RampEffect::_SetState(ControlState state)
|
void Joystick::RampEffect::SetSDLHapticEffect(ControlState state)
|
||||||
{
|
{
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
m_effect.type = SDL_HAPTIC_RAMP;
|
m_effect.type = SDL_HAPTIC_RAMP;
|
||||||
m_effect.ramp.length = SDL_HAPTIC_INFINITY;
|
m_effect.ramp.length = SDL_HAPTIC_INFINITY;
|
||||||
|
m_effect.ramp.start = (Sint16)(state * 0x7FFF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_effect.type = 0;
|
m_effect.type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_effect.ramp.start = (Sint16)(state * 0x7FFF);
|
|
||||||
Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::SineEffect::_SetState(ControlState state)
|
void Joystick::SineEffect::SetSDLHapticEffect(ControlState state)
|
||||||
{
|
{
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
@ -260,11 +257,9 @@ void Joystick::SineEffect::_SetState(ControlState state)
|
|||||||
{
|
{
|
||||||
m_effect.type = 0;
|
m_effect.type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::TriangleEffect::_SetState(ControlState state)
|
void Joystick::TriangleEffect::SetSDLHapticEffect(ControlState state)
|
||||||
{
|
{
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
@ -281,11 +276,9 @@ void Joystick::TriangleEffect::_SetState(ControlState state)
|
|||||||
{
|
{
|
||||||
m_effect.type = 0;
|
m_effect.type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::LeftRightEffect::_SetState(ControlState state)
|
void Joystick::LeftRightEffect::SetSDLHapticEffect(ControlState state)
|
||||||
{
|
{
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
@ -299,8 +292,6 @@ void Joystick::LeftRightEffect::_SetState(ControlState state)
|
|||||||
{
|
{
|
||||||
m_effect.type = 0;
|
m_effect.type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Update();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Update();
|
void Update();
|
||||||
virtual void _SetState(ControlState state) = 0;
|
virtual void SetSDLHapticEffect(ControlState state) = 0;
|
||||||
|
|
||||||
SDL_HapticEffect m_effect;
|
SDL_HapticEffect m_effect;
|
||||||
SDL_Haptic* m_haptic;
|
SDL_Haptic* m_haptic;
|
||||||
@ -91,7 +91,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
ConstantEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
ConstantEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
||||||
std::string GetName() const override;
|
std::string GetName() const override;
|
||||||
void _SetState(ControlState state) override;
|
private:
|
||||||
|
void SetSDLHapticEffect(ControlState state) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RampEffect : public HapticEffect
|
class RampEffect : public HapticEffect
|
||||||
@ -99,7 +100,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
RampEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
RampEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
||||||
std::string GetName() const override;
|
std::string GetName() const override;
|
||||||
void _SetState(ControlState state) override;
|
private:
|
||||||
|
void SetSDLHapticEffect(ControlState state) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SineEffect : public HapticEffect
|
class SineEffect : public HapticEffect
|
||||||
@ -107,7 +109,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
SineEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
SineEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
||||||
std::string GetName() const override;
|
std::string GetName() const override;
|
||||||
void _SetState(ControlState state) override;
|
private:
|
||||||
|
void SetSDLHapticEffect(ControlState state) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TriangleEffect : public HapticEffect
|
class TriangleEffect : public HapticEffect
|
||||||
@ -115,7 +118,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
TriangleEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
TriangleEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
||||||
std::string GetName() const override;
|
std::string GetName() const override;
|
||||||
void _SetState(ControlState state) override;
|
private:
|
||||||
|
void SetSDLHapticEffect(ControlState state) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LeftRightEffect : public HapticEffect
|
class LeftRightEffect : public HapticEffect
|
||||||
@ -123,7 +127,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
LeftRightEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
LeftRightEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
|
||||||
std::string GetName() const override;
|
std::string GetName() const override;
|
||||||
void _SetState(ControlState state) override;
|
private:
|
||||||
|
void SetSDLHapticEffect(ControlState state) override;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user