Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Kill off dangling else's in the InputCommon project.
Some indentations were also too far for some things. Fixed this.

Also update the license header to show Git instead of SVN.

Got rid of some trailing spaces/tabs too.
  • Loading branch information
lioncash committed Apr 15, 2013
1 parent b91930a commit 8a9fcd3
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Source/Core/InputCommon/Src/ControllerEmu.cpp
Expand Up @@ -12,7 +12,7 @@
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official SVN repository and contact information can be found at
// Official Git repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/

#include "ControllerEmu.h"
Expand Down
11 changes: 8 additions & 3 deletions Source/Core/InputCommon/Src/ControllerEmu.h
Expand Up @@ -12,7 +12,7 @@
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/

// Official SVN repository and contact information can be found at
// Official Git repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/

#ifndef _CONTROLLEREMU_H_
Expand Down Expand Up @@ -196,11 +196,15 @@ class ControllerEmu
template <typename C>
void GetState(C* const buttons, const C* bitmasks)
{
std::vector<Control*>::iterator i = controls.begin(),
std::vector<Control*>::iterator
i = controls.begin(),
e = controls.end();

for (; i!=e; ++i, ++bitmasks)
{
if ((*i)->control_ref->State() > settings[0]->value) // threshold
*buttons |= *bitmasks;
}
}

};
Expand All @@ -221,8 +225,9 @@ class ControllerEmu
*digital |= *bitmasks;
}
else
{
*analog = S(controls[i+trig_count]->control_ref->State() * range);
}
}
}

Expand Down
Expand Up @@ -157,7 +157,7 @@ bool ControllerInterface::UpdateOutput(const bool force)
if (force)
lk.lock();
else if (!lk.try_lock())
return false;
return false;

size_t ok_count = 0;

Expand All @@ -173,7 +173,7 @@ bool ControllerInterface::UpdateOutput(const bool force)
//
// Device :: ~Device
//
// dtor, delete all inputs/outputs on device destruction
// Destructor, delete all inputs/outputs on device destruction
//
ControllerInterface::Device::~Device()
{
Expand Down Expand Up @@ -209,9 +209,9 @@ void ControllerInterface::Device::AddOutput(Output* const o)
//
// Device :: ClearInputState
//
// device classes should override this func
// ControllerInterface will call this when the device returns failure durring UpdateInput
// used to try to set all buttons and axes to their default state when user unplugs a gamepad durring play
// Device classes should override this function
// ControllerInterface will call this when the device returns failure during UpdateInput
// used to try to set all buttons and axes to their default state when user unplugs a gamepad during play
// buttons/axes that were held down at the time of unplugging should be seen as not pressed after unplugging
//
void ControllerInterface::Device::ClearInputState()
Expand Down Expand Up @@ -239,8 +239,10 @@ ControlState ControllerInterface::InputReference::State( const ControlState igno

// bit of hax for "NOT" to work at start of expression
if (ci != ce)
{
if (ci->mode == 2)
state = 1;
}

for (; ci!=ce; ++ci)
{
Expand Down Expand Up @@ -354,7 +356,8 @@ bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface:
if (name == devq.name)
if (source == devq.source)
return true;
return false;

return false;
}

//
Expand Down Expand Up @@ -421,7 +424,9 @@ void ControllerInterface::UpdateReference(ControllerInterface::ControlReference*
break; // no terminating '`' character
}
else
{
ctrl_str += c;
}
}
}

