From 203290c94a1cfa0814bec3de480eb66cede7ede5 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 4 Oct 2023 04:22:04 -0500 Subject: [PATCH] Added static tileset world optimization and generation features. --- Crawler/Crawler.cpp | 164 ++++++++++++++++--------- Crawler/Crawler.tiled-project | 18 +++ Crawler/TMXParser.h | 5 + Crawler/Version.h | 2 +- Crawler/assets/Campaigns/World_Map.tmx | 5 +- 5 files changed, 131 insertions(+), 63 deletions(-) diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 26cb2e01..d2603c86 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -570,7 +570,7 @@ void Crawler::RenderTile(TileRenderData&tileSheet,Pixel col){ } void Crawler::RenderWorld(float fElapsedTime){ - Clear(BLANK); + LayerTag*bridgeLayer=nullptr; bool bridgeLayerFade=false; Player*pl=GetPlayer(); @@ -623,37 +623,67 @@ void Crawler::RenderWorld(float fElapsedTime){ } SetDecalMode(DecalMode::NORMAL); } - for (int x = view.GetTopLeftTile().x/GetCurrentMap().tilewidth-1; x <= view.GetBottomRightTile().x/GetCurrentMap().tilewidth; x++){ - for (int y = view.GetTopLeftTile().y/GetCurrentMap().tilewidth-1; y <= view.GetBottomRightTile().y/GetCurrentMap().tilewidth; y++){ - if(x>=0&&x=0&&yupperLevel){ - int tileID=layer.tiles[y][x]-1; - if(tileID!=-1){ - int playerXTruncated=int(player->GetPos().x)/GetCurrentMap().tilewidth; - int playerYTruncated=int(player->GetPos().y)/GetCurrentMap().tilewidth; - if(playerXTruncated==x&&playerYTruncated==y){ - bridgeLayerFade=true; + if(GetCurrentMap().optimized){ + view.FillRectDecal(-WINDOW_SIZE,vf2d{float(GetCurrentMap().width),float(GetCurrentMap().height)}*GetCurrentMap().tilewidth+WINDOW_SIZE*2,{100,180,100}); + view.DrawDecal({0,0},MAP_DATA[GetCurrentLevel()].optimizedTile->Decal()); + }else{ + for (int x = view.GetTopLeftTile().x/GetCurrentMap().tilewidth-1; x <= view.GetBottomRightTile().x/GetCurrentMap().tilewidth; x++){ + for (int y = view.GetTopLeftTile().y/GetCurrentMap().tilewidth-1; y <= view.GetBottomRightTile().y/GetCurrentMap().tilewidth; y++){ + if(x>=0&&x=0&&yupperLevel){ + int tileID=layer.tiles[y][x]-1; + if(tileID!=-1){ + int playerXTruncated=int(player->GetPos().x)/GetCurrentMap().tilewidth; + int playerYTruncated=int(player->GetPos().y)/GetCurrentMap().tilewidth; + if(playerXTruncated==x&&playerYTruncated==y){ + bridgeLayerFade=true; + } + } + } + continue; + } + int tileID=layer.tiles[y][x]-1; + if(tileID!=-1){ + TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); + int tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; + int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; + int tileSheetIndex=tileID-(tileSheet.firstgid-1); + int tileSheetX=tileSheetIndex%tileSheetWidth; + int tileSheetY=tileSheetIndex/tileSheetWidth; + if(!IsForegroundTile(tileSheet,tileSheetIndex)&&!IsUpperForegroundTile(tileSheetIndex)&&!IsReflectiveTile(tileSheet,tileSheetIndex)){ + if(layer.tag.data["class"]!="CollisionOnly"){visibleTiles.erase({x,y});} + RenderTile({x,y},tileSheet,tileSheetIndex,{tileSheetX,tileSheetY}); + if("debug_collision_boxes"_I){ + if(tileSheet.tileset->collision.find(tileSheetIndex)!=tileSheet.tileset->collision.end()){ + geom2d::rectcollision=tileSheet.tileset->collision[tileSheetIndex].collision; + view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,{0,0,0,128}); + view.DrawRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,GREY); + } } } } - continue; } - int tileID=layer.tiles[y][x]-1; - if(tileID!=-1){ - TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); - int tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; - int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; - int tileSheetIndex=tileID-(tileSheet.firstgid-1); - int tileSheetX=tileSheetIndex%tileSheetWidth; - int tileSheetY=tileSheetIndex/tileSheetWidth; - if(!IsForegroundTile(tileSheet,tileSheetIndex)&&!IsUpperForegroundTile(tileSheetIndex)&&!IsReflectiveTile(tileSheet,tileSheetIndex)){ - if(layer.tag.data["class"]!="CollisionOnly"){visibleTiles.erase({x,y});} - RenderTile({x,y},tileSheet,tileSheetIndex,{tileSheetX,tileSheetY}); + }break; + case RenderMode::REFLECTIVE_TILES:{ + visibleTiles.insert({x,y}); + for(LayerTag&layer:MAP_DATA[currentLevel].LayerData){ + int tileID=layer.tiles[y][x]-1; + if(tileID!=-1){ + TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); + int tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; + int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; + int tileSheetIndex=tileID-(tileSheet.firstgid-1); + int tileSheetX=tileSheetIndex%tileSheetWidth; + int tileSheetY=tileSheetIndex/tileSheetWidth; + if(IsReflectiveTile(tileSheet,tileSheetIndex)){ + if(layer.tag.data["class"]!="CollisionOnly"){visibleTiles.erase({x,y});} + RenderTile({x,y},tileSheet,tileSheetIndex,{tileSheetX,tileSheetY}); + } if("debug_collision_boxes"_I){ if(tileSheet.tileset->collision.find(tileSheetIndex)!=tileSheet.tileset->collision.end()){ geom2d::rectcollision=tileSheet.tileset->collision[tileSheetIndex].collision; @@ -663,41 +693,16 @@ void Crawler::RenderWorld(float fElapsedTime){ } } } - } - }break; - case RenderMode::REFLECTIVE_TILES:{ - visibleTiles.insert({x,y}); - for(LayerTag&layer:MAP_DATA[currentLevel].LayerData){ - int tileID=layer.tiles[y][x]-1; - if(tileID!=-1){ - TilesheetData tileSheet=GetTileSheet(currentLevel,tileID); - int tileSheetWidth=tileSheet.tileset->tileset->Sprite()->width/tileSheet.tileset->tilewidth; - int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; - int tileSheetIndex=tileID-(tileSheet.firstgid-1); - int tileSheetX=tileSheetIndex%tileSheetWidth; - int tileSheetY=tileSheetIndex/tileSheetWidth; - if(IsReflectiveTile(tileSheet,tileSheetIndex)){ - if(layer.tag.data["class"]!="CollisionOnly"){visibleTiles.erase({x,y});} - RenderTile({x,y},tileSheet,tileSheetIndex,{tileSheetX,tileSheetY}); - } - if("debug_collision_boxes"_I){ - if(tileSheet.tileset->collision.find(tileSheetIndex)!=tileSheet.tileset->collision.end()){ - geom2d::rectcollision=tileSheet.tileset->collision[tileSheetIndex].collision; - view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,{0,0,0,128}); - view.DrawRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth+collision.pos,collision.size,GREY); - } - } + }break; + case RenderMode::EMPTY_TILES:{ + if(visibleTiles.count({x,y})){ + view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth,{float(GetCurrentMap().tilewidth),float(GetCurrentMap().tilewidth)},{100,180,100}); } - } - }break; - case RenderMode::EMPTY_TILES:{ - if(visibleTiles.count({x,y})){ - view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth,{float(GetCurrentMap().tilewidth),float(GetCurrentMap().tilewidth)},{100,180,100}); - } - }break; + }break; + } + }else{ + view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth,{float(GetCurrentMap().tilewidth),float(GetCurrentMap().tilewidth)},{100,180,100}); } - }else{ - view.FillRectDecal(vi2d{x,y}*GetCurrentMap().tilewidth,{float(GetCurrentMap().tilewidth),float(GetCurrentMap().tilewidth)},{100,180,100}); } } } @@ -1147,6 +1152,38 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){ r->Load("assets/maps/"+tileset.GetData().ImageData.data["source"]); } } + + if(MAP_DATA[map].MapData.optimized){ + std::cout<<"Generating optimized map for Map "<Create(MAP_DATA[map].MapData.width*MAP_DATA[map].MapData.tilewidth,MAP_DATA[map].MapData.height*MAP_DATA[map].MapData.tileheight); + SetDrawTarget(MAP_DATA[map].optimizedTile->Sprite()); + Pixel::Mode prevMode=GetPixelMode(); + SetPixelMode(Pixel::Mode::MASK); + Clear(BLANK); + for(int y=0;ytileset->Sprite()->width/tileSheet.tileset->tilewidth; + int tileSheetHeight=tileSheet.tileset->tileset->Sprite()->height/tileSheet.tileset->tileheight; + int tileSheetIndex=tileID-(tileSheet.firstgid-1); + int tileSheetX=tileSheetIndex%tileSheetWidth; + int tileSheetY=tileSheetIndex/tileSheetWidth; + vi2d pos=vi2d{x,y}*tileSheet.tileset->tilewidth; + DrawPartialSprite(pos,tileSheet.tileset->tileset->Sprite(),vi2d{tileSheetX,tileSheetY}*tileSheet.tileset->tilewidth,{tileSheet.tileset->tilewidth,tileSheet.tileset->tileheight}); + } + } + } + } + SetPixelMode(prevMode); + MAP_DATA[map].optimizedTile->Decal()->Update(); + SetDrawTarget(nullptr); + std::cout<<" Clearing Layer Data..."< TilesetData; std::vector LayerData; std::map SpawnerData; //Spawn groups have IDs, mobs associate which spawner they are tied to via this ID. @@ -238,6 +240,9 @@ typedef std::map>> ZoneData; parsedMapInfo.SpawnerData[newTag.GetInteger("id")]={newTag}; prevSpawner=newTag.GetInteger("id"); } else + if (newTag.tag=="property"&&newTag.data["name"]=="Optimize"&&newTag.data["value"]=="true") { + parsedMapInfo.MapData.optimized=true; + } else if (newTag.tag=="property"&&newTag.data["name"]=="Boss Title Display") { parsedMapInfo.SpawnerData[prevSpawner].bossNameDisplay=newTag.data["value"]; } else diff --git a/Crawler/Version.h b/Crawler/Version.h index cc541fbb..366de23e 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 1741 +#define VERSION_BUILD 1753 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/Campaigns/World_Map.tmx b/Crawler/assets/Campaigns/World_Map.tmx index 4cbf64d5..6cf989e6 100644 --- a/Crawler/assets/Campaigns/World_Map.tmx +++ b/Crawler/assets/Campaigns/World_Map.tmx @@ -1,5 +1,8 @@ - + + + +