SDL: more global memset

This commit is contained in:
Karol Herbst 2015-01-08 13:37:06 +01:00
parent 306c8d14db
commit 17ad68ff86
2 changed files with 18 additions and 14 deletions

View File

@ -205,9 +205,14 @@ std::string Joystick::LeftRightEffect::GetName() const
return "LeftRight"; return "LeftRight";
} }
void Joystick::ConstantEffect::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);
}
void Joystick::ConstantEffect::_SetState(ControlState state)
{
if (state) if (state)
{ {
m_effect.type = SDL_HAPTIC_CONSTANT; m_effect.type = SDL_HAPTIC_CONSTANT;
@ -222,9 +227,8 @@ void Joystick::ConstantEffect::SetState(ControlState state)
Update(); Update();
} }
void Joystick::RampEffect::SetState(ControlState state) void Joystick::RampEffect::_SetState(ControlState state)
{ {
memset(&m_effect, 0, sizeof(m_effect));
if (state) if (state)
{ {
m_effect.type = SDL_HAPTIC_RAMP; m_effect.type = SDL_HAPTIC_RAMP;
@ -239,9 +243,8 @@ void Joystick::RampEffect::SetState(ControlState state)
Update(); Update();
} }
void Joystick::SineEffect::SetState(ControlState state) void Joystick::SineEffect::_SetState(ControlState state)
{ {
memset(&m_effect, 0, sizeof(m_effect));
if (state) if (state)
{ {
m_effect.type = SDL_HAPTIC_SINE; m_effect.type = SDL_HAPTIC_SINE;
@ -261,9 +264,8 @@ void Joystick::SineEffect::SetState(ControlState state)
Update(); Update();
} }
void Joystick::TriangleEffect::SetState(ControlState state) void Joystick::TriangleEffect::_SetState(ControlState state)
{ {
memset(&m_effect, 0, sizeof(m_effect));
if (state) if (state)
{ {
m_effect.type = SDL_HAPTIC_TRIANGLE; m_effect.type = SDL_HAPTIC_TRIANGLE;
@ -283,9 +285,8 @@ void Joystick::TriangleEffect::SetState(ControlState state)
Update(); Update();
} }
void Joystick::LeftRightEffect::SetState(ControlState state) void Joystick::LeftRightEffect::_SetState(ControlState state)
{ {
memset(&m_effect, 0, sizeof(m_effect));
if (state) if (state)
{ {
m_effect.type = SDL_HAPTIC_LEFTRIGHT; m_effect.type = SDL_HAPTIC_LEFTRIGHT;

View File

@ -77,10 +77,13 @@ private:
protected: protected:
void Update(); void Update();
virtual void _SetState(ControlState state) = 0;
SDL_HapticEffect m_effect; SDL_HapticEffect m_effect;
SDL_Haptic* m_haptic; SDL_Haptic* m_haptic;
int m_id; int m_id;
private:
virtual void SetState(ControlState state) override final;
}; };
class ConstantEffect : public HapticEffect class ConstantEffect : public HapticEffect
@ -88,7 +91,7 @@ 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; void _SetState(ControlState state) override;
}; };
class RampEffect : public HapticEffect class RampEffect : public HapticEffect
@ -96,7 +99,7 @@ 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; void _SetState(ControlState state) override;
}; };
class SineEffect : public HapticEffect class SineEffect : public HapticEffect
@ -104,7 +107,7 @@ 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; void _SetState(ControlState state) override;
}; };
class TriangleEffect : public HapticEffect class TriangleEffect : public HapticEffect
@ -112,7 +115,7 @@ 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; void _SetState(ControlState state) override;
}; };
class LeftRightEffect : public HapticEffect class LeftRightEffect : public HapticEffect
@ -120,7 +123,7 @@ 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; void _SetState(ControlState state) override;
}; };
#endif #endif