From f66fd46b2da630962302cb5da7a5de006337a1b7 Mon Sep 17 00:00:00 2001 From: Andrey Lihatskiy Date: Thu, 14 May 2020 07:51:08 +0000 Subject: Merged in SL-12090 (pull request #105) SL-12090 Initialize the joystick only when required * SL-12090 Initialize the joystick only when required Approved-by: Andrey Kleshchev --- indra/newview/llfloaterjoystick.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'indra/newview/llfloaterjoystick.cpp') diff --git a/indra/newview/llfloaterjoystick.cpp b/indra/newview/llfloaterjoystick.cpp index ee3d633dd0..2b672bc890 100644 --- a/indra/newview/llfloaterjoystick.cpp +++ b/indra/newview/llfloaterjoystick.cpp @@ -61,6 +61,11 @@ static LLTrace::SampleStatHandle<>* sJoystickAxes[6] = LLFloaterJoystick::LLFloaterJoystick(const LLSD& data) : LLFloater(data) { + if (!LLViewerJoystick::getInstance()->isJoystickInitialized()) + { + LLViewerJoystick::getInstance()->init(false); + } + initFromSettings(); } -- cgit v1.2.3 From 0fbe4cf62a236ea24f383818bf81b933f87380d8 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Thu, 9 Jul 2020 23:59:38 +0300 Subject: SL-5894 #2 WIP Changes to display multiple joystick devices --- indra/newview/llfloaterjoystick.cpp | 69 ++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 12 deletions(-) (limited to 'indra/newview/llfloaterjoystick.cpp') diff --git a/indra/newview/llfloaterjoystick.cpp b/indra/newview/llfloaterjoystick.cpp index 2b672bc890..4538d34c95 100644 --- a/indra/newview/llfloaterjoystick.cpp +++ b/indra/newview/llfloaterjoystick.cpp @@ -41,6 +41,7 @@ #include "llappviewer.h" #include "llviewerjoystick.h" #include "llcheckboxctrl.h" +#include "llcombobox.h" static LLTrace::SampleStatHandle<> sJoystickAxis0("Joystick axis 0"), sJoystickAxis1("Joystick axis 1"), @@ -59,7 +60,8 @@ static LLTrace::SampleStatHandle<>* sJoystickAxes[6] = }; LLFloaterJoystick::LLFloaterJoystick(const LLSD& data) - : LLFloater(data) + : LLFloater(data), + mHasDeviceList(false) { if (!LLViewerJoystick::getInstance()->isJoystickInitialized()) { @@ -71,14 +73,13 @@ LLFloaterJoystick::LLFloaterJoystick(const LLSD& data) void LLFloaterJoystick::draw() { - bool joystick_inited = LLViewerJoystick::getInstance()->isJoystickInitialized(); - getChildView("enable_joystick")->setEnabled(joystick_inited); - getChildView("joystick_type")->setEnabled(joystick_inited); - std::string desc = LLViewerJoystick::getInstance()->getDescription(); - if (desc.empty()) desc = getString("NoDevice"); - getChild("joystick_type")->setValue(desc); - - LLViewerJoystick* joystick(LLViewerJoystick::getInstance()); + LLViewerJoystick* joystick(LLViewerJoystick::getInstance()); + bool joystick_inited = joystick->isJoystickInitialized(); + if (joystick_inited != mHasDeviceList) + { + refreshListOfDevices(); + } + for (U32 i = 0; i < 6; i++) { F32 value = joystick->getJoystickAxis(i); @@ -115,8 +116,8 @@ BOOL LLFloaterJoystick::postBuild() } } - mCheckJoystickEnabled = getChild("enable_joystick"); - childSetCommitCallback("enable_joystick",onCommitJoystickEnabled,this); + mJoysticksCombo = getChild("joystick_combo"); + childSetCommitCallback("joystick_combo",onCommitJoystickEnabled,this); mCheckFlycamEnabled = getChild("JoystickFlycamEnabled"); childSetCommitCallback("JoystickFlycamEnabled",onCommitJoystickEnabled,this); @@ -125,6 +126,7 @@ BOOL LLFloaterJoystick::postBuild() childSetAction("ok_btn", onClickOK, this); refresh(); + refreshListOfDevices(); return TRUE; } @@ -210,9 +212,36 @@ void LLFloaterJoystick::initFromSettings() void LLFloaterJoystick::refresh() { LLFloater::refresh(); + initFromSettings(); } +void LLFloaterJoystick::refreshListOfDevices() +{ + mJoysticksCombo->removeall(); + mJoysticksCombo->add(getString("JoystickDisabled"), LLSD(LLSD::Integer(0)), ADD_BOTTOM, 1); + + mHasDeviceList = false; + std::string desc = LLViewerJoystick::getInstance()->getDescription(); + if (!desc.empty()) + { + mJoysticksCombo->add(desc, LLSD(LLSD::Integer(1)), ADD_BOTTOM, 1); + mHasDeviceList = true; + } + + //todo: load list of devices + + if (gSavedSettings.getBOOL("JoystickEnabled") && mHasDeviceList) + { + // todo: select device according to data from LLViewerJoystick + mJoysticksCombo->selectByValue(LLSD::Integer(1)); + } + else + { + mJoysticksCombo->selectByValue(LLSD::Integer(0)); + } +} + void LLFloaterJoystick::cancel() { gSavedSettings.setBOOL("JoystickEnabled", mJoystickEnabled); @@ -285,7 +314,21 @@ void LLFloaterJoystick::cancel() void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel) { LLFloaterJoystick* self = (LLFloaterJoystick*)joy_panel; - BOOL joystick_enabled = self->mCheckJoystickEnabled->get(); + + LLSD value = self->mJoysticksCombo->getValue(); + bool joystick_enabled = true; + if (value.isInteger()) + { + joystick_enabled = value.asInteger(); + // ndof already has a device selected, we are just setting it enabled or disabled + } + else + { + // else joystick is enabled, because combobox holds id of device + joystick_enabled = true; + // todo: make LLViewerJoystick select a device based on value + } + gSavedSettings.setBOOL("JoystickEnabled", joystick_enabled); BOOL flycam_enabled = self->mCheckFlycamEnabled->get(); if (!joystick_enabled || !flycam_enabled) @@ -297,6 +340,8 @@ void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel) joystick->toggleFlycam(); } } + + self->refreshListOfDevices(); } void LLFloaterJoystick::onClickRestoreSNDefaults(void *joy_panel) -- cgit v1.2.3 From 54383cac8fa8a40d96590a300d4fce618f7413f3 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Fri, 10 Jul 2020 20:48:43 +0300 Subject: SL-5894 #3 WIP enumerate devices to flaoter, let floater set device temp --- indra/newview/llfloaterjoystick.cpp | 87 ++++++++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 7 deletions(-) (limited to 'indra/newview/llfloaterjoystick.cpp') diff --git a/indra/newview/llfloaterjoystick.cpp b/indra/newview/llfloaterjoystick.cpp index 4538d34c95..79814de28d 100644 --- a/indra/newview/llfloaterjoystick.cpp +++ b/indra/newview/llfloaterjoystick.cpp @@ -40,9 +40,21 @@ #include "llviewercontrol.h" #include "llappviewer.h" #include "llviewerjoystick.h" +#include "llviewerwindow.h" +#include "llwindow.h" #include "llcheckboxctrl.h" #include "llcombobox.h" +#if LL_WINDOWS && !LL_MESA_HEADLESS +// Require DirectInput version 8 +#define DIRECTINPUT_VERSION 0x0800 + +//#include +//#pragma comment(lib, "dinput8") +//#pragma comment(lib, "dxguid.lib") +#include +#endif + static LLTrace::SampleStatHandle<> sJoystickAxis0("Joystick axis 0"), sJoystickAxis1("Joystick axis 1"), sJoystickAxis2("Joystick axis 2"), @@ -59,6 +71,29 @@ static LLTrace::SampleStatHandle<>* sJoystickAxes[6] = &sJoystickAxis5 }; + +#if LL_WINDOWS && !LL_MESA_HEADLESS + +BOOL CALLBACK di8_list_devices_callback(LPCDIDEVICEINSTANCE device_instance_ptr, LPVOID pvRef) +{ + // Note: If a single device can function as more than one DirectInput + // device type, it is enumerated as each device type that it supports. + // Capable of detecting devices like Oculus Rift + if (device_instance_ptr && pvRef) + { + std::string product_name = utf16str_to_utf8str(llutf16string(device_instance_ptr->tszProductName)); + S32 size = sizeof(GUID); + LLSD::Binary data; //just an std::vector + data.resize(size); + memcpy(&data[0], &device_instance_ptr->guidInstance /*POD _GUID*/, size); + + LLFloaterJoystick * floater = (LLFloaterJoystick*)pvRef; + floater->addDevice(product_name, LLSD(data)); + } + return DIENUM_CONTINUE; +} +#endif + LLFloaterJoystick::LLFloaterJoystick(const LLSD& data) : LLFloater(data), mHasDeviceList(false) @@ -216,25 +251,62 @@ void LLFloaterJoystick::refresh() initFromSettings(); } +void LLFloaterJoystick::addDevice(std::string &name, LLSD& value) +{ + mJoysticksCombo->add(name, value, ADD_BOTTOM, 1); +} + void LLFloaterJoystick::refreshListOfDevices() { mJoysticksCombo->removeall(); - mJoysticksCombo->add(getString("JoystickDisabled"), LLSD(LLSD::Integer(0)), ADD_BOTTOM, 1); + std::string no_device = getString("JoystickDisabled"); + addDevice(no_device, LLSD(LLSD::Integer(0))); mHasDeviceList = false; - std::string desc = LLViewerJoystick::getInstance()->getDescription(); - if (!desc.empty()) + + // di8_devices_callback callback is immediate and happens in scope of getInputDevices() +#if LL_WINDOWS && !LL_MESA_HEADLESS + // space navigator is marked as DI8DEVCLASS_GAMECTRL in ndof lib + U32 device_type = DI8DEVCLASS_GAMECTRL; + void* callback = &di8_list_devices_callback; +#elif + // MAC doesn't support device search yet + // On MAC there is an ndof_idsearch and it is possible to specify product + // and manufacturer in NDOF_Device for ndof_init_first to pick specific one + U32 device_type = 0; + void* callback = NULL; +#endif + if (gViewerWindow->getWindow()->getInputDevices(device_type, callback, this)) { - mJoysticksCombo->add(desc, LLSD(LLSD::Integer(1)), ADD_BOTTOM, 1); mHasDeviceList = true; } - //todo: load list of devices + LLSD guid = LLViewerJoystick::getInstance()->getDeviceUUID(); + + if (LLViewerJoystick::getInstance()->isJoystickInitialized() && + (!mHasDeviceList || !guid.isBinary())) + { +#if LL_WINDOWS && !LL_MESA_HEADLESS + LL_WARNS() << "NDOF connected to device without using SL provided handle" << LL_ENDL; +#endif + std::string desc = LLViewerJoystick::getInstance()->getDescription(); + if (!desc.empty()) + { + addDevice(desc, LLSD(LLSD::Integer(1))); + mHasDeviceList = true; + } + } if (gSavedSettings.getBOOL("JoystickEnabled") && mHasDeviceList) { - // todo: select device according to data from LLViewerJoystick - mJoysticksCombo->selectByValue(LLSD::Integer(1)); + if (guid.isBinary()) + { + mJoysticksCombo->selectByValue(guid); + } + else + { + mJoysticksCombo->selectByValue(LLSD::Integer(1)); + } } else { @@ -324,6 +396,7 @@ void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel) } else { + LLViewerJoystick::getInstance()->initDevice(value); // else joystick is enabled, because combobox holds id of device joystick_enabled = true; // todo: make LLViewerJoystick select a device based on value -- cgit v1.2.3 From 8c66f54cfa9b1d26271338b7629290b35222617f Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 14 Jul 2020 00:28:21 +0300 Subject: SL-5894 #4 Organize device storage between sessions --- indra/newview/llfloaterjoystick.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'indra/newview/llfloaterjoystick.cpp') diff --git a/indra/newview/llfloaterjoystick.cpp b/indra/newview/llfloaterjoystick.cpp index 79814de28d..93a26f31cc 100644 --- a/indra/newview/llfloaterjoystick.cpp +++ b/indra/newview/llfloaterjoystick.cpp @@ -49,9 +49,6 @@ // Require DirectInput version 8 #define DIRECTINPUT_VERSION 0x0800 -//#include -//#pragma comment(lib, "dinput8") -//#pragma comment(lib, "dxguid.lib") #include #endif @@ -88,7 +85,8 @@ BOOL CALLBACK di8_list_devices_callback(LPCDIDEVICEINSTANCE device_instance_ptr, memcpy(&data[0], &device_instance_ptr->guidInstance /*POD _GUID*/, size); LLFloaterJoystick * floater = (LLFloaterJoystick*)pvRef; - floater->addDevice(product_name, LLSD(data)); + LLSD value = data; + floater->addDevice(product_name, value); } return DIENUM_CONTINUE; } @@ -178,6 +176,7 @@ void LLFloaterJoystick::apply() void LLFloaterJoystick::initFromSettings() { mJoystickEnabled = gSavedSettings.getBOOL("JoystickEnabled"); + mJoystickId = gSavedSettings.getLLSD("JoystickDeviceUUID"); mJoystickAxis[0] = gSavedSettings.getS32("JoystickAxis0"); mJoystickAxis[1] = gSavedSettings.getS32("JoystickAxis1"); @@ -260,7 +259,8 @@ void LLFloaterJoystick::refreshListOfDevices() { mJoysticksCombo->removeall(); std::string no_device = getString("JoystickDisabled"); - addDevice(no_device, LLSD(LLSD::Integer(0))); + LLSD value = LLSD::Integer(0); + addDevice(no_device, value); mHasDeviceList = false; @@ -269,7 +269,7 @@ void LLFloaterJoystick::refreshListOfDevices() // space navigator is marked as DI8DEVCLASS_GAMECTRL in ndof lib U32 device_type = DI8DEVCLASS_GAMECTRL; void* callback = &di8_list_devices_callback; -#elif +#else // MAC doesn't support device search yet // On MAC there is an ndof_idsearch and it is possible to specify product // and manufacturer in NDOF_Device for ndof_init_first to pick specific one @@ -281,10 +281,10 @@ void LLFloaterJoystick::refreshListOfDevices() mHasDeviceList = true; } - LLSD guid = LLViewerJoystick::getInstance()->getDeviceUUID(); + bool is_device_id_set = LLViewerJoystick::getInstance()->isDeviceUUIDSet(); if (LLViewerJoystick::getInstance()->isJoystickInitialized() && - (!mHasDeviceList || !guid.isBinary())) + (!mHasDeviceList || !is_device_id_set)) { #if LL_WINDOWS && !LL_MESA_HEADLESS LL_WARNS() << "NDOF connected to device without using SL provided handle" << LL_ENDL; @@ -292,15 +292,17 @@ void LLFloaterJoystick::refreshListOfDevices() std::string desc = LLViewerJoystick::getInstance()->getDescription(); if (!desc.empty()) { - addDevice(desc, LLSD(LLSD::Integer(1))); + LLSD value = LLSD::Integer(0); + addDevice(desc, value); mHasDeviceList = true; } } if (gSavedSettings.getBOOL("JoystickEnabled") && mHasDeviceList) { - if (guid.isBinary()) + if (is_device_id_set) { + LLSD guid = LLViewerJoystick::getInstance()->getDeviceUUID(); mJoysticksCombo->selectByValue(guid); } else @@ -317,6 +319,7 @@ void LLFloaterJoystick::refreshListOfDevices() void LLFloaterJoystick::cancel() { gSavedSettings.setBOOL("JoystickEnabled", mJoystickEnabled); + gSavedSettings.setLLSD("JoystickDeviceUUID", mJoystickId); gSavedSettings.setS32("JoystickAxis0", mJoystickAxis[0]); gSavedSettings.setS32("JoystickAxis1", mJoystickAxis[1]); @@ -391,15 +394,14 @@ void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel) bool joystick_enabled = true; if (value.isInteger()) { - joystick_enabled = value.asInteger(); // ndof already has a device selected, we are just setting it enabled or disabled + joystick_enabled = value.asInteger(); } else { LLViewerJoystick::getInstance()->initDevice(value); // else joystick is enabled, because combobox holds id of device joystick_enabled = true; - // todo: make LLViewerJoystick select a device based on value } gSavedSettings.setBOOL("JoystickEnabled", joystick_enabled); BOOL flycam_enabled = self->mCheckFlycamEnabled->get(); @@ -414,6 +416,10 @@ void LLFloaterJoystick::onCommitJoystickEnabled(LLUICtrl*, void *joy_panel) } } + std::string device_id = LLViewerJoystick::getInstance()->getDeviceUUIDString(); + gSavedSettings.setString("JoystickDeviceUUID", device_id); + LL_DEBUGS("Joystick") << "Selected " << device_id << " as joystick." << LL_ENDL; + self->refreshListOfDevices(); } -- cgit v1.2.3