Răsfoiți Sursa

* memory usage significantly decreased (now it's about half of what was before ;])
* load time significantly decreased also (now it's almost like in OH3)
* TODO: make extensively used CSDL_Ext::blit8bppAlphaTo24bpp faster - it slows down VCMI too significantly, but I'm sure it can be as fast as the code from SDL and anyway those speed-ups and memory usage decrease were worth it ;]

mateuszb 17 ani în urmă
părinte
comite
f0e2f1d205
9 a modificat fișierele cu 219 adăugiri și 263 ștergeri
  1. 15 9
      CAdvmapInterface.cpp
  2. 13 8
      CMT.cpp
  3. 36 36
      CPlayerInterface.cpp
  4. 109 86
      SDL_Extensions.cpp
  5. 2 2
      SDL_Extensions.h
  6. 3 3
      hch/CAmbarCendamo.cpp
  7. 1 1
      hch/CHeroHandler.cpp
  8. 39 117
      mapHandler.cpp
  9. 1 1
      mapHandler.h

+ 15 - 9
CAdvmapInterface.cpp

@@ -238,7 +238,7 @@ CTerrainRect::CTerrainRect():currentPath(NULL)
 	arrows = CGI->spriteh->giveDef("ADAG.DEF");
 	for(int y=0; y<arrows->ourImages.size(); ++y)
 	{
-		CSDL_Ext::fullAlphaTransform(arrows->ourImages[y].bitmap);
+		arrows->ourImages[y].bitmap = CSDL_Ext::alphaTransform(arrows->ourImages[y].bitmap);
 	}
 }
 void CTerrainRect::activate()
@@ -516,21 +516,27 @@ void CTerrainRect::showPath()
 			int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
 				hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
 			if (hvx<0 && hvy<0)
-				blitAt(arrows->ourImages[pn].bitmap,x,y);
+			{
+				CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, NULL, ekran, &genRect(32, 32, x, y));
+			}
 			else if(hvx<0)
-				SDL_BlitSurface
-				(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
-				ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
+			{
+				CSDL_Ext::blit8bppAlphaTo24bpp
+					(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,0,0),
+					ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w,x,y));
+			}
 			else if (hvy<0)
 			{
-				SDL_BlitSurface
+				CSDL_Ext::blit8bppAlphaTo24bpp
 					(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,0,0),
 					ekran,&genRect(arrows->ourImages[pn].bitmap->h,arrows->ourImages[pn].bitmap->w-hvx,x,y));
 			}
 			else
-				SDL_BlitSurface
-				(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
-				ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
+			{
+				CSDL_Ext::blit8bppAlphaTo24bpp
+					(arrows->ourImages[pn].bitmap,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,0,0),
+					ekran,&genRect(arrows->ourImages[pn].bitmap->h-hvy,arrows->ourImages[pn].bitmap->w-hvx,x,y));
+			}
 
 		}
 	} //for (int i=0;i<currentPath->nodes.size()-1;i++)

+ 13 - 8
CMT.cpp

@@ -485,9 +485,9 @@ int _tmain(int argc, _TCHAR* argv[])
 				}
 			}
 
-			for(int ff=80; ff<cgi->heroh->flags1[q]->ourImages.size(); ++ff)
+			for(int ff=0; ff<cgi->heroh->flags1[q]->ourImages.size(); ++ff)
 			{
-				CSDL_Ext::fullAlphaTransform(cgi->heroh->flags1[q]->ourImages[ff].bitmap);
+				CSDL_Ext::alphaTransform(cgi->heroh->flags1[q]->ourImages[ff].bitmap);
 			}
 			cgi->heroh->flags1[q]->alphaTransformed = true;
 		}
@@ -543,9 +543,9 @@ int _tmain(int argc, _TCHAR* argv[])
 				}
 			}
 
-			for(int ff=80; ff<cgi->heroh->flags2[q]->ourImages.size(); ++ff)
+			for(int ff=0; ff<cgi->heroh->flags2[q]->ourImages.size(); ++ff)
 			{
-				CSDL_Ext::fullAlphaTransform(cgi->heroh->flags2[q]->ourImages[ff].bitmap);
+				CSDL_Ext::alphaTransform(cgi->heroh->flags2[q]->ourImages[ff].bitmap);
 			}
 			cgi->heroh->flags2[q]->alphaTransformed = true;
 		}
@@ -601,9 +601,9 @@ int _tmain(int argc, _TCHAR* argv[])
 				}
 			}
 
-			for(int ff=80; ff<cgi->heroh->flags3[q]->ourImages.size(); ++ff)
+			for(int ff=0; ff<cgi->heroh->flags3[q]->ourImages.size(); ++ff)
 			{
-				CSDL_Ext::fullAlphaTransform(cgi->heroh->flags3[q]->ourImages[ff].bitmap);
+				CSDL_Ext::alphaTransform(cgi->heroh->flags3[q]->ourImages[ff].bitmap);
 			}
 			cgi->heroh->flags3[q]->alphaTransformed = true;
 		}
