1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00

less bugs and works faster

This commit is contained in:
mateuszb 2007-07-12 11:41:31 +00:00
parent 91a6f3cc6c
commit 217e98e345
8 changed files with 98 additions and 52 deletions

View File

@ -1757,13 +1757,13 @@ void CAmbarCendamo::loadDefs()
{ {
if (loadedTypes.find(map.terrain[i][j].tertype)==loadedTypes.end()) 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); loadedTypes.insert(map.terrain[i][j].tertype);
defs.push_back(sdh); defs.push_back(sdh);
} }
if (map.twoLevel && loadedTypes.find(map.undergroungTerrain[i][j].tertype)==loadedTypes.end()) 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); loadedTypes.insert(map.undergroungTerrain[i][j].tertype);
defs.push_back(sdh); defs.push_back(sdh);
} }

View File

@ -21,7 +21,7 @@ public:
std::ifstream * is; // stream used to read map file std::ifstream * is; // stream used to read map file
int andame; // length of map file int andame; // length of map file
unsigned char * bufor; // here we store map bytecode unsigned char * bufor; // here we store map bytecode
std::vector<CSemiDefHandler*> defs; std::vector<CDefHandler*> defs;
/////////////////funkcje skladowe /////////////////funkcje skladowe
CAmbarCendamo (const char * tie); // c-tor; tie is the path of the map file 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 CAmbarCendamo (unsigned char * map); // c-tor; map is pointer to array containing map; it is not copied, so don't delete

Binary file not shown.

View File

