summaryrefslogtreecommitdiff
path: root/indra/newview/llappviewer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llappviewer.cpp')
-rw-r--r--indra/newview/llappviewer.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 6fd58ef1be..ffa742d154 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -64,6 +64,7 @@
#include "llluamanager.h"
#include "llurlfloaterdispatchhandler.h"
#include "llviewerjoystick.h"
+#include "llgamecontrol.h"
#include "llcalc.h"
#include "llconversationlog.h"
#if LL_WINDOWS
@@ -1132,6 +1133,7 @@ bool LLAppViewer::init()
{
LLViewerJoystick::getInstance()->init(false);
}
+ LLGameControl::init();
try
{
@@ -1416,6 +1418,59 @@ bool LLAppViewer::frame()
return ret;
}
+
+// static
+bool packGameControlInput(LLMessageSystem* msg)
+{
+ if (! LLGameControl::computeFinalInputAndCheckForChanges())
+ {
+ return false;
+ }
+ if (!gSavedSettings.getBOOL("EnableGameControlInput"))
+ {
+ LLGameControl::clearAllInput();
+ return false;
+ }
+
+ msg->newMessageFast(_PREHASH_GameControlInput);
+ msg->nextBlock("AgentData");
+ msg->addUUID("AgentID", gAgentID);
+ msg->addUUID("SessionID", gAgentSessionID);
+
+ const LLGameControl::State& state = LLGameControl::getState();
+
+ size_t num_indices = state.mAxes.size();
+ for (U8 i = 0; i < num_indices; ++i)
+ {
+ if (state.mAxes[i] != state.mPrevAxes[i])
+ {
+ // only pack an axis if it differs from previously packed value
+ msg->nextBlockFast(_PREHASH_AxisData);
+ msg->addU8Fast(_PREHASH_Index, i);
+ msg->addS16Fast(_PREHASH_Value, state.mAxes[i]);
+ }
+ }
+
+ U32 button_flags = state.mButtons;
+ if (button_flags > 0)
+ {
+ std::vector<U8> buttons;
+ for (U8 i = 0; i < 32; i++)
+ {
+ if (button_flags & (0x1 << i))
+ {
+ buttons.push_back(i);
+ }
+ }
+ msg->nextBlockFast(_PREHASH_ButtonData);
+ msg->addBinaryDataFast(_PREHASH_Data, (void*)(buttons.data()), (S32)(buttons.size()));
+ }
+
+ LLGameControl::updateResendPeriod();
+ return true;
+}
+
+
bool LLAppViewer::doFrame()
{
LL_RECORD_BLOCK_TIME(FTM_FRAME);
@@ -1526,6 +1581,15 @@ bool LLAppViewer::doFrame()
joystick->scanJoystick();
gKeyboard->scanKeyboard();
gViewerInput.scanMouse();
+
+ LLGameControl::setIncludeKeyboardButtons(gSavedSettings.getBOOL("EnableGameControlKeyboardInput"));
+ LLGameControl::processEvents(gFocusMgr.getAppHasFocus());
+ // to help minimize lag we send GameInput packets immediately
+ // after getting the latest GameController input
+ if (packGameControlInput(gMessageSystem))
+ {
+ gAgent.sendMessage();
+ }
}
// Update state based on messages, user input, object idle.
@@ -1961,6 +2025,7 @@ bool LLAppViewer::cleanup()
// Turn off Space Navigator and similar devices
LLViewerJoystick::getInstance()->terminate();
}
+ LLGameControl::terminate();
LL_INFOS() << "Cleaning up Objects" << LL_ENDL;