@@ -639,6 +639,7 @@ int _tmain(int argc, _TCHAR* argv[])
 					{
 						Cimage nci;
 						nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
+						nci.groupNumber = 10;
 						nci.groupNumber = 11;
 						nci.imName = std::string();
 						cgi->heroh->flags4[q]->ourImages.push_back(nci);
@@ -651,6 +652,7 @@ int _tmain(int argc, _TCHAR* argv[])
 					{
 						Cimage nci;
 						nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
+						nci.groupNumber = 10;
 						nci.groupNumber = 12;
 						nci.imName = std::string();
 						cgi->heroh->flags4[q]->ourImages.push_back(nci);
@@ -667,6 +669,7 @@ int _tmain(int argc, _TCHAR* argv[])
 					{
 						Cimage nci;
 						nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
+						nci.groupNumber = 10;
 						nci.groupNumber = 13;
 						nci.imName = std::string();
 						cgi->heroh->flags4[q]->ourImages.push_back(nci);
@@ -679,6 +682,7 @@ int _tmain(int argc, _TCHAR* argv[])
 					{
 						Cimage nci;
 						nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
+						nci.groupNumber = 10;
 						nci.groupNumber = 14;
 						nci.imName = std::string();
 						cgi->heroh->flags4[q]->ourImages.push_back(nci);
@@ -691,6 +695,7 @@ int _tmain(int argc, _TCHAR* argv[])
 					{
 						Cimage nci;
 						nci.bitmap = CSDL_Ext::rotate01(cgi->heroh->flags4[q]->ourImages[o+e].bitmap);
+						nci.groupNumber = 10;
 						nci.groupNumber = 15;
 						nci.imName = std::string();
 						cgi->heroh->flags4[q]->ourImages.push_back(nci);
@@ -699,9 +704,9 @@ int _tmain(int argc, _TCHAR* argv[])
 				}
 			}
 
-			for(int ff=80; ff<cgi->heroh->flags4[q]->ourImages.size(); ++ff)
+			for(int ff=0; ff<cgi->heroh->flags4[q]->ourImages.size(); ++ff)
 			{
-				CSDL_Ext::fullAlphaTransform(cgi->heroh->flags4[q]->ourImages[ff].bitmap);
+				CSDL_Ext::alphaTransform(cgi->heroh->flags4[q]->ourImages[ff].bitmap);
 			}
 			cgi->heroh->flags4[q]->alphaTransformed = true;
 		}

+ 36 - 36
CPlayerInterface.cpp

@@ -29,7 +29,7 @@ extern TTF_Font * GEOR16;
 class OCM_HLP_CGIN
 {
 public:
-	bool operator ()(const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>>  & a, const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & b) const
+	bool operator ()(const std::pair<CGObjectInstance*,SDL_Rect>  & a, const std::pair<CGObjectInstance*,SDL_Rect> & b) const
 	{
 		return (*a.first)<(*b.first);
 	}
@@ -878,7 +878,7 @@ inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, c
 	for(int h=0; h<hlp.objects.size(); ++h)
 		if(hlp.objects[h].first->id==hid)
 		{
-			hlp.objects[h].second.first = r;
+			hlp.objects[h].second = r;
 			return;
 		}
 }
@@ -963,17 +963,17 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 	{
 		ho->moveDir = 1;
 		ho->isStanding = false;
-		CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, -31), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 1, -31), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 33, -31), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 65, -31), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-3][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -31)));
+		CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, -31)));
+		CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, -31)));
+		CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, -31)));
 
-		CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 1), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 1)));
 		subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 1), ho->id);
 		subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 1), ho->id);
 		subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 1), ho->id);
 
-		CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 33), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 33)));
 		subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 33), ho->id);
 		subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 33), ho->id);
 		subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 33), ho->id);
@@ -997,9 +997,9 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 	{
 		ho->moveDir = 2;
 		ho->isStanding = false;
-		CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 0, -31), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 32, -31), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 64, -31), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, -31)));
+		CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, -31)));
+		CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, -31)));
 
 		subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 0, 1), ho->id);
 		subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 32, 1), ho->id);
@@ -1025,20 +1025,20 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 	{
 		ho->moveDir = 3;
 		ho->isStanding = false;
-		CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -1, -31), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 31, -31), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 63, -31), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, -31), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, -31)));
+		CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, -31)));
+		CGI->mh->ttiles[hp.x][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, -31)));
+		CGI->mh->ttiles[hp.x+1][hp.y-2][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -31)));
 
 		subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 1), ho->id);
 		subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 1), ho->id);
 		subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 1), ho->id);
-		CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 1), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 1)));
 
 		subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 33), ho->id);
 		subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 33), ho->id);
 		subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 33), ho->id);
-		CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 33), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 33)));
 
 		std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
 		std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-2][hp.z].objects.end(), ocmptwo_cgin);
