Browse Source

World view mode drawing: refactoring, part 1 (merged main drawing method);

Fay 10 years ago
parent
commit
97d89d1d6c
4 changed files with 600 additions and 682 deletions
  1. 466 661
      client/mapHandler.cpp
  2. 115 6
      client/mapHandler.h
  3. 14 11
      client/windows/CAdvmapInterface.cpp
  4. 5 4
      client/windows/GUIClasses.cpp

File diff suppressed because it is too large
+ 466 - 661
client/mapHandler.cpp


+ 115 - 6
client/mapHandler.h

@@ -57,6 +57,43 @@ struct TerrainTile2
 	TerrainTile2();
 };
 
+struct MapDrawingInfo
+{
+	bool scaled;
+	int3 &topTile; // top-left tile in viewport [in tiles]
+	const std::vector< std::vector< std::vector<ui8> > > * visibilityMap;
+	SDL_Rect * drawBounds; // map rect drawing bounds on screen
+	CDefHandler * iconsDef; // holds overlay icons for world view mode
+	float scale; // map scale for world view mode (only if scaled == true)
+
+	bool otherheroAnim;
+	ui8 anim;
+	ui8 heroAnim;
+
+	int3 movement; // used for smooth map movement
+
+	bool puzzleMode;
+	int3 grailPos; // location of grail for puzzle mode [in tiles]
+
+	MapDrawingInfo(int3 &topTile_, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap_, SDL_Rect * drawBounds_, CDefHandler * iconsDef_ = nullptr)
+		: scaled(false),
+		  topTile(topTile_),
+		  visibilityMap(visibilityMap_),
+		  drawBounds(drawBounds_),
+		  iconsDef(iconsDef_),
+		  scale(1.0f),
+		  otherheroAnim(false),
+		  anim(0u),
+		  heroAnim(0u),
+		  movement(int3()),
+		  puzzleMode(false),
+		  grailPos(int3())
+	{}
+
+	ui8 getHeroAnim() const { return otherheroAnim ? anim : heroAnim; }
+};
+
+
 template <typename T> class PseudoV
 {
 public:
@@ -93,7 +130,6 @@ private:
 	int offset;
 	std::vector<T> inver;
 };
-
 class CMapHandler
 {
 	enum class EMapCacheType
@@ -120,11 +156,85 @@ class CMapHandler
 		intptr_t genKey(intptr_t realPtr, ui8 mod);
 	};
 
