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

Map handler refactoring, part 2.

This commit is contained in:
AlexVinS 2016-11-08 00:19:53 +03:00
parent aad675a7c4
commit a8a661b159
14 changed files with 841 additions and 879 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

@ -3,7 +3,6 @@
#include "../lib/filesystem/Filesystem.h"
#include "../lib/filesystem/CBinaryReader.h"
#include "CDefHandler.h"
#include "gui/SDL_Extensions.h"
#include "gui/CAnimation.h"
#include <SDL_ttf.h>
@ -130,18 +129,9 @@ 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);
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 +141,6 @@ Graphics::Graphics()
#else
loadFonts();
loadPaletteAndColors();
loadHeroFlags();
initializeBattleGraphics();
loadErmuToPicture();
initializeImageLists();
@ -165,168 +154,119 @@ void Graphics::load()
heroMoveArrows = std::make_shared<CAnimation>("ADAG");
heroMoveArrows->preload();
loadHeroAnims();
loadHeroAnimations();
loadHeroFlagAnimations();
loadFogOfWar();
}
void Graphics::loadHeroAnims()
void Graphics::loadHeroAnimations()
{
//first - group number to be rotated1, second - group number after rotation1
std::vector<std::pair<int,int> > rotations =
for(auto & elem : CGI->heroh->classes.heroClasses)
{
for (auto & templ : VLC->objtypeh->getHandlerFor(Obj::HERO, elem->id)->getTemplates())
{
if (!heroAnimations.count(templ.animationFile))
heroAnimations[templ.animationFile] = loadHeroAnimation(templ.animationFile);
}
}
boatAnimations[0] = loadHeroAnimation("AB01_.DEF");
boatAnimations[1] = loadHeroAnimation("AB02_.DEF");
boatAnimations[2] = loadHeroAnimation("AB03_.DEF");
mapObjectAnimations["AB01_.DEF"] = boatAnimations[0];
mapObjectAnimations["AB02_.DEF"] = boatAnimations[1];
mapObjectAnimations["AB03_.DEF"] = boatAnimations[2];
}
void Graphics::loadHeroFlagAnimations()
{
static const std::vector<std::string> HERO_FLAG_ANIMATIONS =
{
"AF00", "AF01","AF02","AF03",
"AF04", "AF05","AF06","AF07"
};
static const std::vector< std::vector<std::string> > BOAT_FLAG_ANIMATIONS =
{
{
"ABF01L", "ABF01G", "ABF01R", "ABF01D",
"ABF01B", "ABF01P", "ABF01W", "ABF01K"
},
{
"ABF02L", "ABF02G", "ABF02R", "ABF02D",
"ABF02B", "ABF02P", "ABF02W", "ABF02K"
},
{
"ABF03L", "ABF03G", "ABF03R", "ABF03D",
"ABF03B", "ABF03P", "ABF03W", "ABF03K"
}
};
for(const auto & name : HERO_FLAG_ANIMATIONS)
heroFlagAnimations.push_back(loadHeroFlagAnimation(name));
for(int i = 0; i < BOAT_FLAG_ANIMATIONS.size(); i++)
for(const auto & name : BOAT_FLAG_ANIMATIONS[i])
boatFlagAnimations[i].push_back(loadHeroFlagAnimation(name));
}
std::shared_ptr<CAnimation> Graphics::loadHeroFlagAnimation(const std::string & name)
{
//first - group number to be rotated, second - group number after rotation
static const 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)
std::shared_ptr<CAnimation> anim = std::make_shared<CAnimation>(name);
anim->preload();
for(const auto & rotation : rotations)
{
for (auto & templ : VLC->objtypeh->getHandlerFor(Obj::HERO, elem->id)->getTemplates())
const int sourceGroup = rotation.first;
const int targetGroup = rotation.second;
for(size_t frame = 0; frame < anim->size(sourceGroup); ++frame)
{
if (!heroAnims.count(templ.animationFile))
heroAnims[templ.animationFile] = loadHeroAnim(templ.animationFile, rotations);
anim->duplicateImage(sourceGroup, frame, targetGroup);
IImage * image = anim->getImage(frame, targetGroup);
image->verticalFlip();
}
}
boatAnims.push_back(loadHeroAnim("AB01_.DEF", rotations));
boatAnims.push_back(loadHeroAnim("AB02_.DEF", rotations));
boatAnims.push_back(loadHeroAnim("AB03_.DEF", rotations));
}
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;
}
void Graphics::loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphics::*, std::vector<const char *> > &pr, bool mode)
std::shared_ptr<CAnimation> Graphics::loadHeroAnimation(const std::string &name)
{
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 =
//first - group number to be rotated, second - group number after rotation
static const std::vector<std::pair<int,int> > rotations =
{
{6,10}, {7,11}, {8,12}
{6,10}, {7,11}, {8,12}, {1,13},
{2,14}, {3,15}
};
for(int q=0; q<8; ++q)
std::shared_ptr<CAnimation> anim = std::make_shared<CAnimation>(name);
anim->preload();
for(const auto & rotation : rotations)
{
std::vector<Cimage> &curImgs = (this->*pr.first)[q]->ourImages;
for(size_t o=0; o<curImgs.size(); ++o)
const int sourceGroup = rotation.first;
const int targetGroup = rotation.second;
for(size_t frame = 0; frame < anim->size(sourceGroup); ++frame)
{
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;
}
}
}
if (mode)
{
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);
anim->duplicateImage(sourceGroup, frame, targetGroup);
IImage * image = anim->getImage(frame, targetGroup);
image->verticalFlip();
}
}
}
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"}
}
};
#if 0
boost::thread_group grupa;
for(int g=3; g>=0; --g)
{
grupa.create_thread(std::bind(&Graphics::loadHeroFlagsDetail, this, std::ref(pr[g]), true));
}
grupa.join_all();
#else
for(auto p: pr)
{
loadHeroFlagsDetail(p,true);
}
#endif
logGlobal->infoStream() << "Loading and transforming heroes' flags: "<<th.getDiff();
return anim;
}
void Graphics::blueToPlayersAdv(SDL_Surface * sur, PlayerColor player)
@ -359,6 +299,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"));
@ -374,32 +334,47 @@ void Graphics::loadFonts()
std::string filename = bmpConf[i].String();
if (!hanConf[filename].isNull())
fonts[i] = new CBitmapHanFont(hanConf[filename]);
fonts[i] = std::make_shared<CBitmapHanFont>(hanConf[filename]);
else if (!ttfConf[filename].isNull()) // no ttf override
fonts[i] = new CTrueTypeFont(ttfConf[filename]);
fonts[i] = std::make_shared<CTrueTypeFont>(ttfConf[filename]);
else
fonts[i] = new CBitmapFont(filename);
fonts[i] = std::make_shared<CBitmapFont>(filename);
}
}
CDefEssential * Graphics::getDef( const CGObjectInstance * obj )
std::shared_ptr<CAnimation> Graphics::getAnimation(const CGObjectInstance* obj)
{
if (obj->appearance.animationFile.empty())
return getAnimation(obj->appearance);
}
std::shared_ptr<CAnimation> Graphics::getAnimation(const ObjectTemplate & info)
{
//the only(?) invisible object
if(info.id == Obj::EVENT)
{
logGlobal->warnStream() << boost::format("Def name for obj %d (%d,%d) is empty!") % obj->id % obj->ID % obj->subID;
return nullptr;
return std::shared_ptr<CAnimation>();
}
return advmapobjGraphics[obj->appearance.animationFile];
}
CDefEssential * Graphics::getDef( const ObjectTemplate & info )
{
if (info.animationFile.empty())
if(info.animationFile.empty())
{
logGlobal->warnStream() << boost::format("Def name for obj (%d,%d) is empty!") % info.id % info.subid;
return nullptr;
return std::shared_ptr<CAnimation>();
}
return advmapobjGraphics[info.animationFile];
std::shared_ptr<CAnimation> ret = mapObjectAnimations[info.animationFile];
//already loaded
if(ret)
{
ret->preload();
return ret;
}
ret = std::make_shared<CAnimation>(info.animationFile);
mapObjectAnimations[info.animationFile] = ret;
ret->preload();
return ret;
}
void Graphics::loadErmuToPicture()