@@ -1062,12 +1062,12 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 		subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, 0), ho->id);
 		subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, 0), ho->id);
 		subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, 0), ho->id);
-		CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 0), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 0)));
 
 		subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 32), ho->id);
 		subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 32), ho->id);
 		subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 32), ho->id);
-		CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 32), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 32)));
 
 		//std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
 		//std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
@@ -1086,17 +1086,17 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 		subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, -1, -1), ho->id);
 		subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 31, -1), ho->id);
 		subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 63, -1), ho->id);
-		CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, -1), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x+1][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, -1)));
 
 		subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, -1, 31), ho->id);
 		subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 31, 31), ho->id);
 		subRect(hp.x, hp.y, hp.z, genRect(32, 32, 63, 31), ho->id);
-		CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 31), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x+1][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 31)));
 
-		CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -1, 63), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 31, 63), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 63, 63), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 95, 63), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -1, 63)));
+		CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 31, 63)));
+		CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 63, 63)));
+		CGI->mh->ttiles[hp.x+1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 95, 63)));
 
 		//std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
 		//std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
@@ -1125,9 +1125,9 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 		subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 32, 31), ho->id);
 		subRect(hp.x, hp.y, hp.z, genRect(32, 32, 64, 31), ho->id);
 
-		CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 0, 63), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 32, 63), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 64, 63), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 0, 63)));
+		CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 32, 63)));
+		CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 64, 63)));
 
 		//std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
 		//std::stable_sort(CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-1][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
@@ -1145,20 +1145,20 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 	{
 		ho->moveDir = 7;
 		ho->isStanding = false;
-		CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, -1), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, -1)));
 		subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, -1), ho->id);
 		subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, -1), ho->id);
 		subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, -1), ho->id);
 
-		CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 31), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 31)));
 		subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 31), ho->id);
 		subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 31), ho->id);
 		subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 31), ho->id);
 
-		CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 63), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 1, 63), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 33, 63), std::vector<std::list<int3>>())));
-		CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, 65, 63), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-3][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 63)));
+		CGI->mh->ttiles[hp.x-2][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 1, 63)));
+		CGI->mh->ttiles[hp.x-1][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 33, 63)));
+		CGI->mh->ttiles[hp.x][hp.y+1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, 65, 63)));
 
 		std::stable_sort(CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
 		//std::stable_sort(CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.begin(), CGI->mh->ttiles[hp.x-2][hp.y-1][hp.z].objects.end(), ocmptwo_cgin);
@@ -1179,12 +1179,12 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
 	{
 		ho->moveDir = 8;
 		ho->isStanding = false;
-		CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 0), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-3][hp.y-1][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 0)));
 		subRect(hp.x-2, hp.y-1, hp.z, genRect(32, 32, 1, 0), ho->id);
 		subRect(hp.x-1, hp.y-1, hp.z, genRect(32, 32, 33, 0), ho->id);
 		subRect(hp.x, hp.y-1, hp.z, genRect(32, 32, 65, 0), ho->id);
 
-		CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, std::make_pair(genRect(32, 32, -31, 32), std::vector<std::list<int3>>())));
+		CGI->mh->ttiles[hp.x-3][hp.y][hp.z].objects.push_back(std::make_pair(ho, genRect(32, 32, -31, 32)));
 		subRect(hp.x-2, hp.y, hp.z, genRect(32, 32, 1, 32), ho->id);
 		subRect(hp.x-1, hp.y, hp.z, genRect(32, 32, 33, 32), ho->id);
 		subRect(hp.x, hp.y, hp.z, genRect(32, 32, 65, 32), ho->id);

+ 109 - 86
SDL_Extensions.cpp

@@ -480,106 +480,129 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
 
 SDL_Surface * CSDL_Ext::secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha)
 {
-	SDL_Surface * hide2 = SDL_ConvertSurface(src, alpha->format, SDL_SWSURFACE);
-	for(int i=0; i<hide2->w; ++i)
-	{
-		for(int j=0; j<hide2->h; ++j)
-		{
-			Uint32 * place = (Uint32*)( (Uint8*)hide2->pixels + j * hide2->pitch + i * hide2->format->BytesPerPixel);
-			(*place) &= 0xffffffff - (SDL_GetPixel(src, i, j, true) & 0xff000000);
-		}
-	}
-	return hide2;
-	//return copySurface(src);
+	return copySurface(src);
 }
 
