Scuffed lambda function passing for tile group handling. Need to prep multi-layer rendering for tile groups.
This commit is contained in:
parent
c75e56d642
commit
d601f0945a
@ -26,6 +26,7 @@ std::vector<Monster>MONSTER_LIST;
|
||||
std::vector<MonsterSpawner>SPAWNER_LIST;
|
||||
std::vector<std::shared_ptr<DamageNumber>>DAMAGENUMBER_LIST;
|
||||
std::vector<std::unique_ptr<Bullet>>BULLET_LIST;
|
||||
safemap<std::string,MapName>LEVEL_NAMES;
|
||||
utils::datafile DATA;
|
||||
Crawler*game;
|
||||
|
||||
@ -68,14 +69,7 @@ Crawler::Crawler()
|
||||
|
||||
bool Crawler::OnUserCreate(){
|
||||
|
||||
#define INITLEVEL(map) InitializeLevel("map_path"_S + "Levels."#map ## _S,map);
|
||||
|
||||
INITLEVEL(WORLD_MAP);
|
||||
|
||||
INITLEVEL(CAMPAIGN_1_1);
|
||||
INITLEVEL(BOSS_1);
|
||||
|
||||
INITLEVEL(CAMPAIGN_1_2);
|
||||
InitializeLevels();
|
||||
|
||||
player=std::make_unique<Warrior>();
|
||||
|
||||
@ -129,7 +123,7 @@ bool Crawler::OnUserCreate(){
|
||||
sig::Animation::SetupPlayerAnimations();
|
||||
view=TileTransformedView{GetScreenSize(),{1,1}};
|
||||
|
||||
LoadLevel(BOSS_1);
|
||||
LoadLevel(LEVEL_NAMES["starting_map"_S]);
|
||||
InitializeClasses();
|
||||
ChangePlayerClass(WARRIOR);
|
||||
Warrior::ability4=Ranger::ability1; //Class ability swapping demonstration.
|
||||
@ -926,69 +920,42 @@ void Crawler::LoadLevel(MapName map){
|
||||
int tileSheetX=tileSheetIndex%tileSheetWidth;
|
||||
int tileSheetY=tileSheetIndex/tileSheetWidth;
|
||||
#pragma region TileGroupShenanigans
|
||||
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()){
|
||||
std::queue<vi2d>tileGroupChecks;
|
||||
TileGroup group;
|
||||
foregroundTilesIncluded.insert({x,y});
|
||||
group.InsertTile(tile);
|
||||
if(x>0)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<WORLD_SIZE.y-1)tileGroupChecks.push({x,y+1});
|
||||
while(!tileGroupChecks.empty()){
|
||||
vi2d&pos=tileGroupChecks.front();
|
||||
tileGroupChecks.pop();
|
||||
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(IsForegroundTile(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});
|
||||
}
|
||||
}
|
||||
groups.push_back(group);
|
||||
}
|
||||
};
|
||||
TileRenderData tile={tileSheet.tileset.tileset->Decal(),vi2d{x,y}*24,vi2d{tileSheetX,tileSheetY}*24};
|
||||
if(IsForegroundTile(tileSheet,tileSheetIndex)&&foregroundTilesAdded.find({x,y})==foregroundTilesAdded.end()){
|
||||
std::queue<vi2d>tileGroupChecks;
|
||||
TileGroup group;
|
||||
foregroundTilesAdded.insert({x,y});
|
||||
group.InsertTile(tile);
|
||||
if(x>0)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<WORLD_SIZE.y-1)tileGroupChecks.push({x,y+1});
|
||||
while(!tileGroupChecks.empty()){
|
||||
vi2d&pos=tileGroupChecks.front();
|
||||
tileGroupChecks.pop();
|
||||
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(IsForegroundTile(tileSheet,tileSheetIndex)&&foregroundTilesAdded.find(pos)==foregroundTilesAdded.end()){
|
||||
foregroundTilesAdded.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});
|
||||
}
|
||||
}
|
||||
foregroundTileGroups.push_back(group);
|
||||
} else
|
||||
if(IsUpperForegroundTile(tileSheet,tileSheetIndex)&&upperForegroundTilesAdded.find({x,y})==upperForegroundTilesAdded.end()){
|
||||
std::queue<vi2d>tileGroupChecks;
|
||||
TileGroup group;
|
||||
upperForegroundTilesAdded.insert({x,y});
|
||||
group.InsertTile(tile);
|
||||
if(x>0)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<WORLD_SIZE.y-1)tileGroupChecks.push({x,y+1});
|
||||
while(!tileGroupChecks.empty()){
|
||||
vi2d&pos=tileGroupChecks.front();
|
||||
tileGroupChecks.pop();
|
||||
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(IsUpperForegroundTile(tileSheet,tileSheetIndex)&&upperForegroundTilesAdded.find(pos)==upperForegroundTilesAdded.end()){
|
||||
upperForegroundTilesAdded.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});
|
||||
}
|
||||
}
|
||||
upperForegroundTileGroups.push_back(group);
|
||||
}
|
||||
SetupTileGroups([&](TilesheetData sheet,int tileID){return IsForegroundTile(sheet,tileID);},tile,foregroundTilesAdded,foregroundTileGroups);
|
||||
SetupTileGroups([&](TilesheetData sheet,int tileID){return IsUpperForegroundTile(sheet,tileID);},tile,foregroundTilesAdded,foregroundTileGroups);
|
||||
#pragma endregion
|
||||
}
|
||||
}
|
||||
@ -1241,4 +1208,17 @@ void Crawler::OutputDebugInfo(const char*key,std::size_t len){
|
||||
std::cout<<"Reading "<<k<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Crawler::InitializeLevels(){
|
||||
#define INITLEVEL(map) \
|
||||
InitializeLevel("map_path"_S + "Levels."#map ## _S,map); \
|
||||
LEVEL_NAMES[#map]=map;
|
||||
|
||||
INITLEVEL(WORLD_MAP);
|
||||
INITLEVEL(CAMPAIGN_1_1);
|
||||
INITLEVEL(BOSS_1);
|
||||
INITLEVEL(CAMPAIGN_1_2);
|
||||
|
||||
LEVEL_NAMES.SetInitialized();
|
||||
}
|
@ -108,4 +108,5 @@ public:
|
||||
double GetDouble(std::string key);
|
||||
datafiledoubledata GetDoubleList(std::string key);
|
||||
static void OutputDebugInfo(const char*key,std::size_t len);
|
||||
void InitializeLevels();
|
||||
};
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 1057
|
||||
#define VERSION_BUILD 1069
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
@ -9,6 +9,9 @@ gfx_config = gfx/gfx.txt
|
||||
# Map Files Loading Config
|
||||
map_config = levels.txt
|
||||
|
||||
# Starting map when loading the game.
|
||||
starting_map = CAMPAIGN_1_1
|
||||
|
||||
# Player Properties Loading Config
|
||||
player_config = Player.txt
|
||||
|
||||
|
@ -324,7 +324,7 @@ namespace olc
|
||||
|
||||
olc::vf2d TransformedView::WorldToScreen(const olc::vf2d& vWorldPos) const
|
||||
{
|
||||
olc::vf2d vFloat = ((vWorldPos - m_vWorldOffset) * m_vWorldScale);
|
||||
olc::vf2d vFloat = ((vd2d(vWorldPos) - vd2d(m_vWorldOffset)) * vd2d(m_vWorldScale));
|
||||
//vFloat = { std::floor(vFloat.x + 0.5f), std::floor(vFloat.y + 0.5f) };
|
||||
return vFloat;
|
||||
}
|
||||
@ -551,17 +551,17 @@ namespace olc
|
||||
|
||||
void TransformedView::DrawDecal(const olc::vf2d & pos, olc::Decal * decal, const olc::vf2d & scale, const olc::Pixel & tint)
|
||||
{
|
||||
pge->DrawDecal(WorldToScreen(pos), decal, scale * m_vWorldScale * m_vRecipPixel, tint);
|
||||
pge->DrawDecal(WorldToScreen(pos), decal, vd2d(scale) * vd2d(m_vWorldScale) * vd2d(m_vRecipPixel), tint);
|
||||
}
|
||||
|
||||
void TransformedView::DrawPartialDecal(const olc::vf2d & pos, olc::Decal * decal, const olc::vf2d & source_pos, const olc::vf2d & source_size, const olc::vf2d & scale, const olc::Pixel & tint)
|
||||
{
|
||||
pge->DrawPartialDecal(WorldToScreen(pos), decal, source_pos, source_size, scale * m_vWorldScale * m_vRecipPixel, tint);
|
||||
pge->DrawPartialDecal(WorldToScreen(pos), decal, source_pos, source_size, vd2d(scale)* vd2d(m_vWorldScale) * vd2d(m_vRecipPixel), tint);
|
||||
}
|
||||
|
||||
void TransformedView::DrawPartialDecal(const olc::vf2d & pos, const olc::vf2d & size, olc::Decal * decal, const olc::vf2d & source_pos, const olc::vf2d & source_size, const olc::Pixel & tint)
|
||||
{
|
||||
pge->DrawPartialDecal(WorldToScreen(pos), size * m_vWorldScale * m_vRecipPixel, decal, source_pos, source_size, tint);
|
||||
pge->DrawPartialDecal(WorldToScreen(pos), vd2d(size)* vd2d(m_vWorldScale) * vd2d(m_vRecipPixel), decal, source_pos, source_size, tint);
|
||||
}
|
||||
|
||||
void TransformedView::DrawExplicitDecal(olc::Decal* decal, const olc::vf2d* pos, const olc::vf2d* uv, const olc::Pixel* col, uint32_t elements)
|
||||
|
@ -10,6 +10,7 @@ public:
|
||||
O&operator[](T key){
|
||||
if(initialized&&map.count(key)==0){
|
||||
std::cout<<"WARNING! Trying to get non-existent key "<<key<<"!"<<std::endl;
|
||||
throw;
|
||||
}
|
||||
return map[key];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user