Merge pull request #992 from Jupeyy/master

RAM usage reduction for map buffering and foreground layer count fix
This commit is contained in:
Dennis Felsing 2018-01-22 20:44:56 +01:00 committed by GitHub
commit fac054275c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 137 additions and 110 deletions

View file

@ -328,11 +328,7 @@ bool CMapLayers::STileLayerVisuals::Init(unsigned int Width, unsigned int Height
m_Width = Width;
m_Height = Height;
m_TilesOfLayer = new CMapLayers::STileLayerVisuals::STileVisual*[Height];
for(unsigned int i = 0; i < Height; ++i)
{
m_TilesOfLayer[i] = new CMapLayers::STileLayerVisuals::STileVisual[Width];
}
m_TilesOfLayer = new CMapLayers::STileLayerVisuals::STileVisual[Height*Width];
if(Width > 2)
{
@ -351,10 +347,6 @@ CMapLayers::STileLayerVisuals::~STileLayerVisuals()
{
if(m_TilesOfLayer)
{
for(unsigned int i = 0; i < m_Height; ++i)
{
delete[] m_TilesOfLayer[i];
}
delete[] m_TilesOfLayer;
}
@ -472,6 +464,11 @@ void CMapLayers::OnMapLoad()
if(PassedGameLayer)
return;
}
else if(m_Type == TYPE_FOREGROUND)
{
if(!PassedGameLayer)
continue;
}
if(pLayer->m_Type == LAYERTYPE_TILES)
{
@ -632,75 +629,70 @@ void CMapLayers::OnMapLoad()
//the amount of tiles handled before this tile
int TilesHandledCount = tmpTiles.size();
Visuals.m_TilesOfLayer[y][x].m_IndexBufferByteOffset = (char*)(TilesHandledCount*6*sizeof(unsigned int));
Visuals.m_TilesOfLayer[y][x].m_TilesHandledCount = tmpTiles.size();
Visuals.m_TilesOfLayer[y*pTMap->m_Width + x].SetIndexBufferByteOffset((offset_ptr32)(TilesHandledCount*6*sizeof(unsigned int)));
bool AddAsSpeedup = false;
if(IsSpeedupLayer && CurOverlay == 0)
AddAsSpeedup = true;
if(AddTile(tmpTiles, tmpTileTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_TilesOfLayer[y][x].m_Draw = true;
Visuals.m_TilesOfLayer[y*pTMap->m_Width + x].Draw(true);
//do the border tiles
if(x == 0)
{
if(y == 0)
{
Visuals.m_BorderTopLeft.m_IndexBufferByteOffset = (char*)(tmpBorderCorners.size()*6*sizeof(unsigned int));
Visuals.m_BorderTopLeft.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderTopLeft.m_Draw = true;
Visuals.m_BorderTopLeft.Draw(true);
} else if(y == pTMap->m_Height - 1)
{
Visuals.m_BorderBottomLeft.m_IndexBufferByteOffset = (char*)(tmpBorderCorners.size()*6*sizeof(unsigned int));
Visuals.m_BorderBottomLeft.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderBottomLeft.m_Draw = true;
Visuals.m_BorderBottomLeft.Draw(true);
} else
{
Visuals.m_BorderLeft[y-1].m_IndexBufferByteOffset = (char*)(tmpBorderLeftTiles.size()*6*sizeof(unsigned int));
Visuals.m_BorderLeft[y-1].m_TilesHandledCount = tmpBorderLeftTiles.size();
Visuals.m_BorderLeft[y-1].SetIndexBufferByteOffset((offset_ptr32)(tmpBorderLeftTiles.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderLeftTiles, tmpBorderLeftTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderLeft[y-1].m_Draw = true;
Visuals.m_BorderLeft[y-1].Draw(true);
}
} else if(x == pTMap->m_Width - 1)
{
if(y == 0)
{
Visuals.m_BorderTopRight.m_IndexBufferByteOffset = (char*)(tmpBorderCorners.size()*6*sizeof(unsigned int));
Visuals.m_BorderTopRight.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderTopRight.m_Draw = true;
Visuals.m_BorderTopRight.Draw(true);
} else if(y == pTMap->m_Height - 1)
{
Visuals.m_BorderBottomRight.m_IndexBufferByteOffset = (char*)(tmpBorderCorners.size()*6*sizeof(unsigned int));
Visuals.m_BorderBottomRight.SetIndexBufferByteOffset((offset_ptr32)(tmpBorderCorners.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderCorners, tmpBorderCornersTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderBottomRight.m_Draw = true;
Visuals.m_BorderBottomRight.Draw(true);
} else
{
Visuals.m_BorderRight[y-1].m_IndexBufferByteOffset = (char*)(tmpBorderRightTiles.size()*6*sizeof(unsigned int));
Visuals.m_BorderRight[y-1].m_TilesHandledCount = tmpBorderRightTiles.size();
Visuals.m_BorderRight[y-1].SetIndexBufferByteOffset((offset_ptr32)(tmpBorderRightTiles.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderRightTiles, tmpBorderRightTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderRight[y-1].m_Draw = true;
Visuals.m_BorderRight[y-1].Draw(true);
}
} else if(y == 0)
{
if(x > 0 && x < pTMap->m_Width - 1)
{
Visuals.m_BorderTop[x-1].m_IndexBufferByteOffset = (char*)(tmpBorderTopTiles.size()*6*sizeof(unsigned int));
Visuals.m_BorderTop[x-1].m_TilesHandledCount = tmpBorderTopTiles.size();
Visuals.m_BorderTop[x-1].SetIndexBufferByteOffset((offset_ptr32)(tmpBorderTopTiles.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderTopTiles, tmpBorderTopTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderTop[x-1].m_Draw = true;
Visuals.m_BorderTop[x-1].Draw(true);
}
} else if(y == pTMap->m_Height - 1)
{
if(x > 0 && x < pTMap->m_Width - 1)
{
Visuals.m_BorderBottom[x-1].m_IndexBufferByteOffset = (char*)(tmpBorderBottomTiles.size()*6*sizeof(unsigned int));
Visuals.m_BorderBottom[x-1].m_TilesHandledCount = tmpBorderBottomTiles.size();
Visuals.m_BorderBottom[x-1].SetIndexBufferByteOffset((offset_ptr32)(tmpBorderBottomTiles.size()*6*sizeof(unsigned int)));
if(AddTile(tmpBorderBottomTiles, tmpBorderBottomTilesTexCoords, Index, Flags, x, y, pGroup, DoTextureCoords, AddAsSpeedup, AngleRotate))
Visuals.m_BorderBottom[x-1].m_Draw = true;
Visuals.m_BorderBottom[x-1].Draw(true);
}
}
}
@ -709,17 +701,17 @@ void CMapLayers::OnMapLoad()
//append one kill tile to the gamelayer
if(IsGameLayer)
{
Visuals.m_BorderKillTile.m_IndexBufferByteOffset = (char*)(tmpTiles.size() * 6 * sizeof(unsigned int));
Visuals.m_BorderKillTile.SetIndexBufferByteOffset((offset_ptr32)(tmpTiles.size() * 6 * sizeof(unsigned int)));
if(AddTile(tmpTiles, tmpTileTexCoords, TILE_DEATH, 0, 0, 0, pGroup, DoTextureCoords))
Visuals.m_BorderKillTile.m_Draw = true;
Visuals.m_BorderKillTile.Draw(true);
}
//add the border corners, then the borders and fix their byte offsets
int TilesHandledCount = tmpTiles.size();
Visuals.m_BorderTopLeft.m_IndexBufferByteOffset += TilesHandledCount*6*sizeof(unsigned int);
Visuals.m_BorderTopRight.m_IndexBufferByteOffset += TilesHandledCount*6*sizeof(unsigned int);
Visuals.m_BorderBottomLeft.m_IndexBufferByteOffset += TilesHandledCount*6*sizeof(unsigned int);
Visuals.m_BorderBottomRight.m_IndexBufferByteOffset += TilesHandledCount*6*sizeof(unsigned int);
Visuals.m_BorderTopLeft.AddIndexBufferByteOffset(TilesHandledCount*6*sizeof(unsigned int));
Visuals.m_BorderTopRight.AddIndexBufferByteOffset(TilesHandledCount*6*sizeof(unsigned int));
Visuals.m_BorderBottomLeft.AddIndexBufferByteOffset(TilesHandledCount*6*sizeof(unsigned int));
Visuals.m_BorderBottomRight.AddIndexBufferByteOffset(TilesHandledCount*6*sizeof(unsigned int));
//add the Corners to the tiles
tmpTiles.insert(tmpTiles.end(), tmpBorderCorners.begin(), tmpBorderCorners.end());
tmpTileTexCoords.insert(tmpTileTexCoords.end(), tmpBorderCornersTexCoords.begin(), tmpBorderCornersTexCoords.end());
@ -730,7 +722,7 @@ void CMapLayers::OnMapLoad()
{
for(int i = 0; i < pTMap->m_Width-2; ++i)
{
Visuals.m_BorderTop[i].m_IndexBufferByteOffset += TilesHandledCount*6*sizeof(unsigned int);
Visuals.m_BorderTop[i].AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int));
}
}
tmpTiles.insert(tmpTiles.end(), tmpBorderTopTiles.begin(), tmpBorderTopTiles.end());
@ -741,7 +733,7 @@ void CMapLayers::OnMapLoad()
{
for(int i = 0; i < pTMap->m_Width-2; ++i)
{
Visuals.m_BorderBottom[i].m_IndexBufferByteOffset += TilesHandledCount*6*sizeof(unsigned int);
Visuals.m_BorderBottom[i].AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int));
}
}
tmpTiles.insert(tmpTiles.end(), tmpBorderBottomTiles.begin(), tmpBorderBottomTiles.end());
@ -752,7 +744,7 @@ void CMapLayers::OnMapLoad()
{
for(int i = 0; i < pTMap->m_Height-2; ++i)
{
Visuals.m_BorderLeft[i].m_IndexBufferByteOffset += TilesHandledCount*6*sizeof(unsigned int);
Visuals.m_BorderLeft[i].AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int));
}
}
tmpTiles.insert(tmpTiles.end(), tmpBorderLeftTiles.begin(), tmpBorderLeftTiles.end());
@ -763,7 +755,7 @@ void CMapLayers::OnMapLoad()
{
for(int i = 0; i < pTMap->m_Height-2; ++i)
{
Visuals.m_BorderRight[i].m_IndexBufferByteOffset += TilesHandledCount*6*sizeof(unsigned int);
Visuals.m_BorderRight[i].AddIndexBufferByteOffset(TilesHandledCount * 6 * sizeof(unsigned int));
}
}
tmpTiles.insert(tmpTiles.end(), tmpBorderRightTiles.begin(), tmpBorderRightTiles.end());
@ -852,15 +844,16 @@ void CMapLayers::RenderTileLayer(int LayerIndex, vec4* pColor, CMapItemLayerTile
for(int y = Y0; y <= Y1; ++y)
{
if (X0 > X1) continue;
if(X0 > X1)
continue;
dbg_assert(Visuals.m_TilesOfLayer[y][X1].m_TilesHandledCount >= Visuals.m_TilesOfLayer[y][X0].m_TilesHandledCount, "Tile count wrong.");
dbg_assert(Visuals.m_TilesOfLayer[y*pTileLayer->m_Width + X1].IndexBufferByteOffset() >= Visuals.m_TilesOfLayer[y*pTileLayer->m_Width + X0].IndexBufferByteOffset(), "Tile count wrong.");
unsigned int NumVertices = (Visuals.m_TilesOfLayer[y][X1].m_TilesHandledCount - Visuals.m_TilesOfLayer[y][X0].m_TilesHandledCount) * 6lu + (Visuals.m_TilesOfLayer[y][X1].m_Draw ? 6lu : 0lu);
unsigned int NumVertices = ((Visuals.m_TilesOfLayer[y*pTileLayer->m_Width + X1].IndexBufferByteOffset() - Visuals.m_TilesOfLayer[y*pTileLayer->m_Width + X0].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_TilesOfLayer[y*pTileLayer->m_Width + X1].DoDraw() ? 6lu : 0lu);
if(NumVertices)
{
s_IndexOffsets.push_back(Visuals.m_TilesOfLayer[y][X0].m_IndexBufferByteOffset);
s_IndexOffsets.push_back((offset_ptr_size)Visuals.m_TilesOfLayer[y*pTileLayer->m_Width + X0].IndexBufferByteOffset());
s_DrawCounts.push_back(NumVertices);
}
}
@ -898,7 +891,7 @@ void CMapLayers::DrawTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerTilem
//draw corners on left side
if(BorderY0 < 0)
{
if (Visuals.m_BorderTopLeft.m_Draw)
if(Visuals.m_BorderTopLeft.DoDraw())
{
vec2 Offset;
Offset.x = BorderX0 * 32.f;
@ -909,12 +902,12 @@ void CMapLayers::DrawTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerTilem
int Count = (absolute(BorderX0)+1) * (absolute(BorderY0)+1) - 1;//dont draw the corner again
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, Visuals.m_BorderTopLeft.m_IndexBufferByteOffset, (float*)&Offset, (float*)&Dir, absolute(BorderX0)+1, Count);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, (offset_ptr_size)Visuals.m_BorderTopLeft.IndexBufferByteOffset(), (float*)&Offset, (float*)&Dir, absolute(BorderX0)+1, Count);
}
}
if(BorderY1 >= pTileLayer->m_Height)
{
if (Visuals.m_BorderBottomLeft.m_Draw)
if(Visuals.m_BorderBottomLeft.DoDraw())
{
vec2 Offset;
Offset.x = BorderX0 * 32.f;
@ -925,14 +918,14 @@ void CMapLayers::DrawTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerTilem
int Count = (absolute(BorderX0)+1) * ((BorderY1-pTileLayer->m_Height)+1) - 1;//dont draw the corner again
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, Visuals.m_BorderBottomLeft.m_IndexBufferByteOffset, (float*)&Offset, (float*)&Dir, absolute(BorderX0)+1, Count);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, (offset_ptr_size)Visuals.m_BorderBottomLeft.IndexBufferByteOffset(), (float*)&Offset, (float*)&Dir, absolute(BorderX0)+1, Count);
}
}
//draw left border
if(Y0 < pTileLayer->m_Height - 1 && Y1 > 0)
{
unsigned int DrawNum = (Visuals.m_BorderLeft[Y1-1].m_TilesHandledCount - Visuals.m_BorderLeft[Y0-1].m_TilesHandledCount) * 6lu + (Visuals.m_BorderLeft[Y1-1].m_Draw ? 6lu : 0lu);
char* pOffset = Visuals.m_BorderLeft[Y0-1].m_IndexBufferByteOffset;
unsigned int DrawNum = ((Visuals.m_BorderLeft[Y1-1].IndexBufferByteOffset() - Visuals.m_BorderLeft[Y0-1].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_BorderLeft[Y1-1].DoDraw() ? 6lu : 0lu);
offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_BorderLeft[Y0-1].IndexBufferByteOffset();
vec2 Dir;
Dir.x = -32.f;
Dir.y = 0.f;
@ -945,7 +938,7 @@ void CMapLayers::DrawTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerTilem
//draw corners on right side
if(BorderY0 < 0)
{
if (Visuals.m_BorderTopRight.m_Draw)
if(Visuals.m_BorderTopRight.DoDraw())
{
vec2 Offset;
Offset.x = (BorderX1-pTileLayer->m_Width) * 32.f;
@ -956,12 +949,12 @@ void CMapLayers::DrawTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerTilem
int Count = (BorderX1-pTileLayer->m_Width+1) * (absolute(BorderY0)+1) - 1;//dont draw the corner again
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, Visuals.m_BorderTopRight.m_IndexBufferByteOffset, (float*)&Offset, (float*)&Dir, (BorderX1-pTileLayer->m_Width)+1, Count);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, (offset_ptr_size)Visuals.m_BorderTopRight.IndexBufferByteOffset(), (float*)&Offset, (float*)&Dir, (BorderX1-pTileLayer->m_Width)+1, Count);
}
}
if(BorderY1 >= pTileLayer->m_Height)
{
if (Visuals.m_BorderBottomRight.m_Draw)
if(Visuals.m_BorderBottomRight.DoDraw())
{
vec2 Offset;
Offset.x = (BorderX1-pTileLayer->m_Width) * 32.f;
@ -972,14 +965,14 @@ void CMapLayers::DrawTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerTilem
int Count = (BorderX1-pTileLayer->m_Width+1) * ((BorderY1-pTileLayer->m_Height)+1) - 1;//dont draw the corner again
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, Visuals.m_BorderBottomRight.m_IndexBufferByteOffset, (float*)&Offset, (float*)&Dir, (BorderX1-pTileLayer->m_Width)+1, Count);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, (offset_ptr_size)Visuals.m_BorderBottomRight.IndexBufferByteOffset(), (float*)&Offset, (float*)&Dir, (BorderX1-pTileLayer->m_Width)+1, Count);
}
}
//draw right border
if(Y0 < pTileLayer->m_Height - 1 && Y1 > 0)
{
unsigned int DrawNum = (Visuals.m_BorderRight[Y1-1].m_TilesHandledCount - Visuals.m_BorderRight[Y0-1].m_TilesHandledCount) * 6lu + (Visuals.m_BorderRight[Y1-1].m_Draw ? 6lu : 0lu);;
char* pOffset = Visuals.m_BorderRight[Y0-1].m_IndexBufferByteOffset;
unsigned int DrawNum = ((Visuals.m_BorderRight[Y1-1].IndexBufferByteOffset() - Visuals.m_BorderRight[Y0-1].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_BorderRight[Y1-1].DoDraw() ? 6lu : 0lu);;
offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_BorderRight[Y0-1].IndexBufferByteOffset();
vec2 Dir;
Dir.x = 32.f;
Dir.y = 0.f;
@ -991,8 +984,8 @@ void CMapLayers::DrawTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerTilem
//draw top border
if(X0 < pTileLayer->m_Width - 1 && X1 > 0)
{
unsigned int DrawNum = (Visuals.m_BorderTop[X1-1].m_TilesHandledCount - Visuals.m_BorderTop[X0-1].m_TilesHandledCount) * 6lu + (Visuals.m_BorderTop[X1-1].m_Draw ? 6lu : 0lu);;
char* pOffset = Visuals.m_BorderTop[X0-1].m_IndexBufferByteOffset;
unsigned int DrawNum = ((Visuals.m_BorderTop[X1-1].IndexBufferByteOffset() - Visuals.m_BorderTop[X0-1].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_BorderTop[X1-1].DoDraw() ? 6lu : 0lu);;
offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_BorderTop[X0-1].IndexBufferByteOffset();
vec2 Dir;
Dir.x = 0.f;
Dir.y = -32.f;
@ -1004,8 +997,8 @@ void CMapLayers::DrawTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerTilem
//draw bottom border
if(X0 < pTileLayer->m_Width - 1 && X1 > 0)
{
unsigned int DrawNum = (Visuals.m_BorderBottom[X1-1].m_TilesHandledCount - Visuals.m_BorderBottom[X0-1].m_TilesHandledCount) * 6lu + (Visuals.m_BorderBottom[X1-1].m_Draw ? 6lu : 0lu);;
char* pOffset = Visuals.m_BorderBottom[X0-1].m_IndexBufferByteOffset;
unsigned int DrawNum = ((Visuals.m_BorderBottom[X1-1].IndexBufferByteOffset() - Visuals.m_BorderBottom[X0-1].IndexBufferByteOffset()) / sizeof(unsigned int)) + (Visuals.m_BorderBottom[X1-1].DoDraw() ? 6lu : 0lu);;
offset_ptr_size pOffset = (offset_ptr_size)Visuals.m_BorderBottom[X0-1].IndexBufferByteOffset();
vec2 Dir;
Dir.x = 0.f;
Dir.y = 32.f;
@ -1036,7 +1029,7 @@ void CMapLayers::DrawKillTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerT
if(BorderY1 >= pTileLayer->m_Height + 201) DrawBorder = true;
if(!DrawBorder) return;
if (!Visuals.m_BorderKillTile.m_Draw) return;
if(!Visuals.m_BorderKillTile.DoDraw()) return;
if(BorderX0 < -300) BorderX0 = -300;
if(BorderY0 < -300) BorderY0 = -300;
@ -1060,7 +1053,7 @@ void CMapLayers::DrawKillTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerT
int Count = (absolute(BorderX0) - 201) * (BorderY1 - BorderY0);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, Visuals.m_BorderKillTile.m_IndexBufferByteOffset, (float*)&Offset, (float*)&Dir, (absolute(BorderX0) - 201), Count);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(), (float*)&Offset, (float*)&Dir, (absolute(BorderX0) - 201), Count);
}
//draw top kill tile border
if(BorderY0 < -201)
@ -1076,7 +1069,7 @@ void CMapLayers::DrawKillTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerT
int Count = (OffX1 - OffX0) * (absolute(BorderY0)-201);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, Visuals.m_BorderKillTile.m_IndexBufferByteOffset, (float*)&Offset, (float*)&Dir, (OffX1 - OffX0), Count);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(), (float*)&Offset, (float*)&Dir, (OffX1 - OffX0), Count);
}
if(BorderX1 >= pTileLayer->m_Width + 201)
{
@ -1089,7 +1082,7 @@ void CMapLayers::DrawKillTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerT
int Count = (BorderX1 - (pTileLayer->m_Width + 201)) * (BorderY1 - BorderY0);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, Visuals.m_BorderKillTile.m_IndexBufferByteOffset, (float*)&Offset, (float*)&Dir, (BorderX1 - (pTileLayer->m_Width + 201)), Count);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(), (float*)&Offset, (float*)&Dir, (BorderX1 - (pTileLayer->m_Width + 201)), Count);
}
if(BorderY1 >= pTileLayer->m_Height + 201)
{
@ -1104,7 +1097,7 @@ void CMapLayers::DrawKillTileBorder(int LayerIndex, vec4* pColor, CMapItemLayerT
int Count = (OffX1 - OffX0) * (BorderY1-(pTileLayer->m_Height + 201));
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, Visuals.m_BorderKillTile.m_IndexBufferByteOffset, (float*)&Offset, (float*)&Dir, (OffX1 - OffX0), Count);
Graphics()->DrawBorderTile(Visuals.m_VisualObjectsIndex, (float*)pColor, (offset_ptr_size)Visuals.m_BorderKillTile.IndexBufferByteOffset(), (float*)&Offset, (float*)&Dir, (OffX1 - OffX0), Count);
}
}
@ -1141,11 +1134,17 @@ int CMapLayers::TileLayersOfGroup(CMapItemGroup* pGroup)
if(pLayer == (CMapItemLayer*)m_pLayers->TuneLayer())
IsTuneLayer = true;
else if(m_Type <= TYPE_BACKGROUND_FORCE)
if(m_Type <= TYPE_BACKGROUND_FORCE)
{
if(PassedGameLayer)
return TileLayerCounter;
}
else if(m_Type == TYPE_FOREGROUND)
{
if(!PassedGameLayer)
continue;
}
if(pLayer->m_Type == LAYERTYPE_TILES)
{
@ -1327,7 +1326,7 @@ void CMapLayers::OnRender()
}
}
if(pLayer->m_Type == LAYERTYPE_TILES)
if((Render || IsGameLayer) && pLayer->m_Type == LAYERTYPE_TILES)
{
CMapItemLayerTilemap *pTMap = (CMapItemLayerTilemap *)pLayer;
int DataIndex = 0;

View file

@ -11,6 +11,10 @@
#define INDEX_BUFFER_GROUP_HEIGHT 9
#define INDEX_BORDER_BUFFER_GROUP_SIZE 20
typedef char* offset_ptr_size;
typedef uintptr_t offset_ptr;
typedef unsigned int offset_ptr32;
class CMapLayers : public CComponent
{
friend class CBackground;
@ -40,12 +44,36 @@ class CMapLayers : public CComponent
struct STileVisual
{
STileVisual() : m_IndexBufferByteOffset(0), m_TilesHandledCount(0), m_Draw(false) { }
char* m_IndexBufferByteOffset;
unsigned int m_TilesHandledCount; //number of tiles that were handled before this tile + this tile if added
bool m_Draw;
STileVisual() : m_IndexBufferByteOffset(0) { }
private:
offset_ptr32 m_IndexBufferByteOffset;
public:
bool DoDraw()
{
return (bool)((m_IndexBufferByteOffset&0x80000000) != 0);
}
void Draw(bool SetDraw)
{
m_IndexBufferByteOffset = (SetDraw ? 0x80000000 : 0) | (m_IndexBufferByteOffset & 0x7FFFFFFF);
}
offset_ptr IndexBufferByteOffset()
{
return ((offset_ptr)(m_IndexBufferByteOffset & 0x7FFFFFFF));
}
void SetIndexBufferByteOffset(offset_ptr32 IndexBufferByteOff)
{
m_IndexBufferByteOffset = IndexBufferByteOff | (m_IndexBufferByteOffset & 0x80000000);
}
void AddIndexBufferByteOffset(offset_ptr32 IndexBufferByteOff)
{
m_IndexBufferByteOffset = (((offset_ptr32)(m_IndexBufferByteOffset & 0x7FFFFFFF)) + IndexBufferByteOff) | (m_IndexBufferByteOffset & 0x80000000);
}
};
STileVisual** m_TilesOfLayer;
STileVisual* m_TilesOfLayer;
STileVisual m_BorderTopLeft;
STileVisual m_BorderTopRight;