Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 4bb04b8

Browse files
committed
move network set to cpp
1 parent d281de8 commit 4bb04b8

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed

Managers/UInputMan.cpp

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -984,34 +984,6 @@ namespace RTE {
984984
}
985985
}
986986

987-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
988-
989-
void UInputMan::UpdateNetworkMouseMovement() {
990-
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; player++) {
991-
if (!m_NetworkAccumulatedRawMouseMovement[player].IsZero()) {
992-
// TODO: Figure out why we're multiplying by 3 here. Possibly related to mouse sensitivity.
993-
m_NetworkAnalogMoveData[player].m_X += m_NetworkAccumulatedRawMouseMovement[player].m_X * 3;
994-
m_NetworkAnalogMoveData[player].m_Y += m_NetworkAccumulatedRawMouseMovement[player].m_Y * 3;
995-
m_NetworkAnalogMoveData[player].CapMagnitude(m_MouseTrapRadius);
996-
}
997-
m_NetworkAccumulatedRawMouseMovement[player].Reset();
998-
999-
// Clear mouse events and inputs as they should've been already processed during by recipients.
1000-
// This is important so mouse readings are correct, e.g. to ensure events don't trigger multiple times on a single press.
1001-
for (int inputState = InputState::Pressed; inputState < InputState::InputStateCount; inputState++) {
1002-
for (int element = InputElements::INPUT_L_UP; element < InputElements::INPUT_COUNT; element++) {
1003-
m_NetworkInputElementState[player][element][inputState] = false;
1004-
}
1005-
for (int mouseButton = MouseButtons::MOUSE_LEFT; mouseButton < MouseButtons::MAX_MOUSE_BUTTONS; mouseButton++) {
1006-
m_NetworkMouseButtonState[player][mouseButton][inputState] = false;
1007-
}
1008-
}
1009-
1010-
// Reset mouse wheel state to stop over-wheeling
1011-
m_NetworkMouseWheelState[player] = 0;
1012-
}
1013-
}
1014-
1015987
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1016988

1017989
void UInputMan::UpdateMouseInput() {
@@ -1039,9 +1011,10 @@ namespace RTE {
10391011
}
10401012
}
10411013
}
1042-
10431014
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10441015

1016+
1017+
10451018
void UInputMan::UpdateJoystickAxis(std::vector<Gamepad>::iterator device, int axis, int value) {
10461019
if (device != s_PrevJoystickStates.end()) {
10471020
int joystickIndex = device - s_PrevJoystickStates.begin();
@@ -1183,8 +1156,49 @@ namespace RTE {
11831156
}
11841157
}
11851158

1159+
1160+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1161+
void UInputMan::UpdateNetworkMouseMovement() {
1162+
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; player++) {
1163+
if (!m_NetworkAccumulatedRawMouseMovement[player].IsZero()) {
1164+
// TODO: Figure out why we're multiplying by 3 here. Possibly related to mouse sensitivity.
1165+
m_NetworkAnalogMoveData[player].m_X += m_NetworkAccumulatedRawMouseMovement[player].m_X * 3;
1166+
m_NetworkAnalogMoveData[player].m_Y += m_NetworkAccumulatedRawMouseMovement[player].m_Y * 3;
1167+
m_NetworkAnalogMoveData[player].CapMagnitude(m_MouseTrapRadius);
1168+
}
1169+
m_NetworkAccumulatedRawMouseMovement[player].Reset();
1170+
1171+
// Clear mouse events and inputs as they should've been already processed during by recipients.
1172+
// This is important so mouse readings are correct, e.g. to ensure events don't trigger multiple times on a single press.
1173+
for (int inputState = InputState::Pressed; inputState < InputState::InputStateCount; inputState++) {
1174+
for (int element = InputElements::INPUT_L_UP; element < InputElements::INPUT_COUNT; element++) {
1175+
m_NetworkInputElementState[player][element][inputState] = false;
1176+
}
1177+
for (int mouseButton = MouseButtons::MOUSE_LEFT; mouseButton < MouseButtons::MAX_MOUSE_BUTTONS; mouseButton++) {
1178+
m_NetworkMouseButtonState[player][mouseButton][inputState] = false;
1179+
}
1180+
}
1181+
1182+
// Reset mouse wheel state to stop over-wheeling
1183+
m_NetworkMouseWheelState[player] = 0;
1184+
}
1185+
}
1186+
11861187
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1188+
void UInputMan::SetNetworkInputElementState(int player, int element, InputState whichState, bool newState) {
1189+
if (element >= InputElements::INPUT_L_UP && element < InputElements::INPUT_COUNT && player >= Players::PlayerOne && player < Players::MaxPlayerCount) {
1190+
m_NetworkInputElementState[player][element][whichState] |= newState;
1191+
}
1192+
}
11871193

