Use structured bindings for map k,v pairs. Place counters for for range iterator loops locally inside their scopes.

This commit is contained in:
2023-12-05 22:12:43 -06:00
parent 6d4f024d3c
commit 30287c91d2
7 changed files with 93 additions and 98 deletions
+17 -19
View File
@@ -126,8 +126,8 @@ Crawler::Crawler()
std::string ITEM_SET_CONFIG = CONFIG_PATH + "item_set_config"_S;
utils::datafile::Read(DATA,ITEM_SET_CONFIG);
for(auto&key:DATA.GetProperty("ItemConfiguration").GetKeys()){
std::string config = DATA["ItemConfiguration"][key.first].GetString();
for(auto&[key,value]:DATA.GetProperty("ItemConfiguration").GetKeys()){
std::string config = DATA["ItemConfiguration"][key].GetString();
utils::datafile::Read(DATA,CONFIG_PATH + "item_directory"_S + config);
}
@@ -1436,8 +1436,8 @@ void Crawler::LoadLevel(MapName map){
Inventory::Clear("Stage Loot");
#pragma region Monster Spawn Data Setup
for(auto&key:MAP_DATA[map].SpawnerData){
SpawnerTag&spawnData=MAP_DATA[map].SpawnerData[key.first];
for(auto&[key,value]:MAP_DATA[map].SpawnerData){
SpawnerTag&spawnData=MAP_DATA[map].SpawnerData[key];
std::vector<std::pair<int,vf2d>>monster_list;
vf2d spawnerRadius=vf2d{spawnData.ObjectData.GetFloat("width"),spawnData.ObjectData.GetFloat("height")}/2;
@@ -1565,9 +1565,8 @@ void Crawler::LoadLevel(MapName map){
#pragma endregion
#pragma region Bridge Layer Setup
int counter=0;
bridgeLayerIndex=-1;
for(LayerTag&layer:MAP_DATA[map].LayerData){
for(int counter=0;LayerTag&layer:MAP_DATA[map].LayerData){
if(IsBridgeLayer(layer)){
bridgeLayerIndex=counter;
}
@@ -1644,9 +1643,8 @@ geom2d::rect<int>Crawler::GetTileCollision(MapName map,vf2d pos,bool upperLevel)
return NO_COLLISION;
}
}
int counter=0;
geom2d::rect<int>foundRect=NO_COLLISION;
for(LayerTag&layer:MAP_DATA[map].LayerData){
for(int counter=0;LayerTag&layer:MAP_DATA[map].LayerData){
//auto HasNoClass=[&](){return layer.tag.data.find("class")==layer.tag.data.end();};
if(counter!=bridgeLayerIndex){
int tileID=layer.tiles[int(pos.y)/game->GetCurrentMap().tilewidth][int(pos.x)/game->GetCurrentMap().tilewidth]-1;
@@ -1868,21 +1866,21 @@ bool Crawler::IsReflectiveTile(TilesheetData tileSheet,int tileID){
bool Crawler::OnUserDestroy(){
GFX.Reset();
for(auto&data:MAP_DATA){
if(MAP_DATA[data.first].optimizedTile!=nullptr){
delete MAP_DATA[data.first].optimizedTile;
for(auto&[key,value]:MAP_DATA){
if(MAP_DATA[key].optimizedTile!=nullptr){
delete MAP_DATA[key].optimizedTile;
}
}
for(auto&key:MAP_TILESETS){
delete key.second.tileset;
for(auto&[key,value]:MAP_TILESETS){
delete value.tileset;
}
for(auto&data:GameState::states){
delete data.second;
for(auto&[key,value]:GameState::states){
delete value;
}
delete[]pathfinder.nodes;
Menu::CleanupAllMenus();
for(auto&key:MonsterData::imgs){
delete key.second;
for(auto&[key,value]:MonsterData::imgs){
delete value;
}
return true;
}
@@ -2049,8 +2047,8 @@ void Crawler::InitializeGraphics(){
mappedKeys.push_back(key);
}
std::sort(mappedKeys.begin(),mappedKeys.end(),[](std::pair<std::string,size_t>&key1,std::pair<std::string,size_t>&key2){return key1.second<key2.second;});
for(auto&key:mappedKeys){
std::string themeName=key.first;
for(auto&[key,value]:mappedKeys){
std::string themeName=key;
std::string imgPath=DATA["Themes"][themeName]["filename"].GetString();
Renderable&img=GFX["theme_img_directory"_S+imgPath+".png"];
img.Load("GFX_Prefix"_S+"theme_img_directory"_S+imgPath+".png");