SDL: Apply updates immediately rather than going through UpdateOutput

We're going to remove UpdateOutput as it's redundant, and horribly
complicates the code.
This commit is contained in:
Jasper St. Pierre
2014-11-13 00:49:18 -08:00
parent e43ad58a3a
commit 1b3d0173f5
2 changed files with 86 additions and 146 deletions

View File

@ -33,17 +33,6 @@ class Joystick : public Core::Device
{
private:
#ifdef USE_SDL_HAPTIC
struct EffectIDState
{
EffectIDState() : effect(SDL_HapticEffect()), id(-1), changed(false) {}
SDL_HapticEffect effect;
int id;
bool changed;
};
#endif
class Button : public Core::Device::Input
{
public:
@ -80,62 +69,65 @@ private:
};
#ifdef USE_SDL_HAPTIC
class ConstantEffect : public Output
class HapticEffect : public Output
{
public:
std::string GetName() const override;
ConstantEffect(EffectIDState& effect) : m_effect(effect) {}
void SetState(ControlState state) override;
private:
EffectIDState& m_effect;
HapticEffect(SDL_Haptic* haptic) : m_haptic(haptic), m_id(-1) {}
~HapticEffect() { m_effect.type = 0; Update(); }
protected:
void Update();
SDL_HapticEffect m_effect;
SDL_Haptic* m_haptic;
int m_id;
};
class RampEffect : public Output
class ConstantEffect : public HapticEffect
{
public:
ConstantEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const override;
RampEffect(EffectIDState& effect) : m_effect(effect) {}
void SetState(ControlState state) override;
private:
EffectIDState& m_effect;
};
class SineEffect : public Output
class RampEffect : public HapticEffect
{
public:
RampEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const override;
void SetState(ControlState state) override;
};
class SineEffect : public HapticEffect
{
public:
SineEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const override;
SineEffect(EffectIDState& effect) : m_effect(effect) {}
void SetState(ControlState state) override;
private:
EffectIDState& m_effect;
};
#ifdef SDL_HAPTIC_SQUARE
class SquareEffect : public Output
class SquareEffect : public HapticEffect
{
public:
SquareEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const;
SquareEffect(EffectIDState& effect) : m_effect(effect) {}
void SetState(ControlState state);
private:
EffectIDState& m_effect;
};
#endif // defined(SDL_HAPTIC_SQUARE)
class TriangleEffect : public Output
class TriangleEffect : public HapticEffect
{
public:
TriangleEffect(SDL_Haptic* haptic) : HapticEffect(haptic) {}
std::string GetName() const override;
TriangleEffect(EffectIDState& effect) : m_effect(effect) {}
void SetState(ControlState state) override;
private:
EffectIDState& m_effect;
};
#endif
public:
void UpdateInput() override;
void UpdateOutput() override;
Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index);
~Joystick();
@ -150,7 +142,6 @@ private:
const unsigned int m_index;
#ifdef USE_SDL_HAPTIC
std::list<EffectIDState> m_state_out;
SDL_Haptic* m_haptic;
#endif
};