1194+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1195+
void UInputMan::SetNetworkMouseButtonState(int player, int whichButton, InputState whichState, bool newState) {
1196+
if (whichButton >= MouseButtons::MOUSE_LEFT && whichButton < MouseButtons::MAX_MOUSE_BUTTONS && player >= Players::PlayerOne && player < Players::MaxPlayerCount) {
1197+
m_NetworkMouseButtonState[player][whichButton][whichState] |= newState;
1198+
}
1199+
}
1200+
1201+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11881202
void UInputMan::StoreInputEventsForNextUpdate() {
11891203
// Store pressed and released events to be picked by NetworkClient during its update. These will be cleared after update so we don't care about false but we store the result regardless.
11901204
for (int inputState = InputState::Pressed; inputState < InputState::InputStateCount; inputState++) {
@@ -1193,4 +1207,8 @@ namespace RTE {
11931207
}
11941208
}
11951209
}
1210+
1211+
1212+
1213+
11961214
}

Managers/UInputMan.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ namespace RTE {
625625
/// </summary>
626626
/// <param name="player">The player to set for.</param>
627627
/// <param name="state">The new state of the mouse wheel.</param>
628-
void SetNetworkMouseWheelState(int player, int state) { if (player >= Players::PlayerOne && player < Players::MaxPlayerCount) { m_NetworkMouseWheelState[player] = state; } }
628+
void SetNetworkMouseWheelState(int player, int state) { if (player >= Players::PlayerOne && player < Players::MaxPlayerCount) { m_NetworkMouseWheelState[player] += state; } }
629629

630630
/// <summary>
631631
/// Gets whether the specified input element is pressed during network multiplayer.
@@ -783,11 +783,7 @@ namespace RTE {
783783
/// <param name="element">Which element to set. See InputElements enumeration.</param>
784784
/// <param name="whichState">Which input state to set. See InputState enumeration.</param>
785785
/// <param name="newState">The new state of the specified InputState. True or false.</param>
786-
void SetNetworkInputElementState(int player, int element, InputState whichState, bool newState) {
787-
if (element >= InputElements::INPUT_L_UP && element < InputElements::INPUT_COUNT && player >= Players::PlayerOne && player < Players::MaxPlayerCount) {
788-
m_NetworkInputElementState[player][element][whichState] = newState;
789-
}
790-
}
786+
void SetNetworkInputElementState(int player, int element, InputState whichState, bool newState);
791787

792788
/// <summary>
793789
/// Sets a mouse button for a player to the specified state during network multiplayer.
@@ -796,11 +792,7 @@ namespace RTE {
796792
/// <param name="whichButton">Which mouse button to set for. See MouseButtons enumeration.</param>
797793
/// <param name="whichState">Which input state to set. See InputState enumeration.</param>
798794
/// <param name="newState">The new state of the specified InputState. True or false.</param>
799-
void SetNetworkMouseButtonState(int player, int whichButton, InputState whichState, bool newState) {
800-
if (whichButton >= MouseButtons::MOUSE_LEFT && whichButton < MouseButtons::MAX_MOUSE_BUTTONS && player >= Players::PlayerOne && player < Players::MaxPlayerCount) {
801-
m_NetworkMouseButtonState[player][whichButton][whichState] = newState;
802-
}
803-
}
795+
void SetNetworkMouseButtonState(int player, int whichButton, InputState whichState, bool newState);
804796

805797
/// <summary>
806798
/// Gets whether an input element is in the specified state during network multiplayer.

0 commit comments

Comments
 (0)