mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
Only load envelope points once at mapload
This commit is contained in:
parent
65be3d8766
commit
a56a14af72
|
@ -55,53 +55,48 @@ void CMapLayers::OnInit()
|
|||
}
|
||||
}
|
||||
|
||||
void CMapLayers::EnvelopeUpdate()
|
||||
void CMapLayers::OnMapLoad()
|
||||
{
|
||||
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
||||
if(m_Type == TYPE_BACKGROUND)
|
||||
{
|
||||
const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo();
|
||||
m_CurrentLocalTick = pInfo->m_CurrentTick;
|
||||
m_LastLocalTick = pInfo->m_CurrentTick;
|
||||
m_EnvelopeUpdate = true;
|
||||
if(Layers())
|
||||
LoadEnvPoints(Layers(), m_lEnvPoints);
|
||||
else if(m_pMenuLayers)
|
||||
LoadEnvPoints(m_pMenuLayers, m_lEnvPointsMenu);
|
||||
}
|
||||
}
|
||||
|
||||
void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void *pUser)
|
||||
void CMapLayers::LoadEnvPoints(const CLayers *pLayers, array<CEnvPoint>& lEnvPoints)
|
||||
{
|
||||
CMapLayers *pThis = (CMapLayers *)pUser;
|
||||
pChannels[0] = 0;
|
||||
pChannels[1] = 0;
|
||||
pChannels[2] = 0;
|
||||
pChannels[3] = 0;
|
||||
lEnvPoints.clear();
|
||||
|
||||
CEnvPoint *pPoints = 0;
|
||||
CLayers *pLayers = 0;
|
||||
// get envelope points
|
||||
CEnvPoint *pPoints = 0x0;
|
||||
{
|
||||
int Start, Num;
|
||||
if(pThis->Client()->State() == IClient::STATE_ONLINE || pThis->Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
||||
pLayers = pThis->Layers();
|
||||
else
|
||||
pLayers = pThis->m_pMenuLayers;
|
||||
pLayers->Map()->GetType(MAPITEMTYPE_ENVPOINTS, &Start, &Num);
|
||||
if(Num)
|
||||
|
||||
if(!Num)
|
||||
return;
|
||||
|
||||
pPoints = (CEnvPoint *)pLayers->Map()->GetItem(Start, 0, 0);
|
||||
}
|
||||
|
||||
// get envelopes
|
||||
int Start, Num;
|
||||
pLayers->Map()->GetType(MAPITEMTYPE_ENVELOPE, &Start, &Num);
|
||||
|
||||
if(Env >= Num)
|
||||
if(!Num)
|
||||
return;
|
||||
|
||||
CMapItemEnvelope *pItem = (CMapItemEnvelope *)pLayers->Map()->GetItem(Start+Env, 0, 0);
|
||||
|
||||
array<CEnvPoint> lEnvPoints;
|
||||
lEnvPoints.set_size(pItem->m_NumPoints);
|
||||
for(int env = 0; env < Num; env++)
|
||||
{
|
||||
CMapItemEnvelope *pItem = (CMapItemEnvelope *)pLayers->Map()->GetItem(Start+env, 0, 0);
|
||||
|
||||
if(pItem->m_Version >= 3)
|
||||
{
|
||||
for(int i = 0; i < pItem->m_NumPoints; i++)
|
||||
lEnvPoints[i] = pPoints[i + pItem->m_StartPoint];
|
||||
lEnvPoints.add(pPoints[i + pItem->m_StartPoint]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -124,9 +119,53 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void
|
|||
p.m_aOutTangentdy[c] = 0;
|
||||
}
|
||||
|
||||
lEnvPoints[i] = p;
|
||||
lEnvPoints.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMapLayers::EnvelopeUpdate()
|
||||
{
|
||||
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
||||
{
|
||||
const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo();
|
||||
m_CurrentLocalTick = pInfo->m_CurrentTick;
|
||||
m_LastLocalTick = pInfo->m_CurrentTick;
|
||||
m_EnvelopeUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void *pUser)
|
||||
{
|
||||
CMapLayers *pThis = (CMapLayers *)pUser;
|
||||
pChannels[0] = 0;
|
||||
pChannels[1] = 0;
|
||||
pChannels[2] = 0;
|
||||
pChannels[3] = 0;
|
||||
|
||||
CEnvPoint *pPoints = 0;
|
||||
CLayers *pLayers = 0;
|
||||
{
|
||||
if(pThis->Client()->State() == IClient::STATE_ONLINE || pThis->Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
||||
{
|
||||
pLayers = pThis->Layers();
|
||||
pPoints = pThis->m_lEnvPoints.base_ptr();
|
||||
}
|
||||
else
|
||||
{
|
||||
pLayers = pThis->m_pMenuLayers;
|
||||
pPoints = pThis->m_lEnvPointsMenu.base_ptr();
|
||||
}
|
||||
}
|
||||
|
||||
int Start, Num;
|
||||
pLayers->Map()->GetType(MAPITEMTYPE_ENVELOPE, &Start, &Num);
|
||||
|
||||
if(Env >= Num)
|
||||
return;
|
||||
|
||||
CMapItemEnvelope *pItem = (CMapItemEnvelope *)pLayers->Map()->GetItem(Start+Env, 0, 0);
|
||||
|
||||
static float s_Time = 0.0f;
|
||||
static float s_LastLocalTime = pThis->Client()->LocalTime();
|
||||
|
@ -147,7 +186,7 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void
|
|||
pThis->Client()->IntraGameTick());
|
||||
}
|
||||
|
||||
pThis->RenderTools()->RenderEvalEnvelope(lEnvPoints.base_ptr(), pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels);
|
||||
pThis->RenderTools()->RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels);
|
||||
}
|
||||
else if(pThis->Client()->State() != IClient::STATE_OFFLINE)
|
||||
{
|
||||
|
@ -162,13 +201,13 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void
|
|||
else
|
||||
s_Time += pThis->Client()->LocalTime()-s_LastLocalTime;
|
||||
}
|
||||
pThis->RenderTools()->RenderEvalEnvelope(lEnvPoints.base_ptr(), pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels);
|
||||
pThis->RenderTools()->RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels);
|
||||
s_LastLocalTime = pThis->Client()->LocalTime();
|
||||
}
|
||||
else
|
||||
{
|
||||
s_Time = pThis->Client()->LocalTime();
|
||||
pThis->RenderTools()->RenderEvalEnvelope(lEnvPoints.base_ptr(), pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels);
|
||||
pThis->RenderTools()->RenderEvalEnvelope(pPoints + pItem->m_StartPoint, pItem->m_NumPoints, 4, s_Time+TimeOffset, pChannels);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||
#ifndef GAME_CLIENT_COMPONENTS_MAPLAYERS_H
|
||||
#define GAME_CLIENT_COMPONENTS_MAPLAYERS_H
|
||||
#include <base/tl/array.h>
|
||||
#include <game/client/component.h>
|
||||
|
||||
class CMapLayers : public CComponent
|
||||
|
@ -14,7 +15,13 @@ class CMapLayers : public CComponent
|
|||
int m_LastLocalTick;
|
||||
bool m_EnvelopeUpdate;
|
||||
|
||||
array<CEnvPoint> m_lEnvPoints;
|
||||
array<CEnvPoint> m_lEnvPointsMenu;
|
||||
|
||||
static void EnvelopeEval(float TimeOffset, int Env, float *pChannels, void *pUser);
|
||||
|
||||
void LoadEnvPoints(const CLayers *pLayers, array<CEnvPoint>& lEnvPoints);
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
|
@ -25,6 +32,7 @@ public:
|
|||
CMapLayers(int Type);
|
||||
virtual void OnInit();
|
||||
virtual void OnRender();
|
||||
virtual void OnMapLoad();
|
||||
|
||||
void EnvelopeUpdate();
|
||||
|
||||
|
|
Loading…
Reference in a new issue