1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00
This commit is contained in:
AlexVinS 2016-11-06 02:04:54 +03:00
parent 6a272d8f0c
commit 46196daa07
6 changed files with 35 additions and 130 deletions

View File

@ -3,7 +3,6 @@
#include "../lib/filesystem/Filesystem.h" #include "../lib/filesystem/Filesystem.h"
#include "../lib/filesystem/CBinaryReader.h" #include "../lib/filesystem/CBinaryReader.h"
#include "CDefHandler.h"
#include "gui/SDL_Extensions.h" #include "gui/SDL_Extensions.h"
#include "gui/CAnimation.h" #include "gui/CAnimation.h"
#include <SDL_ttf.h> #include <SDL_ttf.h>
@ -335,11 +334,11 @@ void Graphics::loadFonts()
std::string filename = bmpConf[i].String(); std::string filename = bmpConf[i].String();
if (!hanConf[filename].isNull()) 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 else if (!ttfConf[filename].isNull()) // no ttf override
fonts[i] = new CTrueTypeFont(ttfConf[filename]); fonts[i] = std::make_shared<CTrueTypeFont>(ttfConf[filename]);
else else
fonts[i] = new CBitmapFont(filename); fonts[i] = std::make_shared<CBitmapFont>(filename);
} }
} }

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "gui/Fonts.h" #include "gui/Fonts.h"
#include "../lib/GameConstants.h" #include "../lib/GameConstants.h"
#include "gui/Geometries.h" #include "gui/Geometries.h"
@ -18,7 +17,6 @@
struct SDL_Surface; struct SDL_Surface;
class CGHeroInstance; class CGHeroInstance;
class CGTownInstance; class CGTownInstance;
class CDefHandler;
class CHeroClass; class CHeroClass;
struct SDL_Color; struct SDL_Color;
struct InfoAboutHero; struct InfoAboutHero;
@ -57,7 +55,7 @@ class Graphics
public: public:
//Fonts //Fonts
static const int FONTS_NUMBER = 9; static const int FONTS_NUMBER = 9;
IFont * fonts[FONTS_NUMBER]; std::array< std::shared_ptr<IFont>, FONTS_NUMBER> fonts;
//various graphics //various graphics
SDL_Color * playerColors; //array [8] SDL_Color * playerColors; //array [8]

View File

@ -703,11 +703,8 @@ void CMapHandler::CMapWorldViewBlitter::drawObject(SDL_Surface * targetSurf, con
void CMapHandler::CMapBlitter::drawTileTerrain(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile2 & tile) const void CMapHandler::CMapBlitter::drawTileTerrain(SDL_Surface * targetSurf, const TerrainTile & tinfo, const TerrainTile2 & tile) const
{ {
Rect destRect(realTileRect); Rect destRect(realTileRect);
if(tile.terbitmap) //if custom terrain graphic - use it
drawElement(EMapCacheType::TERRAIN_CUSTOM, tile.terbitmap, nullptr, targetSurf, &destRect); drawElement(EMapCacheType::TERRAIN, parent->terrainGraphics[tinfo.terType][tinfo.terView], nullptr, targetSurf, &destRect, false, tinfo.extTileFlags % 4);
else //use default terrain graphic
drawElement(EMapCacheType::TERRAIN, parent->terrainGraphics[tinfo.terType][tinfo.terView],
nullptr, targetSurf, &destRect, false, tinfo.extTileFlags % 4);
} }
void CMapHandler::CMapWorldViewBlitter::init(const MapDrawingInfo * drawingInfo) void CMapHandler::CMapWorldViewBlitter::init(const MapDrawingInfo * drawingInfo)
@ -1377,77 +1374,6 @@ bool CMapHandler::removeObject(CGObjectInstance *obj, bool fadeout /* = false */
return true; return true;
} }
void CMapHandler::validateRectTerr(SDL_Rect * val, const SDL_Rect * ext)
{
if(ext)
{
if(val->x<0)
{
val->w += val->x;
val->x = ext->x;
}
else
{
val->x += ext->x;
}
if(val->y<0)
{
val->h += val->y;
val->y = ext->y;
}
else
{
val->y += ext->y;
}
if(val->x+val->w > ext->x+ext->w)
{
val->w = ext->x+ext->w-val->x;
}
if(val->y+val->h > ext->y+ext->h)
{
val->h = ext->y+ext->h-val->y;
}
//for sign problems
if(val->h > 20000 || val->w > 20000)
{
val->h = val->w = 0;
}
}
}
ui8 CMapHandler::getDir(const int3 &a, const int3 &b)
{
if(a.z!=b.z)
return -1; //error!
if(a.x==b.x+1 && a.y==b.y+1) //lt
return 0;
else if(a.x==b.x && a.y==b.y+1) //t
return 1;
else if(a.x==b.x-1 && a.y==b.y+1) //rt
return 2;
else if(a.x==b.x-1 && a.y==b.y) //r
return 3;
else if(a.x==b.x-1 && a.y==b.y-1) //rb
return 4;
else if(a.x==b.x && a.y==b.y-1) //b
return 5;
else if(a.x==b.x+1 && a.y==b.y-1) //lb
return 6;
else if(a.x==b.x+1 && a.y==b.y) //l
return 7;
return -2; //shouldn't happen
}
bool CMapHandler::canStartHeroMovement() bool CMapHandler::canStartHeroMovement()
{ {
return fadeAnims.empty(); // don't allow movement during fade animation return fadeAnims.empty(); // don't allow movement during fade animation
@ -1561,16 +1487,16 @@ void CMapHandler::discardWorldViewCache()
void CMapHandler::CMapCache::discardWorldViewCache() void CMapHandler::CMapCache::discardWorldViewCache()
{ {
for (auto &cacheDataPair : data) for (auto & cache : data)
{ {
for (auto &cacheEntryPair : cacheDataPair.second) for (auto &cacheEntryPair : cache)
{ {
if (cacheEntryPair.second) if (cacheEntryPair.second)
{ {
SDL_FreeSurface(cacheEntryPair.second); SDL_FreeSurface(cacheEntryPair.second);
} }
} }
data[cacheDataPair.first].clear(); cache.clear();
} }
logGlobal->debugStream() << "Discarded world view cache"; logGlobal->debugStream() << "Discarded world view cache";
} }
@ -1584,18 +1510,18 @@ void CMapHandler::CMapCache::updateWorldViewScale(float scale)
void CMapHandler::CMapCache::removeFromWorldViewCache(CMapHandler::EMapCacheType type, intptr_t key) void CMapHandler::CMapCache::removeFromWorldViewCache(CMapHandler::EMapCacheType type, intptr_t key)
{ {
auto iter = data[type].find(key); auto iter = data[(ui8)type].find(key);
if (iter != data[type].end()) if (iter != data[(ui8)type].end())
{ {
SDL_FreeSurface((*iter).second); SDL_FreeSurface((*iter).second);
data[type].erase(iter); data[(ui8)type].erase(iter);
} }
} }
SDL_Surface * CMapHandler::CMapCache::requestWorldViewCache(CMapHandler::EMapCacheType type, intptr_t key) SDL_Surface * CMapHandler::CMapCache::requestWorldViewCache(CMapHandler::EMapCacheType type, intptr_t key)
{ {
auto iter = data[type].find(key); auto iter = data[(ui8)type].find(key);
if (iter == data[type].end()) if (iter == data[(ui8)type].end())
return nullptr; return nullptr;
return (*iter).second; return (*iter).second;
} }
@ -1620,7 +1546,7 @@ SDL_Surface * CMapHandler::CMapCache::requestWorldViewCacheOrCreate(CMapHandler:
auto scaled = fullSurface->scaleFast(scale); auto scaled = fullSurface->scaleFast(scale);
data[type][key] = scaled; data[(ui8)type][key] = scaled;
return scaled; return scaled;
} }
@ -1632,7 +1558,7 @@ SDL_Surface *CMapHandler::CMapCache::cacheWorldViewEntry(CMapHandler::EMapCacheT
if (requestWorldViewCache(type, key)) // valid cache already present, no need to do it again if (requestWorldViewCache(type, key)) // valid cache already present, no need to do it again
return requestWorldViewCache(type, key); return requestWorldViewCache(type, key);
data[type][key] = entry; data[(ui8)type][key] = entry;
return entry; return entry;
} }

