From ed6ecca2a45e52d9be1d91107b9643b5ecdfb8bf Mon Sep 17 00:00:00 2001 From: Leviathan Linden Date: Thu, 16 Nov 2023 13:53:37 -0800 Subject: avatar_motion-->GameControl translation and flycam --- indra/llwindow/llgamecontroltranslator.h | 83 ++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 indra/llwindow/llgamecontroltranslator.h (limited to 'indra/llwindow/llgamecontroltranslator.h') diff --git a/indra/llwindow/llgamecontroltranslator.h b/indra/llwindow/llgamecontroltranslator.h new file mode 100644 index 0000000000..13cbf29db2 --- /dev/null +++ b/indra/llwindow/llgamecontroltranslator.h @@ -0,0 +1,83 @@ +/** + * @file llgamecontroltranslator.h + * @brief LLGameControlTranslator class definition + * + * $LicenseInfo:firstyear=2023&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2023, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#pragma once + +#include + +#include "stdtypes.h" +#include "llgamecontrol.h" + + +class LLGameControlTranslator +{ +public: + + using ActionToMaskMap = std::map< std::string, U32 >; // < action : mask > + using MaskToChannelMap = std::map< U32, LLGameControl::InputChannel >; // < mask : channel > + using NamedChannel = std::pair < std::string , LLGameControl::InputChannel >; + using NamedChannels = std::vector< NamedChannel >; + + + LLGameControlTranslator(); + void setAvailableActions(ActionToMaskMap& action_to_mask); + LLGameControl::InputChannel getChannelByAction(const std::string& action) const; + void setMappings(NamedChannels& list); + bool updateMap(const std::string& name, const LLGameControl::InputChannel& channel); + // Note: to remove a mapping you can call updateMap() with a TYPE_NONE channel + + // Given external action_flags (i.e. raw avatar input) + // compute the corresponding LLGameControl::State that would have produced those flags. + // Note: "action flags" are similar to, but not quite the same as, "control flags". + const LLGameControl::State& computeStateFromFlags(U32 action_flags); + + // Given LLGameControl::State (i.e. from a real controller) + // compute corresponding action flags (e.g. for moving the avatar around) + U32 computeFlagsFromState(const std::vector& axes, U32 buttons); + + U32 getMappedFlags() const { return mMappedFlags; } + +private: + bool updateMapInternal(const std::string& name, const LLGameControl::InputChannel& channel); + bool addOrRemoveMaskMapping(U32 mask, const LLGameControl::InputChannel& channel); + +private: + // mActionToMask is an invarient map between the possible actions + // and the action bit masks. Only actions therein can have their + // bit masks mapped to channels. + ActionToMaskMap mActionToMask; // invariant map after init + + // mMaskToChannel is a dynamic map between action bit masks + // and GameControl channels. + MaskToChannelMap mMaskToChannel; // dynamic map, per preference changes + + // mCachedState is an optimization: + // it is only recomputed when external action_flags change + LLGameControl::State mCachedState; + + U32 mMappedFlags { 0 }; + U32 mPrevActiveFlags { 0 }; +}; -- cgit v1.2.3 From ec39ac89e8529da206dafd519d75ad5944888076 Mon Sep 17 00:00:00 2001 From: leviathan Date: Fri, 1 Mar 2024 14:04:54 -0800 Subject: more GameControl prefs UI --- indra/llwindow/llgamecontroltranslator.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'indra/llwindow/llgamecontroltranslator.h') diff --git a/indra/llwindow/llgamecontroltranslator.h b/indra/llwindow/llgamecontroltranslator.h index 13cbf29db2..f47c4f4a5f 100644 --- a/indra/llwindow/llgamecontroltranslator.h +++ b/indra/llwindow/llgamecontroltranslator.h @@ -32,6 +32,17 @@ #include "llgamecontrol.h" +// GameControl data is sent to the server to expose game controller input to LSL scripts, +// however not everyone will have a game controller device. To allow keyboard users to provide +// GameControl data we allow the User to configure equivalences between avatar actions +// (i.e. "push forward", "strafe left", etc) and keyboard buttons to GameControl axes +// and buttons. +// +// The LLGameControlTranslator stores the equivalences and translates avatar action_flags +// and keyboard state into GameContrl data, and in some cases the other direction: from +// LLGameControl::State into avatar action_flags. +// + class LLGameControlTranslator { public: @@ -51,7 +62,7 @@ public: // Given external action_flags (i.e. raw avatar input) // compute the corresponding LLGameControl::State that would have produced those flags. - // Note: "action flags" are similar to, but not quite the same as, "control flags". + // Note: "action_flags" are similar to, but not quite the same as, "control_flags". const LLGameControl::State& computeStateFromFlags(U32 action_flags); // Given LLGameControl::State (i.e. from a real controller) -- cgit v1.2.3 From 2daf175650cdda7cc8f820b6cb17b1475496e7ac Mon Sep 17 00:00:00 2001 From: Alexander Gavriliuk Date: Wed, 8 May 2024 23:32:58 +0200 Subject: Add GameControl UI for per device settings --- indra/llwindow/llgamecontroltranslator.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'indra/llwindow/llgamecontroltranslator.h') diff --git a/indra/llwindow/llgamecontroltranslator.h b/indra/llwindow/llgamecontroltranslator.h index f47c4f4a5f..533408014c 100644 --- a/indra/llwindow/llgamecontroltranslator.h +++ b/indra/llwindow/llgamecontroltranslator.h @@ -54,10 +54,10 @@ public: LLGameControlTranslator(); - void setAvailableActions(ActionToMaskMap& action_to_mask); + void setAvailableActionMasks(ActionToMaskMap& action_to_mask); LLGameControl::InputChannel getChannelByAction(const std::string& action) const; - void setMappings(NamedChannels& list); - bool updateMap(const std::string& name, const LLGameControl::InputChannel& channel); + void setMappings(NamedChannels& named_channels); + void updateMap(const std::string& action, const LLGameControl::InputChannel& channel); // Note: to remove a mapping you can call updateMap() with a TYPE_NONE channel // Given external action_flags (i.e. raw avatar input) @@ -72,8 +72,7 @@ public: U32 getMappedFlags() const { return mMappedFlags; } private: - bool updateMapInternal(const std::string& name, const LLGameControl::InputChannel& channel); - bool addOrRemoveMaskMapping(U32 mask, const LLGameControl::InputChannel& channel); + void updateMapInternal(const std::string& name, const LLGameControl::InputChannel& channel); private: // mActionToMask is an invarient map between the possible actions -- cgit v1.2.3