1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +02:00

Fixed and cleanup

This commit is contained in:
AlexVinS 2016-11-05 19:39:39 +03:00
parent 186cd7a163
commit c11a660d21
7 changed files with 171 additions and 410 deletions

View File

@ -167,6 +167,10 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
{
CSDL_Ext::setDefaultColorKeyPresize(ret);
}
else if (ret->format->Amask)
{
SDL_SetSurfaceBlendMode(ret, SDL_BLENDMODE_BLEND);
}
else // always set
{
CSDL_Ext::setDefaultColorKey(ret);

View File

@ -141,7 +141,6 @@ Graphics::Graphics()
std::vector<Task> tasks; //preparing list of graphics to load
tasks += std::bind(&Graphics::loadFonts,this);
tasks += std::bind(&Graphics::loadPaletteAndColors,this);
tasks += std::bind(&Graphics::loadHeroFlags,this);
tasks += std::bind(&Graphics::initializeBattleGraphics,this);
tasks += std::bind(&Graphics::loadErmuToPicture,this);
tasks += std::bind(&Graphics::initializeImageLists,this);
@ -151,7 +150,6 @@ Graphics::Graphics()
#else
loadFonts();
loadPaletteAndColors();
loadHeroFlags();
initializeBattleGraphics();
loadErmuToPicture();
initializeImageLists();
@ -165,34 +163,10 @@ void Graphics::load()
heroMoveArrows = std::make_shared<CAnimation>("ADAG");
heroMoveArrows->preload();
loadHeroAnims();//todo: remove
loadHeroAnimations();
loadHeroFlagAnimations();
}
void Graphics::loadHeroAnims()
{
//first - group number to be rotated1, second - group number after rotation1
std::vector<std::pair<int,int> > rotations =
{
{6,10}, {7,11}, {8,12}, {1,13},
{2,14}, {3,15}
};
for(auto & elem : CGI->heroh->classes.heroClasses)
{
for (auto & templ : VLC->objtypeh->getHandlerFor(Obj::HERO, elem->id)->getTemplates())
{
if (!heroAnims.count(templ.animationFile))
heroAnims[templ.animationFile] = loadHeroAnim(templ.animationFile, rotations);
}
}
boatAnims.push_back(loadHeroAnim("AB01_.DEF", rotations));
boatAnims.push_back(loadHeroAnim("AB02_.DEF", rotations));
boatAnims.push_back(loadHeroAnim("AB03_.DEF", rotations));
}
void Graphics::loadHeroAnimations()
{
for(auto & elem : CGI->heroh->classes.heroClasses)
@ -274,43 +248,6 @@ std::shared_ptr<CAnimation> Graphics::loadHeroFlagAnimation(const std::string &
return anim;
}
CDefEssential * Graphics::loadHeroAnim( const std::string &name, const std::vector<std::pair<int,int> > &rotations)
{
CDefEssential *anim = CDefHandler::giveDefEss(name);
int pom = 0; //how many groups has been rotated
for(int o=7; pom<6; ++o)
{
for(int p=0;p<6;p++)
{
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;
}
}
}
for(auto & elem : anim->ourImages)
{
CSDL_Ext::alphaTransform(elem.bitmap);
}
return anim;
}
std::shared_ptr<CAnimation> Graphics::loadHeroAnimation(const std::string &name)
{
//first - group number to be rotated, second - group number after rotation
@ -332,7 +269,6 @@ std::shared_ptr<CAnimation> Graphics::loadHeroAnimation(const std::string &name)
for(size_t frame = 0; frame < anim->size(sourceGroup); ++frame)
{
anim->duplicateImage(sourceGroup, frame, targetGroup);
IImage * image = anim->getImage(frame, targetGroup);
image->verticalFlip();
}
@ -372,98 +308,6 @@ std::shared_ptr<CAnimation> Graphics::loadHeroAnimation(const std::string &name)
return anim;
}
void Graphics::loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphics::*, std::vector<const char *> > &pr)
{
for(int i=0;i<8;i++)
(this->*pr.first).push_back(CDefHandler::giveDefEss(pr.second[i]));
//first - group number to be rotated1, second - group number after rotation1
std::vector<std::pair<int,int> > rotations =
{
{6,10}, {7,11}, {8,12}
};
for(int q=0; q<8; ++q)
{
std::vector<Cimage> &curImgs = (this->*pr.first)[q]->ourImages;
for(size_t o=0; o<curImgs.size(); ++o)
{
for(auto & rotation : rotations)
{
if(curImgs[o].groupNumber==rotation.first)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::verticalFlip(curImgs[o+e].bitmap);
nci.groupNumber = rotation.second;
nci.imName = std::string();
curImgs.push_back(nci);
}
o+=8;
}
}
}
for(size_t o=0; o<curImgs.size(); ++o)
{
if(curImgs[o].groupNumber==1 || curImgs[o].groupNumber==2 || curImgs[o].groupNumber==3)
{
for(int e=0; e<8; ++e)
{
Cimage nci;
nci.bitmap = CSDL_Ext::verticalFlip(curImgs[o+e].bitmap);
nci.groupNumber = 12 + curImgs[o].groupNumber;
nci.imName = std::string();
curImgs.push_back(nci);
}
o+=8;
}
}
for(auto & curImg : curImgs)
{
CSDL_Ext::setDefaultColorKey(curImg.bitmap);
SDL_SetSurfaceBlendMode(curImg.bitmap,SDL_BLENDMODE_NONE);
}
}
}
void Graphics::loadHeroFlags()
{
CStopWatch th;
std::pair<std::vector<CDefEssential *> Graphics::*, std::vector<const char *> > pr[4] =
{
{
&Graphics::flags1,
{"ABF01L.DEF","ABF01G.DEF","ABF01R.DEF","ABF01D.DEF","ABF01B.DEF",
"ABF01P.DEF","ABF01W.DEF","ABF01K.DEF"}
},
{
&Graphics::flags2,
{"ABF02L.DEF","ABF02G.DEF","ABF02R.DEF","ABF02D.DEF","ABF02B.DEF",
"ABF02P.DEF","ABF02W.DEF","ABF02K.DEF"}
},
{
&Graphics::flags3,
{"ABF03L.DEF","ABF03G.DEF","ABF03R.DEF","ABF03D.DEF","ABF03B.DEF",
"ABF03P.DEF","ABF03W.DEF","ABF03K.DEF"}
},
{
&Graphics::flags4,
{"AF00.DEF","AF01.DEF","AF02.DEF","AF03.DEF","AF04.DEF",
"AF05.DEF","AF06.DEF","AF07.DEF"}
}
};
for(auto p: pr)
{
loadHeroFlagsDetail(p);
}
logGlobal->infoStream() << "Loading and transforming heroes' flags: "<<th.getDiff();
}
void Graphics::blueToPlayersAdv(SDL_Surface * sur, PlayerColor player)
{
if(sur->format->palette)
@ -517,26 +361,6 @@ void Graphics::loadFonts()
}
}
CDefEssential * Graphics::getDef( const CGObjectInstance * obj )
{
if (obj->appearance.animationFile.empty())
{
logGlobal->warnStream() << boost::format("Def name for obj %d (%d,%d) is empty!") % obj->id % obj->ID % obj->subID;
return nullptr;
}
return advmapobjGraphics[obj->appearance.animationFile];
}
CDefEssential * Graphics::getDef( const ObjectTemplate & info )
{
if (info.animationFile.empty())
{
logGlobal->warnStream() << boost::format("Def name for obj (%d,%d) is empty!") % info.id % info.subid;
return nullptr;
}
return advmapobjGraphics[info.animationFile];
}
std::shared_ptr<CAnimation> Graphics::getAnimation(const CGObjectInstance* obj)
{
return getAnimation(obj->appearance);

View File

@ -40,11 +40,6 @@ class Graphics
void initializeBattleGraphics();
void loadPaletteAndColors();
void loadHeroFlags(); //deprecated
void loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphics::*, std::vector<const char *> > &pr); //deprecated
void loadHeroAnims();//deprecated
CDefEssential * loadHeroAnim(const std::string &name, const std::vector<std::pair<int,int> > &rotations);//deprecated
void loadHeroAnimations();
//loads animation and adds required rotated frames
@ -71,7 +66,6 @@ public:
SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256]
SDL_Color * neutralColorPalette;
std::vector<CDefEssential *> flags1, flags2, flags3, flags4; //DEPRECATED flags blitted on heroes when ,
std::shared_ptr<CAnimation> heroMoveArrows;
// [hero class def name] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
@ -86,16 +80,11 @@ public:
//all other objects (not hero or boat)
std::map< std::string, std::shared_ptr<CAnimation> > mapObjectAnimations;
std::map<std::string, CDefEssential *> heroAnims; // DEPRECATED [hero class def name] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
std::vector<CDefEssential *> boatAnims; // DEPRECATED [boat type: 0 - 3] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
CDefHandler * FoWfullHide; //for Fog of War
CDefHandler * FoWpartialHide; //for For of War
std::map<std::string, JsonNode> imageLists;
std::map<std::string, CDefEssential *> advmapobjGraphics; // DEPRECATED
CDefEssential * getDef(const CGObjectInstance * obj); // DEPRECATED
CDefEssential * getDef(const ObjectTemplate & info); // DEPRECATED
//towns
std::map<int, std::string> ERMUtoPicture[GameConstants::F_NUMBER]; //maps building ID to it's picture's name for each town type
//for battles