Expand Down Expand Up @@ -478,7 +483,9 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec
return *i;
}
else if ((*i)->GetState() < (1 - INPUT_DETECT_THRESHOLD))
{
*state = false;
}
}
Common::SleepCurrentThread(10); time += 10;
}
Expand All @@ -490,16 +497,16 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec
//
// OutputReference :: Detect
//
// totally different from the inputReference detect / i have them combined so it was simplier to make the gui.
// the gui doesnt know the difference between an input and an output / its odd but i was lazy and it was easy
// Totally different from the inputReference detect / I have them combined so it was simpler to make the GUI.
// The GUI doesn't know the difference between an input and an output / it's odd but I was lazy and it was easy
//
// set all binded outputs to <range> power for x milliseconds return false
//
ControllerInterface::Device::Control* ControllerInterface::OutputReference::Detect(const unsigned int ms, Device* const device)
{
// ignore device

// dont hang if we dont even have any controls mapped
// don't hang if we don't even have any controls mapped
if (m_controls.size())
{
State(1);
Expand Down
Expand Up @@ -319,9 +319,13 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
eff.lpvTypeSpecificParams = &diCF;
}
else if (1 == f)
{
eff.cbTypeSpecificParams = sizeof(DIRAMPFORCE);
}
else
{
eff.cbTypeSpecificParams = sizeof(DIPERIODIC);
}

LPDIRECTINPUTEFFECT pEffect;
if (SUCCEEDED(m_device->CreateEffect(force_type_names[f].guid, &eff, &pEffect, NULL)))
Expand Down Expand Up @@ -427,7 +431,9 @@ bool Joystick::UpdateInput()
}
}
else
{
hr = m_device->GetDeviceState(sizeof(m_state_in), &m_state_in);
}

// try reacquire if input lost
if (DIERR_INPUTLOST == hr || DIERR_NOTACQUIRED == hr)
Expand Down Expand Up @@ -460,12 +466,16 @@ bool Joystick::UpdateOutput()
ok_count += SUCCEEDED(i->iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
}
else
{
ok_count += SUCCEEDED(i->iface->Stop());
}

i->params = NULL;
}
else
{
++ok_count;
}
}

return (m_state_out.size() == ok_count);
Expand All @@ -492,7 +502,9 @@ std::string Joystick::Axis::GetName() const
}
// slider
else
{
ss << "Slider " << (int)(m_index - 6);
}

ss << (m_range < 0 ? '-' : '+');
return ss.str();
Expand Down
Expand Up @@ -56,15 +56,19 @@ void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<ControllerInterfac
if (SUCCEEDED(idi8->CreateDevice( GUID_SysKeyboard, &kb_device, NULL)))
{
if (SUCCEEDED(kb_device->SetDataFormat(&c_dfDIKeyboard)))
if (SUCCEEDED(kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
if (SUCCEEDED(idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL )))
if (SUCCEEDED(kb_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2)))
if (SUCCEEDED(mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
if (SUCCEEDED(idi8->CreateDevice( GUID_SysMouse, &mo_device, NULL )))
{
devices.push_back(new KeyboardMouse(kb_device, mo_device));
return;
if (SUCCEEDED(mo_device->SetDataFormat(&c_dfDIMouse2)))
{
if (SUCCEEDED(mo_device->SetCooperativeLevel(NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
devices.push_back(new KeyboardMouse(kb_device, mo_device));
return;
}
}
}
}
}
Expand Down Expand Up @@ -203,7 +207,9 @@ bool KeyboardMouse::UpdateOutput()
memset( this, 0, sizeof(*this) );
type = INPUT_KEYBOARD;
ki.wVk = key;
if (up) ki.dwFlags = KEYEVENTF_KEYUP;

if (up)
ki.dwFlags = KEYEVENTF_KEYUP;
}
};

Expand Down
42 changes: 27 additions & 15 deletions Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
Expand Up @@ -34,7 +34,7 @@ void Init( std::vector<ControllerInterface::Device*>& devices )
std::map<std::string, int> name_counts;

if (SDL_Init( SDL_INIT_FLAGS ) >= 0)
{
{
// joysticks
for(int i = 0; i < SDL_NumJoysticks(); ++i)
{
Expand All @@ -49,7 +49,7 @@ void Init( std::vector<ControllerInterface::Device*>& devices )
delete js;
}
}
}
}
}

Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index)
Expand All @@ -63,7 +63,7 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
// "why don't my 360 gamepad triggers/rumble work correctly"
#ifdef _WIN32
// checking the name is probably good (and hacky) enough
// but i'll double check with the num of buttons/axes
// but I'll double check with the num of buttons/axes
std::string lcasename = GetName();
std::transform(lcasename.begin(), lcasename.end(), lcasename.begin(), tolower);