View File

@ -133,16 +133,6 @@ template <typename T> class PseudoV
{ {
public: public:
PseudoV() : offset(0) { } 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) inline T & operator[](const int & n)
{ {
return inver[n+offset]; return inver[n+offset];
@ -167,15 +157,15 @@ private:
}; };
class CMapHandler 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 /// temporarily caches rescaled sdl surfaces for map world view redrawing
class CMapCache 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; float worldViewCachedScale;
public: public:
/// destroys all cached data (frees surfaces) /// destroys all cached data (frees surfaces)
@ -405,8 +395,6 @@ public:
EMapAnimRedrawStatus drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info, bool redrawOnlyAnim = false); EMapAnimRedrawStatus drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info, bool redrawOnlyAnim = false);
void updateWater(); 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) /// determines if the map is ready to handle new hero movement (not available during fading animations)
bool canStartHeroMovement(); bool canStartHeroMovement();

View File

@ -107,7 +107,7 @@ void CMultiLineLabel::setText(const std::string &Txt)
void CTextContainer::blitLine(SDL_Surface *to, Rect destRect, std::string what) 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(); Point where = destRect.topLeft();
// input is rect in which given text should be placed // input is rect in which given text should be placed
@ -164,7 +164,7 @@ void CMultiLineLabel::showAll(SDL_Surface * to)
{ {
CIntObject::showAll(to); CIntObject::showAll(to);
const IFont * f = graphics->fonts[font]; const auto f = graphics->fonts[font];
// calculate which lines should be visible // calculate which lines should be visible
int totalLines = lines.size(); int totalLines = lines.size();
@ -201,7 +201,7 @@ void CMultiLineLabel::splitText(const std::string &Txt)
{ {
lines.clear(); lines.clear();
const IFont * f = graphics->fonts[font]; const auto f = graphics->fonts[font];
int lineHeight = f->getLineHeight(); int lineHeight = f->getLineHeight();
lines = CMessage::breakText(Txt, pos.w, font); lines = CMessage::breakText(Txt, pos.w, font);

View File

@ -457,12 +457,6 @@ std::vector < const CGObjectInstance * > CGameInfoCallback::getFlaggableObjects(
for(const CGObjectInstance *obj : t->blockingObjects) for(const CGObjectInstance *obj : t->blockingObjects)
if(obj->tempOwner != PlayerColor::UNFLAGGABLE) if(obj->tempOwner != PlayerColor::UNFLAGGABLE)
ret.push_back(obj); 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; return ret;
} }