|
|
@ -922,39 +922,67 @@ void Crawler::LoadLevel(MapName map){ |
|
|
|
#pragma region TileGroupShenanigans |
|
|
|
#pragma region TileGroupShenanigans |
|
|
|
auto SetupTileGroups=[&](std::function<bool(TilesheetData,int)>IsForeground,TileRenderData tile,std::set<vi2d>&foregroundTilesIncluded,std::vector<TileGroup>&groups){ |
|
|
|
auto SetupTileGroups=[&](std::function<bool(TilesheetData,int)>IsForeground,TileRenderData tile,std::set<vi2d>&foregroundTilesIncluded,std::vector<TileGroup>&groups){ |
|
|
|
int layerID=layer.tag.GetInteger("id"); |
|
|
|
int layerID=layer.tag.GetInteger("id"); |
|
|
|
if(IsForeground(tileSheet,tileSheetIndex)){ |
|
|
|
if(IsForeground(tileSheet,tileSheetIndex)&&foregroundTilesIncluded.find({x,y})==foregroundTilesIncluded.end()){ |
|
|
|
if(foregroundTilesIncluded.find({x,y})==foregroundTilesIncluded.end()){ |
|
|
|
std::queue<vi2d>tileGroupChecks; |
|
|
|
std::queue<vi2d>tileGroupChecks; |
|
|
|
TileGroup group; |
|
|
|
TileGroup group; |
|
|
|
foregroundTilesIncluded.insert({x,y}); |
|
|
|
foregroundTilesIncluded.insert({x,y}); |
|
|
|
group.originatingLayer=layerID; |
|
|
|
group.originatingLayer=layerID; |
|
|
|
group.InsertTile(tile); |
|
|
|
group.InsertTile(tile); |
|
|
|
if(x>0)tileGroupChecks.push({x-1,y}); |
|
|
|
if(x>0)tileGroupChecks.push({x-1,y}); |
|
|
|
if(x<WORLD_SIZE.x-1)tileGroupChecks.push({x+1,y}); |
|
|
|
if(x<WORLD_SIZE.x-1)tileGroupChecks.push({x+1,y}); |
|
|
|
if(y>0)tileGroupChecks.push({x,y-1}); |
|
|
|
if(y>0)tileGroupChecks.push({x,y-1}); |
|
|
|
if(y<WORLD_SIZE.y-1)tileGroupChecks.push({x,y+1}); |
|
|
|
if(y<WORLD_SIZE.y-1)tileGroupChecks.push({x,y+1}); |
|
|
|
for(LayerTag&layer2:MAP_DATA[currentLevel].LayerData){ |
|
|
|
while(!tileGroupChecks.empty()){ |
|
|
|
if(&layer==&layer2)continue; |
|
|
|
vi2d&pos=tileGroupChecks.front(); |
|
|
|
int tileID=layer2.tiles[y][x]-1; |
|
|
|
tileGroupChecks.pop(); |
|
|
|
TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); |
|
|
|
int tileID=layer.tiles[pos.y][pos.x]-1; |
|
|
|
int tileSheetWidth=tileSheet.tileset.tileset->Sprite()->width/24; |
|
|
|
TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); |
|
|
|
int tileSheetHeight=tileSheet.tileset.tileset->Sprite()->height/24; |
|
|
|
int tileSheetWidth=tileSheet.tileset.tileset->Sprite()->width/24; |
|
|
|
int tileSheetIndex=tileID-(tileSheet.firstgid-1); |
|
|
|
int tileSheetHeight=tileSheet.tileset.tileset->Sprite()->height/24; |
|
|
|
int tileSheetX=tileSheetIndex%tileSheetWidth; |
|
|
|
int tileSheetIndex=tileID-(tileSheet.firstgid-1); |
|
|
|
int tileSheetY=tileSheetIndex/tileSheetWidth; |
|
|
|
int tileSheetX=tileSheetIndex%tileSheetWidth; |
|
|
|
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24}; |
|
|
|
int tileSheetY=tileSheetIndex/tileSheetWidth; |
|
|
|
if(IsForeground(tileSheet,tileSheetIndex)){ |
|
|
|
TileRenderData tile={tileSheet.tileset.tileset->Decal(),pos*24,vi2d{tileSheetX,tileSheetY}*24}; |
|
|
|
foregroundTilesIncluded.insert({x,y}); |
|
|
|
if(IsForeground(tileSheet,tileSheetIndex)&&foregroundTilesIncluded.find(pos)==foregroundTilesIncluded.end()){ |
|
|
|
group.InsertTile(tile); |
|
|
|
foregroundTilesIncluded.insert(pos); |
|
|
|
} |
|
|
|
group.InsertTile(tile); |
|
|
|
} |
|
|
|
if(pos.x>0)tileGroupChecks.push(pos+vi2d{-1,0}); |
|
|
|
while(!tileGroupChecks.empty()){ |
|
|
|
if(pos.x<WORLD_SIZE.x-1)tileGroupChecks.push(pos+vi2d{1,0}); |
|
|
|
vi2d&pos=tileGroupChecks.front(); |
|
|
|
if(pos.y>0)tileGroupChecks.push(pos+vi2d{0,-1}); |
|
|
|
tileGroupChecks.pop(); |
|
|
|
if(pos.y<WORLD_SIZE.y-1)tileGroupChecks.push(pos+vi2d{0,1}); |
|
|
|
int tileID=layer.tiles[pos.y][pos.x]-1; |
|
|
|
|
|
|
|
TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); |
|
|
|
|
|
|
|
int tileSheetWidth=tileSheet.tileset.tileset->Sprite()->width/24; |
|
|
|
|
|
|
|
int tileSheetHeight=tileSheet.tileset.tileset->Sprite()->height/24; |
|
|
|
|
|
|
|
int tileSheetIndex=tileID-(tileSheet.firstgid-1); |
|
|
|
|
|
|
|
int tileSheetX=tileSheetIndex%tileSheetWidth; |
|
|
|
|
|
|
|
int tileSheetY=tileSheetIndex/tileSheetWidth; |
|
|
|
|
|
|
|
TileRenderData tile={tileSheet.tileset.tileset->Decal(),pos*24,vi2d{tileSheetX,tileSheetY}*24}; |
|
|
|
|
|
|
|
if(IsForeground(tileSheet,tileSheetIndex)&&foregroundTilesIncluded.find(pos)==foregroundTilesIncluded.end()){ |
|
|
|
|
|
|
|
foregroundTilesIncluded.insert(pos); |
|
|
|
|
|
|
|
group.InsertTile(tile); |
|
|
|
|
|
|
|
if(pos.x>0)tileGroupChecks.push(pos+vi2d{-1,0}); |
|
|
|
|
|
|
|
if(pos.x<WORLD_SIZE.x-1)tileGroupChecks.push(pos+vi2d{1,0}); |
|
|
|
|
|
|
|
if(pos.y>0)tileGroupChecks.push(pos+vi2d{0,-1}); |
|
|
|
|
|
|
|
if(pos.y<WORLD_SIZE.y-1)tileGroupChecks.push(pos+vi2d{0,1}); |
|
|
|
|
|
|
|
for(LayerTag&layer2:MAP_DATA[currentLevel].LayerData){ |
|
|
|
|
|
|
|
if(&layer==&layer2)continue; |
|
|
|
|
|
|
|
int tileID=layer2.tiles[pos.y][pos.x]-1; |
|
|
|
|
|
|
|
TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); |
|
|
|
|
|
|
|
int tileSheetWidth=tileSheet.tileset.tileset->Sprite()->width/24; |
|
|
|
|
|
|
|
int tileSheetHeight=tileSheet.tileset.tileset->Sprite()->height/24; |
|
|
|
|
|
|
|
int tileSheetIndex=tileID-(tileSheet.firstgid-1); |
|
|
|
|
|
|
|
int tileSheetX=tileSheetIndex%tileSheetWidth; |
|
|
|
|
|
|
|
int tileSheetY=tileSheetIndex/tileSheetWidth; |
|
|
|
|
|
|
|
TileRenderData tile={tileSheet.tileset.tileset->Decal(),pos*24,vi2d{tileSheetX,tileSheetY}*24}; |
|
|
|
|
|
|
|
if(IsForeground(tileSheet,tileSheetIndex)){ |
|
|
|
|
|
|
|
foregroundTilesIncluded.insert(pos); |
|
|
|
|
|
|
|
group.InsertTile(tile); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
groups.push_back(group); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
groups.push_back(group); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24}; |
|
|
|
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24}; |
|
|
|