diff --git a/src/game/client/components/maplayers.cpp b/src/game/client/components/maplayers.cpp index 66e3e865e..824c91e47 100644 --- a/src/game/client/components/maplayers.cpp +++ b/src/game/client/components/maplayers.cpp @@ -28,6 +28,13 @@ CMapLayers::CMapLayers(int t) m_EnvelopeUpdate = false; m_pMenuMap = 0; m_pMenuLayers = 0; + m_OnlineStartTime = 0; +} + +void CMapLayers::OnStateChange(int NewState, int OldState) +{ + if(NewState == IClient::STATE_ONLINE) + m_OnlineStartTime = Client()->LocalTime(); // reset time for non-scynchronized envelopes } void CMapLayers::LoadBackgroundMap() @@ -89,7 +96,7 @@ void CMapLayers::LoadEnvPoints(const CLayers *pLayers, array& lEnvPoi pLayers->Map()->GetType(MAPITEMTYPE_ENVELOPE, &Start, &Num); if(!Num) return; - + for(int env = 0; env < Num; env++) { @@ -167,14 +174,13 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void if(Env >= Num) return; - CMapItemEnvelope *pItem = (CMapItemEnvelope *)pLayers->Map()->GetItem(Start+Env, 0, 0); + CMapItemEnvelope *pItem = (CMapItemEnvelope *)pLayers->Map()->GetItem(Start+Env, 0, 0); - static float s_Time = 0.0f; - static float s_LastLocalTime = pThis->Client()->LocalTime(); + float Time = 0.0f; if(pThis->Client()->State() == IClient::STATE_DEMOPLAYBACK) { const IDemoPlayer::CInfo *pInfo = pThis->DemoPlayer()->BaseInfo(); - + if(!pInfo->m_Paused || pThis->m_EnvelopeUpdate) { if(pThis->m_CurrentLocalTick != pInfo->m_CurrentTick) @@ -183,12 +189,12 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void pThis->m_CurrentLocalTick = pInfo->m_CurrentTick; } - s_Time = mix(pThis->m_LastLocalTick / (float)pThis->Client()->GameTickSpeed(), + Time = mix(pThis->m_LastLocalTick / (float)pThis->Client()->GameTickSpeed(), pThis->m_CurrentLocalTick / (float)pThis->Client()->GameTickSpeed(), pThis->Client()->IntraGameTick()); } - pThis->RenderTools()->RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels); + pThis->RenderTools()->RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, Time+TimeOffset, pChannels); } else if(pThis->Client()->State() != IClient::STATE_OFFLINE) { @@ -196,20 +202,20 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void { if(pItem->m_Version < 2 || pItem->m_Synchronized) { - s_Time = mix((pThis->Client()->PrevGameTick()-pThis->m_pClient->m_Snap.m_pGameData->m_GameStartTick) / (float)pThis->Client()->GameTickSpeed(), + Time = mix((pThis->Client()->PrevGameTick()-pThis->m_pClient->m_Snap.m_pGameData->m_GameStartTick) / (float)pThis->Client()->GameTickSpeed(), (pThis->Client()->GameTick()-pThis->m_pClient->m_Snap.m_pGameData->m_GameStartTick) / (float)pThis->Client()->GameTickSpeed(), pThis->Client()->IntraGameTick()); } else - s_Time += pThis->Client()->LocalTime()-s_LastLocalTime; + Time = pThis->Client()->LocalTime()-pThis->m_OnlineStartTime; } - pThis->RenderTools()->RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels); - s_LastLocalTime = pThis->Client()->LocalTime(); + + pThis->RenderTools()->RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, Time+TimeOffset, pChannels); } else { - s_Time = pThis->Client()->LocalTime(); - pThis->RenderTools()->RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels); + Time = pThis->Client()->LocalTime(); + pThis->RenderTools()->RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, Time+TimeOffset, pChannels); } } @@ -248,7 +254,7 @@ void CMapLayers::OnRender() float y0 = (pGroup->m_ClipY - Points[1]) / (Points[3]-Points[1]); float x1 = ((pGroup->m_ClipX+pGroup->m_ClipW) - Points[0]) / (Points[2]-Points[0]); float y1 = ((pGroup->m_ClipY+pGroup->m_ClipH) - Points[1]) / (Points[3]-Points[1]); - + if(x1 < 0.0f || x0 > 1.0f || y1 < 0.0f || y0 > 1.0f) continue; diff --git a/src/game/client/components/maplayers.h b/src/game/client/components/maplayers.h index 53f62e5c3..07a90cb33 100644 --- a/src/game/client/components/maplayers.h +++ b/src/game/client/components/maplayers.h @@ -13,6 +13,7 @@ class CMapLayers : public CComponent int m_Type; int m_CurrentLocalTick; int m_LastLocalTick; + float m_OnlineStartTime; bool m_EnvelopeUpdate; array m_lEnvPoints; @@ -31,6 +32,7 @@ public: }; CMapLayers(int Type); + virtual void OnStateChange(int NewState, int OldState); virtual void OnInit(); virtual void OnRender(); virtual void OnMapLoad();