diff --git a/client/mapHandler.cpp b/client/mapHandler.cpp index ecd952492..9f9570397 100644 --- a/client/mapHandler.cpp +++ b/client/mapHandler.cpp @@ -174,8 +174,6 @@ void CMapHandler::prepareFOWDefs() FoWpartialHide.resize(size); for(size_t frame = 0; frame < size; frame++) FoWpartialHide[frame] = graphics->fogOfWarPartialHide->getImage(frame); - - } EMapAnimRedrawStatus CMapHandler::drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info, bool redrawOnlyAnim /* = false */) @@ -228,31 +226,32 @@ void CMapHandler::roadsRiverTerrainInit() void CMapHandler::borderAndTerrainBitmapInit() { - CDefHandler * bord = CDefHandler::giveDef("EDG.DEF"); - bord->notFreeImgs = true; - terrainGraphics.resize(10); - for (int i = 0; i < 10 ; i++) + egdeImages.resize(egdeAnimation->size(0)); + for(size_t i = 0; i < egdeImages.size(); i++) + egdeImages[i] = egdeAnimation->getImage(i); + + edgeFrames.resize(sizes.x, frameW, frameW); + for (int i=0-frameW;iourImages.size()); - hlp->notFreeImgs = true; - for(size_t j=0; j < hlp->ourImages.size(); ++j) - terrainGraphics[i][j] = hlp->ourImages[j].bitmap; - delete hlp; + edgeFrames[i].resize(sizes.y, frameH, frameH); } + for (int i=0-frameW;i (sizes.x-1) || j < 0 || j > (sizes.y-1)) { - int terBitmapNum = -1; - - auto & rand = CRandomGenerator::getDefault(); - if(i==-1 && j==-1) terBitmapNum = 16; else if(i==-1 && j==(sizes.y)) @@ -272,16 +271,22 @@ void CMapHandler::borderAndTerrainBitmapInit() else terBitmapNum = rand.nextInt(15); - if(terBitmapNum != -1) - { - ttiles[i][j][k].terbitmap = bord->ourImages[terBitmapNum].bitmap; - continue; - } } + edgeFrames[i][j][k] = terBitmapNum; } } } - delete bord; + + terrainGraphics.resize(10); + for (int i = 0; i < 10 ; i++) + { + CDefHandler *hlp = CDefHandler::giveDef(nameFromType(i)); + terrainGraphics[i].resize(hlp->ourImages.size()); + hlp->notFreeImgs = true; + for(size_t j=0; j < hlp->ourImages.size(); ++j) + terrainGraphics[i][j] = hlp->ourImages[j].bitmap; + delete hlp; + } } void CMapHandler::initObjectRects() @@ -791,7 +796,7 @@ CMapHandler::CMapPuzzleViewBlitter::CMapPuzzleViewBlitter(CMapHandler * parent) void CMapHandler::CMapBlitter::drawFrame(SDL_Surface * targetSurf) const { Rect destRect(realTileRect); - drawElement(EMapCacheType::FRAME, parent->ttiles[pos.x][pos.y][topTile.z].terbitmap, nullptr, targetSurf, &destRect); + drawElement(EMapCacheType::FRAME, parent->egdeImages[parent->edgeFrames[pos.x][pos.y][topTile.z]], nullptr, targetSurf, &destRect); } void CMapHandler::CMapBlitter::drawOverlayEx(SDL_Surface * targetSurf) @@ -1452,6 +1457,9 @@ CMapHandler::CMapHandler() worldViewBlitter = new CMapWorldViewBlitter(this); puzzleViewBlitter = new CMapPuzzleViewBlitter(this); fadeAnimCounter = 0; + + egdeAnimation = make_unique("EDG"); + egdeAnimation->preload(); } void CMapHandler::getTerrainDescr( const int3 &pos, std::string & out, bool terName ) @@ -1567,10 +1575,6 @@ intptr_t CMapHandler::CMapCache::genKey(intptr_t realPtr, ui8 mod) return (intptr_t)(realPtr ^ (mod << (sizeof(intptr_t) - 2))); // maybe some cleaner method to pack rotation into cache key? } -TerrainTile2::TerrainTile2() - :terbitmap(nullptr) -{} - bool CMapHandler::compareObjectBlitOrder(const CGObjectInstance * a, const CGObjectInstance * b) { if (!a) diff --git a/client/mapHandler.h b/client/mapHandler.h index 3f72c5206..42ffd6af5 100644 --- a/client/mapHandler.h +++ b/client/mapHandler.h @@ -80,10 +80,7 @@ struct TerrainTileObject struct TerrainTile2 { - SDL_Surface * terbitmap; //bitmap of terrain - std::vector objects; //pointers to objects being on this tile with rects to be easier to blit this tile on screen - TerrainTile2(); }; struct MapDrawingInfo @@ -366,15 +363,20 @@ public: int offsetX; int offsetY; - //Fog of War cache (not owned) - std::vector FoWfullHide; - std::vector FoWpartialHide; - - std::vector > terrainGraphics; // [terrain id] [view type] [rotation type] + std::vector > terrainGraphics; // [terrain id] [view type] std::vector roadDefs; std::vector staticRiverDefs; - std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile + //Fog of War cache (not owned) + std::vector FoWfullHide; + std::vector > > hideBitmap; //frame indexes (in FoWfullHide) of graphic that should be used to fully hide a tile + + std::vector FoWpartialHide; + + //edge graphics + std::unique_ptr egdeAnimation; + std::vector egdeImages;//cache of links to egdeAnimation (for faster access) + PseudoV< PseudoV< PseudoV > > edgeFrames; //frame indexes (in egdeImages) of tile outside of map mutable std::map animationPhase;