View File

@ -1,6 +1,5 @@
#pragma once
#include "gui/Fonts.h"
#include "../lib/GameConstants.h"
#include "gui/Geometries.h"
@ -15,11 +14,9 @@
*
*/
class CDefEssential;
struct SDL_Surface;
class CGHeroInstance;
class CGTownInstance;
class CDefHandler;
class CHeroClass;
struct SDL_Color;
struct InfoAboutHero;
@ -40,19 +37,25 @@ class Graphics
void initializeBattleGraphics();
void loadPaletteAndColors();
void loadHeroFlags();
void loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphics::*, std::vector<const char *> > &pr, bool mode);
void loadHeroAnims();
CDefEssential * loadHeroAnim(const std::string &name, const std::vector<std::pair<int,int> > &rotations);
void loadErmuToPicture();
void loadHeroAnimations();
//loads animation and adds required rotated frames
std::shared_ptr<CAnimation> loadHeroAnimation(const std::string &name);
void loadHeroFlagAnimations();
//loads animation and adds required rotated frames
std::shared_ptr<CAnimation> loadHeroFlagAnimation(const std::string &name);
void loadErmuToPicture();
void loadFogOfWar();
void loadFonts();
void initializeImageLists();
public:
//Fonts
static const int FONTS_NUMBER = 9;
IFont * fonts[FONTS_NUMBER];
std::array< std::shared_ptr<IFont>, FONTS_NUMBER> fonts;
//various graphics
SDL_Color * playerColors; //array [8]
@ -60,18 +63,25 @@ public:
SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256]
SDL_Color * neutralColorPalette;
std::vector<CDefEssential *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,
std::shared_ptr<CAnimation> heroMoveArrows;
std::map<std::string, CDefEssential *> heroAnims; // [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; // [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
// [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::map< std::string, std::shared_ptr<CAnimation> > heroAnimations;
std::vector< std::shared_ptr<CAnimation> > heroFlagAnimations;
// [boat type: 0 .. 2] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
std::array< std::shared_ptr<CAnimation>, 3> boatAnimations;
std::array< std::vector<std::shared_ptr<CAnimation> >, 3> boatFlagAnimations;
//all other objects (not hero or boat)
std::map< std::string, std::shared_ptr<CAnimation> > mapObjectAnimations;
std::shared_ptr<CAnimation> fogOfWarFullHide;
std::shared_ptr<CAnimation> fogOfWarPartialHide;
std::map<std::string, JsonNode> imageLists;
std::map<std::string, CDefEssential *> advmapobjGraphics;
CDefEssential * getDef(const CGObjectInstance * obj);
CDefEssential * getDef(const ObjectTemplate & info);
//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
@ -83,6 +93,9 @@ public:
void load();
void blueToPlayersAdv(SDL_Surface * sur, PlayerColor player); //replaces blue interface colour with a color of player
std::shared_ptr<CAnimation> getAnimation(const CGObjectInstance * obj);
std::shared_ptr<CAnimation> getAnimation(const ObjectTemplate & info);
};
extern Graphics * graphics;