-void CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)
+int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)
 {
 	if(src && src->format->BytesPerPixel==1 && dst && (dst->format->BytesPerPixel==3 || dst->format->BytesPerPixel==4)) //everything's ok
 	{
-		int xFromSrc=-1, xToSrc=-1,
-			yFromSrc=-1, yToSrc=-1; //source pseudorect without errors
+		SDL_Rect fulldst;
+		int srcx, srcy, w, h;
 
-		int xO=-1, yO=-1; //dst offsets
+		/* Make sure the surfaces aren't locked */
+		if ( ! src || ! dst ) {
+			SDL_SetError("SDL_UpperBlit: passed a NULL surface");
+			return(-1);
+		}
+		if ( src->locked || dst->locked ) {
+			SDL_SetError("Surfaces must not be locked during blit");
+			return(-1);
+		}
 
-		if(srcRect)
-		{
-			xFromSrc = srcRect->x;
-			yFromSrc = srcRect->y;
-			xToSrc = srcRect->w + srcRect->x;
-			yToSrc = srcRect->h + srcRect->y;
+		/* If the destination rectangle is NULL, use the entire dest surface */
+		if ( dstRect == NULL ) {
+				fulldst.x = fulldst.y = 0;
+			dstRect = &fulldst;
 		}
-		else
-		{
-			xFromSrc = 0;
-			yFromSrc = 0;
-			xToSrc = src->w;
-			yToSrc = src->h;
 
-			if(dstRect)
-			{
-				if(dstRect->w<xToSrc)
-				{
-					xToSrc = dstRect->w;
-				}
-				if(dstRect->h<yToSrc)
-				{
-					yToSrc = dstRect->h;
-				}
+		/* clip the source rectangle to the source surface */
+		if(srcRect) {
+				int maxw, maxh;
+		
+			srcx = srcRect->x;
+			w = srcRect->w;
+			if(srcx < 0) {
+					w += srcx;
+				dstRect->x -= srcx;
+				srcx = 0;
 			}
-			else
-			{
-				if(dst->w<xToSrc)
-				{
-					xToSrc = dst->w;
-				}
-				if(dst->h<yToSrc)
-				{
-					yToSrc = dst->h;
-				}
+			maxw = src->w - srcx;
+			if(maxw < w)
+				w = maxw;
+
+			srcy = srcRect->y;
+			h = srcRect->h;
+			if(srcy < 0) {
+					h += srcy;
+				dstRect->y -= srcy;
+				srcy = 0;
 			}
+			maxh = src->h - srcy;
+			if(maxh < h)
+				h = maxh;
+		    
+		} else {
+				srcx = srcy = 0;
+			w = src->w;
+			h = src->h;
 		}
 
-		if(dstRect)
-		{
-			xO = dstRect->x - xFromSrc;
-			yO = dstRect->y - yFromSrc;
-		}
-		else
+		/* clip the destination rectangle against the clip rectangle */
 		{
-			xO = -xFromSrc;
-			yO = -yFromSrc;
+				SDL_Rect *clip = &dst->clip_rect;
+			int dx, dy;
+
+			dx = clip->x - dstRect->x;
+			if(dx > 0) {
+				w -= dx;
+				dstRect->x += dx;
+				srcx += dx;
+			}
+			dx = dstRect->x + w - clip->x - clip->w;
+			if(dx > 0)
+				w -= dx;
+
+			dy = clip->y - dstRect->y;
+			if(dy > 0) {
+				h -= dy;
+				dstRect->y += dy;
+				srcy += dy;
+			}
+			dy = dstRect->y + h - clip->y - clip->h;
+			if(dy > 0)
+				h -= dy;
 		}
 
-		if(xO+xToSrc>dst->w)
-		{
-			xToSrc = dst->w - xO;
-		}
-		if(yO+yToSrc>dst->h)
-		{
-			yToSrc = dst->h - yO;
-		}
-		if(xO+xFromSrc<0)
+		if(w > 0 && h > 0)
 		{
-			xFromSrc = - xO;
-		}
-		if(yO+yFromSrc<0)
-		{
-			yFromSrc = - yO;
-		}
+			SDL_Rect sr;
+			sr.x = srcx;
+			sr.y = srcy;
+			sr.w = dstRect->w = w;
+			sr.h = dstRect->h = h;
 
-		for(int x=xFromSrc; x<xToSrc; ++x)
-		{
-			for(int y=yFromSrc; y<yToSrc; ++y)
+			if(dst->format->Rshift==0) //like in most surfaces
+			{
+				for(int x=0; x<sr.w; ++x)
+				{
+					for(int y=0; y<sr.h; ++y)
+					{
+						SDL_Color tbc = src->format->palette->colors[*((Uint8*)src->pixels + (y+sr.y)*src->pitch + x + sr.x)]; //color to blit
+						Uint8 * p = (Uint8*)dst->pixels + (y+dstRect->y)*dst->pitch + (x+dstRect->x)*dst->format->BytesPerPixel; //place to blit at
+						p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red
+						p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green
+						p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue
+					}
+				}
+			}
+			else if(dst->format->Rshift==16) //such as screen
 			{
-				SDL_Color tbc = src->format->palette->colors[*((Uint8*)src->pixels + y*src->pitch + x)]; //color to blit
-				Uint8 * p = (Uint8*)dst->pixels + (y+yO)*dst->pitch + (x+xO)*dst->format->BytesPerPixel; //place to blit at
-				p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red
-				p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green
-				p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue
+				for(int x=0; x<sr.w; ++x)
+				{
+					for(int y=0; y<sr.h; ++y)
+					{
+						SDL_Color tbc = src->format->palette->colors[*((Uint8*)src->pixels + (y+sr.y)*src->pitch + x + sr.x)]; //color to blit
+						Uint8 * p = (Uint8*)dst->pixels + (y+dstRect->y)*dst->pitch + (x+dstRect->x)*dst->format->BytesPerPixel; //place to blit at
+						p[2] = ((Uint32)tbc.unused*(Uint32)p[2] + (Uint32)tbc.r*(Uint32)(255-tbc.unused))>>8; //red
+						p[1] = ((Uint32)tbc.unused*(Uint32)p[1] + (Uint32)tbc.g*(Uint32)(255-tbc.unused))>>8; //green
+						p[0] = ((Uint32)tbc.unused*(Uint32)p[0] + (Uint32)tbc.b*(Uint32)(255-tbc.unused))>>8; //blue
+					}
+				}
 			}
 		}
 	}
+	return 0;
 }
 
 Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
@@ -817,14 +840,14 @@ int readNormalNr (std::istream &in, int bytCon)
 	return ret;
 }
 
-void CSDL_Ext::fullAlphaTransform(SDL_Surface *& src)
-{
-	src = alphaTransform(src);
-	SDL_Surface * hlp2;
-	hlp2 = secondAlphaTransform(src, std32bppSurface);
-	SDL_FreeSurface(src);
-	src = hlp2;
-}
+//void CSDL_Ext::fullAlphaTransform(SDL_Surface *& src)
+//{
+//	src = alphaTransform(src);
+//	//SDL_Surface * hlp2;
+//	//hlp2 = secondAlphaTransform(src, std32bppSurface);
+//	//SDL_FreeSurface(src);
+//	//src = hlp2;
+//}
 
 std::string CSDL_Ext::processStr(std::string str, std::vector<std::string> & tor)
 {

+ 2 - 2
SDL_Extensions.h

@@ -35,8 +35,8 @@ namespace CSDL_Ext
 	SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y);
 	SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details)
 	SDL_Surface * secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha); //alpha is a surface we want to blit src to
-	void blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface
-	void fullAlphaTransform(SDL_Surface *& src); //performs first and second alpha transform
+	int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface
+	//void fullAlphaTransform(SDL_Surface *& src); //performs first and second alpha transform
 	Uint32 colorToUint32(const SDL_Color * color); //little endian only
 	void printTo(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
 	void printAtMiddle(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest

+ 3 - 3
hch/CAmbarCendamo.cpp

@@ -2153,9 +2153,9 @@ borderguardend:
 		for(int yy=0; yy<map.defy[vv]->handler->ourImages.size(); ++yy)
 		{
 			map.defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap);
-			SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap, CSDL_Ext::std32bppSurface);
-			SDL_FreeSurface(map.defy[vv]->handler->ourImages[yy].bitmap);
-			map.defy[vv]->handler->ourImages[yy].bitmap = bufs;
+			//SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap, CSDL_Ext::std32bppSurface);
+			//SDL_FreeSurface(map.defy[vv]->handler->ourImages[yy].bitmap);
+			//map.defy[vv]->handler->ourImages[yy].bitmap = bufs;
 			map.defy[vv]->handler->alphaTransformed = true;
 		}
 	}