View File

@ -23,10 +23,137 @@
*
*/
class SDLImageLoader;
class CompImageLoader;
typedef std::map <size_t, std::vector <JsonNode> > source_map;
typedef std::map<size_t, IImage* > image_map;
typedef std::map<size_t, image_map > group_map;
/// Class for def loading, methods are based on CDefHandler
/// After loading will store general info (palette and frame offsets) and pointer to file itself
class CDefFile
{
private:
struct SSpriteDef
{
ui32 size;
ui32 format; /// format in which pixel data is stored
ui32 fullWidth; /// full width and height of frame, including borders
ui32 fullHeight;
ui32 width; /// width and height of pixel data, borders excluded
ui32 height;
si32 leftMargin;
si32 topMargin;
} PACKED_STRUCT;
//offset[group][frame] - offset of frame data in file
std::map<size_t, std::vector <size_t> > offset;
std::unique_ptr<ui8[]> data;
std::unique_ptr<SDL_Color[]> palette;
public:
CDefFile(std::string Name);
~CDefFile();
//load frame as SDL_Surface
template<class ImageLoader>
void loadFrame(size_t frame, size_t group, ImageLoader &loader) const;
const std::map<size_t, size_t> getEntries() const;
};
/*
* Wrapper around SDL_Surface
*/
class SDLImage : public IImage
{
public:
//Surface without empty borders
SDL_Surface * surf;
//size of left and top borders
Point margins;
//total size including borders
Point fullSize;
public:
//Load image from def file
SDLImage(CDefFile *data, size_t frame, size_t group=0, bool compressed=false);
//Load from bitmap file
SDLImage(std::string filename, bool compressed=false);
//Create using existing surface, extraRef will increase refcount on SDL_Surface
SDLImage(SDL_Surface * from, bool extraRef);
~SDLImage();
void draw(SDL_Surface * where, int posX=0, int posY=0, Rect *src=nullptr, ui8 alpha=255) const override;
void draw(SDL_Surface * where, SDL_Rect * dest, SDL_Rect * src, ui8 alpha=255) const override;
SDL_Surface * scaleFast(float scale) const override;
void playerColored(PlayerColor player) override;
void setFlagColor(PlayerColor player) override;
int width() const override;
int height() const override;
void verticalFlip() override;
friend class SDLImageLoader;
};
/*
* RLE-compressed image data for 8-bit images with alpha-channel, currently far from finished
* primary purpose is not high compression ratio but fast drawing.
* Consist of repeatable segments with format similar to H3 def compression:
* 1st byte:
* if (byte == 0xff)
* raw data, opaque and semi-transparent data always in separate blocks
* else
* RLE-compressed image data with this color
* 2nd byte = size of segment
* raw data (if any)
*/
class CompImage : public IImage
{
//x,y - margins, w,h - sprite size
Rect sprite;
//total size including borders
Point fullSize;
//RLE-d data
ui8 * surf;
//array of offsets for each line
ui32 * line;
//palette
SDL_Color *palette;
//Used internally to blit one block of data
template<int bpp, int dir>
void BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha) const;
void BlitBlockWithBpp(ui8 bpp, ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha, bool rotated) const;
public:
//Load image from def file
CompImage(const CDefFile *data, size_t frame, size_t group=0);
//TODO: load image from SDL_Surface
CompImage(SDL_Surface * surf);
~CompImage();
void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=nullptr, ui8 alpha=255) const override;
void draw(SDL_Surface * where, SDL_Rect * dest, SDL_Rect * src, ui8 alpha=255) const override;
SDL_Surface * scaleFast(float scale) const override;
void playerColored(PlayerColor player) override;
void setFlagColor(PlayerColor player) override;
int width() const override;
int height() const override;
void verticalFlip() override;
friend class CompImageLoader;
};
class SDLImageLoader
{
SDLImage * image;
@ -572,26 +699,6 @@ IImage::IImage():
}
void IImage::draw(SDL_Surface * where, SDL_Rect * dest, SDL_Rect * src) const
{
int x = 0, y = 0;
if(dest)
{
x = dest->x;
y = dest->y;
}
if(src)
{
Rect srcTemp(*src);
draw(where, x, y, &srcTemp);
}
else
{
draw(where, x, y);
}
}
bool IImage::decreaseRef()
{
refCount--;
@ -661,7 +768,7 @@ void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alpha
draw(where, &destRect, src);
}
void SDLImage::draw(SDL_Surface* where, SDL_Rect* dest, SDL_Rect* src) const
void SDLImage::draw(SDL_Surface* where, SDL_Rect* dest, SDL_Rect* src, ui8 alpha) const
{
if (!surf)
return;
@ -700,15 +807,9 @@ void SDLImage::draw(SDL_Surface* where, SDL_Rect* dest, SDL_Rect* src) const
{
CSDL_Ext::blit8bppAlphaTo24bpp(surf, &sourceRect, where, &destRect);
}
else if(surf->format->Amask == 0)
{
SDL_BlitSurface(surf, &sourceRect, where, &destRect);
}
else
{
SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_BLEND);
SDL_BlitSurface(surf, &sourceRect, where, &destRect);
SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE);
}
}
@ -781,6 +882,12 @@ CompImage::CompImage(SDL_Surface * surf)
}
void CompImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alpha) const
{
Rect dest(posX,posY, width(), height());
draw(where, &dest, src, alpha);
}
void CompImage::draw(SDL_Surface* where, SDL_Rect* dest, SDL_Rect* src, ui8 alpha) const
{
int rotation = 0; //TODO
//rotation & 2 = horizontal rotation
@ -795,11 +902,18 @@ void CompImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alph
sourceRect = sourceRect & Rect(0, 0, where->w, where->h);
//Starting point on SDL surface
Point dest(posX+sourceRect.x, posY+sourceRect.y);
Point dst(sourceRect.x,sourceRect.y);
if (dest)
{
dst.x += dest->x;
dst.y += dest->y;
}
if (rotation & 2)
dest.y += sourceRect.h;
dst.y += sourceRect.h;
if (rotation & 4)
dest.x += sourceRect.w;
dst.x += sourceRect.w;
sourceRect -= sprite.topLeft();
@ -830,10 +944,10 @@ void CompImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alph
//Calculate position for blitting: pixels + Y + X
ui8* blitPos = (ui8*) where->pixels;
if (rotation & 4)
blitPos += (dest.y - currY) * where->pitch;
blitPos += (dst.y - currY) * where->pitch;
else
blitPos += (dest.y + currY) * where->pitch;
blitPos += dest.x * bpp;
blitPos += (dst.y + currY) * where->pitch;
blitPos += dst.x * bpp;
//Blit blocks that must be fully visible
while (currX + size < sourceRect.w)
@ -851,6 +965,7 @@ void CompImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alph
}
}
SDL_Surface * CompImage::scaleFast(float scale) const
{
//todo: CompImage::scaleFast
@ -1018,6 +1133,7 @@ IImage * CAnimation::getFromExtraDef(std::string filename)
pos = filename.find(':', pos);
if (pos != -1)
{
pos++;
group = frame;
frame = atoi(filename.c_str()+pos);
}
@ -1065,7 +1181,7 @@ bool CAnimation::loadFrame(CDefFile * file, size_t frame, size_t group)
}
else //load from separate file
{
std::string filename = source[group][frame].Struct().find("file")->second.String();
std::string filename = source[group][frame]["file"].String();
IImage * img = getFromExtraDef(filename);
if (!img)
@ -1214,13 +1330,14 @@ void CAnimation::duplicateImage(const size_t sourceGroup, const size_t sourceFra
if(clone.getType() == JsonNode::DATA_NULL)
{
clone["file"].String() = name+":"+boost::lexical_cast<std::string>(sourceGroup)+":"+boost::lexical_cast<std::string>(sourceFrame);
std::string temp = name+":"+boost::lexical_cast<std::string>(sourceGroup)+":"+boost::lexical_cast<std::string>(sourceFrame);
clone["file"].String() = temp;
}
source[targetGroup].push_back(clone);
if(preloaded)
load(source[targetGroup].size()-1, targetGroup);
load(sourceFrame, targetGroup);
}
void CAnimation::setCustom(std::string filename, size_t frame, size_t group)

View File

@ -15,43 +15,8 @@
*/
struct SDL_Surface;
class SDLImageLoader;
class CompImageLoader;
class JsonNode;
/// Class for def loading, methods are based on CDefHandler
/// After loading will store general info (palette and frame offsets) and pointer to file itself
class CDefFile
{
private:
struct SSpriteDef
{
ui32 size;
ui32 format; /// format in which pixel data is stored
ui32 fullWidth; /// full width and height of frame, including borders
ui32 fullHeight;
ui32 width; /// width and height of pixel data, borders excluded
ui32 height;
si32 leftMargin;
si32 topMargin;
} PACKED_STRUCT;
//offset[group][frame] - offset of frame data in file
std::map<size_t, std::vector <size_t> > offset;
std::unique_ptr<ui8[]> data;
std::unique_ptr<SDL_Color[]> palette;
public:
CDefFile(std::string Name);
~CDefFile();
//load frame as SDL_Surface
template<class ImageLoader>
void loadFrame(size_t frame, size_t group, ImageLoader &loader) const;
const std::map<size_t, size_t> getEntries() const;
};
class CDefFile;
/*
* Base class for images, can be used for non-animation pictures as well
@ -62,8 +27,8 @@ class IImage
public:
//draws image on surface "where" at position
virtual void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=nullptr, ui8 alpha=255) const=0;
virtual void draw(SDL_Surface * where, SDL_Rect * dest, SDL_Rect * src) const;
virtual void draw(SDL_Surface * where, int posX = 0, int posY = 0, Rect * src = nullptr, ui8 alpha = 255) const=0;
virtual void draw(SDL_Surface * where, SDL_Rect * dest, SDL_Rect * src, ui8 alpha = 255) const = 0;
virtual SDL_Surface * scaleFast(float scale) const = 0;
@ -86,95 +51,6 @@ public:
virtual ~IImage() {};
};
/*
* Wrapper around SDL_Surface
*/
class SDLImage : public IImage
{
public:
//Surface without empty borders
SDL_Surface * surf;
//size of left and top borders
Point margins;
//total size including borders
Point fullSize;
public:
//Load image from def file
SDLImage(CDefFile *data, size_t frame, size_t group=0, bool compressed=false);
//Load from bitmap file
SDLImage(std::string filename, bool compressed=false);
//Create using existing surface, extraRef will increase refcount on SDL_Surface
SDLImage(SDL_Surface * from, bool extraRef);
~SDLImage();
void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=nullptr, ui8 alpha=255) const override;
void draw(SDL_Surface * where, SDL_Rect * dest, SDL_Rect * src) const override;
SDL_Surface * scaleFast(float scale) const override;
void playerColored(PlayerColor player) override;
void setFlagColor(PlayerColor player) override;
int width() const override;
int height() const override;
void verticalFlip() override;
friend class SDLImageLoader;
};
/*
* RLE-compressed image data for 8-bit images with alpha-channel, currently far from finished
* primary purpose is not high compression ratio but fast drawing.
* Consist of repeatable segments with format similar to H3 def compression:
* 1st byte:
* if (byte == 0xff)
* raw data, opaque and semi-transparent data always in separate blocks
* else
* RLE-compressed image data with this color
* 2nd byte = size of segment
* raw data (if any)
*/
class CompImage : public IImage
{
//x,y - margins, w,h - sprite size
Rect sprite;
//total size including borders
Point fullSize;
//RLE-d data
ui8 * surf;
//array of offsets for each line
ui32 * line;
//palette
SDL_Color *palette;
//Used internally to blit one block of data
template<int bpp, int dir>
void BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha) const;
void BlitBlockWithBpp(ui8 bpp, ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha, bool rotated) const;
public:
//Load image from def file
CompImage(const CDefFile *data, size_t frame, size_t group=0);
//TODO: load image from SDL_Surface
CompImage(SDL_Surface * surf);
~CompImage();
void draw(SDL_Surface *where, int posX=0, int posY=0, Rect *src=nullptr, ui8 alpha=255) const override;
SDL_Surface * scaleFast(float scale) const override;
void playerColored(PlayerColor player) override;
void setFlagColor(PlayerColor player) override;
int width() const override;
int height() const override;
void verticalFlip() override;
friend class CompImageLoader;
};
/// Class for handling animation
class CAnimation
{

View File

@ -292,35 +292,6 @@ void CMapHandler::borderAndTerrainBitmapInit()
delete bord;
}
static void processDef (const ObjectTemplate & objTempl) //deprecated
{
if(objTempl.id == Obj::EVENT)
{
graphics->advmapobjGraphics[objTempl.animationFile] = nullptr;
return;
}
CDefEssential * ourDef = graphics->getDef(objTempl);
if(!ourDef) //if object has already set handler (eg. heroes) it should not be overwritten
{
if(objTempl.animationFile.size())
{
graphics->advmapobjGraphics[objTempl.animationFile] = CDefHandler::giveDefEss(objTempl.animationFile);
}
else
{
logGlobal->warnStream() << "No def name for " << objTempl.id << " " << objTempl.subid;
return;
}
ourDef = graphics->getDef(objTempl);
}
//alpha transformation
for(auto & elem : ourDef->ourImages)
{
CSDL_Ext::alphaTransform(elem.bitmap);
}
}
void CMapHandler::initObjectRects()
{
//initializing objects / rects
@ -388,9 +359,6 @@ void CMapHandler::init()
CStopWatch th;
th.getDiff();
graphics->advmapobjGraphics["AB01_.DEF"] = graphics->boatAnims[0];
graphics->advmapobjGraphics["AB02_.DEF"] = graphics->boatAnims[1];
graphics->advmapobjGraphics["AB03_.DEF"] = graphics->boatAnims[2];
// Size of visible terrain.
int mapW = conf.go()->ac.advmapW;
int mapH = conf.go()->ac.advmapH;
@ -880,18 +848,6 @@ void CMapHandler::CMapBlitter::drawObjects(SDL_Surface * targetSurf, const Terra
continue;
}
if (!graphics->getDef(obj))
processDef(obj->appearance);
if (!graphics->getDef(obj))
{
if (!obj->appearance.animationFile.empty())
logGlobal->errorStream() << "Failed to load image " << obj->appearance.animationFile;
else
logGlobal->warnStream() << boost::format("Def name for obj %d (%d,%d) is empty!") % obj->id % obj->ID % obj->subID;
continue;
}
if (!canDrawObject(obj))
continue;
@ -1162,14 +1118,6 @@ IImage * CMapHandler::CMapBlitter::findFlagBitmapInternal(std::shared_ptr<CAnima
return animation->getImage((anim / 4) % animation->size(group), group);
}
int CMapHandler::CMapBlitter::findAnimIndexByGroup(const CDefEssential * def, int groupNum) const
{
auto iter = std::find_if(def->ourImages.begin(), def->ourImages.end(), [&](const Cimage &img){ return img.groupNumber == groupNum; });
if (iter == def->ourImages.end())
return -1;
return static_cast<int>(iter - def->ourImages.begin());
}
CMapHandler::AnimBitmapHolder CMapHandler::CMapBlitter::findObjectBitmap(const CGObjectInstance * obj, int anim) const
{
if (!obj)
@ -1322,12 +1270,18 @@ bool CMapHandler::startObjectFade(TerrainTileObject & obj, bool in, int3 pos)
bool CMapHandler::printObject(const CGObjectInstance *obj, bool fadein /* = false */)
{
if (!graphics->getDef(obj))
processDef(obj->appearance);
auto animation = graphics->getAnimation(obj);
SDL_Surface *bitmap = graphics->getDef(obj)->ourImages[0].bitmap;
const int tilesW = bitmap->w/32;
const int tilesH = bitmap->h/32;
if(!animation)
return false;
IImage * bitmap = animation->getImage(0);
if(!bitmap)
return false;
const int tilesW = bitmap->width()/32;
const int tilesH = bitmap->height()/32;
for(int fx=0; fx<tilesW; ++fx)
{
@ -1364,7 +1318,6 @@ bool CMapHandler::printObject(const CGObjectInstance *obj, bool fadein /* = fals
if(i == curt.objects.end())
curt.objects.insert(i, toAdd);
}
}
}
return true;

View File

@ -281,7 +281,6 @@ class CMapHandler
IImage * findHeroFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor * color, int group) const;
IImage * findBoatFlagBitmap(const CGBoat * obj, int anim, const PlayerColor * color, int group, ui8 dir) const;
IImage * findFlagBitmapInternal(std::shared_ptr<CAnimation> animation, int anim, int group, ui8 dir, bool moving) const;
int findAnimIndexByGroup(const CDefEssential * def, int groupNum) const; //deprecated
public:
CMapBlitter(CMapHandler * p) : parent(p) {}
@ -289,7 +288,6 @@ class CMapHandler
void blit(SDL_Surface * targetSurf, const MapDrawingInfo * info);
/// helper method that chooses correct bitmap(s) for given object
AnimBitmapHolder findObjectBitmap(const CGObjectInstance * obj, int anim) const;
};
class CMapNormalBlitter : public CMapBlitter