View File

@ -369,7 +369,7 @@ void TryMoveHero::applyFirstCl(CClient *cl)
}
if(result == TELEPORTATION || result == EMBARK || result == DISEMBARK || !humanKnows)
CGI->mh->removeObject(h, result == EMBARK && humanKnows);
CGI->mh->hideObject(h, result == EMBARK && humanKnows);
if(result == DISEMBARK)

View File

@ -23,10 +23,143 @@
*
*/
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 horizontalFlip() override;
void verticalFlip() override;
void shiftPalette(int from, int howMany) 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 horizontalFlip() override;
void verticalFlip() override;
void shiftPalette(int from, int howMany) override;
friend class CompImageLoader;
};
class SDLImageLoader
{
SDLImage * image;
@ -214,7 +347,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();
}
@ -636,37 +769,82 @@ void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alpha
if (!surf)
return;
Rect sourceRect(margins.x, margins.y, surf->w, surf->h);
//TODO: rotation and scaling
if (src)
{
sourceRect = sourceRect & *src;
}
Rect destRect(posX, posY, surf->w, surf->h);
destRect += sourceRect.topLeft();
sourceRect -= margins;
draw(where, &destRect, src);
}
void SDLImage::draw(SDL_Surface* where, SDL_Rect* dest, SDL_Rect* src, ui8 alpha) const
{
if (!surf)
return;
Rect sourceRect(0, 0, surf->w, surf->h);
Point destShift(0,0);
if(src)
{
if(src->x < margins.x)
destShift.x += margins.x - src->x;
if(src->y < margins.y)
destShift.y += margins.y - src->y;
sourceRect = Rect(*src) & Rect(margins.x, margins.y, surf->w, surf->h);
sourceRect -= margins;
}
else
destShift = margins;
Rect destRect(margins.x, margins.y, surf->w, surf->h);
if(dest)
{
destRect = *dest;
destRect = destRect & Rect(destRect.x, destRect.y, sourceRect.w, sourceRect.h);
destRect += destShift;
}
if(surf->format->BitsPerPixel == 8)
{
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);
SDL_UpperBlit(surf, &sourceRect, where, &destRect);
}
}
SDL_Surface * SDLImage::scaleFast(float scale) const
{
//todo: margins
auto scaled = CSDL_Ext::scaleSurfaceFast(surf, surf->w * scale, surf->h * scale);
if (scaled->format && scaled->format->palette) // fix color keying, because SDL loses it at this point
CSDL_Ext::setColorKey(scaled, scaled->format->palette->colors[0]);
else if(scaled->format && scaled->format->Amask)
SDL_SetSurfaceBlendMode(scaled, SDL_BLENDMODE_BLEND);//just in case
else
CSDL_Ext::setDefaultColorKey(scaled);//just in case
return scaled;
}
void SDLImage::playerColored(PlayerColor player)
{
graphics->blueToPlayersAdv(surf, player);
}
void SDLImage::setFlagColor(PlayerColor player)
{
if(player < PlayerColor::PLAYER_LIMIT || player==PlayerColor::NEUTRAL)
CSDL_Ext::setPlayerColor(surf, player);
}
int SDLImage::width() const
{
return fullSize.x;
@ -677,6 +855,45 @@ int SDLImage::height() const
return fullSize.y;
}
void SDLImage::horizontalFlip()
{
SDL_Surface * flipped = CSDL_Ext::horizontalFlip(surf);
SDL_FreeSurface(surf);
surf = flipped;
margins.y = fullSize.y - surf->h - margins.y;
}
void SDLImage::verticalFlip()
{
SDL_Surface * flipped = CSDL_Ext::verticalFlip(surf);
SDL_FreeSurface(surf);
surf = flipped;
margins.x = fullSize.x - surf->w - margins.x;
}
void SDLImage::shiftPalette(int from, int howMany)
{
//works with at most 16 colors, if needed more -> increase values
assert(howMany < 16);
if(surf->format->palette)
{
SDL_Color palette[16];
for(int i=0; i<howMany; ++i)
{
palette[(i+1)%howMany] = surf->format->palette->colors[from + i];
}
SDL_SetColors(surf, palette, from, howMany);
}
}
SDLImage::~SDLImage()
{
SDL_FreeSurface(surf);
@ -699,6 +916,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
@ -713,11 +936,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();
@ -748,10 +978,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)
@ -769,6 +999,16 @@ void CompImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 alph
}
}
SDL_Surface * CompImage::scaleFast(float scale) const
{
//todo: CompImage::scaleFast
logAnim->error("CompImage::scaleFast is not implemented");
return CSDL_Ext::newSurface(width() * scale, height() * scale);
}
#define CASEBPP(x,y) case x: BlitBlock<x,y>(type, size, data, dest, alpha); break
//FIXME: better way to get blitter
@ -883,6 +1123,11 @@ void CompImage::playerColored(PlayerColor player)
}
}
void CompImage::setFlagColor(PlayerColor player)
{
logAnim->error("CompImage::setFlagColor is not implemented");
}
int CompImage::width() const
{
return fullSize.x;
@ -900,6 +1145,22 @@ CompImage::~CompImage()
delete [] palette;
}
void CompImage::horizontalFlip()
{
logAnim->error("CompImage::horizontalFlip is not implemented");
}
void CompImage::verticalFlip()
{
logAnim->error("CompImage::verticalFlip is not implemented");
}
void CompImage::shiftPalette(int from, int howMany)
{
logAnim->error("CompImage::shiftPalette is not implemented");
}
/*************************************************************************
* CAnimation for animations handling, can load part of file if needed *
*************************************************************************/
@ -916,6 +1177,7 @@ IImage * CAnimation::getFromExtraDef(std::string filename)
pos = filename.find(':', pos);
if (pos != -1)
{
pos++;
group = frame;
frame = atoi(filename.c_str()+pos);
}
@ -963,7 +1225,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)
@ -1105,6 +1367,25 @@ CAnimation::~CAnimation()
}
}
void CAnimation::duplicateImage(const size_t sourceGroup, const size_t sourceFrame, const size_t targetGroup)
{
//todo: clone actual loaded Image object
JsonNode clone(source[sourceGroup][sourceFrame]);
if(clone.getType() == JsonNode::DATA_NULL)
{
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);
size_t index = source[targetGroup].size() - 1;
if(preloaded)
load(index, targetGroup);
}
void CAnimation::setCustom(std::string filename, size_t frame, size_t group)
{
if (source[group].size() <= frame)
@ -1148,8 +1429,11 @@ void CAnimation::unload()
void CAnimation::preload()
{
preloaded = true;
load();
if(!preloaded)
{
preloaded = true;
load();
}
}
void CAnimation::loadGroup(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,7 +27,10 @@ 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, 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;
//decrease ref count, returns true if image can be deleted (refCount <= 0)
bool decreaseRef();
@ -70,90 +38,23 @@ public:
//Change palette to specific player
virtual void playerColored(PlayerColor player)=0;
//set special color for flag
virtual void setFlagColor(PlayerColor player)=0;
virtual int width() const=0;
virtual int height() const=0;
//only indexed bitmaps, 16 colors maximum
virtual void shiftPalette(int from, int howMany) = 0;
virtual void horizontalFlip() = 0;
virtual void verticalFlip() = 0;
IImage();
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 playerColored(PlayerColor player) override;
int width() const override;
int height() const 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 playerColored(PlayerColor player) override;
int width() const override;
int height() const override;
friend class CompImageLoader;
};
/// Class for handling animation
class CAnimation
{
@ -198,6 +99,10 @@ public:
CAnimation();
~CAnimation();
//duplicates frame at [sourceGroup, sourceFrame] as last frame in targetGroup
//and loads it if animation is preloaded
void duplicateImage(const size_t sourceGroup, const size_t sourceFrame, const size_t targetGroup);
//add custom surface to the selected position.
void setCustom(std::string filename, size_t frame, size_t group=0);

View File

@ -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);
}
}

