made a lot of changes, to get the render pipeline working
This commit is contained in:
@@ -7,9 +7,14 @@ TSE::TileMapChunk::TileMapChunk(int _chunksize, const Vector2 &_pos, SortingOrde
|
||||
order = _order;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::SetTile(const Vector2& p, const Vector2& Spriteindex, TileSet* set)
|
||||
void TSE::TileMapChunk::SetTile(const Vector2& p, const Vector2& Spriteindex, const Vector2& Normalindex, TileSet* set)
|
||||
{
|
||||
sprites[p] = set->GetSpriteIdAt(Spriteindex.x, Spriteindex.y);
|
||||
int normalid = -1;
|
||||
if(Normalindex != Vector2(-1,-1))
|
||||
normalid = set->GetSpriteIdAt(Normalindex.x, Normalindex.y);
|
||||
sprites[p] = {set->GetSpriteIdAt(Spriteindex.x, Spriteindex.y), normalid};
|
||||
dirtyPositions = true;
|
||||
dirtySpriteIds = true;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::RemoveTile(Vector2 p)
|
||||
@@ -22,118 +27,130 @@ void TSE::TileMapChunk::SetOrdering(SortingOrder _order)
|
||||
order = _order;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::GetOrderedPositions(Vector2 *array)
|
||||
const std::vector<TSE::Vector2>* TSE::TileMapChunk::GetOrderedPositions()
|
||||
{
|
||||
switch (order)
|
||||
if(dirtyPositions)
|
||||
{
|
||||
case TopLeft:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
orderedPositions.clear();
|
||||
switch (order)
|
||||
{
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
case TopLeft:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->first - offset;
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedPositions.push_back(v->first - offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->first - offset;
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedPositions.push_back(v->first - offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->first - offset;
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedPositions.push_back(v->first - offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->first - offset;
|
||||
Vector2 offset = nextLine * y;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedPositions.push_back(v->first - offset);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
dirtyPositions = false;
|
||||
}
|
||||
return &orderedPositions;
|
||||
}
|
||||
|
||||
void TSE::TileMapChunk::GetOrderedSpriteIds(int *array)
|
||||
const std::vector<TSE::Vector2i>* TSE::TileMapChunk::GetOrderedSpriteIds()
|
||||
{
|
||||
switch (order)
|
||||
if(dirtySpriteIds)
|
||||
{
|
||||
case TopLeft:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
orderedSpriteIDs.clear();
|
||||
switch (order)
|
||||
{
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
case TopLeft:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->second;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedSpriteIDs.push_back(v->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = 0; y < chunksize; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->second;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedSpriteIDs.push_back(v->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->second;
|
||||
for (int x = 0; x < chunksize; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedSpriteIDs.push_back(v->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = chunksize - 1; y >= 0; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
*array++ = v->second;
|
||||
for (int x = chunksize - 1; x >= 0; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = sprites.find(p);
|
||||
if(v != sprites.end())
|
||||
orderedSpriteIDs.push_back(v->second);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
dirtySpriteIds = false;
|
||||
}
|
||||
return &orderedSpriteIDs;
|
||||
}
|
||||
|
||||
int TSE::TileMapChunk::GetChunksize()
|
||||
@@ -154,17 +171,18 @@ void TSE::TileMap::RemoveTile(Vector2 p)
|
||||
chunks[chunkIndex].RemoveTile(chunkInnerPos);
|
||||
}
|
||||
|
||||
void TSE::TileMap::SetTile(Vector2 p, Vector2 Spriteindex)
|
||||
void TSE::TileMap::SetTile(Vector2 p, Vector2 Spriteindex, Vector2 Normalindex)
|
||||
{
|
||||
Vector2 chunkInnerPos = LocalToChunkPos(p);
|
||||
Vector2 chunkIndex = p - chunkInnerPos;
|
||||
if(!chunks.contains(chunkIndex))
|
||||
{
|
||||
dirty = true;
|
||||
chunks[chunkIndex] = TileMapChunk(chunkSize, chunkIndex, order);
|
||||
chunks[chunkIndex].nextLine = nextLine;
|
||||
CheckBounds(chunkIndex);
|
||||
}
|
||||
chunks[chunkIndex].SetTile(chunkInnerPos, Spriteindex, set);
|
||||
chunks[chunkIndex].SetTile(chunkInnerPos, Spriteindex, Normalindex, set);
|
||||
}
|
||||
|
||||
TSE::TileMapChunk* TSE::TileMap::GetChunk(const Vector2 &pos)
|
||||
@@ -175,60 +193,65 @@ TSE::TileMapChunk* TSE::TileMap::GetChunk(const Vector2 &pos)
|
||||
return &chunks[pos];
|
||||
}
|
||||
|
||||
void TSE::TileMap::GetChunkPositionsInOrder(Vector2 *arr)
|
||||
const std::vector<TSE::Vector2>* TSE::TileMap::GetChunkPositionsInOrder()
|
||||
{
|
||||
|
||||
switch (order)
|
||||
if(dirty)
|
||||
{
|
||||
case TopLeft:
|
||||
for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++)
|
||||
orderedChunks.clear();
|
||||
switch (order)
|
||||
{
|
||||
for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++)
|
||||
case TopLeft:
|
||||
for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
*arr++ = v->first;
|
||||
for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
orderedChunks.push_back(v->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++)
|
||||
{
|
||||
for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--)
|
||||
break;
|
||||
case TopRight:
|
||||
for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
*arr++ = v->first;
|
||||
for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
orderedChunks.push_back(v->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--)
|
||||
{
|
||||
for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++)
|
||||
break;
|
||||
case BottomLeft:
|
||||
for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
*arr++ = v->first;
|
||||
for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
orderedChunks.push_back(v->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--)
|
||||
{
|
||||
for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--)
|
||||
break;
|
||||
case BottomRight:
|
||||
for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
*arr++ = v->first;
|
||||
for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--)
|
||||
{
|
||||
Vector2 p(x,y);
|
||||
auto v = chunks.find(p);
|
||||
if(v != chunks.end())
|
||||
orderedChunks.push_back(v->first);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
dirty = false;
|
||||
}
|
||||
return &orderedChunks;
|
||||
}
|
||||
|
||||
int TSE::TileMap::GetChunkCount()
|
||||
|
||||
Reference in New Issue
Block a user