Browse Source

Merge pull request #164 from Hoikas/game-ping

Implement NglGame pinging
Branan Purvine-Riley 13 years ago
parent
commit
7d7bb6935b
  1. 10
      Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp
  2. 1
      Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h
  3. 16
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  4. 73
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp
  5. 18
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp

10
Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.cpp

@ -628,7 +628,6 @@ void plArmatureModBase::IEnableBones(int lod, hsBool enable)
const char *plArmatureMod::BoneStrings[] = {"Male", "Female", "Critter", "Actor"}; const char *plArmatureMod::BoneStrings[] = {"Male", "Female", "Critter", "Actor"};
const float plArmatureMod::kAvatarInputSynchThreshold = 10.f;
float plArmatureMod::fMouseTurnSensitivity = 1.f; float plArmatureMod::fMouseTurnSensitivity = 1.f;
hsBool plArmatureMod::fClickToTurn = true; hsBool plArmatureMod::fClickToTurn = true;
@ -656,7 +655,6 @@ void plArmatureMod::IInitDefaults()
fReverseFBOnIdle = false; fReverseFBOnIdle = false;
fFollowerParticleSystemSO = nil; fFollowerParticleSystemSO = nil;
fPendingSynch = false; fPendingSynch = false;
fLastInputSynch = 0;
fOpaque = true; fOpaque = true;
fPhysHeight = 0.f; fPhysHeight = 0.f;
fPhysWidth = 0.f; fPhysWidth = 0.f;
@ -1524,8 +1522,6 @@ void plArmatureMod::SynchInputState(uint32_t rcvID /* = kInvalidPlayerID */)
msg->AddNetReceiver(rcvID); msg->AddNetReceiver(rcvID);
msg->Send(); msg->Send();
fLastInputSynch = hsTimer::GetSysSeconds();
} }
void plArmatureMod::ILinkToPersonalAge() void plArmatureMod::ILinkToPersonalAge()
@ -1590,12 +1586,6 @@ hsBool plArmatureMod::IEval(double time, float elapsed, uint32_t dirty)
} }
} }
if (localPlayer == this)
{
if (time - fLastInputSynch > kAvatarInputSynchThreshold)
SynchInputState();
}
if (noOverlap) if (noOverlap)
{ {
EnablePhysics(false, kDisableReasonRelRegion); EnablePhysics(false, kDisableReasonRelRegion);

1
Sources/Plasma/PubUtilLib/plAvatar/plArmatureMod.h

@ -414,7 +414,6 @@ protected:
uint8_t fStealthMode; uint8_t fStealthMode;
int fStealthLevel; // you are invisible to other players/CCRs of lower stealthLevel int fStealthLevel; // you are invisible to other players/CCRs of lower stealthLevel
double fLastInputSynch;
plAGModifier * fRootAGMod; plAGModifier * fRootAGMod;
plAvBoneMap * fBoneMap; // uses id codes to look up bones. set up by the brain as needed. plAvBoneMap * fBoneMap; // uses id codes to look up bones. set up by the brain as needed.
double fLastSynch; double fLastSynch;

16
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp

@ -1698,9 +1698,9 @@ void CliAuConn::AutoPing () {
void CliAuConn::StopAutoPing () { void CliAuConn::StopAutoPing () {
critsect.Enter(); critsect.Enter();
{ {
if (AsyncTimer * timer = pingTimer) { if (pingTimer) {
AsyncTimerDeleteCallback(pingTimer, CliAuConnTimerDestroyed);
pingTimer = nil; pingTimer = nil;
AsyncTimerDeleteCallback(timer, CliAuConnTimerDestroyed);
} }
} }
critsect.Leave(); critsect.Leave();
@ -1708,17 +1708,6 @@ void CliAuConn::StopAutoPing () {
//============================================================================ //============================================================================
void CliAuConn::TimerPing () { void CliAuConn::TimerPing () {
#if 0
// if the time difference between when we last sent a ping and when we last
// heard from the server is >= 3x the ping interval, the socket is stale.
if (pingSendTimeMs && abs(int(pingSendTimeMs - lastHeardTimeMs)) >= kPingTimeoutMs) {
// ping timed out, disconnect the socket
AsyncSocketDisconnect(sock, true);
}
else
#endif
{
// Send a ping request // Send a ping request
pingSendTimeMs = GetNonZeroTimeMs(); pingSendTimeMs = GetNonZeroTimeMs();
@ -1731,7 +1720,6 @@ void CliAuConn::TimerPing () {
}; };
Send(msg, arrsize(msg)); Send(msg, arrsize(msg));
}
} }
//============================================================================ //============================================================================

73
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp

@ -74,6 +74,11 @@ struct CliGmConn : AtomicRef {
CliGmConn (); CliGmConn ();
~CliGmConn (); ~CliGmConn ();
// ping
void AutoPing ();
void StopAutoPing ();
void TimerPing ();
void Send (const uintptr_t fields[], unsigned count); void Send (const uintptr_t fields[], unsigned count);
}; };
@ -207,6 +212,8 @@ static void UnlinkAndAbandonConn_CS (CliGmConn * conn) {
//============================================================================ //============================================================================
static bool ConnEncrypt (ENetError error, void * param) { static bool ConnEncrypt (ENetError error, void * param) {
CliGmConn * conn = (CliGmConn *) param; CliGmConn * conn = (CliGmConn *) param;
if (!s_perf[kPingDisabled])
conn->AutoPing();
if (IS_NET_SUCCESS(error)) { if (IS_NET_SUCCESS(error)) {
s_critsect.Enter(); s_critsect.Enter();
@ -262,6 +269,7 @@ static void NotifyConnSocketConnectFailed (CliGmConn * conn) {
//============================================================================ //============================================================================
static void NotifyConnSocketDisconnect (CliGmConn * conn) { static void NotifyConnSocketDisconnect (CliGmConn * conn) {
conn->StopAutoPing();
bool notify; bool notify;
s_critsect.Enter(); s_critsect.Enter();
@ -392,6 +400,19 @@ static void Connect (
* *
***/ ***/
//===========================================================================
static unsigned CliGmConnTimerDestroyed (void * param) {
CliGmConn * conn = (CliGmConn *) param;
conn->DecRef("TimerDestroyed");
return kAsyncTimeInfinite;
}
//===========================================================================
static unsigned CliGmConnPingTimerProc (void * param) {
((CliGmConn *) param)->TimerPing();
return kPingIntervalMs;
}
//============================================================================ //============================================================================
CliGmConn::CliGmConn () { CliGmConn::CliGmConn () {
AtomicAdd(&s_perf[kPerfConnCount], 1); AtomicAdd(&s_perf[kPerfConnCount], 1);
@ -404,6 +425,47 @@ CliGmConn::~CliGmConn () {
AtomicAdd(&s_perf[kPerfConnCount], -1); AtomicAdd(&s_perf[kPerfConnCount], -1);
} }
//============================================================================
void CliGmConn::AutoPing () {
ASSERT(!pingTimer);
IncRef("PingTimer");
critsect.Enter();
{
AsyncTimerCreate(
&pingTimer,
CliGmConnPingTimerProc,
sock ? 0 : kAsyncTimeInfinite,
this
);
}
critsect.Leave();
}
//============================================================================
void CliGmConn::StopAutoPing () {
critsect.Enter();
{
if (pingTimer) {
AsyncTimerDeleteCallback(pingTimer, CliGmConnTimerDestroyed);
pingTimer = nil;
}
}
critsect.Leave();
}
//============================================================================
void CliGmConn::TimerPing () {
// Send a ping request
pingSendTimeMs = GetNonZeroTimeMs();
const uintptr_t msg[] = {
kCli2Game_PingRequest,
pingSendTimeMs
};
Send(msg, arrsize(msg));
}
//============================================================================ //============================================================================
void CliGmConn::Send (const uintptr_t fields[], unsigned count) { void CliGmConn::Send (const uintptr_t fields[], unsigned count) {
critsect.Enter(); critsect.Enter();
@ -710,6 +772,17 @@ unsigned GameGetConnId () {
//============================================================================ //============================================================================
void GamePingEnable (bool enable) { void GamePingEnable (bool enable) {
s_perf[kPingDisabled] = !enable; s_perf[kPingDisabled] = !enable;
s_critsect.Enter();
for (;;) {
if (!s_active)
break;
if (enable)
s_active->AutoPing();
else
s_active->StopAutoPing();
break;
}
s_critsect.Leave();
} }
} using namespace Ngl; } using namespace Ngl;

18
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp

@ -636,9 +636,9 @@ void CliGkConn::AutoPing () {
void CliGkConn::StopAutoPing () { void CliGkConn::StopAutoPing () {
critsect.Enter(); critsect.Enter();
{ {
if (AsyncTimer * timer = pingTimer) { if (pingTimer) {
AsyncTimerDeleteCallback(pingTimer, CliGkConnTimerDestroyed);
pingTimer = nil; pingTimer = nil;
AsyncTimerDeleteCallback(timer, CliGkConnTimerDestroyed);
} }
} }
critsect.Leave(); critsect.Leave();
@ -646,17 +646,6 @@ void CliGkConn::StopAutoPing () {
//============================================================================ //============================================================================
void CliGkConn::TimerPing () { void CliGkConn::TimerPing () {
#if 0
// if the time difference between when we last sent a ping and when we last
// heard from the server is >= 3x the ping interval, the socket is stale.
if (pingSendTimeMs && abs(int(pingSendTimeMs - lastHeardTimeMs)) >= kPingTimeoutMs) {
// ping timed out, disconnect the socket
AsyncSocketDisconnect(sock, true);
}
else
#endif
{
// Send a ping request // Send a ping request
pingSendTimeMs = GetNonZeroTimeMs(); pingSendTimeMs = GetNonZeroTimeMs();
@ -668,8 +657,7 @@ void CliGkConn::TimerPing () {
nil nil
}; };
//Send(msg, arrsize(msg)); Send(msg, arrsize(msg));
}
} }
//============================================================================ //============================================================================

Loading…
Cancel
Save