1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Map edge drawing converted to CAnimation

This commit is contained in:
AlexVinS 2016-11-06 04:28:57 +03:00
parent 46196daa07
commit 6782136e3e
2 changed files with 43 additions and 37 deletions

View File

@ -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;i<edgeFrames.size()-frameW;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;
edgeFrames[i].resize(sizes.y, frameH, frameH);
}
for (int i=0-frameW;i<edgeFrames.size()-frameW;i++)
{
for (int j=0-frameH;j<(int)sizes.y+frameH;j++)
edgeFrames[i][j].resize(sizes.z, 0, 0);
}
auto & rand = CRandomGenerator::getDefault();
for (int i=0-frameW; i<sizes.x+frameW; i++) //by width
{
for (int j=0-frameH; j<sizes.y+frameH;j++) //by height
{
for(int k=0; k<sizes.z; ++k) //by levles
for(int k=0; k<sizes.z; ++k) //by levels
{
ui8 terBitmapNum = 0;
if(i < 0 || 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<CAnimation>("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)

View File

@ -80,10 +80,7 @@ struct TerrainTileObject
struct TerrainTile2
{
SDL_Surface * terbitmap; //bitmap of terrain
std::vector<TerrainTileObject> 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<const IImage *> FoWfullHide;
std::vector<const IImage *> FoWpartialHide;
std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type] [rotation type]
std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type]
std::vector<CDefEssential *> roadDefs;
std::vector<CDefEssential *> staticRiverDefs;
std::vector<std::vector<std::vector<ui8> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
//Fog of War cache (not owned)
std::vector<const IImage *> FoWfullHide;
std::vector<std::vector<std::vector<ui8> > > hideBitmap; //frame indexes (in FoWfullHide) of graphic that should be used to fully hide a tile
std::vector<const IImage *> FoWpartialHide;
//edge graphics
std::unique_ptr<CAnimation> egdeAnimation;
std::vector<const IImage *> egdeImages;//cache of links to egdeAnimation (for faster access)
PseudoV< PseudoV< PseudoV <ui8> > > edgeFrames; //frame indexes (in egdeImages) of tile outside of map
mutable std::map<const CGObjectInstance*, ui8> animationPhase;