View File

@ -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);

File diff suppressed because it is too large Load Diff

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
@ -133,16 +130,6 @@ template <typename T> class PseudoV
{
public:
PseudoV() : offset(0) { }
PseudoV(std::vector<T> &src, int rest, int before, int after, const T& fill) : offset(before)
{
inver.resize(before + rest + after);
for(int i=0; i<before;i++)
inver[i] = fill;
for(int i=0;i<src.size();i++)
inver[offset+i] = src[i];
for(int i=src.size(); i<src.size()+after;i++)
inver[offset+i] = fill;
}
inline T & operator[](const int & n)
{
return inver[n+offset];
@ -167,26 +154,26 @@ private:
};
class CMapHandler
{
enum class EMapCacheType
enum class EMapCacheType : ui8
{
TERRAIN, TERRAIN_CUSTOM, OBJECTS, ROADS, RIVERS, FOW, HEROES, HERO_FLAGS, FRAME
TERRAIN, OBJECTS, ROADS, RIVERS, FOW, HEROES, HERO_FLAGS, FRAME, AFTER_LAST
};
/// temporarily caches rescaled sdl surfaces for map world view redrawing
class CMapCache
{
std::map<EMapCacheType, std::map<intptr_t, SDL_Surface *>> data;
std::array< std::map<intptr_t, SDL_Surface *>, (ui8)EMapCacheType::AFTER_LAST> data;
float worldViewCachedScale;
public:
/// destroys all cached data (frees surfaces)
void discardWorldViewCache();
/// updates scale and determines if currently cached data is still valid
void updateWorldViewScale(float scale);
void removeFromWorldViewCache(EMapCacheType type, intptr_t key);
/// asks for cached data; @returns cached surface or nullptr if data is not in cache
SDL_Surface * requestWorldViewCache(EMapCacheType type, intptr_t key);
/// asks for cached data; @returns cached data if found, new scaled surface otherwise
SDL_Surface * requestWorldViewCacheOrCreate(EMapCacheType type, intptr_t key, SDL_Surface * fullSurface, float scale);
SDL_Surface * requestWorldViewCacheOrCreate(EMapCacheType type, intptr_t key, const IImage * fullSurface, float scale);
SDL_Surface * cacheWorldViewEntry(EMapCacheType type, intptr_t key, SDL_Surface * entry);
intptr_t genKey(intptr_t realPtr, ui8 mod);
};
@ -194,11 +181,11 @@ class CMapHandler
/// helper struct to pass around resolved bitmaps of an object; surfaces can be nullptr if object doesn't have bitmap of that type
struct AnimBitmapHolder
{
SDL_Surface * objBitmap; // main object bitmap
SDL_Surface * flagBitmap; // flag bitmap for the object (probably only for heroes and boats with heroes)
IImage * objBitmap; // main object bitmap
IImage * flagBitmap; // flag bitmap for the object (probably only for heroes and boats with heroes)
bool isMoving; // indicates if the object is moving (again, heroes/boats only)
AnimBitmapHolder(SDL_Surface * objBitmap_ = nullptr, SDL_Surface * flagBitmap_ = nullptr, bool moving = false)
AnimBitmapHolder(IImage * objBitmap_ = nullptr, IImage * flagBitmap_ = nullptr, bool moving = false)
: objBitmap(objBitmap_),
flagBitmap(flagBitmap_),
isMoving(moving)
@ -223,8 +210,7 @@ class CMapHandler
const MapDrawingInfo * info; // data for drawing passed from outside
/// general drawing method, called internally by more specialized ones
virtual void drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect,
SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit = false, ui8 rotationInfo = 0u) const = 0;
virtual void drawElement(EMapCacheType cacheType, const IImage * source, SDL_Rect * sourceRect, SDL_Surface * targetSurf, SDL_Rect * destRect) const = 0;
// first drawing pass
@ -236,8 +222,8 @@ class CMapHandler
virtual void drawRoad(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile * tinfoUpper) const;
/// draws all objects on current tile (higher-level logic, unlike other draw*** methods)
virtual void drawObjects(SDL_Surface * targetSurf, const TerrainTile2 & tile) const;
virtual void drawObject(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving) const;
virtual void drawHeroFlag(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const;
virtual void drawObject(SDL_Surface * targetSurf, const IImage * source, SDL_Rect * sourceRect, bool moving) const;
virtual void drawHeroFlag(SDL_Surface * targetSurf, const IImage * source, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const;
// second drawing pass
@ -262,9 +248,7 @@ class CMapHandler
/// calculates clip region for map viewport
virtual SDL_Rect clip(SDL_Surface * targetSurf) const = 0;
virtual ui8 getHeroFrameNum(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 getHeroFrameGroup(ui8 dir, bool isMoving) const;
virtual ui8 getPhaseShift(const CGObjectInstance *object) const;
virtual bool canDrawObject(const CGObjectInstance * obj) const;
@ -273,11 +257,10 @@ class CMapHandler
// internal helper methods to choose correct bitmap(s) for object; called internally by findObjectBitmap
AnimBitmapHolder findHeroBitmap(const CGHeroInstance * hero, int anim) const;
AnimBitmapHolder findBoatBitmap(const CGBoat * hero, int anim) const;
SDL_Surface * findFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor * color, int indexOffset) const;
SDL_Surface * findHeroFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor * color, int indexOffset) const;
SDL_Surface * findBoatFlagBitmap(const CGBoat * obj, int anim, const PlayerColor * color, int indexOffset, ui8 dir) const;
SDL_Surface * findFlagBitmapInternal(const CDefEssential * def, int anim, int indexOffset, ui8 dir, bool moving) const;
int findAnimIndexByGroup(const CDefEssential * def, int groupNum) const;
IImage * findFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor * color, int group) const;
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;
public:
CMapBlitter(CMapHandler * p) : parent(p) {}
@ -285,15 +268,12 @@ 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
{
protected:
void drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect,
SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit = false, ui8 rotationInfo = 0u) const override;
void drawElement(EMapCacheType cacheType, const IImage * source, SDL_Rect * sourceRect, SDL_Surface * targetSurf, SDL_Rect * destRect) const override;
void drawTileOverlay(SDL_Surface * targetSurf,const TerrainTile2 & tile) const override {}
void init(const MapDrawingInfo * info) override;
SDL_Rect clip(SDL_Surface * targetSurf) const override;
@ -307,22 +287,15 @@ class CMapHandler
private:
IImage * objectToIcon(Obj id, si32 subId, PlayerColor owner) const;
protected:
void drawElement(EMapCacheType cacheType, SDL_Surface * sourceSurf, SDL_Rect * sourceRect,
SDL_Surface * targetSurf, SDL_Rect * destRect, bool alphaBlit = false, ui8 rotationInfo = 0u) const override;
void drawElement(EMapCacheType cacheType, const IImage * source, SDL_Rect * sourceRect, SDL_Surface * targetSurf, SDL_Rect * destRect) const override;
void drawTileOverlay(SDL_Surface * targetSurf, const TerrainTile2 & tile) const override;
void drawHeroFlag(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const override;
void drawObject(SDL_Surface * targetSurf, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving) const override;
void drawHeroFlag(SDL_Surface * targetSurf, const IImage * source, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) const override;
void drawObject(SDL_Surface * targetSurf, const IImage * source, SDL_Rect * sourceRect, bool moving) const override;
void drawFrame(SDL_Surface * targetSurf) const override {}
void drawOverlayEx(SDL_Surface * targetSurf) override;
void init(const MapDrawingInfo * info) override;
SDL_Rect clip(SDL_Surface * targetSurf) const override;
// ui8 getHeroFrameNum(ui8 dir, bool isMoving) const override { return 0u; }
ui8 getPhaseShift(const CGObjectInstance *object) const override { return 0u; }
void drawScaledRotatedElement(EMapCacheType type, SDL_Surface * baseSurf, SDL_Surface * targetSurf, ui8 rotation,
float scale, SDL_Rect * dstRect, SDL_Rect * srcRect = nullptr) const;
void calculateWorldViewCameraPos();
public:
CMapWorldViewBlitter(CMapHandler * parent);
@ -353,6 +326,11 @@ class CMapHandler
CMapBlitter * resolveBlitter(const MapDrawingInfo * info) const;
bool updateObjectsFade();
bool startObjectFade(TerrainTileObject & obj, bool in, int3 pos);
void initObjectRects();
void initBorderGraphics();
void initTerrainGraphics();
void prepareFOWDefs();
public:
PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles; //informations about map tiles
int3 sizes; //map size (x = width, y = height, z = number of levels)
@ -373,13 +351,30 @@ public:
int offsetX;
int offsetY;
//std::set<int> usedHeroes;
//terrain graphics
std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type] [rotation type]
std::vector<CDefEssential *> roadDefs;
std::vector<CDefEssential *> staticRiverDefs;
typedef std::vector<std::array<std::unique_ptr<CAnimation>, 4>> TFlippedAnimations; //[type, rotation]
typedef std::vector<std::vector<std::array<IImage *, 4>>> TFlippedCache;//[type, view type, rotation]
std::vector<std::vector<std::vector<ui8> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
TFlippedAnimations terrainAnimations;//[terrain type, rotation]
TFlippedCache terrainImages;//[terrain type, view type, rotation]
TFlippedAnimations roadAnimations;//[road type, rotation]
TFlippedCache roadImages;//[road type, view type, rotation]
TFlippedAnimations riverAnimations;//[river type, rotation]
TFlippedCache riverImages;//[river type, view type, rotation]
//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;
@ -387,21 +382,12 @@ public:
~CMapHandler(); //d-tor
void getTerrainDescr(const int3 &pos, std::string & out, bool terName); //if tername == false => empty string when tile is clear
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
bool printObject(const CGObjectInstance * obj, bool fadein = false); //puts appropriate things to tiles, so obj will be visible on map
bool hideObject(const CGObjectInstance * obj, bool fadeout = false); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
bool removeObject(CGObjectInstance * obj, bool fadeout = false); //removes object from each place in VCMI (I hope)
void init();
void calculateBlockedPos();
void initObjectRects();
void borderAndTerrainBitmapInit();
void roadsRiverTerrainInit();
void prepareFOWDefs();
EMapAnimRedrawStatus drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info, bool redrawOnlyAnim = false);
void updateWater();
void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
static ui8 getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b]
/// determines if the map is ready to handle new hero movement (not available during fading animations)
bool canStartHeroMovement();

