https://github.com/libsdl-org/Maelstrom/commit/265d8cbf15258e4b80f0e740bea252d2d65094da
From 265d8cbf15258e4b80f0e740bea252d2d65094da Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 23 Nov 2011 22:58:51 -0500
Subject: [PATCH] The joystick code spams control updates, don't send them on
to the network.
---
game/player.cpp | 11 +++++++++++
game/player.h | 1 +
2 files changed, 12 insertions(+)
diff --git a/game/player.cpp b/game/player.cpp
index fdbed83f..62da3ae1 100644
--- a/game/player.cpp
+++ b/game/player.cpp
@@ -124,6 +124,7 @@ Player::NewShip(void)
{
if ( Lives == 0 )
return(-1);
+ controlState = 0;
solid = 1;
shootable = 1;
Set_Blit(gPlayerShip);
@@ -644,6 +645,16 @@ Player::SetControlType(Uint8 controlType)
void
Player::SetControl(unsigned char which, bool enabled)
{
+ // Don't spam the network with duplicate state changes
+ if (!!(controlState & (1 << which)) == enabled) {
+ return;
+ }
+ if (enabled) {
+ controlState |= (1 << which);
+ } else {
+ controlState &= ~(1 << which);
+ }
+
QueueInput(EncodeInput(which, enabled));
}
diff --git a/game/player.h b/game/player.h
index 69fe2520..59c7dddf 100644
--- a/game/player.h
+++ b/game/player.h
@@ -176,6 +176,7 @@ class Player : public Object {
Uint32 ship_color;
Uint8 controlType;
+ Uint32 controlState;
/* Create a new shot */
int MakeShot(int offset);