Fix sprites being indexed funky. Consolidated tile group code, broke some of the overlapping tiles functionality.

This commit is contained in:
sigonasr2 2023-09-07 04:41:23 -05:00
parent 56f9aaca1d
commit 2831c8d626
8 changed files with 44 additions and 31 deletions

View File

@ -921,41 +921,45 @@ void Crawler::LoadLevel(MapName map){
int tileSheetY=tileSheetIndex/tileSheetWidth; int tileSheetY=tileSheetIndex/tileSheetWidth;
#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){
if(IsForeground(tileSheet,tileSheetIndex)&&foregroundTilesIncluded.find({x,y})==foregroundTilesIncluded.end()){ int layerID=layer.tag.GetInteger("id");
std::queue<vi2d>tileGroupChecks; if(IsForeground(tileSheet,tileSheetIndex)){
TileGroup group; if(foregroundTilesIncluded.find({x,y})==foregroundTilesIncluded.end()){
foregroundTilesIncluded.insert({x,y}); std::queue<vi2d>tileGroupChecks;
group.InsertTile(tile); TileGroup group;
if(x>0)tileGroupChecks.push({x-1,y}); foregroundTilesIncluded.insert({x,y});
if(x<WORLD_SIZE.x-1)tileGroupChecks.push({x+1,y}); group.originatingLayer=layerID;
if(y>0)tileGroupChecks.push({x,y-1}); group.InsertTile(tile);
if(y<WORLD_SIZE.y-1)tileGroupChecks.push({x,y+1}); if(x>0)tileGroupChecks.push({x-1,y});
while(!tileGroupChecks.empty()){ if(x<WORLD_SIZE.x-1)tileGroupChecks.push({x+1,y});
vi2d&pos=tileGroupChecks.front(); if(y>0)tileGroupChecks.push({x,y-1});
tileGroupChecks.pop(); if(y<WORLD_SIZE.y-1)tileGroupChecks.push({x,y+1});
int tileID=layer.tiles[pos.y][pos.x]-1; while(!tileGroupChecks.empty()){
TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); vi2d&pos=tileGroupChecks.front();
int tileSheetWidth=tileSheet.tileset.tileset->Sprite()->width/24; tileGroupChecks.pop();
int tileSheetHeight=tileSheet.tileset.tileset->Sprite()->height/24; int tileID=layer.tiles[pos.y][pos.x]-1;
int tileSheetIndex=tileID-(tileSheet.firstgid-1); TilesheetData tileSheet=GetTileSheet(currentLevel,tileID);
int tileSheetX=tileSheetIndex%tileSheetWidth; int tileSheetWidth=tileSheet.tileset.tileset->Sprite()->width/24;
int tileSheetY=tileSheetIndex/tileSheetWidth; int tileSheetHeight=tileSheet.tileset.tileset->Sprite()->height/24;
TileRenderData tile={tileSheet.tileset.tileset->Decal(),pos*24,vi2d{tileSheetX,tileSheetY}*24}; int tileSheetIndex=tileID-(tileSheet.firstgid-1);
if(IsForegroundTile(tileSheet,tileSheetIndex)&&foregroundTilesIncluded.find(pos)==foregroundTilesIncluded.end()){ int tileSheetX=tileSheetIndex%tileSheetWidth;
foregroundTilesIncluded.insert(pos); int tileSheetY=tileSheetIndex/tileSheetWidth;
group.InsertTile(tile); TileRenderData tile={tileSheet.tileset.tileset->Decal(),pos*24,vi2d{tileSheetX,tileSheetY}*24};
if(pos.x>0)tileGroupChecks.push(pos+vi2d{-1,0}); if(IsForeground(tileSheet,tileSheetIndex)&&foregroundTilesIncluded.find(pos)==foregroundTilesIncluded.end()){
if(pos.x<WORLD_SIZE.x-1)tileGroupChecks.push(pos+vi2d{1,0}); foregroundTilesIncluded.insert(pos);
if(pos.y>0)tileGroupChecks.push(pos+vi2d{0,-1}); group.InsertTile(tile);
if(pos.y<WORLD_SIZE.y-1)tileGroupChecks.push(pos+vi2d{0,1}); 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});
}
} }
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};
SetupTileGroups([&](TilesheetData sheet,int tileID){return IsForegroundTile(sheet,tileID);},tile,foregroundTilesAdded,foregroundTileGroups); SetupTileGroups([&](TilesheetData sheet,int tileID){return IsForegroundTile(sheet,tileID);},tile,foregroundTilesAdded,foregroundTileGroups);
SetupTileGroups([&](TilesheetData sheet,int tileID){return IsUpperForegroundTile(sheet,tileID);},tile,foregroundTilesAdded,foregroundTileGroups); SetupTileGroups([&](TilesheetData sheet,int tileID){return IsUpperForegroundTile(sheet,tileID);},tile,upperForegroundTilesAdded,upperForegroundTileGroups);
#pragma endregion #pragma endregion
} }
} }

View File

@ -109,4 +109,12 @@ public:
datafiledoubledata GetDoubleList(std::string key); datafiledoubledata GetDoubleList(std::string key);
static void OutputDebugInfo(const char*key,std::size_t len); static void OutputDebugInfo(const char*key,std::size_t len);
void InitializeLevels(); void InitializeLevels();
struct TileGroupData{
vi2d tilePos;
int layer;
bool operator<(const TileGroupData&rhs)const{
return layer<rhs.layer||(layer==rhs.layer&&tilePos<rhs.tilePos);
}
};
}; };

View File

@ -44,4 +44,5 @@ public:
void InsertTile(TileRenderData tile); void InsertTile(TileRenderData tile);
bool playerBehind=false; bool playerBehind=false;
float fadeFactor=0.f; float fadeFactor=0.f;
int originatingLayer=-1;
}; };

View File

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 1069 #define VERSION_BUILD 1079
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB