From cc0a4c5d09dab736e091378329e71944ec03485c Mon Sep 17 00:00:00 2001 From: mateuszb Date: Thu, 9 Aug 2007 16:28:01 +0000 Subject: [PATCH] * new objects displaying system --- CObjectHandler.cpp | 27 ++++++- CObjectHandler.h | 2 + mapHandler.cpp | 175 +++++++++++++++------------------------------ mapHandler.h | 15 ---- 4 files changed, 85 insertions(+), 134 deletions(-) diff --git a/CObjectHandler.cpp b/CObjectHandler.cpp index 86477bdb3..cab2c43b3 100644 --- a/CObjectHandler.cpp +++ b/CObjectHandler.cpp @@ -3,6 +3,8 @@ #include "CGameInfo.h" #include "CGeneralTextHandler.h" +#define CGI (CGameInfo::mainObj) + void CObjectHandler::loadObjects() { int ID=0; @@ -14,4 +16,27 @@ void CObjectHandler::loadObjects() CGeneralTextHandler::loadToIt(nobj.name,buf,it,3); objects.push_back(nobj); } -} \ No newline at end of file +} + +bool CObjectInstance::operator <(const CObjectInstance &cmp) const +{ + if(CGI->ac->map.defy[this->defNumber].printPriority==1 && CGI->ac->map.defy[cmp.defNumber].printPriority==0) + return true; + if(CGI->ac->map.defy[cmp.defNumber].printPriority==1 && CGI->ac->map.defy[this->defNumber].printPriority==0) + return false; + if(this->pos.ypos.y>cmp.pos.y) + return false; + if(CGI->ac->map.defy[this->defNumber].isOnDefList && !(CGI->ac->map.defy[cmp.defNumber].isOnDefList)) + return true; + if(CGI->ac->map.defy[cmp.defNumber].isOnDefList && !(CGI->ac->map.defy[this->defNumber].isOnDefList)) + return false; + if(!CGI->ac->map.defy[this->defNumber].isVisitable() && CGI->ac->map.defy[cmp.defNumber].isVisitable()) + return true; + if(!CGI->ac->map.defy[cmp.defNumber].isVisitable() && CGI->ac->map.defy[this->defNumber].isVisitable()) + return false; + if(this->pos.x extern SDL_Surface * ekran; -// -//bool ObjSorter::operator <(const ObjSorter & por) const -//{ -// if(this->xpos>=por.xpos) -// return false; -// if(this->ypos>=por.ypos) -// return false; -// return true; -//}; -class poX +class OCM_HLP { public: - bool operator()(const ObjSorter & por2, const ObjSorter & por) const + bool operator ()(const std::pair & a, const std::pair & b) { - if(por2.xpos<=por.xpos) - return false; - return true; - }; -} pox; -class poY -{ -public: - bool operator ()(const ObjSorter & por2, const ObjSorter & por) const - { - if(por2.ypos>=por.ypos) - return false; - return true; - }; -} poy; + return (*a.first)<(*b.first); + } +} ocmptwo ; void CMapHandler::init() { @@ -342,6 +321,36 @@ void CMapHandler::init() } } } + //initializing objects / rects + for(int f=0; fobjh->objInstances.size(); ++f) + { + CDefHandler * curd = CGI->ac->map.defy[CGI->objh->objInstances[f]->defNumber].handler; + for(int fx=0; fxourImages[0].bitmap->w/32; ++fx) + { + for(int fy=0; fyourImages[0].bitmap->h/32; ++fy) + { + SDL_Rect cr; + cr.w = 32; + cr.h = 32; + cr.x = fx*32; + cr.y = fy*32; + std::pair toAdd = std::make_pair(CGI->objh->objInstances[f], cr); + if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+Woff)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+Woff)<=ttiles[0].size() && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+Hoff)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+Hoff)<=ttiles[0].size()) + ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+Woff][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+Hoff][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd); + + } // for(int fy=0; fyourImages[0].bitmap->h/32; ++fy) + } //for(int fx=0; fxourImages[0].bitmap->w/32; ++fx) + } // for(int f=0; fobjh->objInstances.size(); ++f) + for(int ix=0; ix lowPrObjs; - std::vector highPrObjs; - std::vector highPrObjsVis; - for(int gg=0; ggobjh->objInstances.size(); ++gg) + + for (int bx=(x==0 ? 0 : -1); bxobjh->objInstances[gg]->pos.x >= x-Woff-4 && CGameInfo::mainObj->objh->objInstances[gg]->pos.x < dx+x-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg]->pos.y >= y-Hoff-4 && CGameInfo::mainObj->objh->objInstances[gg]->pos.y < dy+y-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg]->pos.z == level) + for (int by=( y==0 ? 0 : -1); byac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].isOnDefList) + if(true) { - ObjSorter os; - os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].handler->ourImages.size()].bitmap; - os.xpos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.x-x+Woff)*32; - os.ypos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.y-y+Hoff)*32; - highPrObjsVis.push_back(os); - } - else if(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].printPriority==0) - { - ObjSorter os; + for(int h=0; hw = 32; + sr->h = 32; + sr->x = (bx+1)*32; + sr->y = (by+1)*32; - int defyod = CGameInfo::mainObj->objh->objInstances[gg]->defNumber; - int ourimagesod = anim%CGameInfo::mainObj->ac->map.defy[defyod].handler->ourImages.size(); - - os.bitmap = CGameInfo::mainObj->ac->map.defy[defyod].handler->ourImages[ourimagesod].bitmap; - - os.xpos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.x-x+Woff)*32; - os.ypos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.y-y+Hoff)*32; - if (CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].isVisitable()) - highPrObjsVis.push_back(os); - else - highPrObjs.push_back(os); - } - else - { - ObjSorter os; - os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg]->defNumber].handler->ourImages.size()].bitmap; - os.xpos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.x-x+Woff)*32; - os.ypos = (CGameInfo::mainObj->objh->objInstances[gg]->pos.y-y+Hoff)*32; - lowPrObjs.push_back(os); + SDL_Rect pp = ttiles[x+bx][y+by][level].objects[h].second; + int imgVal = CGI->ac->map.defy[ + ttiles[x+bx][y+by][level].objects[h].first->defNumber] + .handler->ourImages.size(); + SDL_Surface * tb = CGI->ac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages[anim%imgVal].bitmap; + SDL_BlitSurface( + CGI->ac->map.defy[ttiles[x+bx][y+by][level].objects[h].first->defNumber].handler->ourImages[anim%imgVal].bitmap, + &pp,su,sr); + delete sr; + } } } } -#ifndef _DEBUG - std::stable_sort(lowPrObjs.begin(), lowPrObjs.end(), pox); - std::stable_sort(lowPrObjs.begin(), lowPrObjs.end(), poy); - std::stable_sort(highPrObjs.begin(), highPrObjs.end(),pox); - std::stable_sort(highPrObjs.begin(), highPrObjs.end(),poy); - std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),pox); - std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),poy); -#else - std::sort(lowPrObjs.begin(), lowPrObjs.end(), pox); - std::sort(lowPrObjs.begin(), lowPrObjs.end(), poy); - std::sort(highPrObjs.begin(), highPrObjs.end(),pox); - std::sort(highPrObjs.begin(), highPrObjs.end(),poy); - std::sort(highPrObjsVis.begin(), highPrObjsVis.end(),pox); - std::sort(highPrObjsVis.begin(), highPrObjsVis.end(),poy); -#endif - for(int yy=0; yyw = lowPrObjs[yy].bitmap->w; - sr->h = lowPrObjs[yy].bitmap->h; - sr->x = lowPrObjs[yy].xpos - lowPrObjs[yy].bitmap->w + 32; - sr->y = lowPrObjs[yy].ypos - lowPrObjs[yy].bitmap->h + 32; - SDL_BlitSurface(lowPrObjs[yy].bitmap, NULL, su, sr); - delete sr; - } - for(int yy=0; yyw = highPrObjs[yy].bitmap->w; - sr->h = highPrObjs[yy].bitmap->h; - sr->x = highPrObjs[yy].xpos - highPrObjs[yy].bitmap->w + 32; - sr->y = highPrObjs[yy].ypos - highPrObjs[yy].bitmap->h + 32; - SDL_BlitSurface(highPrObjs[yy].bitmap, NULL, su, sr); - delete sr; - } - for(int yy=0; yyw = highPrObjsVis[yy].bitmap->w; - sr->h = highPrObjsVis[yy].bitmap->h; - sr->x = highPrObjsVis[yy].xpos - highPrObjsVis[yy].bitmap->w + 32; - sr->y = highPrObjsVis[yy].ypos - highPrObjsVis[yy].bitmap->h + 32; - SDL_BlitSurface(highPrObjsVis[yy].bitmap, NULL, su, sr); - delete sr; - } - /*for(int gg=0; ggobjh->objInstances.size(); ++gg) - { - if(CGameInfo::mainObj->objh->objInstances[gg].x >= x-3 && CGameInfo::mainObj->objh->objInstances[gg].x < dx+x-3 && CGameInfo::mainObj->objh->objInstances[gg].y >= y-3 && CGameInfo::mainObj->objh->objInstances[gg].y < dy+y-3 && CGameInfo::mainObj->objh->objInstances[gg].z == level) - { - SDL_Rect * sr = new SDL_Rect; - sr->w = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->w; - sr->h = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->h; - sr->x = (CGameInfo::mainObj->objh->objInstances[gg].x-x+4)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->w + 32; - sr->y = (CGameInfo::mainObj->objh->objInstances[gg].y-y+4)*32 - CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[0].bitmap->h + 32; - SDL_BlitSurface(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap, NULL, su, sr); - delete sr; - } - }*/ + ////objects printed, printing shadow for (int bx=0; bx visitableObjects; }; - //pathfinder // map iDTerenu=>koszt_pola @@ -49,8 +40,6 @@ class CMapHandler public: std::vector< std::vector< std::vector > > ttiles; CAmbarCendamo * reader; - //SDL_Surface *** terrainBitmap; - //SDL_Surface *** undTerrainBitmap; // used only if there is underground level SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0); SDL_Surface * terrBitmap(int x, int y); SDL_Surface * undTerrBitmap(int x, int y); @@ -61,10 +50,6 @@ public: std::vector< std::vector > undVisibility; //true means that pointed place is visible std::vector roadDefs; std::vector staticRiverDefs; - //SDL_Surface *** roadBitmaps; - //SDL_Surface *** undRoadBitmaps; - //SDL_Surface *** staticRiverBitmaps; - //SDL_Surface *** undStaticRiverBitmaps; char & visAccess(int x, int y); char & undVisAccess(int x, int y); SDL_Surface mirrorImage(SDL_Surface *src); //what is this??