+ 1 - 1
hch/CHeroHandler.cpp

@@ -432,7 +432,7 @@ void CHeroHandler::loadHeroClasses()
 
 		for(int ff=0; ff<hc->moveAnim->ourImages.size(); ++ff)
 		{
-			CSDL_Ext::fullAlphaTransform(hc->moveAnim->ourImages[ff].bitmap);
+			CSDL_Ext::alphaTransform(hc->moveAnim->ourImages[ff].bitmap);
 		}
 		hc->moveAnim->alphaTransformed = true;
 		heroClasses.push_back(hc);

+ 39 - 117
mapHandler.cpp

@@ -20,7 +20,7 @@ extern SDL_Surface * ekran;
 class OCM_HLP
 {
 public:
-	bool operator ()(const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & a, const std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> & b)
+	bool operator ()(const std::pair<CGObjectInstance*, SDL_Rect> & a, const std::pair<CGObjectInstance*, SDL_Rect> & b)
 	{
 		return (*a.first)<(*b.first);
 	}
@@ -31,9 +31,9 @@ void alphaTransformDef(CGDefInfo * defInfo)
 	for(int yy=0;yy<defInfo->handler->ourImages.size();yy++)
 	{
 		defInfo->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap);
-		SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(defInfo->handler->ourImages[yy].bitmap, alphaTransSurf);
-		SDL_FreeSurface(defInfo->handler->ourImages[yy].bitmap);
-		defInfo->handler->ourImages[yy].bitmap = bufs;
+		//SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(defInfo->handler->ourImages[yy].bitmap, alphaTransSurf);
+		//SDL_FreeSurface(defInfo->handler->ourImages[yy].bitmap);
+		//defInfo->handler->ourImages[yy].bitmap = bufs;
 		defInfo->handler->alphaTransformed = true;
 	}
 	SDL_FreeSurface(alphaTransSurf);
