Fix #586 (display the killing clipping rectangle)

This commit is contained in:
necropotame 2017-03-15 12:06:13 +01:00
parent 7f407aa303
commit 6f58c49f7d
3 changed files with 94 additions and 1 deletions

View file

@ -263,6 +263,21 @@ void CMapLayers::OnRender()
RenderTools()->RenderTilemap(pTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE, RenderTools()->RenderTilemap(pTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_OPAQUE,
EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset); EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset);
Graphics()->BlendNormal(); Graphics()->BlendNormal();
//Draw kill tiles outside the entity clipping rectangle
if(IsGameLayer)
{
//Slow blinking to hint that it's not a part of the map
double Seconds = time_get()/(double)time_freq();
vec4 ColorHint = vec4(1.0f, 1.0f, 1.0f, 0.3f + 0.7f*(1.0+sin(2.0f*pi*Seconds/3.f))/2.0f);
RenderTools()->RenderTileRetangle(-201, -201, pTMap->m_Width+402, pTMap->m_Height+402,
0, TILE_DEATH, //Display air inside, death outside
32.0f, Color*ColorHint, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT,
EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset);
}
RenderTools()->RenderTilemap(pTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT, RenderTools()->RenderTilemap(pTiles, pTMap->m_Width, pTMap->m_Height, 32.0f, Color, TILERENDERFLAG_EXTEND|LAYERRENDERFLAG_TRANSPARENT,
EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset); EnvelopeEval, this, pTMap->m_ColorEnv, pTMap->m_ColorEnvOffset);
} }

View file

@ -76,6 +76,7 @@ public:
void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser); void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser);
void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha = 1.0f); void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha = 1.0f);
void RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset); void RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset);
void RenderTileRetangle(int X, int Y, int w, int h, unsigned char indexIn, unsigned char indexOut, float Scale, vec4 Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset);
// helpers // helpers
void MapscreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY, void MapscreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY,

View file

@ -176,6 +176,83 @@ void CRenderTools::ForceRenderQuads(CQuad *pQuads, int NumQuads, int RenderFlags
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
} }
void CRenderTools::RenderTileRetangle(int X, int Y, int w, int h, unsigned char indexIn, unsigned char indexOut, float Scale, vec4 Color, int RenderFlags,
ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset)
{
//Graphics()->TextureSet(img_get(tmap->image));
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
//Graphics()->MapScreen(screen_x0-50, screen_y0-50, screen_x1+50, screen_y1+50);
// calculate the final pixelsize for the tiles
float TilePixelSize = 1024/32.0f;
float FinalTileSize = Scale/(ScreenX1-ScreenX0) * Graphics()->ScreenWidth();
float FinalTilesetScale = FinalTileSize/TilePixelSize;
float r=1, g=1, b=1, a=1;
if(ColorEnv >= 0)
{
float aChannels[4];
pfnEval(ColorEnvOffset/1000.0f, ColorEnv, aChannels, pUser);
r = aChannels[0];
g = aChannels[1];
b = aChannels[2];
a = aChannels[3];
}
Graphics()->QuadsBegin();
Graphics()->SetColor(Color.r*r, Color.g*g, Color.b*b, Color.a*a);
int StartY = (int)(ScreenY0/Scale)-1;
int StartX = (int)(ScreenX0/Scale)-1;
int EndY = (int)(ScreenY1/Scale)+1;
int EndX = (int)(ScreenX1/Scale)+1;
// adjust the texture shift according to mipmap level
float TexSize = 1024.0f;
float Frac = (1.25f/TexSize) * (1/FinalTilesetScale);
float Nudge = (0.5f/TexSize) * (1/FinalTilesetScale);
for(int y = StartY; y < EndY; y++)
for(int x = StartX; x < EndX; x++)
{
unsigned char Index = (x<X || x>=X+w || y<Y || y>Y+h) ? indexOut : indexIn;
if(Index)
{
bool Render = false;
if(RenderFlags&LAYERRENDERFLAG_TRANSPARENT)
Render = true;
if(Render)
{
int tx = Index%16;
int ty = Index/16;
int Px0 = tx*(1024/16);
int Py0 = ty*(1024/16);
int Px1 = Px0+(1024/16)-1;
int Py1 = Py0+(1024/16)-1;
float x0 = Nudge + Px0/TexSize+Frac;
float y0 = Nudge + Py0/TexSize+Frac;
float x1 = Nudge + Px1/TexSize-Frac;
float y1 = Nudge + Py0/TexSize+Frac;
float x2 = Nudge + Px1/TexSize-Frac;
float y2 = Nudge + Py1/TexSize-Frac;
float x3 = Nudge + Px0/TexSize+Frac;
float y3 = Nudge + Py1/TexSize-Frac;
Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3);
IGraphics::CQuadItem QuadItem(x*Scale, y*Scale, Scale, Scale);
Graphics()->QuadsDrawTL(&QuadItem, 1);
}
}
}
Graphics()->QuadsEnd();
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}
void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags, void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags,
ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset) ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset)
{ {