summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon
diff options
context:
space:
mode:
authorNeoBrainX <NeoBrainX@gmail.com>2013-04-25 14:01:07 +0200
committerNeoBrainX <NeoBrainX@gmail.com>2013-04-25 14:05:54 +0200
commit5e6b712651dc042b06ce59bcfb4becda5ee15022 (patch)
treec82731464d76517cce5ffb6d7e9764c47a433804 /Source/Core/InputCommon
parenteef95fa4c5919bf93335e10dd61cd5a9fd6a5f6d (diff)
parentd18b71ccf91c9578236b44ae26e8bc35314cc180 (diff)
Merge 'master' into shader-uids-awesome.
Conflicts: Source/Core/VideoCommon/Src/BPMemory.h Source/Core/VideoCommon/Src/LightingShaderGen.cpp Source/Core/VideoCommon/Src/PixelShaderGen.cpp Source/Core/VideoCommon/Src/PixelShaderGen.h Source/Core/VideoCommon/Src/PixelShaderManager.cpp Source/Core/VideoCommon/Src/VertexShaderGen.cpp Source/Core/VideoCommon/Src/VertexShaderGen.h
Diffstat (limited to 'Source/Core/InputCommon')
-rw-r--r--Source/Core/InputCommon/CMakeLists.txt4
-rw-r--r--Source/Core/InputCommon/Src/Android/ButtonManager.cpp90
-rw-r--r--Source/Core/InputCommon/Src/Android/ButtonManager.h63
-rw-r--r--Source/Core/InputCommon/Src/ControllerEmu.cpp19
-rw-r--r--Source/Core/InputCommon/Src/ControllerEmu.h36
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/Android/Android.cpp67
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/Android/Android.h57
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp34
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h11
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp41
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp26
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp42
-rw-r--r--Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp22
-rw-r--r--Source/Core/InputCommon/Src/GCPadStatus.h19
-rw-r--r--Source/Core/InputCommon/Src/InputConfig.cpp22
-rw-r--r--Source/Core/InputCommon/Src/InputConfig.h19
-rw-r--r--Source/Core/InputCommon/Src/UDPWiimote.cpp82
-rw-r--r--Source/Core/InputCommon/Src/UDPWiimote.h2
18 files changed, 481 insertions, 175 deletions
diff --git a/Source/Core/InputCommon/CMakeLists.txt b/Source/Core/InputCommon/CMakeLists.txt
index 3a8ea1e7a2..8fc2a344c7 100644
--- a/Source/Core/InputCommon/CMakeLists.txt
+++ b/Source/Core/InputCommon/CMakeLists.txt
@@ -21,6 +21,10 @@ elseif(X11_FOUND)
set(SRCS ${SRCS}
Src/ControllerInterface/SDL/SDL.cpp
Src/ControllerInterface/Xlib/Xlib.cpp)
+elseif(ANDROID)
+ set(SRCS ${SRCS}
+ Src/ControllerInterface/Android/Android.cpp
+ Src/Android/ButtonManager.cpp)
endif()
add_library(inputcommon ${SRCS})
diff --git a/Source/Core/InputCommon/Src/Android/ButtonManager.cpp b/Source/Core/InputCommon/Src/Android/ButtonManager.cpp
new file mode 100644
index 0000000000..947f7b0081
--- /dev/null
+++ b/Source/Core/InputCommon/Src/Android/ButtonManager.cpp
@@ -0,0 +1,90 @@
+// Copyright (C) 2003 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// 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
+// http://code.google.com/p/dolphin-emu/
+
+#include <vector>
+#include "GLInterface.h"
+#include "Android/TextureLoader.h"
+#include "Android/ButtonManager.h"
+
+extern void DrawButton(GLuint tex, float *coords);
+
+namespace ButtonManager
+{
+ std::vector<Button*> m_buttons;
+
+ // XXX: This needs to not be here so we can load the locations from file
+ // This will allow customizable button locations in the future
+ // These are the OpenGL on screen coordinates
+ float m_coords[][8] = { // X, Y, X, EY, EX, EY, EX, Y
+ {0.75f, -1.0f, 0.75f, -0.75f, 1.0f, -0.75f, 1.0f, -1.0f}, // A
+ {0.50f, -1.0f, 0.50f, -0.75f, 0.75f, -0.75f, 0.75f, -1.0f}, // B
+ {-0.10f, -1.0f, -0.10f, -0.80f, 0.10f, -0.80f, 0.10f, -1.0f}, // Start
+ };
+
+ void Init()
+ {
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ // Initialize our buttons
+ m_buttons.push_back(new Button("ButtonA.png", BUTTON_A, m_coords[0]));
+ m_buttons.push_back(new Button("ButtonB.png", BUTTON_B, m_coords[1]));
+ m_buttons.push_back(new Button("ButtonStart.png", BUTTON_START, m_coords[2]));
+ }
+ bool GetButtonPressed(ButtonType button)
+ {
+ for (auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
+ if ((*it)->GetButtonType() == button)
+ return (*it)->Pressed();
+ return false;
+ }
+ void TouchEvent(int action, float x, float y)
+ {
+ // Actions
+ // 0 is press
+ // 1 is let go
+ // 2 is move
+ for (auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
+ {
+ float *coords = (*it)->GetCoords();
+ if ( x >= coords[0] &&
+ x <= coords[4] &&
+ y >= coords[1] &&
+ y <= coords[3])
+ {
+ if (action == 0)
+ (*it)->SetState(BUTTON_PRESSED);
+ if (action == 1)
+ (*it)->SetState(BUTTON_RELEASED);
+ if (action == 2)
+ ; // XXX: Be used later for analog stick
+ }
+ }
+ }
+ void Shutdown()
+ {
+ for(auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
+ delete *it;
+ }
+
+ void DrawButtons()
+ {
+ for(auto it = m_buttons.begin(); it != m_buttons.end(); ++it)
+ DrawButton((*it)->GetTexture(), (*it)->GetCoords());
+ }
+
+}
diff --git a/Source/Core/InputCommon/Src/Android/ButtonManager.h b/Source/Core/InputCommon/Src/Android/ButtonManager.h
new file mode 100644
index 0000000000..f21ceedd98
--- /dev/null
+++ b/Source/Core/InputCommon/Src/Android/ButtonManager.h
@@ -0,0 +1,63 @@
+// Copyright (C) 2003 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// 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
+// http://code.google.com/p/dolphin-emu/
+
+#include <string>
+#include "CommonPaths.h"
+#include "Android/TextureLoader.h"
+
+namespace ButtonManager
+{
+ enum ButtonType
+ {
+ BUTTON_A = 0,
+ BUTTON_B,
+ BUTTON_START,
+ };
+ enum ButtonState
+ {
+ BUTTON_RELEASED = 0,
+ BUTTON_PRESSED = 1
+ };
+ class Button
+ {
+ private:
+ GLuint m_tex;
+ ButtonType m_button;
+ ButtonState m_state;
+ float m_coords[8];
+ public:
+ Button(std::string filename, ButtonType button, float *coords)
+ {
+ m_tex = LoadPNG((std::string(DOLPHIN_DATA_DIR "/") + filename).c_str());
+ m_button = button;
+ memcpy(m_coords, coords, sizeof(float) * 8);
+ m_state = BUTTON_RELEASED;
+ }
+ void SetState(ButtonState state) { m_state = state; }
+ bool Pressed() { return m_state == BUTTON_PRESSED; }
+ ButtonType GetButtonType() { return m_button; }
+ GLuint GetTexture() { return m_tex; }
+ float *GetCoords() { return m_coords; }
+
+ ~Button() { glDeleteTextures(1, &m_tex); }
+ };
+ void Init();
+ void DrawButtons();
+ bool GetButtonPressed(ButtonType button);
+ void TouchEvent(int action, float x, float y);
+ void Shutdown();
+}
diff --git a/Source/Core/InputCommon/Src/ControllerEmu.cpp b/Source/Core/InputCommon/Src/ControllerEmu.cpp
index 2e6ad10617..b7eee1a143 100644
--- a/Source/Core/InputCommon/Src/ControllerEmu.cpp
+++ b/Source/Core/InputCommon/Src/ControllerEmu.cpp
@@ -1,19 +1,6 @@
-// Copyright (C) 2010 Dolphin Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// 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
-// http://code.google.com/p/dolphin-emu/
+// Copyright 2013 Dolphin Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
#include "ControllerEmu.h"
diff --git a/Source/Core/InputCommon/Src/ControllerEmu.h b/Source/Core/InputCommon/Src/ControllerEmu.h
index 6084a610a1..33057434cd 100644
--- a/Source/Core/InputCommon/Src/ControllerEmu.h
+++ b/Source/Core/InputCommon/Src/ControllerEmu.h
@@ -1,19 +1,6 @@
-// Copyright (C) 2010 Dolphin Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// 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
-// http://code.google.com/p/dolphin-emu/
+// Copyright 2013 Dolphin Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
#ifndef _CONTROLLEREMU_H_
#define _CONTROLLEREMU_H_
@@ -153,7 +140,7 @@ public:
// deadzone / square stick code
if (deadzone || square)
{
- // this section might be all wrong, but its working good enough, i think
+ // this section might be all wrong, but its working good enough, I think
ControlState ang = atan2(yy, xx);
ControlState ang_sin = sin(ang);
@@ -163,7 +150,7 @@ public:
ControlState square_full = std::min(ang_sin ? 1/fabsf(ang_sin) : 2, ang_cos ? 1/fabsf(ang_cos) : 2);
// the amt a full stick would have that was ( user setting squareness) at current angle
- // i think this is more like a pointed circle rather than a rounded square like it should be
+ // I think this is more like a pointed circle rather than a rounded square like it should be
ControlState stick_full = (1 + (square_full - 1) * square);
ControlState dist = sqrt(xx*xx + yy*yy);
@@ -196,11 +183,15 @@ public:
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;
+ }
}
};
@@ -221,8 +212,9 @@ public:
*digital |= *bitmasks;
}
else
+ {
*analog = S(controls[i+trig_count]->control_ref->State() * range);
-
+ }
}
}
@@ -320,7 +312,7 @@ public:
// deadzone / circle stick code
if (deadzone || circle)
{
- // this section might be all wrong, but its working good enough, i think
+ // this section might be all wrong, but its working good enough, I think
ControlState ang = atan2(yy, xx);
ControlState ang_sin = sin(ang);
@@ -330,7 +322,7 @@ public:
ControlState square_full = std::min(ang_sin ? 1/fabsf(ang_sin) : 2, ang_cos ? 1/fabsf(ang_cos) : 2);
// the amt a full stick would have that was (user setting circular) at current angle
- // i think this is more like a pointed circle rather than a rounded square like it should be
+ // I think this is more like a pointed circle rather than a rounded square like it should be
ControlState stick_full = (square_full * (1 - circle)) + (circle);
ControlState dist = sqrt(xx*xx + yy*yy);
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.cpp b/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.cpp
new file mode 100644
index 0000000000..2d01d38f23
--- /dev/null
+++ b/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.cpp
@@ -0,0 +1,67 @@
+// Copyright (C) 2003 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// 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
+// http://code.google.com/p/dolphin-emu/
+
+#include "Android.h"
+
+namespace ciface
+{
+
+namespace Android
+{
+
+void Init( std::vector<ControllerInterface::Device*>& devices )
+{
+ devices.push_back(new Touchscreen());
+}
+
+// Touchscreens and stuff
+std::string Touchscreen::GetName() const
+{
+ return "Touchscreen";
+}
+
+std::string Touchscreen::GetSource() const
+{
+ return "Android";
+}
+
+int Touchscreen::GetId() const
+{
+ return 0;
+}
+Touchscreen::Touchscreen()
+{
+ AddInput(new Button(ButtonManager::BUTTON_A));
+ AddInput(new Button(ButtonManager::BUTTON_B));
+ AddInput(new Button(ButtonManager::BUTTON_START));
+}
+// Buttons and stuff
+
+std::string Touchscreen::Button::GetName() const
+{
+ std::ostringstream ss;
+ ss << "Button " << (int)m_index;
+ return ss.str();
+}
+
+ControlState Touchscreen::Button::GetState() const
+{
+ return ButtonManager::GetButtonPressed(m_index);
+}
+
+}
+}
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.h b/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.h
new file mode 100644
index 0000000000..9bdb52a61d
--- /dev/null
+++ b/Source/Core/InputCommon/Src/ControllerInterface/Android/Android.h
@@ -0,0 +1,57 @@
+// Copyright (C) 2003 Dolphin Project.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, version 2.0.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License 2.0 for more details.
+
+// 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
+// http://code.google.com/p/dolphin-emu/
+#ifndef _CIFACE_ANDROID_H_
+#define _CIFACE_ANDROID_H_
+
+#include "../ControllerInterface.h"
+#include "Android/ButtonManager.h"
+
+namespace ciface
+{
+namespace Android
+{
+
+void Init( std::vector<ControllerInterface::Device*>& devices );
+class Touchscreen : public ControllerInterface::Device
+{
+private:
+ class Button : public Input
+ {
+ public:
+ std::string GetName() const;
+ Button(ButtonManager::ButtonType index) : m_index(index) {}
+ ControlState GetState() const;
+ private:
+ const ButtonManager::ButtonType m_index;
+ };
+
+public:
+ bool UpdateInput() { return true; }
+ bool UpdateOutput() { return true; }
+
+ Touchscreen();
+ ~Touchscreen() {}
+
+ std::string GetName() const;
+ int GetId() const;
+ std::string GetSource() const;
+};
+
+}
+}
+
+#endif
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
index 8e96231674..6db79605a7 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.cpp
@@ -15,6 +15,9 @@
#ifdef CIFACE_USE_SDL
#include "SDL/SDL.h"
#endif
+#ifdef CIFACE_USE_ANDROID
+ #include "Android/Android.h"
+#endif
#include "Thread.h"
@@ -50,6 +53,9 @@ void ControllerInterface::Initialize()
#ifdef CIFACE_USE_SDL
ciface::SDL::Init(m_devices);
#endif
+#ifdef CIFACE_USE_ANDROID
+ ciface::Android::Init(m_devices);
+#endif
m_is_init = true;
}
@@ -100,6 +106,9 @@ void ControllerInterface::Shutdown()
// TODO: there seems to be some sort of memory leak with SDL, quit isn't freeing everything up
SDL_Quit();
#endif
+#ifdef CIFACE_USE_ANDROID
+ // nothing needed
+#endif
m_is_init = false;
}
@@ -157,7 +166,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;
@@ -173,7 +182,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()
{
@@ -209,9 +218,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()
@@ -239,8 +248,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)
{
@@ -354,7 +365,8 @@ bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface:
if (name == devq.name)
if (source == devq.source)
return true;
- return false;
+
+ return false;
}
//
@@ -421,7 +433,9 @@ void ControllerInterface::UpdateReference(ControllerInterface::ControlReference*
break; // no terminating '`' character
}
else
+ {
ctrl_str += c;
+ }
}
}
@@ -478,7 +492,9 @@ ControllerInterface::Device::Control* ControllerInterface::InputReference::Detec
return *i;
}
else if ((*i)->GetState() < (1 - INPUT_DETECT_THRESHOLD))
+ {
*state = false;
+ }
}
Common::SleepCurrentThread(10); time += 10;
}
@@ -490,8 +506,8 @@ 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
//
@@ -499,7 +515,7 @@ ControllerInterface::Device::Control* ControllerInterface::OutputReference::Dete
{
// 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);
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h
index b846bb56e8..8c1a044860 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h
+++ b/Source/Core/InputCommon/Src/ControllerInterface/ControllerInterface.h
@@ -29,14 +29,17 @@
#if defined(__APPLE__)
#define CIFACE_USE_OSX
#endif
-
-// idk in case i wanted to change it to double or somethin, idk what's best
+#ifdef ANDROID
+ #define CIFACE_USE_ANDROID
+#endif
+
+// idk in case I wanted to change it to double or something, idk what's best
typedef float ControlState;
//
// ControllerInterface
//
-// some crazy shit i made to control different device inputs and outputs
+// some crazy shit I made to control different device inputs and outputs
// from lots of different sources, hopefully more easily
//
class ControllerInterface
@@ -186,7 +189,7 @@ public:
//
// these are what you create to actually use the inputs, InputReference or OutputReference
//
- // after being binded to devices and controls with ControllerInterface::UpdateReference,
+ // after being bound to devices and controls with ControllerInterface::UpdateReference,
// each one can link to multiple devices and controls
// when you change a ControlReference's expression,
// you must use ControllerInterface::UpdateReference on it to rebind controls
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp
index 9bc5364e76..916d142149 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputJoystick.cpp
@@ -22,13 +22,13 @@ static const struct
} force_type_names[] =
{
{GUID_ConstantForce, "Constant"}, // DICONSTANTFORCE
- {GUID_RampForce, "Ramp"}, // DIRAMPFORCE
- {GUID_Square, "Square"}, // DIPERIODIC ...
+ {GUID_RampForce, "Ramp"}, // DIRAMPFORCE
+ {GUID_Square, "Square"}, // DIPERIODIC ...
{GUID_Sine, "Sine"},
{GUID_Triangle, "Triangle"},
{GUID_SawtoothUp, "Sawtooth Up"},
{GUID_SawtoothDown, "Sawtooth Down"},
- //{GUID_Spring, "Spring"}, // DICUSTOMFORCE ... < i think
+ //{GUID_Spring, "Spring"}, // DICUSTOMFORCE ... < I think
//{GUID_Damper, "Damper"},
//{GUID_Inertia, "Inertia"},
//{GUID_Friction, "Friction"},
@@ -70,9 +70,9 @@ void GetXInputGUIDS( std::vector<DWORD>& guids )
if( FAILED(hr) || pIWbemLocator == NULL )
goto LCleanup;
- bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto LCleanup;
- bstrClassName = SysAllocString( L"Win32_PNPEntity" ); if( bstrClassName == NULL ) goto LCleanup;
- bstrDeviceID = SysAllocString( L"DeviceID" ); if( bstrDeviceID == NULL ) goto LCleanup;
+ bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto LCleanup;
+ bstrClassName = SysAllocString( L"Win32_PNPEntity" ); if( bstrClassName == NULL ) goto LCleanup;
+ bstrDeviceID = SysAllocString( L"DeviceID" ); if( bstrDeviceID == NULL ) goto LCleanup;
// Connect to WMI
hr = pIWbemLocator->ConnectServer( bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices );
@@ -81,7 +81,7 @@ void GetXInputGUIDS( std::vector<DWORD>& guids )
// Switch security level to IMPERSONATE.
CoSetProxyBlanket( pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
- RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
+ RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
hr = pIWbemServices->CreateInstanceEnum( bstrClassName, 0, NULL, &pEnumDevices );
if( FAILED(hr) || pEnumDevices == NULL )
@@ -184,7 +184,7 @@ void InitJoystick(IDirectInput8* const idi8, std::vector<ControllerInterface::De
}
Joystick* js = new Joystick(/*&*i, */js_device, name_counts[i->tszInstanceName]++);
- // only add if it has some inputs/outpus
+ // only add if it has some inputs/outputs
if (js->Inputs().size() || js->Outputs().size())
devices.push_back(js);
else
@@ -196,7 +196,6 @@ void InitJoystick(IDirectInput8* const idi8, std::vector<ControllerInterface::De
js_device->Release();
}
}
-
}
}
@@ -226,7 +225,7 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
if (FAILED(m_device->GetCapabilities(&js_caps)))
return;
- // max of 32 buttons and 4 hats / the limit of the data format i am using
+ // max of 32 buttons and 4 hats / the limit of the data format I am using
js_caps.dwButtons = std::min((DWORD)32, js_caps.dwButtons);
js_caps.dwPOVs = std::min((DWORD)4, js_caps.dwPOVs);
@@ -258,9 +257,9 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
range.lMin = -(1 << 7);
range.lMax = (1 << 7);
m_device->SetProperty(DIPROP_RANGE, &range.diph);
- // but i guess not all devices support setting range
- // so i getproperty right afterward incase it didn't set :P
- // this also checks that the axis is present
+ // but I guess not all devices support setting range
+ // so I getproperty right afterward incase it didn't set.
+ // This also checks that the axis is present
if (SUCCEEDED(m_device->GetProperty(DIPROP_RANGE, &range.diph)))
{
const LONG base = (range.lMin + range.lMax) / 2;
@@ -319,9 +318,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)))
@@ -400,7 +403,7 @@ bool Joystick::UpdateInput()
HRESULT hr = 0;
// just always poll,
- // msdn says if this isn't needed it doesnt do anything
+ // MSDN says if this isn't needed it doesn't do anything
m_device->Poll();
if (m_buffered)
@@ -427,7 +430,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)
@@ -460,12 +465,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);
@@ -492,7 +501,9 @@ std::string Joystick::Axis::GetName() const
}
// slider
else
+ {
ss << "Slider " << (int)(m_index - 6);
+ }
ss << (m_range < 0 ? '-' : '+');
return ss.str();
@@ -527,7 +538,7 @@ ControlState Joystick::Button::GetState() const
ControlState Joystick::Hat::GetState() const
{
// can this func be simplified ?
- // hat centered code from msdn
+ // hat centered code from MSDN
if (0xFFFF == LOWORD(m_hat))
return 0;
return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2);
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp
index aea12c065c..ea6452376d 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/DInput/DInputKeyboardMouse.cpp
@@ -6,7 +6,7 @@
#include "DInput.h"
// (lower would be more sensitive) user can lower sensitivity by setting range
- // seems decent here ( at 8 ), I dont think anyone would need more sensitive than this
+ // seems decent here ( at 8 ), I don't think anyone would need more sensitive than this
// and user can lower it much farther than they would want to with the range
#define MOUSE_AXIS_SENSITIVITY 8
@@ -47,7 +47,7 @@ void InitKeyboardMouse(IDirectInput8* const idi8, std::vector<ControllerInterfac
hwnd = _hwnd;
// mouse and keyboard are a combined device, to allow shift+click and stuff
- // if thats dumb, i will make a VirtualDevice class that just uses ranges of inputs/outputs from other devices
+ // if that's dumb, I will make a VirtualDevice class that just uses ranges of inputs/outputs from other devices
// so there can be a separated Keyboard and mouse, as well as combined KeyboardMouse
LPDIRECTINPUTDEVICE8 kb_device = NULL;
@@ -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;
+ }
+ }
}
}
}
@@ -177,7 +181,7 @@ bool KeyboardMouse::UpdateInput()
if (SUCCEEDED(kb_hr) && SUCCEEDED(mo_hr))
{
- // need to smooth out the axes, otherwise it doesnt work for shit
+ // need to smooth out the axes, otherwise it doesn't work for shit
for (unsigned int i = 0; i < 3; ++i)
((&m_state_in.mouse.lX)[i] += (&tmp_mouse.lX)[i]) /= 2;
@@ -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;
}
};
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
index c5ee3af23f..6c74c55d97 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/SDL/SDL.cpp
@@ -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)
{
@@ -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)
@@ -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);
@@ -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;
@@ -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;
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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
diff --git a/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp b/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp
index 7fe54d0d09..3c7f3c48ae 100644
--- a/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp
+++ b/Source/Core/InputCommon/Src/ControllerInterface/XInput/XInput.cpp
@@ -31,13 +31,13 @@ static const struct
{ "Thumb R", XINPUT_GAMEPAD_RIGHT_THUMB }
};
-static const char* const named_triggers[] =
+static const char* const named_triggers[] =
{
"Trigger L",
"Trigger R"
};
-static const char* const named_axes[] =
+static const char* const named_axes[] =
{
"Left X",
"Left Y",
@@ -45,7 +45,7 @@ static const char* const named_axes[] =
"Right Y"
};
-static const char* const named_motors[] =
+static const char* const named_motors[] =
{
"Motor L",
"Motor R"
@@ -66,17 +66,19 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index)
ZeroMemory(&m_current_state_out, sizeof(m_current_state_out));
// XInputGetCaps seems to always claim all capabilities are supported
- // but i will leave all this stuff in, incase m$ fixes xinput up a bit
+ // but I will leave all this stuff in, incase m$ fixes xinput up a bit
// get supported buttons
for (int i = 0; i != sizeof(named_buttons)/sizeof(*named_buttons); ++i)
+ {
if (named_buttons[i].bitmask & caps.Gamepad.wButtons)
AddInput(new Button(i, m_state_in.Gamepad.wButtons));
+ }
// get supported triggers
for (int i = 0; i != sizeof(named_triggers)/sizeof(*named_triggers); ++i)
{
- //BYTE val = (&caps.Gamepad.bLeftTrigger)[i]; // should be max value / msdn lies
+ //BYTE val = (&caps.Gamepad.bLeftTrigger)[i]; // should be max value / MSDN lies
if ((&caps.Gamepad.bLeftTrigger)[i])
AddInput(new Trigger(i, (&m_state_in.Gamepad.bLeftTrigger)[i], 255 ));
}
@@ -84,7 +86,7 @@ Device::Device(const XINPUT_CAPABILITIES& caps, u8 index)
// get supported axes
for (int i = 0; i != sizeof(named_axes)/sizeof(*named_axes); ++i)
{
- //SHORT val = (&caps.Gamepad.sThumbLX)[i]; // xinput doesnt give the range / msdn is lier
+ //SHORT val = (&caps.Gamepad.sThumbLX)[i]; // xinput doesn't give the range / MSDN is a liar
if ((&caps.Gamepad.sThumbLX)[i])
{
const SHORT& ax = (&m_state_in.Gamepad.sThumbLX)[i];
@@ -114,8 +116,8 @@ void Device::ClearInputState()
std::string Device::GetName() const
{
// why aren't these defined
- // subtype doesn't seem to work, i tested with 2 diff arcade sticks, both were shown as gamepad
- // ill leave it in anyway, maybe m$ will fix it
+ // subtype doesn't seem to work, I tested with 2 different arcade sticks, both were shown as gamepad
+ // I'll leave it in anyway, maybe m$ will fix it
switch (m_subtype)
{
@@ -140,7 +142,7 @@ std::string Device::GetSource() const
return "XInput";
}
-// update i/o
+// Update I/O
bool Device::UpdateInput()
{
@@ -157,7 +159,9 @@ bool Device::UpdateOutput()
return (ERROR_SUCCESS == XInputSetState(m_index, &m_state_out));
}
else
+ {
return true;
+ }
}
// GET name/source/id
diff --git a/Source/Core/InputCommon/Src/GCPadStatus.h b/Source/Core/InputCommon/Src/GCPadStatus.h
index 835089a70d..c94f0b7fe8 100644
--- a/Source/Core/InputCommon/Src/GCPadStatus.h
+++ b/Source/Core/InputCommon/Src/GCPadStatus.h
@@ -1,19 +1,6 @@
-// Copyright (C) 2003 Dolphin Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// 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
-// http://code.google.com/p/dolphin-emu/
+// Copyright 2013 Dolphin Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
#ifndef _GCPAD_H_INCLUDED__
#define _GCPAD_H_INCLUDED__
diff --git a/Source/Core/InputCommon/Src/InputConfig.cpp b/Source/Core/InputCommon/Src/InputConfig.cpp
index 1988a9ebb7..65529b0a3f 100644
--- a/Source/Core/InputCommon/Src/InputConfig.cpp
+++ b/Source/Core/InputCommon/Src/InputConfig.cpp
@@ -1,19 +1,6 @@
-// Copyright (C) 2010 Dolphin Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// 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
-// http://code.google.com/p/dolphin-emu/
+// Copyright 2013 Dolphin Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
#include "InputConfig.h"
#include "../../Core/Src/ConfigManager.h"
@@ -78,7 +65,10 @@ bool InputPlugin::LoadConfig(bool isGC)
(*i)->LoadConfig(profile_ini.GetOrCreateSection("Profile"));
}
else
+ {
(*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
+ }
+
// update refs
(*i)->UpdateReferences(g_controller_interface);
}
diff --git a/Source/Core/InputCommon/Src/InputConfig.h b/Source/Core/InputCommon/Src/InputConfig.h
index 71505bb935..0d14f325d1 100644
--- a/Source/Core/InputCommon/Src/InputConfig.h
+++ b/Source/Core/InputCommon/Src/InputConfig.h
@@ -1,19 +1,6 @@
-// Copyright (C) 2010 Dolphin Project.
-
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 2.0.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License 2.0 for more details.
-
-// 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
-// http://code.google.com/p/dolphin-emu/
+// Copyright 2013 Dolphin Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
#ifndef _CONFIG_H_
#define _CONFIG_H_
diff --git a/Source/Core/InputCommon/Src/UDPWiimote.cpp b/Source/Core/InputCommon/Src/UDPWiimote.cpp
index f14f9ed7e2..e0cf787e0f 100644
--- a/Source/Core/InputCommon/Src/UDPWiimote.cpp
+++ b/Source/Core/InputCommon/Src/UDPWiimote.cpp
@@ -96,32 +96,39 @@ UDPWiimote::UDPWiimote(const char *_port, const char * name, int _index) :
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE; // use my IP
- if (!int_port){
+ if (!int_port)
+ {
cleanup;
err=-1;
return;
}
- if ((rv = getaddrinfo(NULL, _port, &hints, &servinfo)) != 0) {
+ if ((rv = getaddrinfo(NULL, _port, &hints, &servinfo)) != 0)
+ {
cleanup;
err=-1;
return;
}
// loop through all the results and bind to everything we can
- for(p = servinfo; p != NULL; p = p->ai_next) {
+ for(p = servinfo; p != NULL; p = p->ai_next)
+ {
sock_t sock;
- if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == BAD_SOCK) {
+ if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == BAD_SOCK)
+ {
continue;
}
- if (bind(sock, p->ai_addr, (int)p->ai_addrlen) == -1) {
+
+ if (bind(sock, p->ai_addr, (int)p->ai_addrlen) == -1)
+ {
close(sock);
continue;
}
d->sockfds.push_back(sock);
}
- if (d->sockfds.empty()) {
+ if (d->sockfds.empty())
+ {
cleanup;
err=-2;
return;
@@ -170,7 +177,9 @@ void UDPWiimote::mainThread()
timeout.tv_sec=1;
timeout.tv_usec=500000;
broadcastPresence();
- } else {
+ }
+ else
+ {
tleft-=telapsed;
timeout.tv_sec=(long)(tleft/1000);
timeout.tv_usec=(tleft%1000)*1000;
@@ -186,6 +195,7 @@ void UDPWiimote::mainThread()
if (rt)
{
for (std::list<sock_t>::iterator i=d->sockfds.begin(); i!=d->sockfds.end(); i++)
+ {
if (FD_ISSET(*i,&fds))
{
sock_t fd=*i;
@@ -206,11 +216,14 @@ void UDPWiimote::mainThread()
if (pharsePacket(bf,size)==0)
{
//NOTICE_LOG(WIIMOTE,"UDPWII New pack");
- } else {
+ }
+ else
+ {
//NOTICE_LOG(WIIMOTE,"UDPWII Wrong pack format... ignoring");
}
}
}
+ }
}
} while (!(d->exit));
}
@@ -230,16 +243,18 @@ UDPWiimote::~UDPWiimote()
delete d;
}
-#define ACCEL_FLAG (1<<0)
-#define BUTT_FLAG (1<<1)
-#define IR_FLAG (1<<2)
-#define NUN_FLAG (1<<3)
-#define NUNACCEL_FLAG (1<<4)
+#define ACCEL_FLAG (1 << 0)
+#define BUTT_FLAG (1 << 1)
+#define IR_FLAG (1 << 2)
+#define NUN_FLAG (1 << 3)
+#define NUNACCEL_FLAG (1 << 4)
int UDPWiimote::pharsePacket(u8 * bf, size_t size)
{
- if (size<3) return -1;
- if (bf[0]!=0xde)
+ if (size < 3)
+ return -1;
+
+ if (bf[0] != 0xde)
return -1;
//if (bf[1]==0)
// time=0;
@@ -247,9 +262,11 @@ int UDPWiimote::pharsePacket(u8 * bf, size_t size)
// return -1;
//time=bf[1];
u32 *p=(u32*)(&bf[3]);
- if (bf[2]&ACCEL_FLAG)
+ if (bf[2] & ACCEL_FLAG)
{
- if ((size-(((u8*)p)-bf))<12) return -1;
+ if ((size-(((u8*)p)-bf)) < 12)
+ return -1;
+
double ux,uy,uz;
ux=(double)((s32)ntohl(*p)); p++;
uy=(double)((s32)ntohl(*p)); p++;
@@ -258,27 +275,39 @@ int UDPWiimote::pharsePacket(u8 * bf, size_t size)
y=uy/1048576;
z=uz/1048576;
}
- if (bf[2]&BUTT_FLAG)
+
+ if (bf[2] & BUTT_FLAG)
{
- if ((size-(((u8*)p)-bf))<4) return -1;
+ if ((size-(((u8*)p)-bf)) < 4)
+ return -1;
+
mask=ntohl(*p); p++;
}
- if (bf[2]&IR_FLAG)
+
+ if (bf[2] & IR_FLAG)
{
- if ((size-(((u8*)p)-bf))<8) return -1;
+ if ((size-(((u8*)p)-bf)) < 8)
+ return -1;
+
pointerX=((double)((s32)ntohl(*p)))/1048576; p++;
pointerY=((double)((s32)ntohl(*p)))/1048576; p++;
}
- if (bf[2]&NUN_FLAG)
+
+ if (bf[2] & NUN_FLAG)
{
- if ((size-(((u8*)p)-bf))<9) return -1;
+ if ((size-(((u8*)p)-bf)) < 9)
+ return -1;
+
nunMask=*((u8*)p); p=(u32*)(((u8*)p)+1);
nunX=((double)((s32)ntohl(*p)))/1048576; p++;
nunY=((double)((s32)ntohl(*p)))/1048576; p++;
}
- if (bf[2]&NUNACCEL_FLAG)
+
+ if (bf[2] & NUNACCEL_FLAG)
{
- if ((size-(((u8*)p)-bf))<12) return -1;
+ if ((size-(((u8*)p)-bf)) < 12)
+ return -1;
+
double ux,uy,uz;
ux=(double)((s32)ntohl(*p)); p++;
uy=(double)((s32)ntohl(*p)); p++;
@@ -287,6 +316,7 @@ int UDPWiimote::pharsePacket(u8 * bf, size_t size)
naY=uy/1048576;
naZ=uz/1048576;
}
+
return 0;
}
@@ -314,7 +344,7 @@ void UDPWiimote::broadcastIPv4(const void * data, size_t size)
their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(4431);
their_addr.sin_addr.s_addr = INADDR_BROADCAST;
- memset(their_addr.sin_zero, '\0', sizeof their_addr.sin_zero);
+ memset(their_addr.sin_zero, '\0', sizeof their_addr.sin_zero);
int num;
if ((num=sendto(d->bipv4_fd,(const dataz)data,(int)size,0,(struct sockaddr *) &their_addr, sizeof their_addr)) == -1)
diff --git a/Source/Core/InputCommon/Src/UDPWiimote.h b/Source/Core/InputCommon/Src/UDPWiimote.h
index 1be83dbf74..01b9b11969 100644
--- a/Source/Core/InputCommon/Src/UDPWiimote.h
+++ b/Source/Core/InputCommon/Src/UDPWiimote.h
@@ -37,7 +37,7 @@ public:
private:
std::string port,displayName;
int pharsePacket(u8 * data, size_t size);
- struct _d; //using pimpl because Winsock2.h doesen't have include guards -_-
+ struct _d; //using pimpl because Winsock2.h doesn't have include guards -_-
_d *d;
double x,y,z;
double naX,naY,naZ;