@@ -310,7 +310,7 @@ void CMapHandler::prepareFOWDefs()
 
 	for(int i=0; i<partialHide->ourImages.size(); ++i)
 	{
-		CSDL_Ext::fullAlphaTransform(partialHide->ourImages[i].bitmap);
+		CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap);
 	}
 	//visibility.resize(reader->map.width+2*Woff);
 	//for(int gg=0; gg<reader->map.width+2*Woff; ++gg)
@@ -370,6 +370,20 @@ void CMapHandler::roadsRiverTerrainInit()
 	staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("icyrvr.def"));
 	staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("mudrvr.def"));
 	staticRiverDefs.push_back(CGameInfo::mainObj->spriteh->giveDef("lavrvr.def"));
+	for(int g=0; g<staticRiverDefs.size(); ++g)
+	{
+		for(int h=0; h<staticRiverDefs[g]->ourImages.size(); ++h)
+		{
+			CSDL_Ext::alphaTransform(staticRiverDefs[g]->ourImages[h].bitmap);
+		}
+	}
+	for(int g=0; g<roadDefs.size(); ++g)
+	{
+		for(int h=0; h<roadDefs[g]->ourImages.size(); ++h)
+		{
+			CSDL_Ext::alphaTransform(roadDefs[g]->ourImages[h].bitmap);
+		}
+	}
 
 	//roadBitmaps = new SDL_Surface** [reader->map.width+2*Woff];
 	//for (int ii=0;ii<reader->map.width+2*Woff;ii++)
@@ -438,9 +452,6 @@ void CMapHandler::roadsRiverTerrainInit()
 					if(rotH || rotV)
 					{
 						ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].roadbitmap[0]);
-						SDL_Surface * buf = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].roadbitmap[0], CSDL_Ext::std32bppSurface);
-						SDL_FreeSurface(ttiles[i][j][k].roadbitmap[0]);
-						ttiles[i][j][k].roadbitmap[0] = buf;
 					}
 				}
 			}
@@ -517,9 +528,6 @@ void CMapHandler::roadsRiverTerrainInit()
 					if(rotH || rotV)
 					{
 						ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].rivbitmap[0]);
-						SDL_Surface * buf = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].rivbitmap[0], CSDL_Ext::std32bppSurface);
-						SDL_FreeSurface(ttiles[i][j][k].rivbitmap[0]);
-						ttiles[i][j][k].rivbitmap[0] = buf;
 					}
 				}
 			}
@@ -666,34 +674,8 @@ void CMapHandler::initObjectRects()
 					cr.h = 32;
 					cr.x = fx<<5; //fx*32
 					cr.y = fy<<5; //fy*32
-					std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector<std::list<int3>>()));
-					///initializing places that will be coloured by blitting (flag colour / player colour positions)
+					std::pair<CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(CGI->objh->objInstances[f],cr);
 					
-					if(toAdd.first->defInfo->isVisitable() && toAdd.first->defInfo->handler->ourImages[0].bitmap->format->BitsPerPixel!=8)
-					{
-						toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size());
-						for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no)
-						{
-							bool breakNow = true;
-							for(int dx=0; dx<32; ++dx)
-							{
-								for(int dy=0; dy<32; ++dy)
-								{
-									SDL_Surface * curs = toAdd.first->defInfo->handler->ourImages[no].bitmap;
-									Uint32* point = (Uint32*)( (Uint8*)curs->pixels + curs->pitch * (fy*32+dy) + curs->format->BytesPerPixel*(fx*32+dx));
-									Uint8 r, g, b, a;
-									SDL_GetRGBA(*point, curs->format, &r, &g, &b, &a);
-									if(r==255 && g==255 && b==0)
-									{
-										toAdd.second.second[no].push_back(int3((fx*32+dx), (fy*32+dy), 0));
-										breakNow = false;
-									}
-								}
-							}
-							if(breakNow)
-								break;
-						}
-					}
 					if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
 					{
 						//TerrainTile2 & curt =
@@ -863,8 +845,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 			sr.h=sr.w=32;
 			if(ttiles[x+bx][y+by][level].rivbitmap.size())
 			{
-				SDL_BlitSurface(ttiles[x+bx][y+by][level].rivbitmap[anim%ttiles[x+bx][y+by][level].rivbitmap.size()],NULL,su,&sr);
-				//CSDL_Ext::blit8bppAlphaTo24bpp(ttiles[x+bx][y+by][level].rivbitmap[anim%ttiles[x+bx][y+by][level].rivbitmap.size()],NULL,su,&sr);
+				CSDL_Ext::blit8bppAlphaTo24bpp(ttiles[x+bx][y+by][level].rivbitmap[anim%ttiles[x+bx][y+by][level].rivbitmap.size()],NULL,su,&sr);
 			}
 		}
 	}
