diff --git a/client/CBitmapHandler.cpp b/client/CBitmapHandler.cpp index d2892fe75..92f83e795 100644 --- a/client/CBitmapHandler.cpp +++ b/client/CBitmapHandler.cpp @@ -22,24 +22,6 @@ int readNormalNr (int pos, int bytCon, const unsigned char * str); extern DLL_EXPORT CLodHandler *bitmaph; -void BMPHeader::print(std::ostream & out) -{ - CDefHandler::print(out,fullSize,4); - CDefHandler::print(out,_h1,4); - CDefHandler::print(out,_c1,4); - CDefHandler::print(out,_c2,4); - CDefHandler::print(out,x,4); - CDefHandler::print(out,y,4); - CDefHandler::print(out,_c3,2); - CDefHandler::print(out,_c4,2); - CDefHandler::print(out,_h2,4); - CDefHandler::print(out,_h3,4); - CDefHandler::print(out,dataSize1,4); - CDefHandler::print(out,dataSize2,4); - for (int i=0;i<8;i++) - out << _c5[i]; - out.flush(); -} void CPCXConv::openPCX(char * PCX, int len) { pcxs=len; @@ -57,11 +39,11 @@ void CPCXConv::fromFile(std::string path) is.close(); } -void CPCXConv::saveBMP(std::string path) +void CPCXConv::saveBMP(std::string path) const { std::ofstream os; os.open(path.c_str(), std::ios::binary); - os.write((char*)bmp,bmps); + os.write(reinterpret_cast(bmp), bmps); os.close(); } @@ -131,19 +113,14 @@ SDL_Surface * CPCXConv::getSurface() const tp.unused = 0; *(ret->format->palette->colors+i) = tp; } - for (y=height;y>0;y--) + for (y=height; y>0; --y) { - it=0xC+(y-1)*width; - for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * j) = pcx[it+j]; - } + it = 0xC + (y-1)*width; + memcpy((char*)ret->pixels + ret->pitch * (y-1), pcx + it, width); + if (add>0) { - for (int j=0;jpixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * (j+width)) = 0; - } + memset((char*)ret->pixels + ret->pitch * (y-1) + width, 0, add); } } } @@ -151,17 +128,13 @@ SDL_Surface * CPCXConv::getSurface() const { for (y=height; y>0; y--) { - it=0xC+(y-1)*width*3; - for (int j=0;jpixels + ret->pitch * (y-1) + j) = pcx[it+j]; - } + it = 0xC + (y-1)*width*3; + + memcpy((char*)ret->pixels + ret->pitch * (y-1), pcx + it, width*3); + if (add>0) { - for (int j=0;jpixels + ret->pitch * (y-1) + (j+width*3)) = 0; - } + memset((char*)ret->pixels + ret->pitch * (y-1) + width*3, 0, add*3); } } } diff --git a/client/CBitmapHandler.h b/client/CBitmapHandler.h index 6c38fbb29..c8683370e 100644 --- a/client/CBitmapHandler.h +++ b/client/CBitmapHandler.h @@ -24,27 +24,13 @@ struct BMPPalette unsigned char R,G,B,F; }; -struct BMPHeader -{ - int fullSize, _h1, _h2, _h3, _c1, _c2, _c3, _c4, x, y, - dataSize1, dataSize2; //DataSize=X*Y+2*Y - unsigned char _c5[8]; - void print(std::ostream & out); - BMPHeader() - { - _h1=_h2=0; - for(int i=0;i<8;i++) - _c5[i]=0; - } -}; - class CPCXConv { public: unsigned char * pcx, *bmp; int pcxs, bmps; void fromFile(std::string path); - void saveBMP(std::string path); + void saveBMP(std::string path) const; void openPCX(char * PCX, int len); SDL_Surface * getSurface() const; //for standard H3 PCX //SDL_Surface * getSurfaceZ(); //for ZSoft PCX diff --git a/client/CCursorHandler.cpp b/client/CCursorHandler.cpp index 366b24bc7..736d74c06 100644 --- a/client/CCursorHandler.cpp +++ b/client/CCursorHandler.cpp @@ -155,4 +155,13 @@ void CCursorHandler::shiftPos( int &x, int &y ) y -= 20; } } -} \ No newline at end of file +} + +CCursorHandler::~CCursorHandler() +{ + if(help) + SDL_FreeSurface(help); + + for(int g=0; g cursors; int xpos, ypos; //position of cursor - void initCursor(); //inits cursorHandler + void initCursor(); //inits cursorHandler - run only once, it's not memleak-proof (rev 1333) void cursorMove(const int & x, const int & y); //change cursor's positions to (x, y) void changeGraphic(const int & type, const int & no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3) void draw1(); @@ -34,6 +34,7 @@ public: void draw2(); void hide(){Show=0;}; void show(){Show=1;}; + ~CCursorHandler(); }; diff --git a/hch/CDefHandler.cpp b/hch/CDefHandler.cpp index c6d3268d9..55aeaba86 100644 --- a/hch/CDefHandler.cpp +++ b/hch/CDefHandler.cpp @@ -77,7 +77,7 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name) DEFType = SDL_SwapLE32(de.DEFType); width = SDL_SwapLE32(de.width); height = SDL_SwapLE32(de.height); - totalBlocks = SDL_SwapLE32(de.totalBlocks); + unsigned int totalBlocks = SDL_SwapLE32(de.totalBlocks); for (unsigned int it=0;it<256;it++) { @@ -91,7 +91,7 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name) p = reinterpret_cast(&de); p += sizeof(de); - totalEntries=0; + int totalEntries=0; for (unsigned int z=0; z(p); @@ -139,27 +139,6 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name) } } -unsigned char * CDefHandler::writeNormalNr (int nr, int bytCon) -{ - //int tralalalatoniedziala = 2*9+100-4*bytCon; - //unsigned char * ret = new unsigned char[bytCon]; - unsigned char * ret = NULL; - for(int jj=0; jj<100; ++jj) - { - ret = (unsigned char*)calloc(1, bytCon); - if(ret!=NULL) - break; - } - long long amp = pow((long long int)256,bytCon-1); - for (int i=bytCon-1; i>=0;i--) - { - int test2 = nr/(amp); - ret[i]=test2; - nr -= (nr/(amp))*amp; - amp/=256; - } - return ret; -} void CDefHandler::expand(unsigned char N,unsigned char & BL, unsigned char & BR) { BL = (N & 0xE0) >> 5; @@ -191,15 +170,8 @@ int CDefHandler::readNormalNr (int pos, int bytCon, const unsigned char * str, b } return ret; } -void CDefHandler::print (std::ostream & stream, int nr, int bytcon) -{ - unsigned char * temp = writeNormalNr(nr,bytcon); - for (int i=0;i(FDef + BaseOffset); + SSpriteDef sd = * reinterpret_cast(FDef + BaseOffset); prSize = SDL_SwapLE32(sd.prSize); //TODO use me defType2 = SDL_SwapLE32(sd.defType2); @@ -261,7 +233,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet // If there's a margin anywhere, just blank out the whole surface. if (TopMargin > 0 || BottomMargin > 0 || LeftMargin > 0 || RightMargin > 0) { - memset(((char *)ret->pixels), 0, FullHeight*FullWidth); + memset( reinterpret_cast(ret->pixels), 0, FullHeight*FullWidth); } // Skip top margin @@ -277,7 +249,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet if (LeftMargin>0) ftcp += LeftMargin; - memcpy((char*)(ret->pixels)+ftcp, &FDef[BaseOffset], SpriteWidth); + memcpy(reinterpret_cast(ret->pixels)+ftcp, &FDef[BaseOffset], SpriteWidth); ftcp += SpriteWidth; BaseOffset += SpriteWidth; @@ -289,7 +261,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet case 1: { - unsigned int * RWEntriesLoc = reinterpret_cast(FDef+BaseOffset); + const unsigned int * RWEntriesLoc = reinterpret_cast(FDef+BaseOffset); BaseOffset += sizeof(int) * SpriteHeight; for (unsigned int i=0;ipixels))[ftcp++]=FDef[BaseOffset+k]; + (reinterpret_cast(ret->pixels))[ftcp++]=FDef[BaseOffset+k]; if ((TotalRowLength+k)>=SpriteWidth) break; } @@ -318,7 +290,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet } else { - memset((char*)(ret->pixels)+ftcp, SegmentType, SegmentLength); + memset(reinterpret_cast(ret->pixels)+ftcp, SegmentType, SegmentLength); ftcp += SegmentLength; TotalRowLength += SegmentLength; } @@ -337,11 +309,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet case 2: { - /*for (int i=0;i( FDef + BaseOffsetor ); //was + RWEntries[0]; for (unsigned int i=0;ipixels)+ftcp, &FDef[BaseOffset], value); + memcpy(reinterpret_cast(ret->pixels)+ftcp, &FDef[BaseOffset], value); ftcp += value; BaseOffset += value; } else { - memset((char*)(ret->pixels)+ftcp, code, value); + memset(reinterpret_cast(ret->pixels)+ftcp, code, value); ftcp += value; } TotalRowLength+=value; @@ -382,10 +350,6 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef, BMPPalet case 3: { - /*for (int i=0;i ourImages; bool alphaTransformed; bool notFreeImgs; CDefHandler(); //c-tor ~CDefHandler(); //d-tor - static void print (std::ostream & stream, int nr, int bytcon); static int readNormalNr (int pos, int bytCon, const unsigned char * str=NULL, bool cyclic=false); - static unsigned char *writeNormalNr (int nr, int bytCon); - SDL_Surface * getSprite (int SIndex, unsigned char * FDef, BMPPalette * palette); //zapisuje klatke o zadanym numerze do "testtt.bmp" + SDL_Surface * getSprite (int SIndex, const unsigned char * FDef, const BMPPalette * palette) const; //zapisuje klatke o zadanym numerze do "testtt.bmp" void openDef(std::string name); - void expand(unsigned char N,unsigned char & BL, unsigned char & BR); + static void expand(unsigned char N,unsigned char & BL, unsigned char & BR); void openFromMemory(unsigned char * table, std::string name); CDefEssential * essentialize(); diff --git a/hch/CLodHandler.cpp b/hch/CLodHandler.cpp index 9352027ff..ab423f190 100644 --- a/hch/CLodHandler.cpp +++ b/hch/CLodHandler.cpp @@ -98,82 +98,6 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length) return NULL; } -int CLodHandler::infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits) -{ - int ret; - unsigned have; - z_stream strm; - unsigned char inx[NLoadHandlerHelp::fCHUNK]; - unsigned char outx[NLoadHandlerHelp::fCHUNK]; - - /* allocate inflate state */ - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, wBits); - if (ret != Z_OK) - return ret; - int chunkNumber = 0; - do - { - int readBytes = 0; - for(int i=0; i(outp), len); + out.close(); } } @@ -368,10 +260,7 @@ std::string CLodHandler::getTextFile(std::string name) exit(1); } - std::string ret; - ret.reserve(length); - for(int i=0;i