From 13221f67c465017f44ca46aeca23b0d820935825 Mon Sep 17 00:00:00 2001 From: Leviathan Linden Date: Tue, 19 Sep 2023 09:40:08 -0700 Subject: add GameControl feature and SDL2 dependency --- indra/llwindow/llgamecontrol.h | 86 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 indra/llwindow/llgamecontrol.h (limited to 'indra/llwindow/llgamecontrol.h') diff --git a/indra/llwindow/llgamecontrol.h b/indra/llwindow/llgamecontrol.h new file mode 100644 index 0000000000..fe6d6f0138 --- /dev/null +++ b/indra/llwindow/llgamecontrol.h @@ -0,0 +1,86 @@ +/** + * @file llgamecontrol.h + * @brief GameController detection and management + * + * $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 "llerror.h" +#include "llsingleton.h" +#include "stdtypes.h" + + +// LLGameControl is a singleton with pure static public interface +class LLGameControl : public LLSingleton +{ + LLSINGLETON_EMPTY_CTOR(LLGameControl); + virtual ~LLGameControl(); + LOG_CLASS(LLGameControl); + +public: + // State is a minimal class for storing axes and buttons values + class State + { + public: + State(); + bool onButton(U8 button, bool pressed); + std::vector mAxes; // [ -32768, 32767 ] + std::vector mPrevAxes; // value in last outgoing packet + U32 mButtons; + }; + + static bool isInitialized(); + static void init(); + static void terminate(); + + static void addKeyButtonMap(U16 key, U8 button); + static void removeKeyButtonMap(U16 key); + static void addKeyAxisMap(U16 key, U8 axis, bool positive); + static void removeKeyAxisMap(U16 key); + + static void onKeyDown(U16 key, U32 mask); + static void onKeyUp(U16 key, U32 mask); + + // returns 'true' if GameControlInput message needs to go out, + // which will be the case for new data or resend. Call this right + // before deciding to put a GameControlInput packet on the wire + // or not. + static bool computeFinalInputAndCheckForChanges(); + + static void clearAllInput(); + static void clearAllKeys(); + + static void processEvents(bool app_has_focus = true); + static const State& getState(); + + static void setIncludeKeyboardButtons(bool include); + static bool getIncludeKeyboardButtons(); + + // call this after putting a GameControlInput packet on the wire + static void updateResendPeriod(); +}; + -- cgit v1.2.3