Expand Down Expand Up @@ -204,7 +204,9 @@ void Joystick::ConstantEffect::SetState(const ControlState state)
m_effect.effect.constant.length = SDL_HAPTIC_INFINITY;
}
else
{
m_effect.effect.type = 0;
}

const Sint16 old = m_effect.effect.constant.level;
m_effect.effect.constant.level = state * 0x7FFF;
Expand All @@ -220,7 +222,9 @@ void Joystick::RampEffect::SetState(const ControlState state)
m_effect.effect.ramp.length = SDL_HAPTIC_INFINITY;
}
else
{
m_effect.effect.type = 0;
}

const Sint16 old = m_effect.effect.ramp.start;
m_effect.effect.ramp.start = state * 0x7FFF;
Expand All @@ -235,15 +239,17 @@ void Joystick::SineEffect::SetState(const ControlState state)
m_effect.effect.type = SDL_HAPTIC_SINE;
m_effect.effect.periodic.length = 250;
}
else {
else
{
m_effect.effect.type = 0;
}

const Sint16 old = m_effect.effect.periodic.magnitude;
m_effect.effect.periodic.period = 5;
m_effect.effect.periodic.period = 5;
m_effect.effect.periodic.magnitude = state * 0x5000;
m_effect.effect.periodic.attack_length = 0;
m_effect.effect.periodic.fade_length = 500;
m_effect.effect.periodic.attack_length = 0;
m_effect.effect.periodic.fade_length = 500;

if (old != m_effect.effect.periodic.magnitude)
m_effect.changed = true;
}
Expand All @@ -255,15 +261,17 @@ void Joystick::SquareEffect::SetState(const ControlState state)
m_effect.effect.type = SDL_HAPTIC_SQUARE;
m_effect.effect.periodic.length = 250;
}
else {
else
{
m_effect.effect.type = 0;
}

const Sint16 old = m_effect.effect.periodic.magnitude;
m_effect.effect.periodic.period = 5;
m_effect.effect.periodic.period = 5;
m_effect.effect.periodic.magnitude = state * 0x5000;
m_effect.effect.periodic.attack_length = 0;
m_effect.effect.periodic.fade_length = 100;
m_effect.effect.periodic.attack_length = 0;
m_effect.effect.periodic.fade_length = 100;

if (old != m_effect.effect.periodic.magnitude)
m_effect.changed = true;
}
Expand All @@ -275,15 +283,17 @@ void Joystick::TriangleEffect::SetState(const ControlState state)
m_effect.effect.type = SDL_HAPTIC_TRIANGLE;
m_effect.effect.periodic.length = 250;
}
else {
else
{
m_effect.effect.type = 0;
}

const Sint16 old = m_effect.effect.periodic.magnitude;
m_effect.effect.periodic.period = 5;
m_effect.effect.periodic.period = 5;
m_effect.effect.periodic.magnitude = state * 0x5000;
m_effect.effect.periodic.attack_length = 0;
m_effect.effect.periodic.fade_length = 100;
m_effect.effect.periodic.attack_length = 0;
m_effect.effect.periodic.fade_length = 100;

if (old != m_effect.effect.periodic.magnitude)
m_effect.changed = true;
}
Expand Down Expand Up @@ -316,7 +326,9 @@ bool Joystick::UpdateOutput()
else // effect is already uploaded
{
if (i->effect.type) // if ouputstate >0
{
SDL_HapticUpdateEffect(m_haptic, i->id, &i->effect); // update the effect
}
else
{
SDL_HapticStopEffect(m_haptic, i->id); // else, stop and remove the effect
Expand Down

0 comments on commit 8a9fcd3

Please sign in to comment.