AlexVinS 9 years ago
parent
commit
46196daa07
6 changed files with 35 additions and 130 deletions
  1. 3 4
      client/Graphics.cpp
  2. 1 3
      client/Graphics.h
  3. 12 86
      client/mapHandler.cpp
  4. 3 15
      client/mapHandler.h
  5. 16 16
      client/widgets/TextControls.cpp
  6. 0 6
      lib/CGameInfoCallback.cpp

+ 3 - 4
client/Graphics.cpp

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

+ 1 - 3
client/Graphics.h

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

+ 12 - 86
client/mapHandler.cpp

@@ -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);
-	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)
 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);
-	if (iter != data[type].end())
+	auto iter = data[(ui8)type].find(key);
+	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);
-	if (iter == data[type].end())
+	auto iter = data[(ui8)type].find(key);
+	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;
 }
 }
 
 

+ 3 - 15
client/mapHandler.h

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

+ 16 - 16
client/widgets/TextControls.cpp

@@ -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);
@@ -427,7 +427,7 @@ CTextInput::CTextInput(const Rect &Pos, SDL_Surface *srf)
 
 
 void CTextInput::focusGot()
 void CTextInput::focusGot()
 {
 {
-	CSDL_Ext::startTextInput(&pos);	
+	CSDL_Ext::startTextInput(&pos);
 }
 }
 
 
 void CTextInput::focusLost()
 void CTextInput::focusLost()
@@ -461,7 +461,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
 	}
 	}
 
 
 	bool redrawNeeded = false;
 	bool redrawNeeded = false;
-	
+
 	switch(key.keysym.sym)
 	switch(key.keysym.sym)
 	{
 	{
 	case SDLK_DELETE: // have index > ' ' so it won't be filtered out by default section
 	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);
 			Unicode::trimRight(text);
 			redrawNeeded = true;
 			redrawNeeded = true;
-		}			
+		}
 		break;
 		break;
 	default:
 	default:
 		break;
 		break;
@@ -486,7 +486,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
 	{
 	{
 		redraw();
 		redraw();
 		cb(text);
 		cb(text);
-	}	
+	}
 }
 }
 
 
 void CTextInput::setText( const std::string &nText, bool callCb )
 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)
 	if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER || key.keysym.sym == SDLK_ESCAPE)
 		return false;
 		return false;
-	
+
 	return true;
 	return true;
 }
 }
 
 
@@ -509,15 +509,15 @@ void CTextInput::textInputed(const SDL_TextInputEvent & event)
 	if(!focus)
 	if(!focus)
 		return;
 		return;
 	std::string oldText = text;
 	std::string oldText = text;
-	
-	text += event.text;	
-	
+
+	text += event.text;
+
 	filters(text,oldText);
 	filters(text,oldText);
 	if (text != oldText)
 	if (text != oldText)
 	{
 	{
 		redraw();
 		redraw();
 		cb(text);
 		cb(text);
-	}	
+	}
 	newText = "";
 	newText = "";
 }
 }
 
 
@@ -525,10 +525,10 @@ void CTextInput::textEdited(const SDL_TextEditingEvent & event)
 {
 {
 	if(!focus)
 	if(!focus)
 		return;
 		return;
-		
+
 	newText = event.text;
 	newText = event.text;
 	redraw();
 	redraw();
-	cb(text+newText);	
+	cb(text+newText);
 }
 }
 
 
 void CTextInput::filenameFilter(std::string & text, const std::string &)
 void CTextInput::filenameFilter(std::string & text, const std::string &)
@@ -586,7 +586,7 @@ CFocusable::~CFocusable()
 	{
 	{
 		focusLost();
 		focusLost();
 		inputWithFocus = nullptr;
 		inputWithFocus = nullptr;
-	}	
+	}
 
 
 	focusables -= this;
 	focusables -= this;
 }
 }
@@ -602,7 +602,7 @@ void CFocusable::giveFocus()
 	focus = true;
 	focus = true;
 	inputWithFocus = this;
 	inputWithFocus = this;
 	focusGot();
 	focusGot();
-	redraw();	
+	redraw();
 }
 }
 
 
 void CFocusable::moveFocus()
 void CFocusable::moveFocus()

+ 0 - 6
lib/CGameInfoCallback.cpp

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