+
+	class CMapBlitter
+	{
+	protected:
+		CMapHandler * parent;
+		int tileSize;
+		int3 tileCount;
+		int3 topTile;
+		int3 initPos;
+		int3 pos;
+		int3 realPos;
+
+		virtual void drawTileOverlay(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile2 & tile) = 0;
+		virtual void drawNormalObject(SDL_Surface * targetSurf, const MapDrawingInfo * info, SDL_Surface * sourceSurf, SDL_Rect * sourceRect) = 0;
+		virtual void drawHeroFlag(SDL_Surface * targetSurf, const MapDrawingInfo * info, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving) = 0;
+		virtual void drawHero(SDL_Surface * targetSurf, const MapDrawingInfo * info, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving) = 0;
+		void drawObjects(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile2 & tile);
+		virtual void drawRoad(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile & tinfo, const TerrainTile * tinfoUpper) = 0;
+		virtual void drawRiver(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile & tinfo) = 0;
+		virtual void drawFow(SDL_Surface * targetSurf, const MapDrawingInfo * info) = 0;
+		virtual void drawFrame(SDL_Surface * targetSurf, const MapDrawingInfo * info) = 0;
+		virtual void drawTileTerrain(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile & tinfo, const TerrainTile2 & tile) = 0;
+		virtual void init(const MapDrawingInfo * info) = 0;
+		virtual SDL_Rect clip(SDL_Surface * targetSurf, const MapDrawingInfo * info) = 0;
+	public:
+		CMapBlitter(CMapHandler * p) : parent(p) {}
+		virtual ~CMapBlitter(){}
+		void blit(SDL_Surface * targetSurf, const MapDrawingInfo * const info);
+	};
+
+	class CMapNormalBlitter : public CMapBlitter
+	{
+	protected:
+		void drawTileOverlay(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile2 & tile) {}
+		void drawNormalObject(SDL_Surface * targetSurf, const MapDrawingInfo * info, SDL_Surface * sourceSurf, SDL_Rect * sourceRect);
+		void drawHeroFlag(SDL_Surface * targetSurf, const MapDrawingInfo * info, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving);
+		void drawHero(SDL_Surface * targetSurf, const MapDrawingInfo * info, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving);
+		void drawRoad(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile & tinfo, const TerrainTile * tinfoUpper);
+		void drawRiver(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile & tinfo);
+		void drawFow(SDL_Surface * targetSurf, const MapDrawingInfo * info);
+		void drawFrame(SDL_Surface * targetSurf, const MapDrawingInfo * info);
+		void drawTileTerrain(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile & tinfo, const TerrainTile2 & tile);
+		void init(const MapDrawingInfo * info);
+		SDL_Rect clip(SDL_Surface * targetSurf, const MapDrawingInfo * info) override;
+	public:
+		CMapNormalBlitter(CMapHandler * parent);
+		virtual ~CMapNormalBlitter(){}
+	};
+
+	class CMapWorldViewBlitter : public CMapBlitter
+	{
+	protected:
+		int halfTargetTileSizeHigh;
+
+		void drawTileOverlay(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile2 & tile);
+		void drawNormalObject(SDL_Surface * targetSurf, const MapDrawingInfo * info, SDL_Surface * sourceSurf, SDL_Rect * sourceRect);
+		void drawHeroFlag(SDL_Surface * targetSurf, const MapDrawingInfo * info, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, SDL_Rect * destRect, bool moving);
+		void drawHero(SDL_Surface * targetSurf, const MapDrawingInfo * info, SDL_Surface * sourceSurf, SDL_Rect * sourceRect, bool moving);
+		void drawRoad(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile & tinfo, const TerrainTile * tinfoUpper);
+		void drawRiver(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile & tinfo);
+		void drawFow(SDL_Surface * targetSurf, const MapDrawingInfo * info);
+		void drawFrame(SDL_Surface * targetSurf, const MapDrawingInfo * info) {}
+		void drawTileTerrain(SDL_Surface * targetSurf, const MapDrawingInfo * info, const TerrainTile & tinfo, const TerrainTile2 & tile);
+		void init(const MapDrawingInfo * info);
+		SDL_Rect clip(SDL_Surface * targetSurf, const MapDrawingInfo * info) override;
+	public:
+		CMapWorldViewBlitter(CMapHandler * parent);
+		virtual ~CMapWorldViewBlitter(){}
+	};
+
+//	class CPuzzleViewBlitter : public CMapNormalBlitter
+//	{
+//		void drawFow(SDL_Surface * targetSurf, const MapDrawingInfo * info) {} // skipping FoW in puzzle view
+//	};
+
 	CMapCache cache;
+	CMapBlitter * normalBlitter;
+	CMapBlitter * worldViewBlitter;
 
-	void drawWorldViewOverlay(int targetTilesX, int targetTilesY, int srx_init, int sry_init, CDefHandler * iconsDef,
-							  const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, float scale,
-							  int targetTileSize, int3 top_tile, SDL_Surface * extSurf);
 	void drawScaledRotatedElement(EMapCacheType type, SDL_Surface * baseSurf, SDL_Surface * targetSurf, ui8 rotation,
 								  float scale, SDL_Rect * dstRect, SDL_Rect * srcRect = nullptr);
 	void calculateWorldViewCameraPos(int targetTilesX, int targetTilesY, int3 &top_tile);