@ -163,22 +163,23 @@ void CPCXConv::convert()
SDL_Surface * CPCXConv::getSurface() SDL_Surface * CPCXConv::getSurface()
{ {
SDL_Surface * ret; SDL_Surface * ret;
BMPHeader bh; BMPHeader bh;
BMPPalette pal[256]; BMPPalette pal[256];
Epcxformat format; Epcxformat format;
int fSize, maxx, maxy,i,y; int fSize,i,y;
bool check1, check2; bool check1, check2;
unsigned char add; unsigned char add;
int it=0; int it=0;
fSize = readNormalNr(it,4,pcx);it+=4; fSize = readNormalNr(it,4,pcx);it+=4;
maxx = readNormalNr(it,4,pcx);it+=4; bh.x = readNormalNr(it,4,pcx);it+=4;
maxy = readNormalNr(it,4,pcx);it+=4; bh.y = readNormalNr(it,4,pcx);it+=4;
if (fSize==maxx*maxy*3) if (fSize==bh.x*bh.y*3)
check1=true; check1=true;
else else
check1=false; check1=false;
if (fSize==maxx*maxy) if (fSize==bh.x*bh.y)
check2=true; check2=true;
else else
check2=false; check2=false;
@ -188,9 +189,41 @@ SDL_Surface * CPCXConv::getSurface()
format=Epcxformat::PCX8B; format=Epcxformat::PCX8B;
else else
return NULL; return NULL;
add=(int)(4*(((float)1)-(((float)maxx/(float)4)-((int)((float)maxx/(float)4))))); add = 4 - bh.x%4;
if (add==4) if (add==4)
add=0; 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) if (format==Epcxformat::PCX8B)
{ {
it = pcxs-256*3; it = pcxs-256*3;
@ -202,50 +235,53 @@ SDL_Surface * CPCXConv::getSurface()
pal[i].F='\0'; 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) if (format==Epcxformat::PCX8B)
{ {
for(int i=0; i<256; ++i) for(int i=0; i<256; ++i)
{ {
SDL_Color pr; SDL_Color tp;
pr.r = pal[i].R; tp.r = pal[i].R;
pr.g = pal[i].G; tp.g = pal[i].G;
pr.b = pal[i].B; tp.b = pal[i].B;
pr.unused = pal[i].F; tp.unused = pal[i].F;
(*(ret->format->palette->colors+i)) = pr; *(ret->format->palette->colors+i) = tp;
} }
for(y=maxy; y>0; --y) for (y=bh.y;y>0;y--)
{ {
it = 0xc + (y-1)*maxx; it=0xC+(y-1)*bh.x;
for(int j=0; j<maxx; ++j) for (int j=0;j<bh.x;j++)
*((char*)ret->pixels + ret->format->BytesPerPixel * (y*(maxx+add) + j)) = pcx[it+j]; {
for(int j=0; j<add; ++j) //out<<pcx[it+j];
*((char*)ret->pixels + ret->format->BytesPerPixel * (y*(maxx+add) + maxx + j)) = 0; *((char*)ret->pixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * j) = pcx[it+j];
}
if (add>0)
{
for (int j=0;j<add;j++)
{
//out<<'\0'; //bylo z buforu, ale onnie byl incjalizowany (?!)
*((char*)ret->pixels + ret->pitch * (y-1) + ret->format->BytesPerPixel * (j+bh.x)) = 0;
}
}
} }
} }
else else
{ {
for(int y=maxy; y>0; --y) for (y=bh.y; y>0; y--)
{ {
it = 0xc + (y-1)*maxx*3; it=0xC+(y-1)*bh.x*3;
for(int j=0; j<maxx*3; ++j) for (int j=0;j<bh.x*3;j++)
{ {
*((char*)ret->pixels + (y*(maxx+add) + j)) = pcx[it+j]; //out<<pcx[it+j];
*((char*)ret->pixels + ret->pitch * (y-1) + j) = pcx[it+j];
} }
for(int j=0; j<add*3; ++j) if (add>0)
{ {
*((char*)ret->pixels + (y*(maxx+add) + j)) = 0; for (int j=0;j<add*3;j++)
{
//out<<'\0'; //bylo z buforu, ale onnie byl incjalizowany (?!)
*((char*)ret->pixels + 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]; unsigned char * pcd = new unsigned char[entries[index].size];
FLOD.read((char*)pcd,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 "<<res<<" ocured during extracting file "<<fname<<std::endl;
}
} }
CPCXConv cp; CPCXConv cp;
cp.openPCX((char*)pcx,entries[index].realSize); cp.openPCX((char*)pcx,entries[index].realSize);
cp.convert(); //cp.convert();
cp.saveBMP("vctemp.bmp"); //cp.saveBMP("vctemp.bmp");
SDL_Surface * ret = SDL_LoadBMP("vctemp.bmp"); //SDL_Surface * ret = SDL_LoadBMP("vctemp.bmp");
boost::filesystem::path p("vctemp.bmp"); //boost::filesystem::path p("vctemp.bmp");
boost::filesystem::remove(p); //boost::filesystem::remove(p);
//return cp.getSurface(); return cp.getSurface();
return ret; //return ret;
} }
int CLodHandler::decompress (unsigned char * source, int size, int realSize, std::string & dest) int CLodHandler::decompress (unsigned char * source, int size, int realSize, std::string & dest)
@ -383,14 +423,13 @@ std::vector<CDefHandler *> CLodHandler::extractManyFiles(std::vector<std::string
{ {
std::transform(defNamesIn[hh].begin(), defNamesIn[hh].end(), defNamesIn[hh].begin(), (int(*)(int))toupper); std::transform(defNamesIn[hh].begin(), defNamesIn[hh].end(), defNamesIn[hh].begin(), (int(*)(int))toupper);
} }
std::ofstream FOut;
int i; int i;
std::vector<char> found(defNamesIn.size(), 0); std::vector<char> found(defNamesIn.size(), 0);
for (int i=0;i<totalFiles;i++) for (int i=0;i<totalFiles;i++)
{ {
//std::cout<<'\r'<<"Reading defs: "<<(100.0*i)/((float)(totalFiles))<<"% "; //std::cout<<'\r'<<"Reading defs: "<<(100.0*i)/((float)(totalFiles))<<"% ";
std::string buf1 = std::string((char*)entries[i].name); std::string buf1 = std::string((char*)entries[i].name);
std::transform(buf1.begin(), buf1.end(), buf1.begin(), (int(*)(int))toupper); //std::transform(buf1.begin(), buf1.end(), buf1.begin(), (int(*)(int))toupper);
bool exists = false; bool exists = false;
int curDef; int curDef;
for(int hh=0; hh<defNamesIn.size(); ++hh) for(int hh=0; hh<defNamesIn.size(); ++hh)
@ -406,7 +445,6 @@ std::vector<CDefHandler *> CLodHandler::extractManyFiles(std::vector<std::string
if(!exists) if(!exists)
continue; continue;
FLOD.seekg(entries[i].offset,std::ios_base::beg); FLOD.seekg(entries[i].offset,std::ios_base::beg);
//std::string bufff = (lodName.substr(0, lodName.size()-4) + "\\" + (char*)entries[i].name);
unsigned char * outp; unsigned char * outp;
if (entries[i].size==0) //file is not compressed if (entries[i].size==0) //file is not compressed
{ {
@ -415,7 +453,6 @@ std::vector<CDefHandler *> CLodHandler::extractManyFiles(std::vector<std::string
CDefHandler * nh = new CDefHandler; CDefHandler * nh = new CDefHandler;
nh->openFromMemory(outp, entries[i].realSize, std::string((char*)entries[i].name)); nh->openFromMemory(outp, entries[i].realSize, std::string((char*)entries[i].name));
ret[curDef] = nh; ret[curDef] = nh;
} }
else //we will decompressing file else //we will decompressing file
{ {

View File

@ -4,6 +4,7 @@
#include "CSemiDefHandler.h" #include "CSemiDefHandler.h"
#include "CDefHandler.h" #include "CDefHandler.h"
#include "CGameInfo.h" #include "CGameInfo.h"
#include "SDL_Extensions.h"
#define CGI (CGameInfo::mainObj) #define CGI (CGameInfo::mainObj)
SDL_Color tytulowy, tlo, zwykly ; SDL_Color tytulowy, tlo, zwykly ;
@ -31,7 +32,9 @@ SDL_Surface * CMessage::drawBox1(int w, int h)
{ {
for (int j=0; j<w; j+=background->w-1) for (int j=0; j<w; j+=background->w-1)
SDL_BlitSurface(background,&genRect(background->h,background->w-1,1,0),ret,&genRect(h,w,j,i)); 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 //obwodka I-szego rzedu pozioma
for (int i=0; i<w; i+=piecesOfBox->ourImages[6].bitmap->w) for (int i=0; i<w; i+=piecesOfBox->ourImages[6].bitmap->w)
{ {

Binary file not shown.

View File

@ -432,3 +432,8 @@ Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
ret+=color->r; ret+=color->r;
return ret; return ret;
} }
void CSDL_Ext::update(SDL_Surface * what)
{
SDL_UpdateRect(what, 0, 0, what->w, what->h);
}

View File

@ -21,6 +21,7 @@ namespace CSDL_Ext
Uint32 colorToUint32(const SDL_Color * color); //little endian only 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 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 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 #endif // SDL_EXTENSIONS_H