View File

@ -8,7 +8,6 @@
#include "../CGameInfo.h"
#include "../CMusicHandler.h"
#include "../CDefHandler.h"
#include "../CPlayerInterface.h"
#include "../CPreGame.h"
#include "../Graphics.h"

View File

@ -107,7 +107,7 @@ void CMultiLineLabel::setText(const std::string &Txt)
void CTextContainer::blitLine(SDL_Surface *to, Rect destRect, std::string what)
{
const IFont * f = graphics->fonts[font];
const auto f = graphics->fonts[font];
Point where = destRect.topLeft();
// input is rect in which given text should be placed
@ -164,7 +164,7 @@ void CMultiLineLabel::showAll(SDL_Surface * to)
{
CIntObject::showAll(to);
const IFont * f = graphics->fonts[font];
const auto f = graphics->fonts[font];
// calculate which lines should be visible
int totalLines = lines.size();
@ -201,7 +201,7 @@ void CMultiLineLabel::splitText(const std::string &Txt)
{
lines.clear();
const IFont * f = graphics->fonts[font];
const auto f = graphics->fonts[font];
int lineHeight = f->getLineHeight();
lines = CMessage::breakText(Txt, pos.w, font);
@ -427,7 +427,7 @@ CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf)
void CTextInput::focusGot()
{
CSDL_Ext::startTextInput(&pos);
CSDL_Ext::startTextInput(&pos);
}
void CTextInput::focusLost()
@ -461,7 +461,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
}
bool redrawNeeded = false;
switch(key.keysym.sym)
{
case SDLK_DELETE: // have index > ' ' so it won't be filtered out by default section
@ -476,7 +476,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
{
Unicode::trimRight(text);
redrawNeeded = true;
}
}
break;
default:
break;
@ -486,7 +486,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
{
redraw();
cb(text);
}
}
}
void CTextInput::setText( const std::string &nText, bool callCb )
@ -500,7 +500,7 @@ bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key)
{
if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER || key.keysym.sym == SDLK_ESCAPE)
return false;
return true;
}
@ -509,15 +509,15 @@ void CTextInput::textInputed(const SDL_TextInputEvent & event)
if(!focus)
return;
std::string oldText = text;
text += event.text;
text += event.text;
filters(text,oldText);
if (text != oldText)
{
redraw();
cb(text);
}
}
newText = "";
}
@ -525,10 +525,10 @@ void CTextInput::textEdited(const SDL_TextEditingEvent & event)
{
if(!focus)
return;
newText = event.text;
redraw();
cb(text+newText);
cb(text+newText);
}
void CTextInput::filenameFilter(std::string & text, const std::string &)
@ -586,7 +586,7 @@ CFocusable::~CFocusable()
{
focusLost();
inputWithFocus = nullptr;
}
}
focusables -= this;
}
@ -602,7 +602,7 @@ void CFocusable::giveFocus()
focus = true;
inputWithFocus = this;
focusGot();
redraw();
redraw();
}
void CFocusable::moveFocus()

View File

@ -9,7 +9,6 @@
#include "CTradeWindow.h"
#include "../CBitmapHandler.h"
#include "../CDefHandler.h"
#include "../CGameInfo.h"
#include "../CMessage.h"
#include "../CMusicHandler.h"

View File

@ -457,12 +457,6 @@ std::vector < const CGObjectInstance * > CGameInfoCallback::getFlaggableObjects(
for(const CGObjectInstance *obj : t->blockingObjects)
if(obj->tempOwner != PlayerColor::UNFLAGGABLE)
ret.push_back(obj);
// const std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & objs = CGI->mh->ttiles[pos.x][pos.y][pos.z].objects;
// for(size_t b=0; b<objs.size(); ++b)
// {
// if(objs[b].first->tempOwner!=254 && !((objs[b].first->defInfo->blockMap[pos.y - objs[b].first->pos.y + 5] >> (objs[b].first->pos.x - pos.x)) & 1))
// ret.push_back(CGI->mh->ttiles[pos.x][pos.y][pos.z].objects[b].first);
// }
return ret;
}