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/CBinaryReader.h"
#include "CDefHandler.h"
#include "gui/SDL_Extensions.h"
#include "gui/CAnimation.h"
#include <SDL_ttf.h>
@ -335,11 +334,11 @@ 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);
}
}

View File

@ -1,6 +1,5 @@
#pragma once
#include "gui/Fonts.h"
#include "../lib/GameConstants.h"
#include "gui/Geometries.h"
@ -18,7 +17,6 @@
struct SDL_Surface;
class CGHeroInstance;
class CGTownInstance;
class CDefHandler;
class CHeroClass;
struct SDL_Color;
struct InfoAboutHero;
@ -57,7 +55,7 @@ class Graphics
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]

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
{
Rect destRect(realTileRect);
if(tile.terbitmap) //if custom terrain graphic - use it
drawElement(EMapCacheType::TERRAIN_CUSTOM, tile.terbitmap, nullptr, targetSurf, &destRect);
else //use default terrain graphic
drawElement(EMapCacheType::TERRAIN, parent->terrainGraphics[tinfo.terType][tinfo.terView],
nullptr, targetSurf, &destRect, false, tinfo.extTileFlags % 4);
drawElement(EMapCacheType::TERRAIN, parent->terrainGraphics[tinfo.terType][tinfo.terView], nullptr, targetSurf, &destRect, false, tinfo.extTileFlags % 4);
}
void CMapHandler::CMapWorldViewBlitter::init(const MapDrawingInfo * drawingInfo)
@ -1377,77 +1374,6 @@ bool CMapHandler::removeObject(CGObjectInstance *obj, bool fadeout /* = false */
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()
{
return fadeAnims.empty(); // don't allow movement during fade animation
@ -1561,16 +1487,16 @@ void CMapHandler::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)
{
SDL_FreeSurface(cacheEntryPair.second);
}
}
data[cacheDataPair.first].clear();
cache.clear();
}
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)
{
auto iter = data[type].find(key);
if (iter != data[type].end())
auto iter = data[(ui8)type].find(key);
if (iter != data[(ui8)type].end())
{
SDL_FreeSurface((*iter).second);
data[type].erase(iter);
data[(ui8)type].erase(iter);
}
}
SDL_Surface * CMapHandler::CMapCache::requestWorldViewCache(CMapHandler::EMapCacheType type, intptr_t key)
{
auto iter = data[type].find(key);
if (iter == data[type].end())
auto iter = data[(ui8)type].find(key);
if (iter == data[(ui8)type].end())
return nullptr;
return (*iter).second;
}
@ -1620,7 +1546,7 @@ SDL_Surface * CMapHandler::CMapCache::requestWorldViewCacheOrCreate(CMapHandler:
auto scaled = fullSurface->scaleFast(scale);
data[type][key] = scaled;
data[(ui8)type][key] = 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
return requestWorldViewCache(type, key);
data[type][key] = entry;
data[(ui8)type][key] = entry;
return entry;
}

View File

@ -133,16 +133,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,15 +157,15 @@ 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)
@ -405,8 +395,6 @@ public:
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

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

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