@@ -176,8 +286,7 @@ public:
 	void roadsRiverTerrainInit();
 	void prepareFOWDefs();
 
-	void terrainRect(int3 top_tile, ui8 anim, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, bool otherHeroAnim, ui8 heroAnim, SDL_Surface * extSurf, const SDL_Rect * extRect, int moveX, int moveY, bool puzzleMode, int3 grailPosRel) const;
-	void terrainRectScaled(int3 top_tile, const std::vector< std::vector< std::vector<ui8> > > * visibilityMap, SDL_Surface * extSurf, const SDL_Rect * extRect, float scale, CDefHandler * iconsDef);
+	void drawTerrainRectNew(SDL_Surface * targetSurface, const MapDrawingInfo * info);
 	void updateWater();
 	ui8 getHeroFrameNum(ui8 dir, bool isMoving) const; //terrainRect helper function
 	void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper

+ 14 - 11
client/windows/CAdvmapInterface.cpp

@@ -266,16 +266,14 @@ void CTerrainRect::show(SDL_Surface * to)
 {
 	if (adventureInt->mode == EAdvMapMode::NORMAL)
 	{
+		MapDrawingInfo info(adventureInt->position, &LOCPLINT->cb->getVisibilityMap(), &pos);
+		info.otherheroAnim = true;
+		info.anim = adventureInt->anim;
+		info.heroAnim = adventureInt->heroAnim;
 		if (ADVOPT.smoothMove)
-			CGI->mh->terrainRect
-				(adventureInt->position, adventureInt->anim,
-					&LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
-					to, &pos, moveX, moveY, false, int3());
-		else
-			CGI->mh->terrainRect
-				(adventureInt->position, adventureInt->anim,
-					&LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
-					to, &pos, 0, 0, false, int3());
+			info.movement = int3(moveX, moveY, 0);
+
+		CGI->mh->drawTerrainRectNew(to, &info);
 
 		if (currentPath/* && adventureInt->position.z==currentPath->startPos().z*/) //drawing path
 		{
@@ -291,8 +289,13 @@ void CTerrainRect::showAll(SDL_Surface * to)
 {
 	// world view map is static and doesn't need redraw every frame
 	if (adventureInt->mode == EAdvMapMode::WORLD_VIEW)
-		CGI->mh->terrainRectScaled (adventureInt->position, &LOCPLINT->cb->getVisibilityMap(),
-									to, &pos, adventureInt->worldViewScale, adventureInt->worldViewIconsDef);
+	{
+		MapDrawingInfo info(adventureInt->position, &LOCPLINT->cb->getVisibilityMap(), &pos, adventureInt->worldViewIconsDef);
+		info.scaled = true;
+		info.scale = adventureInt->worldViewScale;
+
+		CGI->mh->drawTerrainRectNew(to, &info);
+	}
 }
 
 int3 CTerrainRect::whichTileIsIt(const int & x, const int & y)

+ 5 - 4
client/windows/GUIClasses.cpp

@@ -1099,11 +1099,12 @@ void CPuzzleWindow::showAll(SDL_Surface * to)
 {
 	int3 moveInt = int3(8, 9, 0);
 	Rect mapRect = genRect(544, 591, pos.x + 8, pos.y + 7);
+	int3 topTile = grailPos - moveInt;
 
-	CGI->mh->terrainRect
-		(grailPos - moveInt, adventureInt->anim,
-		 &LOCPLINT->cb->getVisibilityMap(), true, adventureInt->heroAnim,
-		 to, &mapRect, 0, 0, true, moveInt);
+	MapDrawingInfo info(topTile, &LOCPLINT->cb->getVisibilityMap(), &mapRect);
+	info.puzzleMode = true;
+	info.grailPos = grailPos;
+	CGI->mh->drawTerrainRectNew(to, &info);
 
 	CWindowObject::showAll(to);
 }

Some files were not shown because too many files changed in this diff