Only load envelope points once at mapload

This commit is contained in:
BeaR 2014-06-04 17:51:03 +02:00
parent 65be3d8766
commit a56a14af72
2 changed files with 88 additions and 41 deletions

View file

@ -55,6 +55,76 @@ void CMapLayers::OnInit()
}
}
void CMapLayers::OnMapLoad()
{
if(m_Type == TYPE_BACKGROUND)
{
if(Layers())
LoadEnvPoints(Layers(), m_lEnvPoints);
else if(m_pMenuLayers)
LoadEnvPoints(m_pMenuLayers, m_lEnvPointsMenu);
}
}
void CMapLayers::LoadEnvPoints(const CLayers *pLayers, array<CEnvPoint>& lEnvPoints)
{
lEnvPoints.clear();
// get envelope points
CEnvPoint *pPoints = 0x0;
{
int Start, Num;
pLayers->Map()->GetType(MAPITEMTYPE_ENVPOINTS, &Start, &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(!Num)
return;
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.add(pPoints[i + pItem->m_StartPoint]);
}
else
{
// backwards compatibility
for(int i = 0; i < pItem->m_NumPoints; i++)
{
// convert CEnvPoint_v1 -> CEnvPoint
CEnvPoint_v1 *pEnvPoint_v1 = &((CEnvPoint_v1 *)pPoints)[i + pItem->m_StartPoint];
CEnvPoint p;
p.m_Time = pEnvPoint_v1->m_Time;
p.m_Curvetype = pEnvPoint_v1->m_Curvetype;
for(int c = 0; c < pItem->m_Channels; c++)
{
p.m_aValues[c] = pEnvPoint_v1->m_aValues[c];
p.m_aInTangentdx[c] = 0;
p.m_aInTangentdy[c] = 0;
p.m_aOutTangentdx[c] = 0;
p.m_aOutTangentdy[c] = 0;
}
lEnvPoints.add(p);
}
}
}
}
void CMapLayers::EnvelopeUpdate()
{
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
@ -77,14 +147,16 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void
CEnvPoint *pPoints = 0;
CLayers *pLayers = 0;
{
int Start, Num;
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;
pLayers->Map()->GetType(MAPITEMTYPE_ENVPOINTS, &Start, &Num);
if(Num)
pPoints = (CEnvPoint *)pLayers->Map()->GetItem(Start, 0, 0);
pPoints = pThis->m_lEnvPointsMenu.base_ptr();
}
}
int Start, Num;
@ -93,40 +165,7 @@ void CMapLayers::EnvelopeEval(float TimeOffset, int Env, float *pChannels, void
if(Env >= Num)
return;
CMapItemEnvelope *pItem = (CMapItemEnvelope *)pLayers->Map()->GetItem(Start+Env, 0, 0);
array<CEnvPoint> lEnvPoints;
lEnvPoints.set_size(pItem->m_NumPoints);
if(pItem->m_Version >= 3)
{
for(int i = 0; i < pItem->m_NumPoints; i++)
lEnvPoints[i] = pPoints[i + pItem->m_StartPoint];
}
else
{
// backwards compatibility
for(int i = 0; i < pItem->m_NumPoints; i++)
{
// convert CEnvPoint_v1 -> CEnvPoint
CEnvPoint_v1 *pEnvPoint_v1 = &((CEnvPoint_v1 *)pPoints)[i + pItem->m_StartPoint];
CEnvPoint p;
p.m_Time = pEnvPoint_v1->m_Time;
p.m_Curvetype = pEnvPoint_v1->m_Curvetype;
for(int c = 0; c < pItem->m_Channels; c++)
{
p.m_aValues[c] = pEnvPoint_v1->m_aValues[c];
p.m_aInTangentdx[c] = 0;
p.m_aInTangentdy[c] = 0;
p.m_aOutTangentdx[c] = 0;
p.m_aOutTangentdy[c] = 0;
}
lEnvPoints[i] = p;
}
}
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);
}
}

View file

@ -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();