From 217e98e345ec76734e5387aa3c6a8d5e1089485e Mon Sep 17 00:00:00 2001 From: mateuszb Date: Thu, 12 Jul 2007 11:41:31 +0000 Subject: [PATCH] less bugs and works faster --- CAmbarCendamo.cpp | 4 +- CAmbarCendamo.h | 2 +- CDefHandler.cpp | Bin 26238 -> 26206 bytes CLodHandler.cpp | 133 +++++++++++++++++++++++++++++---------------- CMessage.cpp | 5 +- CPreGame.cpp | Bin 80482 -> 80950 bytes SDL_Extensions.cpp | 5 ++ SDL_Extensions.h | 1 + 8 files changed, 98 insertions(+), 52 deletions(-) diff --git a/CAmbarCendamo.cpp b/CAmbarCendamo.cpp index bb8b47aff..cfafc91e3 100644 --- a/CAmbarCendamo.cpp +++ b/CAmbarCendamo.cpp @@ -1757,13 +1757,13 @@ void CAmbarCendamo::loadDefs() { if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end()) { - CSemiDefHandler *sdh = CGI->sspriteh->giveDef(CSemiDefHandler::nameFromType(map.terrain[i][j].tertype).c_str()); + CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.terrain[i][j].tertype).c_str()); loadedTypes.insert(map.terrain[i][j].tertype); defs.push_back(sdh); } if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end()) { - CSemiDefHandler *sdh = CGI->sspriteh->giveDef(CSemiDefHandler::nameFromType(map.undergroungTerrain[i][j].tertype).c_str()); + CDefHandler *sdh = CGI->spriteh->giveDef(CSemiDefHandler::nameFromType(map.undergroungTerrain[i][j].tertype).c_str()); loadedTypes.insert(map.undergroungTerrain[i][j].tertype); defs.push_back(sdh); } diff --git a/CAmbarCendamo.h b/CAmbarCendamo.h index 91f3106dd..45ae81e64 100644 --- a/CAmbarCendamo.h +++ b/CAmbarCendamo.h @@ -21,7 +21,7 @@ public: std::ifstream * is; // stream used to read map file int andame; // length of map file unsigned char * bufor; // here we store map bytecode - std::vector defs; + std::vector defs; /////////////////funkcje skladowe CAmbarCendamo (const char * tie); // c-tor; tie is the path of the map file CAmbarCendamo (unsigned char * map); // c-tor; map is pointer to array containing map; it is not copied, so don't delete diff --git a/CDefHandler.cpp b/CDefHandler.cpp index 75232c99d417beeed45cd9b9687cb1504264897c..d9f11bc40c4278910dc1094e744dc16bdb429f8e 100644 GIT binary patch delta 34 ecmex&hVkAR#tjdwgbf&U7!(*#$j!pm+1dcW4G50_ delta 66 tcmcb2hVkDS#tjdwjEfj@84?+a8L}C47!(-NQFuuxyhIpp^JlAUZ2)>S5gGsh diff --git a/CLodHandler.cpp b/CLodHandler.cpp index aae50fa9c..e5306d95e 100644 --- a/CLodHandler.cpp +++ b/CLodHandler.cpp @@ -163,22 +163,23 @@ void CPCXConv::convert() SDL_Surface * CPCXConv::getSurface() { SDL_Surface * ret; + BMPHeader bh; BMPPalette pal[256]; Epcxformat format; - int fSize, maxx, maxy,i,y; + int fSize,i,y; bool check1, check2; unsigned char add; int it=0; fSize = readNormalNr(it,4,pcx);it+=4; - maxx = readNormalNr(it,4,pcx);it+=4; - maxy = readNormalNr(it,4,pcx);it+=4; - if (fSize==maxx*maxy*3) + bh.x = readNormalNr(it,4,pcx);it+=4; + bh.y = readNormalNr(it,4,pcx);it+=4; + if (fSize==bh.x*bh.y*3) check1=true; else check1=false; - if (fSize==maxx*maxy) + if (fSize==bh.x*bh.y) check2=true; else check2=false; @@ -188,9 +189,41 @@ SDL_Surface * CPCXConv::getSurface() format=Epcxformat::PCX8B; else return NULL; - add=(int)(4*(((float)1)-(((float)maxx/(float)4)-((int)((float)maxx/(float)4))))); + add = 4 - bh.x%4; if (add==4) add=0; + bh._h3=bh.x*bh.y; + if (format==Epcxformat::PCX8B) + { + int bmask = 0x0000ff; + int gmask = 0x00ff00; + int rmask = 0xff0000; + ret = SDL_CreateRGBSurface(SDL_SWSURFACE, bh.x+add, bh.y, 8, 0, 0, 0, 0); + bh._c1=0x436; + bh._c2=0x28; + bh._c3=1; + bh._c4=8; + //bh.dataSize2=bh.dataSize1=maxx*maxy; + bh.dataSize1=bh.x; + bh.dataSize2=bh.y; + bh.fullSize = bh.dataSize1+436; + } + else + { + int bmask = 0x0000ff; + int gmask = 0x00ff00; + int rmask = 0xff0000; + ret = SDL_CreateRGBSurface(SDL_SWSURFACE, bh.x+add, bh.y, 24, rmask, gmask, bmask, 0); + bh._c1=0x36; + bh._c2=0x28; + bh._c3=1; + bh._c4=0x18; + //bh.dataSize2=bh.dataSize1=0xB12; + bh.dataSize1=bh.x; + bh.dataSize2=bh.y; + bh.fullSize=(bh.x+add)*bh.y*3+36+18; + bh._h3*=3; + } if (format==Epcxformat::PCX8B) { it = pcxs-256*3; @@ -202,50 +235,53 @@ SDL_Surface * CPCXConv::getSurface() pal[i].F='\0'; } } -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - int rmask = 0xff000000; - int gmask = 0x00ff0000; - int bmask = 0x0000ff00; - int amask = 0x000000ff; -#else - int rmask = 0x000000ff; - int gmask = 0x0000ff00; - int bmask = 0x00ff0000; - int amask = 0xff000000; -#endif - ret = SDL_CreateRGBSurface(SDL_SWSURFACE, maxx, maxy, (format==Epcxformat::PCX8B ? 8 : 24), rmask, gmask, bmask, amask); if (format==Epcxformat::PCX8B) { + for(int i=0; i<256; ++i) { - SDL_Color pr; - pr.r = pal[i].R; - pr.g = pal[i].G; - pr.b = pal[i].B; - pr.unused = pal[i].F; - (*(ret->format->palette->colors+i)) = pr; + SDL_Color tp; + tp.r = pal[i].R; + tp.g = pal[i].G; + tp.b = pal[i].B; + tp.unused = pal[i].F; + *(ret->format->palette->colors+i) = tp; } - for(y=maxy; y>0; --y) + for (y=bh.y;y>0;y--) { - it = 0xc + (y-1)*maxx; - for(int j=0; jpixels + ret->format->BytesPerPixel * (y*(maxx+add) + j)) = pcx[it+j]; - for(int j=0; jpixels + ret->format->BytesPerPixel * (y*(maxx+add) + maxx + j)) = 0; + it=0xC+(y-1)*bh.x; + for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * j) = pcx[it+j]; + } + if (add>0) + { + for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * (j+bh.x)) = 0; + } + } } } else { - for(int y=maxy; y>0; --y) + for (y=bh.y; y>0; y--) { - it = 0xc + (y-1)*maxx*3; - for(int j=0; jpixels + (y*(maxx+add) + j)) = pcx[it+j]; + //out<pixels + ret->pitch * (y-1) + j) = pcx[it+j]; } - for(int j=0; j0) { - *((char*)ret->pixels + (y*(maxx+add) + j)) = 0; + for (int j=0;jpixels + ret->pitch * (y-1) + (j+bh.x*3)) = 0; + } } } } @@ -277,17 +313,21 @@ SDL_Surface * CLodHandler::loadBitmap(std::string fname) { unsigned char * pcd = new unsigned char[entries[index].size]; FLOD.read((char*)pcd,entries[index].size); - infs2(pcd,entries[index].size,entries[index].realSize,pcx); + int res=infs2(pcd,entries[index].size,entries[index].realSize,pcx); + if(res!=0) + { + std::cout<<"an error "< CLodHandler::extractManyFiles(std::vector found(defNamesIn.size(), 0); for (int i=0;i CLodHandler::extractManyFiles(std::vector CLodHandler::extractManyFiles(std::vectoropenFromMemory(outp, entries[i].realSize, std::string((char*)entries[i].name)); ret[curDef] = nh; - } else //we will decompressing file { diff --git a/CMessage.cpp b/CMessage.cpp index b8ab5f652..d29884a8e 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -4,6 +4,7 @@ #include "CSemiDefHandler.h" #include "CDefHandler.h" #include "CGameInfo.h" +#include "SDL_Extensions.h" #define CGI (CGameInfo::mainObj) SDL_Color tytulowy, tlo, zwykly ; @@ -31,7 +32,9 @@ SDL_Surface * CMessage::drawBox1(int w, int h) { for (int j=0; jw-1) SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i)); - }SDL_Flip(ekran); + } + //SDL_Flip(ekran); + CSDL_Ext::update(ekran); //obwodka I-szego rzedu pozioma for (int i=0; iourImages[6].bitmap->w) { diff --git a/CPreGame.cpp b/CPreGame.cpp index f4d4886b748f58368dbad7bd9cfdcf2cfd6ce808..36bf73fc3227f0c16881da0b6587f13d8f3257da 100644 GIT binary patch delta 319 zcmaF#g=O0hmJKqJ%=!%aljCowPIi!FnfxwSh`W@bfFXq;k)ebkb#nd<(ajE$YvkaH z1T5GlZ<`~6p-8|YMP%}WB9_SsH&k$#q&m4SNnrC1p9=ZMHah;WrDU%P(=9s=qpOI(tqI(CT0TnH5ApigX delta 129 zcmdn?gXPf|mJKqJlixkym@IWvVRN123c1OB7F?5Mj>=39uwdETXAvhdS?H+BWVu@c zlMRvuHfQ->Fqq8q6r@55D9E;XUfm)?sD7Ev^EMQSAjzt1o^aFvF0fhd)*;r(`;0+W L$!xZJ@FN-k7{@p9 diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index d6f0e8cfd..c122e2bad 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -432,3 +432,8 @@ Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color) ret+=color->r; return ret; } + +void CSDL_Ext::update(SDL_Surface * what) +{ + SDL_UpdateRect(what, 0, 0, what->w, what->h); +} diff --git a/SDL_Extensions.h b/SDL_Extensions.h index 731915578..b9ed56093 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -21,6 +21,7 @@ namespace CSDL_Ext Uint32 colorToUint32(const SDL_Color * color); //little endian only 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 void printAt(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 + void update(SDL_Surface * what = ekran); //updates whole surface (default - main screen) }; #endif // SDL_EXTENSIONS_H \ No newline at end of file