mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-25 21:38:59 +02:00
FoW drawing converted to CAnimation
This commit is contained in:
parent
c11a660d21
commit
6a272d8f0c
@ -130,14 +130,6 @@ Graphics::Graphics()
|
||||
{
|
||||
#if 0
|
||||
|
||||
#define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \
|
||||
(std::bind(&setData<TYPE>,&DESTINATION,FUNCTION_TO_GET))
|
||||
|
||||
#define GET_DEF_ESS(DESTINATION, DEF_NAME) \
|
||||
(GET_DATA \
|
||||
(CDefEssential*,DESTINATION,\
|
||||
std::function<CDefEssential*()>(std::bind(CDefHandler::giveDefEss,DEF_NAME))))
|
||||
|
||||
std::vector<Task> tasks; //preparing list of graphics to load
|
||||
tasks += std::bind(&Graphics::loadFonts,this);
|
||||
tasks += std::bind(&Graphics::loadPaletteAndColors,this);
|
||||
@ -165,6 +157,7 @@ void Graphics::load()
|
||||
|
||||
loadHeroAnimations();
|
||||
loadHeroFlagAnimations();
|
||||
loadFogOfWar();
|
||||
}
|
||||
|
||||
void Graphics::loadHeroAnimations()
|
||||
@ -274,37 +267,6 @@ std::shared_ptr<CAnimation> Graphics::loadHeroAnimation(const std::string &name)
|
||||
}
|
||||
}
|
||||
|
||||
//todo: apply following commented out optimizations or merge with loadHeroFlagAnimation
|
||||
|
||||
// int pom = 0; //how many groups has been rotated
|
||||
// for(int o = 7; pom < 6; ++o)
|
||||
// {
|
||||
// for(int p = 0; p<6; p++)
|
||||
// {
|
||||
// IImage frame = anim->getImage()
|
||||
// if(anim->ourImages[o].groupNumber == rotations[p].first)
|
||||
// {
|
||||
// for(int e=0; e<8; ++e)
|
||||
// {
|
||||
// Cimage nci;
|
||||
// nci.bitmap = CSDL_Ext::verticalFlip(anim->ourImages[o+e].bitmap);
|
||||
// nci.groupNumber = rotations[p].second;
|
||||
// nci.imName = std::string();
|
||||
// anim->ourImages.push_back(nci);
|
||||
// if(pom>2) //we need only one frame for groups 13/14/15
|
||||
// break;
|
||||
// }
|
||||
// if(pom<3) //there are eight frames of animtion of groups 6/7/8 so for speed we'll skip them
|
||||
// o+=8;
|
||||
// else //there is only one frame of 1/2/3
|
||||
// o+=1;
|
||||
// ++pom;
|
||||
// if(p==2 && pom<4) //group1 starts at index 1
|
||||
// o = 1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return anim;
|
||||
}
|
||||
|
||||
@ -338,6 +300,26 @@ void Graphics::blueToPlayersAdv(SDL_Surface * sur, PlayerColor player)
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::loadFogOfWar()
|
||||
{
|
||||
fogOfWarFullHide = std::make_shared<CAnimation>("TSHRC");
|
||||
fogOfWarFullHide->preload();
|
||||
fogOfWarPartialHide = std::make_shared<CAnimation>("TSHRE");
|
||||
fogOfWarPartialHide->preload();
|
||||
|
||||
static const int rotations [] = {22, 15, 2, 13, 12, 16, 28, 17, 20, 19, 7, 24, 26, 25, 30, 32, 27};
|
||||
|
||||
size_t size = fogOfWarPartialHide->size(0);//group size after next rotation
|
||||
|
||||
for(const int rotation : rotations)
|
||||
{
|
||||
fogOfWarPartialHide->duplicateImage(0, rotation, 0);
|
||||
IImage * image = fogOfWarPartialHide->getImage(size, 0);
|
||||
image->verticalFlip();
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::loadFonts()
|
||||
{
|
||||
const JsonNode config(ResourceID("config/fonts.json"));
|
||||
|
@ -15,7 +15,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
class CDefEssential;
|
||||
struct SDL_Surface;
|
||||
class CGHeroInstance;
|
||||
class CGTownInstance;
|
||||
@ -51,7 +50,7 @@ class Graphics
|
||||
std::shared_ptr<CAnimation> loadHeroFlagAnimation(const std::string &name);
|
||||
|
||||
void loadErmuToPicture();
|
||||
|
||||
void loadFogOfWar();
|
||||
void loadFonts();
|
||||
void initializeImageLists();
|
||||
|
||||
@ -80,8 +79,8 @@ public:
|
||||
//all other objects (not hero or boat)
|
||||
std::map< std::string, std::shared_ptr<CAnimation> > mapObjectAnimations;
|
||||
|
||||
CDefHandler * FoWfullHide; //for Fog of War
|
||||
CDefHandler * FoWpartialHide; //for For of War
|
||||
std::shared_ptr<CAnimation> fogOfWarFullHide;
|
||||
std::shared_ptr<CAnimation> fogOfWarPartialHide;
|
||||
|
||||
std::map<std::string, JsonNode> imageLists;
|
||||
|
||||
|
@ -341,7 +341,7 @@ void CDefFile::loadFrame(size_t frame, size_t group, ImageLoader &loader) const
|
||||
//pixel data is not compressed, copy data to surface
|
||||
for (ui32 i=0; i<sprite.height; i++)
|
||||
{
|
||||
loader.Load(sprite.width, FDef[currentOffset]);
|
||||
loader.Load(sprite.width, FDef + currentOffset);
|
||||
currentOffset += sprite.width;
|
||||
loader.EndLine();
|
||||
}
|
||||
@ -809,7 +809,7 @@ void SDLImage::draw(SDL_Surface* where, SDL_Rect* dest, SDL_Rect* src, ui8 alpha
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_BlitSurface(surf, &sourceRect, where, &destRect);
|
||||
SDL_UpperBlit(surf, &sourceRect, where, &destRect);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1336,8 +1336,10 @@ void CAnimation::duplicateImage(const size_t sourceGroup, const size_t sourceFra
|
||||
|
||||
source[targetGroup].push_back(clone);
|
||||
|
||||
size_t index = source[targetGroup].size() - 1;
|
||||
|
||||
if(preloaded)
|
||||
load(sourceFrame, targetGroup);
|
||||
load(index, targetGroup);
|
||||
}
|
||||
|
||||
void CAnimation::setCustom(std::string filename, size_t frame, size_t group)
|
||||
|
@ -894,11 +894,11 @@ SDL_Surface * CSDL_Ext::scaleSurface(SDL_Surface *surf, int width, int height)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CSDL_Ext::blitSurface( SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect )
|
||||
void CSDL_Ext::blitSurface( SDL_Surface * src, const SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect )
|
||||
{
|
||||
if (dst != screen)
|
||||
{
|
||||
SDL_BlitSurface(src, srcRect, dst, dstRect);
|
||||
SDL_UpperBlit(src, srcRect, dst, dstRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -912,7 +912,7 @@ void CSDL_Ext::blitSurface( SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface *
|
||||
betterDst = Rect(0, 0, dst->w, dst->h);
|
||||
}
|
||||
|
||||
SDL_BlitSurface(src, srcRect, dst, &betterDst);
|
||||
SDL_UpperBlit(src, srcRect, dst, &betterDst);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
* Full text of license available in license.txt file, in main folder
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <SDL_version.h>
|
||||
#include <SDL_render.h>
|
||||
@ -88,7 +88,7 @@ public:
|
||||
|
||||
/** green color used for in-game console */
|
||||
static const SDL_Color GREEN;
|
||||
|
||||
|
||||
/** default key color for all 8 & 24 bit graphics */
|
||||
static const SDL_Color DEFAULT_KEY_COLOR;
|
||||
};
|
||||
@ -167,7 +167,7 @@ namespace CSDL_Ext
|
||||
}
|
||||
};
|
||||
|
||||
void blitSurface(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);
|
||||
void blitSurface(SDL_Surface * src, const SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);
|
||||
void fillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);
|
||||
void fillRectBlack(SDL_Surface * dst, SDL_Rect * dstrect);
|
||||
//fill dest image with source texture.
|
||||
@ -228,10 +228,10 @@ namespace CSDL_Ext
|
||||
template<int bpp>
|
||||
void applyEffectBpp( SDL_Surface * surf, const SDL_Rect * rect, int mode );
|
||||
void applyEffect(SDL_Surface * surf, const SDL_Rect * rect, int mode); //mode: 0 - sepia, 1 - grayscale
|
||||
|
||||
|
||||
void startTextInput(SDL_Rect * where);
|
||||
void stopTextInput();
|
||||
|
||||
|
||||
void setColorKey(SDL_Surface * surface, SDL_Color color);
|
||||
///set key-color to 0,255,255
|
||||
void setDefaultColorKey(SDL_Surface * surface);
|
||||
|
@ -146,26 +146,11 @@ struct NeighborTilesInfo
|
||||
|
||||
void CMapHandler::prepareFOWDefs()
|
||||
{
|
||||
graphics->FoWfullHide = CDefHandler::giveDef("TSHRC.DEF");
|
||||
graphics->FoWpartialHide = CDefHandler::giveDef("TSHRE.DEF");
|
||||
|
||||
//adding necessary rotations
|
||||
static const int missRot [] = {22, 15, 2, 13, 12, 16, 28, 17, 20, 19, 7, 24, 26, 25, 30, 32, 27};
|
||||
|
||||
Cimage nw;
|
||||
for(auto & elem : missRot)
|
||||
{
|
||||
nw = graphics->FoWpartialHide->ourImages[elem];
|
||||
nw.bitmap = CSDL_Ext::verticalFlip(nw.bitmap);
|
||||
graphics->FoWpartialHide->ourImages.push_back(nw);
|
||||
}
|
||||
//necessaary rotations added
|
||||
|
||||
//alpha - transformation
|
||||
for(auto & elem : graphics->FoWpartialHide->ourImages)
|
||||
{
|
||||
CSDL_Ext::alphaTransform(elem.bitmap);
|
||||
}
|
||||
//assume all frames in group 0
|
||||
size_t size = graphics->fogOfWarFullHide->size(0);
|
||||
FoWfullHide.resize(size);
|
||||
for(size_t frame = 0; frame < size; frame++)
|
||||
FoWfullHide[frame] = graphics->fogOfWarFullHide->getImage(frame);
|
||||
|
||||
//initialization of type of full-hide image
|
||||
hideBitmap.resize(sizes.x);
|
||||
@ -180,10 +165,17 @@ void CMapHandler::prepareFOWDefs()
|
||||
elem[j].resize(sizes.z);
|
||||
for(int k = 0; k < sizes.z; ++k)
|
||||
{
|
||||
elem[j][k] = CRandomGenerator::getDefault().nextInt(graphics->FoWfullHide->ourImages.size() - 1);
|
||||
elem[j][k] = CRandomGenerator::getDefault().nextInt(size - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size = graphics->fogOfWarPartialHide->size(0);
|
||||
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 */)
|
||||
@ -903,9 +895,21 @@ void CMapHandler::CMapBlitter::drawRiver(SDL_Surface * targetSurf, const Terrain
|
||||
|
||||
void CMapHandler::CMapBlitter::drawFow(SDL_Surface * targetSurf) const
|
||||
{
|
||||
const NeighborTilesInfo neighborInfo(pos, parent->sizes, *info->visibilityMap);
|
||||
|
||||
int retBitmapID = neighborInfo.getBitmapID();// >=0 -> partial hide, <0 - full hide
|
||||
if (retBitmapID < 0)
|
||||
retBitmapID = - parent->hideBitmap[pos.x][pos.y][pos.z] - 1; //fully hidden
|
||||
|
||||
const IImage * image = nullptr;
|
||||
|
||||
if (retBitmapID >= 0)
|
||||
image = parent->FoWpartialHide.at(retBitmapID);
|
||||
else
|
||||
image = parent->FoWfullHide.at(-retBitmapID - 1);
|
||||
|
||||
Rect destRect(realTileRect);
|
||||
std::pair<SDL_Surface *, bool> hide = getVisBitmap();
|
||||
drawElement(EMapCacheType::FOW, hide.first, nullptr, targetSurf, &destRect, hide.second);
|
||||
drawElement(EMapCacheType::FOW, image, nullptr, targetSurf, &destRect);
|
||||
}
|
||||
|
||||
void CMapHandler::CMapBlitter::blit(SDL_Surface * targetSurf, const MapDrawingInfo * info)
|
||||
@ -1175,26 +1179,6 @@ ui8 CMapHandler::CMapBlitter::getHeroFrameGroup(ui8 dir, bool isMoving) const
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<SDL_Surface *, bool> CMapHandler::CMapBlitter::getVisBitmap() const
|
||||
{
|
||||
const NeighborTilesInfo neighborInfo(pos, parent->sizes, *info->visibilityMap);
|
||||
|
||||
int retBitmapID = neighborInfo.getBitmapID();// >=0 -> partial hide, <0 - full hide
|
||||
if (retBitmapID < 0)
|
||||
{
|
||||
retBitmapID = - parent->hideBitmap[pos.x][pos.y][pos.z] - 1; //fully hidden
|
||||
}
|
||||
|
||||
if (retBitmapID >= 0)
|
||||
{
|
||||
return std::make_pair(graphics->FoWpartialHide->ourImages[retBitmapID].bitmap, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::make_pair(graphics->FoWfullHide->ourImages[-retBitmapID - 1].bitmap, false);
|
||||
}
|
||||
}
|
||||
|
||||
bool CMapHandler::updateObjectsFade()
|
||||
{
|
||||
for (auto iter = fadeAnims.begin(); iter != fadeAnims.end(); )
|
||||
@ -1512,11 +1496,6 @@ void CMapHandler::updateWater() //shift colors in palettes of water tiles
|
||||
|
||||
CMapHandler::~CMapHandler()
|
||||
{
|
||||
delete graphics->FoWfullHide;
|
||||
delete graphics->FoWpartialHide;
|
||||
// if (fadingOffscreenBitmapSurface)
|
||||
// delete fadingOffscreenBitmapSurface;
|
||||
|
||||
delete normalBlitter;
|
||||
delete worldViewBlitter;
|
||||
delete puzzleViewBlitter;
|
||||
@ -1543,8 +1522,6 @@ CMapHandler::~CMapHandler()
|
||||
CMapHandler::CMapHandler()
|
||||
{
|
||||
frameW = frameH = 0;
|
||||
graphics->FoWfullHide = nullptr;
|
||||
graphics->FoWpartialHide = nullptr;
|
||||
normalBlitter = new CMapNormalBlitter(this);
|
||||
worldViewBlitter = new CMapWorldViewBlitter(this);
|
||||
puzzleViewBlitter = new CMapPuzzleViewBlitter(this);
|
||||
|
@ -267,8 +267,6 @@ class CMapHandler
|
||||
virtual SDL_Rect clip(SDL_Surface * targetSurf) const = 0;
|
||||
|
||||
virtual ui8 getHeroFrameGroup(ui8 dir, bool isMoving) const;
|
||||
///returns appropriate bitmap and info if alpha blitting is necessary
|
||||
virtual std::pair<SDL_Surface *, bool> getVisBitmap() const;
|
||||
virtual ui8 getPhaseShift(const CGObjectInstance *object) const;
|
||||
|
||||
virtual bool canDrawObject(const CGObjectInstance * obj) const;
|
||||
@ -378,7 +376,9 @@ public:
|
||||
int offsetX;
|
||||
int offsetY;
|
||||
|
||||
//std::set<int> usedHeroes;
|
||||
//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<CDefEssential *> roadDefs;
|
||||
|
Loading…
x
Reference in New Issue
Block a user