MCPcopy Create free account
hub / github.com/ddnet/ddnet / UpdateLocalTuning

Method UpdateLocalTuning

src/game/client/gameclient.cpp:3341–3417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3339}
3340
3341void CGameClient::UpdateLocalTuning()
3342{
3343 m_GameWorld.m_WorldConfig.m_UseTuneZones = m_GameInfo.m_PredictDDRaceTiles;
3344
3345 // always update default tune zone, even without character
3346 if(!m_GameWorld.m_WorldConfig.m_UseTuneZones)
3347 m_GameWorld.TuningList()[0] = m_aTuning[g_Config.m_ClDummy];
3348
3349 if(!m_Snap.m_pLocalCharacter && !m_Snap.m_pSpectatorInfo)
3350 return;
3351
3352 vec2 LocalPos = m_Snap.m_pLocalCharacter ? vec2(m_Snap.m_pLocalCharacter->m_X, m_Snap.m_pLocalCharacter->m_Y) : vec2(m_Snap.m_pSpectatorInfo->m_X, m_Snap.m_pSpectatorInfo->m_Y);
3353
3354 // update the tuning at the local position with the latest tunings received before the new snapshot
3355 if(m_GameWorld.m_WorldConfig.m_UseTuneZones)
3356 {
3357 int TuneZone =
3358 m_Snap.m_aCharacters[m_Snap.m_LocalClientId].m_HasExtendedData &&
3359 m_Snap.m_aCharacters[m_Snap.m_LocalClientId].m_ExtendedData.m_TuneZoneOverride != TuneZone::OVERRIDE_NONE ?
3360 m_Snap.m_aCharacters[m_Snap.m_LocalClientId].m_ExtendedData.m_TuneZoneOverride :
3361 Collision()->IsTune(Collision()->GetMapIndex(LocalPos));
3362
3363 if(TuneZone != m_aLocalTuneZone[g_Config.m_ClDummy])
3364 {
3365 // our tunezone changed, expecting tuning message
3366 m_aLocalTuneZone[g_Config.m_ClDummy] = m_aExpectingTuningForZone[g_Config.m_ClDummy] = TuneZone;
3367 m_aExpectingTuningSince[g_Config.m_ClDummy] = 0;
3368 }
3369
3370 // tunezone could have changed, send dummy tuning to demo
3371 if(m_ActiveRecordings.any() && m_IsDummySwapping && m_aLocalTuneZone[0] != m_aLocalTuneZone[1])
3372 {
3373 CMsgPacker Msg(NETMSGTYPE_SV_TUNEPARAMS);
3374 int *pParams = (int *)&m_aTuning[g_Config.m_ClDummy];
3375 for(unsigned i = 0; i < sizeof(m_aTuning[0]) / sizeof(int); i++)
3376 Msg.AddInt(pParams[i]);
3377 Client()->SendMsgActive(&Msg, MSGFLAG_RECORD | MSGFLAG_NOSEND);
3378 }
3379
3380 if(m_aExpectingTuningForZone[g_Config.m_ClDummy] >= 0)
3381 {
3382 if(m_aReceivedTuning[g_Config.m_ClDummy])
3383 {
3384 TuningList()[m_aExpectingTuningForZone[g_Config.m_ClDummy]] = m_aTuning[g_Config.m_ClDummy];
3385 m_GameWorld.TuningList()[m_aExpectingTuningForZone[g_Config.m_ClDummy]] = m_aTuning[g_Config.m_ClDummy];
3386 m_aReceivedTuning[g_Config.m_ClDummy] = false;
3387 m_aExpectingTuningForZone[g_Config.m_ClDummy] = -1;
3388 }
3389 else if(m_aExpectingTuningSince[g_Config.m_ClDummy] >= 5)
3390 {
3391 // if we are expecting tuning for more than 10 snaps (less than a quarter of a second)
3392 // it is probably dropped or it was received out of order
3393 // or applied to another tunezone.
3394 // we need to fallback to current tuning to fix ourselves.
3395 m_aExpectingTuningForZone[g_Config.m_ClDummy] = -1;
3396 m_aExpectingTuningSince[g_Config.m_ClDummy] = 0;
3397 m_aReceivedTuning[g_Config.m_ClDummy] = false;
3398 dbg_msg("tunezone", "the tuning was missed");

Callers

nothing calls this directly

Calls 7

dbg_msgFunction · 0.85
IsTuneMethod · 0.80
GetMapIndexMethod · 0.80
AddIntMethod · 0.80
SendMsgActiveMethod · 0.80
ClientFunction · 0.50
TuningListMethod · 0.45

Tested by

no test coverage detected