From f0e2f1d2051812ca7eaf3c99187e4bf45a933433 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sun, 10 Feb 2008 17:44:51 +0000 Subject: [PATCH] * 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 ;] --- CAdvmapInterface.cpp | 24 +++-- CMT.cpp | 21 +++-- CPlayerInterface.cpp | 72 +++++++-------- SDL_Extensions.cpp | 203 +++++++++++++++++++++++------------------- SDL_Extensions.h | 4 +- hch/CAmbarCendamo.cpp | 6 +- hch/CHeroHandler.cpp | 2 +- mapHandler.cpp | 156 ++++++++------------------------ mapHandler.h | 2 +- 9 files changed, 223 insertions(+), 267 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 226e0bacc..c9874af43 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -238,7 +238,7 @@ CTerrainRect::CTerrainRect():currentPath(NULL) arrows = CGI->spriteh->giveDef("ADAG.DEF"); for(int y=0; yourImages.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;inodes.size()-1;i++) diff --git a/CMT.cpp b/CMT.cpp index 539746fe6..39ce707c4 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -485,9 +485,9 @@ int _tmain(int argc, _TCHAR* argv[]) } } - for(int ff=80; ffheroh->flags1[q]->ourImages.size(); ++ff) + for(int ff=0; ffheroh->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; ffheroh->flags2[q]->ourImages.size(); ++ff) + for(int ff=0; ffheroh->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; ffheroh->flags3[q]->ourImages.size(); ++ff) + for(int ff=0; ffheroh->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; ffheroh->flags4[q]->ourImages.size(); ++ff) + for(int ff=0; ffheroh->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; } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 8fa53220f..e711d8fb5 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -29,7 +29,7 @@ extern TTF_Font * GEOR16; class OCM_HLP_CGIN { public: - bool operator ()(const std::pair>>> & a, const std::pair>>> & b) const + bool operator ()(const std::pair & a, const std::pair & 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; hid==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>()))); - 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>()))); - 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>()))); - 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>()))); + 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>()))); + 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>()))); + 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>()))); - 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>()))); - 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>()))); + 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>()))); - 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>()))); - 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>()))); - 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>()))); + 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>()))); + 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>()))); + 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>()))); + 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>()))); + 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>()))); + 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>()))); + 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>()))); - 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>()))); - 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>()))); - 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>()))); + 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>()))); - 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>()))); - 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>()))); + 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>()))); + 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>()))); + 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>()))); - 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>()))); - 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>()))); - 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>()))); + 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>()))); + 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>()))); + 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); diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 42fccf737..5fc33590f 100644 --- a/SDL_Extensions.cpp +++ b/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; iw; ++i) - { - for(int j=0; jh; ++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 - - if(srcRect) - { - xFromSrc = srcRect->x; - yFromSrc = srcRect->y; - xToSrc = srcRect->w + srcRect->x; - yToSrc = srcRect->h + srcRect->y; + /* 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); } - else - { - xFromSrc = 0; - yFromSrc = 0; - xToSrc = src->w; - yToSrc = src->h; - if(dstRect) + /* If the destination rectangle is NULL, use the entire dest surface */ + if ( dstRect == NULL ) { + fulldst.x = fulldst.y = 0; + dstRect = &fulldst; + } + + /* 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; + } + 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; + } + + /* clip the destination rectangle against the clip rectangle */ + { + 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(w > 0 && h > 0) + { + SDL_Rect sr; + sr.x = srcx; + sr.y = srcy; + sr.w = dstRect->w = w; + sr.h = dstRect->h = h; + + if(dst->format->Rshift==0) //like in most surfaces { - if(dstRect->ww; - } - if(dstRect->hh; + for(int y=0; yformat->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 + else if(dst->format->Rshift==16) //such as screen { - if(dst->ww; + for(int y=0; yformat->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 + } } - if(dst->hh; - } - } - } - - if(dstRect) - { - xO = dstRect->x - xFromSrc; - yO = dstRect->y - yFromSrc; - } - else - { - xO = -xFromSrc; - yO = -yFromSrc; - } - - if(xO+xToSrc>dst->w) - { - xToSrc = dst->w - xO; - } - if(yO+yToSrc>dst->h) - { - yToSrc = dst->h - yO; - } - if(xO+xFromSrc<0) - { - xFromSrc = - xO; - } - if(yO+yFromSrc<0) - { - yFromSrc = - yO; - } - - for(int x=xFromSrc; xformat->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 } } } + 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 & tor) { diff --git a/SDL_Extensions.h b/SDL_Extensions.h index 43ca5403b..5ea0f919a 100644 --- a/SDL_Extensions.h +++ b/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 diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index 4dd6ac357..fd2012efd 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -2153,9 +2153,9 @@ borderguardend: for(int yy=0; yyhandler->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; } } diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index 74fde89da..ceaebd25b 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -432,7 +432,7 @@ void CHeroHandler::loadHeroClasses() for(int ff=0; ffmoveAnim->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); diff --git a/mapHandler.cpp b/mapHandler.cpp index 87f114429..0310ff2df 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -20,7 +20,7 @@ extern SDL_Surface * ekran; class OCM_HLP { public: - bool operator ()(const std::pair>>> & a, const std::pair>>> & b) + bool operator ()(const std::pair & a, const std::pair & b) { return (*a.first)<(*b.first); } @@ -31,9 +31,9 @@ void alphaTransformDef(CGDefInfo * defInfo) for(int yy=0;yyhandler->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; iourImages.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; ggmap.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; gourImages.size(); ++h) + { + CSDL_Ext::alphaTransform(staticRiverDefs[g]->ourImages[h].bitmap); + } + } + for(int g=0; gourImages.size(); ++h) + { + CSDL_Ext::alphaTransform(roadDefs[g]->ourImages[h].bitmap); + } + } //roadBitmaps = new SDL_Surface** [reader->map.width+2*Woff]; //for (int ii=0;iimap.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>>> toAdd = std::make_pair(CGI->objh->objInstances[f], std::make_pair(cr, std::vector>())); - ///initializing places that will be coloured by blitting (flag colour / player colour positions) + std::pair 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; nodefInfo->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)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[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 & 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::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::iterator k=CGI->state->players.begin(); k!=CGI->state->players.end(); ++k) - { - for (int l = 0; lsecond.heroes.size(); l++) - k->second.heroes[l]->flagPrinted = false; - } - for(int qq=0; qqheroh->heroInstances.size(); ++qq) - { - CGI->heroh->heroInstances[qq]->flagPrinted = false; - }*/ - - ///flags enabled - ////objects printed, printing shadow for (int bx=0; bx=0 && by+y>=0 && bx+xmh->reader->map.width && by+ymh->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>>> > objs = ttiles[pos.x][pos.y][pos.z].objects; + std::vector < std::pair > objs = ttiles[pos.x][pos.y][pos.z].objects; std::vector ret; for(int g=0; g>>> toAdd = std::make_pair(obj, std::make_pair(cr, std::vector>())); - ///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; nodefInfo->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 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)pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (obj->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (obj->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>>> > & 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 > & 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; ddid==obj->id) diff --git a/mapHandler.h b/mapHandler.h index eba85f0ac..a97e396d0 100644 --- a/mapHandler.h +++ b/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>>> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen + std::vector < std::pair > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen std::vector visitableObjects; //pointers to objects hero is visiting being on this tile };