mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Only render visible particles
This commit is contained in:
parent
2eae2c9a97
commit
2ea2d67b56
|
@ -172,6 +172,17 @@ void CParticles::OnInit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CParticles::ParticleIsVisibleOnScreen(const vec2 &CurPos, float CurSize)
|
||||||
|
{
|
||||||
|
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
|
||||||
|
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
|
||||||
|
|
||||||
|
// always uses the mid of the particle
|
||||||
|
float SizeHalf = CurSize / 2;
|
||||||
|
|
||||||
|
return CurPos.x + SizeHalf >= ScreenX0 && CurPos.x - SizeHalf <= ScreenX1 && CurPos.y + SizeHalf >= ScreenY0 && CurPos.y - SizeHalf <= ScreenY1;
|
||||||
|
}
|
||||||
|
|
||||||
void CParticles::RenderGroup(int Group)
|
void CParticles::RenderGroup(int Group)
|
||||||
{
|
{
|
||||||
// don't use the buffer methods here, else the old renderer gets many draw calls
|
// don't use the buffer methods here, else the old renderer gets many draw calls
|
||||||
|
@ -210,6 +221,9 @@ void CParticles::RenderGroup(int Group)
|
||||||
vec2 p = m_aParticles[i].m_Pos;
|
vec2 p = m_aParticles[i].m_Pos;
|
||||||
float Size = mix(m_aParticles[i].m_StartSize, m_aParticles[i].m_EndSize, a);
|
float Size = mix(m_aParticles[i].m_StartSize, m_aParticles[i].m_EndSize, a);
|
||||||
|
|
||||||
|
// the current position, respecting the size, is inside the viewport, render it, else ignore
|
||||||
|
if(ParticleIsVisibleOnScreen(p, Size))
|
||||||
|
{
|
||||||
if(LastColor[0] != m_aParticles[i].m_Color.r || LastColor[1] != m_aParticles[i].m_Color.g || LastColor[2] != m_aParticles[i].m_Color.b || LastColor[3] != m_aParticles[i].m_Color.a || LastQuadOffset != QuadOffset)
|
if(LastColor[0] != m_aParticles[i].m_Color.r || LastColor[1] != m_aParticles[i].m_Color.g || LastColor[2] != m_aParticles[i].m_Color.b || LastColor[3] != m_aParticles[i].m_Color.a || LastQuadOffset != QuadOffset)
|
||||||
{
|
{
|
||||||
Graphics()->TextureSet(GameClient()->m_ParticlesSkin.m_SpriteParticles[LastQuadOffset - SPRITE_PART_SLICE]);
|
Graphics()->TextureSet(GameClient()->m_ParticlesSkin.m_SpriteParticles[LastQuadOffset - SPRITE_PART_SLICE]);
|
||||||
|
@ -236,6 +250,7 @@ void CParticles::RenderGroup(int Group)
|
||||||
s_aParticleRenderInfo[CurParticleRenderCount].m_Rotation = m_aParticles[i].m_Rot;
|
s_aParticleRenderInfo[CurParticleRenderCount].m_Rotation = m_aParticles[i].m_Rot;
|
||||||
|
|
||||||
++CurParticleRenderCount;
|
++CurParticleRenderCount;
|
||||||
|
}
|
||||||
|
|
||||||
i = m_aParticles[i].m_NextPart;
|
i = m_aParticles[i].m_NextPart;
|
||||||
}
|
}
|
||||||
|
@ -252,12 +267,16 @@ void CParticles::RenderGroup(int Group)
|
||||||
|
|
||||||
while(i != -1)
|
while(i != -1)
|
||||||
{
|
{
|
||||||
Graphics()->TextureSet(GameClient()->m_ParticlesSkin.m_SpriteParticles[m_aParticles[i].m_Spr - SPRITE_PART_SLICE]);
|
|
||||||
Graphics()->QuadsBegin();
|
|
||||||
float a = m_aParticles[i].m_Life / m_aParticles[i].m_LifeSpan;
|
float a = m_aParticles[i].m_Life / m_aParticles[i].m_LifeSpan;
|
||||||
vec2 p = m_aParticles[i].m_Pos;
|
vec2 p = m_aParticles[i].m_Pos;
|
||||||
float Size = mix(m_aParticles[i].m_StartSize, m_aParticles[i].m_EndSize, a);
|
float Size = mix(m_aParticles[i].m_StartSize, m_aParticles[i].m_EndSize, a);
|
||||||
|
|
||||||
|
// the current position, respecting the size, is inside the viewport, render it, else ignore
|
||||||
|
if(ParticleIsVisibleOnScreen(p, Size))
|
||||||
|
{
|
||||||
|
Graphics()->TextureSet(GameClient()->m_ParticlesSkin.m_SpriteParticles[m_aParticles[i].m_Spr - SPRITE_PART_SLICE]);
|
||||||
|
Graphics()->QuadsBegin();
|
||||||
|
|
||||||
Graphics()->QuadsSetRotation(m_aParticles[i].m_Rot);
|
Graphics()->QuadsSetRotation(m_aParticles[i].m_Rot);
|
||||||
|
|
||||||
Graphics()->SetColor(
|
Graphics()->SetColor(
|
||||||
|
@ -268,9 +287,10 @@ void CParticles::RenderGroup(int Group)
|
||||||
|
|
||||||
IGraphics::CQuadItem QuadItem(p.x, p.y, Size, Size);
|
IGraphics::CQuadItem QuadItem(p.x, p.y, Size, Size);
|
||||||
Graphics()->QuadsDraw(&QuadItem, 1);
|
Graphics()->QuadsDraw(&QuadItem, 1);
|
||||||
|
Graphics()->QuadsEnd();
|
||||||
|
}
|
||||||
|
|
||||||
i = m_aParticles[i].m_NextPart;
|
i = m_aParticles[i].m_NextPart;
|
||||||
Graphics()->QuadsEnd();
|
|
||||||
}
|
}
|
||||||
Graphics()->WrapNormal();
|
Graphics()->WrapNormal();
|
||||||
Graphics()->BlendNormal();
|
Graphics()->BlendNormal();
|
||||||
|
|
|
@ -95,5 +95,7 @@ private:
|
||||||
CRenderGroup<GROUP_PROJECTILE_TRAIL> m_RenderTrail;
|
CRenderGroup<GROUP_PROJECTILE_TRAIL> m_RenderTrail;
|
||||||
CRenderGroup<GROUP_EXPLOSIONS> m_RenderExplosions;
|
CRenderGroup<GROUP_EXPLOSIONS> m_RenderExplosions;
|
||||||
CRenderGroup<GROUP_GENERAL> m_RenderGeneral;
|
CRenderGroup<GROUP_GENERAL> m_RenderGeneral;
|
||||||
|
|
||||||
|
bool ParticleIsVisibleOnScreen(const vec2 &CurPos, float CurSize);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue