summaryrefslogtreecommitdiffhomepage
path: root/dinput
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-06-26 22:25:22 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-06-26 23:05:21 +0200
commitd65936200a2756e6619a109fa6fa673b91df802e (patch)
tree80b6b6fc7ba9023cbe47290b8ae1bc5468a19bb1 /dinput
parent4046773c41ee3c0f65840828ab983cfd13451c85 (diff)
modernize C++ syntax
No visible changes (hopefully).
Diffstat (limited to 'dinput')
-rw-r--r--dinput/keybinding-worker.cpp12
-rw-r--r--dinput/keybinding-worker.hpp4
-rw-r--r--dinput/win32-joystick.cpp16
-rw-r--r--dinput/win32-joystick.hpp4
4 files changed, 18 insertions, 18 deletions
diff --git a/dinput/keybinding-worker.cpp b/dinput/keybinding-worker.cpp
index 40754b4f..0bdc18cd 100644
--- a/dinput/keybinding-worker.cpp
+++ b/dinput/keybinding-worker.cpp
@@ -47,7 +47,7 @@ bool KeybindingWorker::init()
return false;
}
- if (din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, NULL) != DI_OK) {
+ if (din->CreateDevice(GUID_SysKeyboard, &dinkeyboard, nullptr) != DI_OK) {
qDebug() << "setup CreateDevice function failed!" << GetLastError();
return false;
}
@@ -55,13 +55,13 @@ bool KeybindingWorker::init()
if (dinkeyboard->SetDataFormat(&c_dfDIKeyboard) != DI_OK) {
qDebug() << "setup SetDataFormat function failed!" << GetLastError();
dinkeyboard->Release();
- dinkeyboard = 0;
+ dinkeyboard = nullptr;
return false;
}
if (dinkeyboard->SetCooperativeLevel((HWND) fake_main_window.winId(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK) {
dinkeyboard->Release();
- dinkeyboard = 0;
+ dinkeyboard = nullptr;
qDebug() << "setup SetCooperativeLevel function failed!" << GetLastError();
return false;
}
@@ -77,7 +77,7 @@ bool KeybindingWorker::init()
{
qDebug() << "setup keyboard buffer mode failed!";
dinkeyboard->Release();
- dinkeyboard = 0;
+ dinkeyboard = nullptr;
return false;
}
}
@@ -85,7 +85,7 @@ bool KeybindingWorker::init()
if (dinkeyboard->Acquire() != DI_OK)
{
dinkeyboard->Release();
- dinkeyboard = 0;
+ dinkeyboard = nullptr;
qDebug() << "setup dinkeyboard Acquire failed!" << GetLastError();
return false;
}
@@ -112,7 +112,7 @@ void KeybindingWorker::run()
{
QMutexLocker l(&mtx);
- if (receivers.size())
+ if (!receivers.empty())
{
/* There are some problems reported on various forums
* with regard to key-up events. But that's what I dug up:
diff --git a/dinput/keybinding-worker.hpp b/dinput/keybinding-worker.hpp
index 2596bda0..7481bcea 100644
--- a/dinput/keybinding-worker.hpp
+++ b/dinput/keybinding-worker.hpp
@@ -42,7 +42,7 @@ struct OTR_DINPUT_EXPORT KeybindingWorker : private QThread
using fun = std::function<void(const Key&)>;
private:
- LPDIRECTINPUTDEVICE8 dinkeyboard;
+ LPDIRECTINPUTDEVICE8 dinkeyboard { nullptr };
win32_joy_ctx joy_ctx;
std::vector<std::unique_ptr<fun>> receivers;
QMutex mtx;
@@ -62,7 +62,7 @@ private:
~KeybindingWorker();
static constexpr int num_keyboard_states = 16;
- DIDEVICEOBJECTDATA keyboard_states[num_keyboard_states];
+ DIDEVICEOBJECTDATA keyboard_states[num_keyboard_states] {};
KeybindingWorker(const KeybindingWorker&) = delete;
KeybindingWorker& operator=(KeybindingWorker&) = delete;
diff --git a/dinput/win32-joystick.cpp b/dinput/win32-joystick.cpp
index e9a6c4ed..ed5bd214 100644
--- a/dinput/win32-joystick.cpp
+++ b/dinput/win32-joystick.cpp
@@ -17,11 +17,11 @@ DIDEVICEOBJECTDATA win32_joy_ctx::joy::keystate_buffers[win32_joy_ctx::joy::num_
QMutex win32_joy_ctx::enum_state::mtx;
win32_joy_ctx::enum_state win32_joy_ctx::enumerator;
-void win32_joy_ctx::poll(fn f)
+void win32_joy_ctx::poll(fn const& f)
{
//refresh(false);
- QMutexLocker l(&enumerator.mtx);
+ QMutexLocker l(&enum_state::mtx);
auto& joys = enumerator.get_joys();
@@ -33,7 +33,7 @@ void win32_joy_ctx::poll(fn f)
bool win32_joy_ctx::poll_axis(const QString &guid, int* axes)
{
- QMutexLocker l(&enumerator.mtx);
+ QMutexLocker l(&enum_state::mtx);
for (int k = 0; k < 10; k++)
{
@@ -102,7 +102,7 @@ bool win32_joy_ctx::poll_axis(const QString &guid, int* axes)
std::vector<win32_joy_ctx::joy_info> win32_joy_ctx::get_joy_info()
{
std::vector<joy_info> ret;
- QMutexLocker l(&enumerator.mtx);
+ QMutexLocker l(&enum_state::mtx);
auto& joys = enumerator.get_joys();
ret.reserve(joys.size());
@@ -121,7 +121,7 @@ win32_joy_ctx::win32_joy_ctx()
void win32_joy_ctx::refresh()
{
- QMutexLocker l(&enumerator.mtx);
+ QMutexLocker l(&enum_state::mtx);
enumerator.refresh();
}
@@ -131,7 +131,7 @@ QString win32_joy_ctx::guid_to_string(const GUID& guid)
wchar_t szGuidW[40] = {0};
StringFromGUID2(guid, szGuidW, 40);
- WideCharToMultiByte(0, 0, szGuidW, -1, buf, 40, NULL, NULL);
+ WideCharToMultiByte(0, 0, szGuidW, -1, buf, 40, nullptr, nullptr);
return QString(buf);
}
@@ -148,7 +148,7 @@ void win32_joy_ctx::joy::release()
}
}
-bool win32_joy_ctx::joy::poll(fn f)
+bool win32_joy_ctx::joy::poll(fn const& f)
{
HRESULT hr;
@@ -380,7 +380,7 @@ BOOL CALLBACK win32_joy_ctx::enum_state::EnumObjectsCallback(const DIDEVICEOBJEC
return DIENUM_CONTINUE;
}
-win32_joy_ctx::joy::joy(LPDIRECTINPUTDEVICE8 handle, const QString &guid, const QString &name)
+win32_joy_ctx::joy::joy(LPDIRECTINPUTDEVICE8 handle, const QString& guid, const QString &name)
: joy_handle(handle), guid(guid), name(name)
{
//qDebug() << "make joy" << guid << name << joy_handle;
diff --git a/dinput/win32-joystick.hpp b/dinput/win32-joystick.hpp
index 8b71b8b7..f42bd450 100644
--- a/dinput/win32-joystick.hpp
+++ b/dinput/win32-joystick.hpp
@@ -54,7 +54,7 @@ struct OTR_DINPUT_EXPORT win32_joy_ctx final
~joy();
void release();
- bool poll(fn f);
+ bool poll(fn const& f);
};
using joys_t = std::unordered_map<QString, std::shared_ptr<joy>>;
@@ -66,7 +66,7 @@ struct OTR_DINPUT_EXPORT win32_joy_ctx final
QString name, guid;
};
- void poll(fn f);
+ void poll(fn const& f);
bool poll_axis(const QString& guid, int* axes);
std::vector<joy_info> get_joy_info();