@@ -881,7 +862,9 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 			sr.x=bx*32;
 			sr.h=sr.w=32;
 			if(ttiles[x+bx][y+by][level].roadbitmap.size())
-				SDL_BlitSurface(ttiles[x+bx][y+by][level].roadbitmap[anim%ttiles[x+bx][y+by][level].roadbitmap.size()],NULL,su,&sr);
+			{
+				CSDL_Ext::blit8bppAlphaTo24bpp(ttiles[x+bx][y+by][level].roadbitmap[anim%ttiles[x+bx][y+by][level].roadbitmap.size()],NULL,su,&sr);
+			}
 		}
 	}
 	////roads printed
@@ -899,7 +882,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 				sr.x = (bx)*32;
 				sr.y = (by)*32;
 
-				SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second.first;
+				SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second;
 				CGHeroInstance * themp = (dynamic_cast<CGHeroInstance*>(ttiles[x+bx][y+by][level].objects[h].first));
 
 				if(themp && themp->moveDir && !themp->isStanding && themp->ID!=62) //last condition - this is not prison
@@ -920,12 +903,10 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 							break;
 						}
 					}
-					SDL_BlitSurface(tb,&pp,su,&sr);
-					//CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,su,&sr);
+					CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,su,&sr);
 					pp.y+=imgVal*2-32;
 					sr.y-=16;
-					SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
-					//CSDL_Ext::blit8bppAlphaTo24bpp(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
+					CSDL_Ext::blit8bppAlphaTo24bpp(CGI->heroh->flags4[themp->getOwner()]->ourImages[gg+heroAnim%imgVal+35].bitmap, &pp, su, &sr);
 				}
 				else if(themp && themp->moveDir && themp->isStanding && themp->ID!=62) //last condition - this is not prison)
 				{
@@ -945,62 +926,30 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 							break;
 						}
 					}
-					SDL_BlitSurface(tb,&pp,su,&sr);
-					//CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,su,&sr);
+					CSDL_Ext::blit8bppAlphaTo24bpp(tb,&pp,su,&sr);
 					if(themp->pos.x==x+bx && themp->pos.y==y+by)
 					{
 						SDL_Rect bufr = sr;
 						bufr.x-=2*32;
 						bufr.y-=1*32;
-						SDL_BlitSurface(CGI->heroh->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
-						//CSDL_Ext::blit8bppAlphaTo24bpp(CGI->heroh->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
+						CSDL_Ext::blit8bppAlphaTo24bpp(CGI->heroh->flags4[themp->getOwner()]->ourImages[ getHeroFrameNum(themp->moveDir, !themp->isStanding) *8+heroAnim%imgVal].bitmap, NULL, su, &bufr);
 						themp->flagPrinted = true;
 					}
 				}
 				else
 				{
 					int imgVal = ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages.size();
-					SDL_BlitSurface(ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages[anim%imgVal].bitmap,&pp,su,&sr);
-					//CSDL_Ext::blit8bppAlphaTo24bpp(ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages[anim%imgVal].bitmap,&pp,su,&sr);
-				}
-				//printing appropriate flag colour
-				if(ttiles[x+bx][y+by][level].objects[h].second.second.size())
-				{
-					std::list<int3> & curl = ttiles[x+bx][y+by][level].objects[h].second.second[anim%ttiles[x+bx][y+by][level].objects[h].second.second.size()];
-					for(std::list<int3>::iterator g=curl.begin(); g!=curl.end(); ++g)
-					{
-						SDL_Color ourC;
-						int own = ttiles[x+bx][y+by][level].objects[h].first->getOwner();
-						if(ttiles[x+bx][y+by][level].objects[h].first->getOwner()!=255 && ttiles[x+bx][y+by][level].objects[h].first->getOwner()!=254)
-							ourC = CGI->playerColors[ttiles[x+bx][y+by][level].objects[h].first->getOwner()];
-						else if(ttiles[x+bx][y+by][level].objects[h].first->getOwner()==255)
-							ourC = CGI->neutralColor;
-						else continue;
-						CSDL_Ext::SDL_PutPixelWithoutRefresh(su, bx*32 + g->x%32 , by*32 + g->y%32, ourC.r , ourC.g, ourC.b, 0);
-					}
+
+					//setting appropriate flag color
+					if((ttiles[x+bx][y+by][level].objects[h].first->tempOwner>=0 && ttiles[x+bx][y+by][level].objects[h].first->tempOwner<=8) || ttiles[x+bx][y+by][level].objects[h].first->tempOwner==255)
+						CSDL_Ext::setPlayerColor(ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages[anim%imgVal].bitmap, ttiles[x+bx][y+by][level].objects[h].first->tempOwner);
+					
+					CSDL_Ext::blit8bppAlphaTo24bpp(ttiles[x+bx][y+by][level].objects[h].first->defInfo->handler->ourImages[anim%imgVal].bitmap,&pp,su,&sr);
 				}
 			}
 		}
 	}
 
