mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #3441
3441: Only render visible particles r=def- a=Jupeyy Helps with maps like "The Dream" view without whitespaces ## Checklist - [ ] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
commit
7ec58f6249
|
@ -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)
|
||||
{
|
||||
// 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;
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
++CurParticleRenderCount;
|
||||
}
|
||||
|
||||
i = m_aParticles[i].m_NextPart;
|
||||
}
|
||||
|
@ -252,12 +267,16 @@ void CParticles::RenderGroup(int Group)
|
|||
|
||||
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;
|
||||
vec2 p = m_aParticles[i].m_Pos;
|
||||
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()->SetColor(
|
||||
|
@ -268,9 +287,10 @@ void CParticles::RenderGroup(int Group)
|
|||
|
||||
IGraphics::CQuadItem QuadItem(p.x, p.y, Size, Size);
|
||||
Graphics()->QuadsDraw(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
}
|
||||
|
||||
i = m_aParticles[i].m_NextPart;
|
||||
Graphics()->QuadsEnd();
|
||||
}
|
||||
Graphics()->WrapNormal();
|
||||
Graphics()->BlendNormal();
|
||||
|
|
|
@ -95,5 +95,7 @@ private:
|
|||
CRenderGroup<GROUP_PROJECTILE_TRAIL> m_RenderTrail;
|
||||
CRenderGroup<GROUP_EXPLOSIONS> m_RenderExplosions;
|
||||
CRenderGroup<GROUP_GENERAL> m_RenderGeneral;
|
||||
|
||||
bool ParticleIsVisibleOnScreen(const vec2 &CurPos, float CurSize);
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue