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

* leading files from Data/ instead of h3bitmap.lod when possible (as in OH3)

* minor improvements
This commit is contained in:
Michał W. Urbańczyk 2008-02-05 07:21:09 +00:00
parent fe5bcc19cf
commit c9cfdacbc5
3 changed files with 86 additions and 51 deletions

22
CMT.cpp
View File

@ -48,6 +48,9 @@
#include "CLua.h"
#include "CAdvmapInterface.h"
#include "CCastleInterface.h"
#include "boost/filesystem/operations.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
@ -338,7 +341,7 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->consoleh = new CConsoleHandler;
cgi->mush = mush;
cgi->curh = new CCursorHandler;
THC std::cout<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl;
cgi->spriteh = new CLodHandler;
cgi->spriteh->init(std::string("Data\\H3sprite.lod"));
@ -346,6 +349,23 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->bitmaph->init(std::string("Data\\H3bitmap.lod"));
THC std::cout<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
boost::filesystem::directory_iterator enddir;
for (boost::filesystem::directory_iterator dir("Data");dir!=enddir;dir++)
{
if(boost::filesystem::is_regular(dir->status()))
{
std::string name = dir->path().leaf();
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
boost::algorithm::replace_all(name,".BMP",".PCX");
Entry * e = cgi->bitmaph->entries.znajdz(name);
if(e)
{
e->offset = -1;
e->realSize = e->size = boost::filesystem::file_size(dir->path());
}
}
}
THC std::cout<<"Scanning Data/: "<<tmh.getDif()<<std::endl;
cgi->curh->initCursor();
cgi->curh->showGraphicCursor();

View File

@ -259,32 +259,29 @@ SDL_Surface * CLodHandler::loadBitmap(std::string fname)
unsigned char * pcx;
std::transform(fname.begin(),fname.end(),fname.begin(),toupper);
fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".PCX");
int index=-1;
for (int i=0;i<entries.size();i++)
{
std::string buf1 = std::string((char*)entries[i].name);
if(buf1==fname)
{
index=i;
break;
}
}
if(index==-1)
Entry *e = entries.znajdz(fname);
if(!e)
{
std::cout<<"File "<<fname<<" not found"<<std::endl;
return NULL;
}
fseek(FLOD, entries[index].offset, 0);
if (entries[index].size==0) //file is not compressed
if(e->offset<0)
{
pcx = new unsigned char[entries[index].realSize];
fread((char*)pcx, 1, entries[index].realSize, FLOD);
fname.replace(fname.find_first_of('.'),fname.find_first_of('.')+4,".BMP");
fname = "Data/"+fname;
return SDL_LoadBMP(fname.c_str());
}
fseek(FLOD, e->offset, 0);
if (e->size==0) //file is not compressed
{
pcx = new unsigned char[e->realSize];
fread((char*)pcx, 1, e->realSize, FLOD);
}
else
{
unsigned char * pcd = new unsigned char[entries[index].size];
fread((char*)pcd, 1, entries[index].size, FLOD);
int res=infs2(pcd,entries[index].size,entries[index].realSize,pcx);
unsigned char * pcd = new unsigned char[e->size];
fread((char*)pcd, 1, e->size, FLOD);
int res=infs2(pcd,e->size,e->realSize,pcx);
if(res!=0)
{
std::cout<<"an error "<<res<<" occured while extracting file "<<fname<<std::endl;
@ -292,7 +289,7 @@ SDL_Surface * CLodHandler::loadBitmap(std::string fname)
delete [] pcd;
}
CPCXConv cp;
cp.openPCX((char*)pcx,entries[index].realSize);
cp.openPCX((char*)pcx,e->realSize);
return cp.getSurface();
}
@ -845,38 +842,50 @@ std::string CLodHandler::getTextFile(std::string name)
{
std::string ret0;
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
int i;
Entry *e;
for (int i=0;i<totalFiles;i++)
{
std::string buf1 = std::string((char*)entries[i].name);
bool exists = false;
int curDef;
if(buf1!=name)
continue;
fseek(FLOD, entries[i].offset, 0);
unsigned char * outp;
if (entries[i].size==0) //file is not compressed
{
outp = new unsigned char[entries[i].realSize];
fread((char*)outp, 1, entries[i].realSize, FLOD);
std::string ret = std::string((char*)outp);
delete[] outp;
return ret;
}
else //we will decompressing file
{
outp = new unsigned char[entries[i].size];
fread((char*)outp, 1, entries[i].size, FLOD);
fseek(FLOD, 0, 0);
unsigned char * decomp = NULL;
int decRes = infs2(outp, entries[i].size, entries[i].realSize, decomp);
std::string ret;
for (int itr=0;itr<entries[i].realSize;itr++)
ret+= *((char*)decomp+itr);
delete[] outp;
delete[] decomp;
return ret;
}
e = entries.znajdz(name);
}
if(!e)
return ret0;
if(e->offset<0)
{
char * outp = new char[e->realSize];
char name[120];for(int i=0;i<120;i++) name[i]='\0';
strcat(name,"Data/");
strcat(name,(char*)e->name);
FILE * f = fopen(name,"rb");
int result = fread(outp,1,e->realSize,f);
if(result<0) {std::cout<<"Error in file reading: "<<name<<std::endl;return ret0;}
for (int itr=0;itr<e->realSize;itr++)
ret0+= *(outp+itr);
delete[] outp;
return ret0;
}
fseek(FLOD, e->offset, 0);
unsigned char * outp;
if (e->size==0) //file is not compressed
{
outp = new unsigned char[e->realSize];
fread((char*)outp, 1, e->realSize, FLOD);
std::string ret = std::string((char*)outp);
delete[] outp;
return ret;
}
else //we will decompressing file
{
outp = new unsigned char[e->size];
fread((char*)outp, 1, e->size, FLOD);
fseek(FLOD, 0, 0);
unsigned char * decomp = NULL;
int decRes = infs2(outp, e->size, e->realSize, decomp);
std::string ret;
for (int itr=0;itr<e->realSize;itr++)
ret+= *((char*)decomp+itr);
delete[] outp;
delete[] decomp;
return ret;
}
return ret0;
}

View File

@ -76,6 +76,7 @@ public:
nodrze():ile(0) //najzwyczajniejszy w swiecie kosntruktor // c-tor
{
NIL=new wezel<T>(CZARNY);
NIL->zawart=NULL;
korzen=NIL;
ostatnio=NIL;
ktory=0;
@ -678,7 +679,12 @@ template <typename T> void nodrze<T>::dodajRBT (wezel<T> * nowy)
{
//CLOG("Dodaje do drzewa "<<nowy->zawart<<std::endl);
ile++;
if ((*nowy->zawart) < (*ostatnio->zawart))
if(ostatnio==NIL)
{
ostatnio = nowy;
ktory=0;
}
else if ((*nowy->zawart) < (*ostatnio->zawart))
{
ktory++;
}