-	///enabling flags
-
-
-
-	//nie zauwazylem aby ustawianie tego cokolwiek zmienialo w wyswietlaniu, wiec komentuje (do dzialania wymaga jeszcze odkomentowania przyjazni w statcie)
-
-	/*for(std::map<int, PlayerState>::iterator k=CGI->state->players.begin(); k!=CGI->state->players.end(); ++k)
-	{
-		for (int l = 0; l<k->second.heroes.size(); l++)
-			k->second.heroes[l]->flagPrinted = false;
-	}
-	for(int qq=0; qq<CGI->heroh->heroInstances.size(); ++qq)
-	{
-		CGI->heroh->heroInstances[qq]->flagPrinted = false;
-	}*/
-
-	///flags enabled
-
 	////objects printed, printing shadow
 	for (int bx=0; bx<dx; bx++)
 	{
@@ -1014,8 +963,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
 			if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->reader->map.width && by+y<CGI->mh->reader->map.height && !visibilityMap[bx+x][by+y][level])
 			{
 				SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibilityMap, level);
-				SDL_BlitSurface(hide, NULL, su, &sr);
-				//CSDL_Ext::blit8bppAlphaTo24bpp(hide, NULL, su, &sr);
+				CSDL_Ext::blit8bppAlphaTo24bpp(hide, NULL, su, &sr);
 			}
 		}
 	}
@@ -1358,7 +1306,7 @@ int CMapHandler::getCost(int3 &a, int3 &b, const CGHeroInstance *hero)
 
 std::vector < std::string > CMapHandler::getObjDescriptions(int3 pos)
 {
-	std::vector < std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> > objs = ttiles[pos.x][pos.y][pos.z].objects;
+	std::vector < std::pair<CGObjectInstance*,SDL_Rect > > objs = ttiles[pos.x][pos.y][pos.z].objects;
 	std::vector<std::string> ret;
 	for(int g=0; g<objs.size(); ++g)
 	{
@@ -1472,33 +1420,7 @@ bool CMapHandler::printObject(CGObjectInstance *obj)
 			cr.h = 32;
 			cr.x = fx*32;
 			cr.y = fy*32;
-			std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> toAdd = std::make_pair(obj, std::make_pair(cr, std::vector<std::list<int3>>()));
-			///initializing places that will be coloured by blitting (flag colour / player colour positions)
-			if(CGI->dobjinfo->gobjs[toAdd.first->ID][toAdd.first->subID]->isVisitable())
-			{
-				toAdd.second.second.resize(toAdd.first->defInfo->handler->ourImages.size());
-				for(int no = 0; no<toAdd.first->defInfo->handler->ourImages.size(); ++no)
-				{
-					bool breakNow = true;
-					for(int dx=0; dx<32; ++dx)
-					{
-						for(int dy=0; dy<32; ++dy)
-						{
-							SDL_Surface * curs = toAdd.first->defInfo->handler->ourImages[no].bitmap;
-							Uint32* point = (Uint32*)( (Uint8*)curs->pixels + curs->pitch * (fy*32+dy) + curs->format->BytesPerPixel*(fx*32+dx));
-							Uint8 r, g, b, a;
-							SDL_GetRGBA(*point, curs->format, &r, &g, &b, &a);
-							if(r==255 && g==255 && b==0)
-							{
-								toAdd.second.second[no].push_back(int3((fx*32+dx), (fy*32+dy), 0));
-								breakNow = false;
-							}
-						}
-					}
-					if(breakNow)
-						break;
-				}
-			}
+			std::pair<CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(obj, cr);
 			if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
 			{
 				TerrainTile2 & curt = 
@@ -1525,7 +1447,7 @@ bool CMapHandler::hideObject(CGObjectInstance *obj)
 		{
 			if((obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
 			{
-				std::vector < std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects;
+				std::vector < std::pair<CGObjectInstance*,SDL_Rect> > & ctile = ttiles[obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][obj->pos.z].objects;
 				for(int dd=0; dd<ctile.size(); ++dd)
 				{
 					if(ctile[dd].first->id==obj->id)

+ 1 - 1
mapHandler.h

@@ -29,7 +29,7 @@ struct TerrainTile2
 	bool visitable; //false = not visitable; true = visitable
 	bool blocked; //false = free; true = blocked;
 
-	std::vector < std::pair<CGObjectInstance*,std::pair<SDL_Rect, std::vector<std::list<int3>>>> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
+	std::vector < std::pair<CGObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
 	std::vector <CGObjectInstance*> visitableObjects; //pointers to objects hero is visiting being on this tile
 
 };