1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-23 12:08:45 +02:00

gcc fixes(bad idea to call global vars such as log2, this name used by math function). Colored log support on some non-win32 platforms. Small Automake project update

This commit is contained in:
Vadim Glazunov 2008-09-18 20:24:53 +00:00
parent 5ee37eeb3d
commit a1dd7f22f9
16 changed files with 227 additions and 179 deletions

View File

@ -17,16 +17,16 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "boost/function.hpp" #include "boost/function.hpp"
#include <boost/thread.hpp> #include <boost/thread.hpp>
#ifdef _MSC_VER
#ifdef _WIN32
#include <windows.h> #include <windows.h>
HANDLE handleIn; HANDLE handleIn;
HANDLE handleOut; HANDLE handleOut;
WORD defColor;
#endif #endif
WORD defColor;
void CConsoleHandler::setColor(int level) void CConsoleHandler::setColor(int level)
{ {
#ifdef _MSC_VER
WORD color; WORD color;
switch(level) switch(level)
{ {
@ -34,28 +34,55 @@ void CConsoleHandler::setColor(int level)
color = defColor; color = defColor;
break; break;
case 0: case 0:
#ifdef _WIN32
color = FOREGROUND_GREEN | FOREGROUND_INTENSITY; color = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
#else
color = "\x1b[1;40;32m";
#endif
break; break;
case 1: case 1:
#ifdef _WIN32
color = FOREGROUND_RED | FOREGROUND_INTENSITY; color = FOREGROUND_RED | FOREGROUND_INTENSITY;
#else
color = "\x1b[1;40;31m";
#endif
break; break;
case 2: case 2:
#ifdef _WIN32
color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
#else
color = "\x1b[1;40;35m";
#endif
break; break;
case 3: case 3:
#ifdef _WIN32
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
#else
color = "\x1b[1;40;32m";
#endif
break; break;
case 4: case 4:
#ifdef _WIN32
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
#else
color = "\x1b[1;40;39m";
#endif
break; break;
case 5: case 5:
#ifdef _WIN32
color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
#else
color = "\x1b[0;40;39m";
#endif
break; break;
default: default:
color = defColor; color = defColor;
break; break;
} }
#ifdef _WIN32
SetConsoleTextAttribute(handleOut,color); SetConsoleTextAttribute(handleOut,color);
#else
std::cout << color;
#endif #endif
} }
@ -73,12 +100,14 @@ int CConsoleHandler::run()
} }
CConsoleHandler::CConsoleHandler() CConsoleHandler::CConsoleHandler()
{ {
#ifdef _MSC_VER #ifdef _WIN32
handleIn = GetStdHandle(STD_INPUT_HANDLE); handleIn = GetStdHandle(STD_INPUT_HANDLE);
handleOut = GetStdHandle(STD_OUTPUT_HANDLE); handleOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi; CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(handleOut,&csbi); GetConsoleScreenBufferInfo(handleOut,&csbi);
defColor = csbi.wAttributes; defColor = csbi.wAttributes;
#else
defColor = "\x1b[0m";
#endif #endif
cb = new boost::function<void(const std::string &)>; cb = new boost::function<void(const std::string &)>;
} }
@ -86,11 +115,13 @@ CConsoleHandler::~CConsoleHandler()
{ {
delete cb; delete cb;
} }
#ifndef _WIN32
void CConsoleHandler::killConsole(pthread_t hThread)
#else
void CConsoleHandler::killConsole(void *hThread) void CConsoleHandler::killConsole(void *hThread)
{
#ifdef _MSC_VER
log3 << "Killing console... ";
TerminateThread(hThread,0);
log3 << "done!\n";
#endif #endif
{
_log3 << "Killing console... ";
_kill_thread(hThread,0);
_log3 << "done!\n";
} }

View File

@ -1,5 +1,16 @@
#ifndef CCONSOLEHANDLER_H #ifndef CCONSOLEHANDLER_H
#define CCONSOLEHANDLER_H #define CCONSOLEHANDLER_H
#ifndef _WIN32
#define WORD std::string
#endif
#ifndef _WIN32
#define _kill_thread(a,b) pthread_cancel(a);
#else
#define _kill_thread(a,b) TerminateThread(a,b);
#endif
namespace boost namespace boost
{ {
template<typename signature> template<typename signature>
@ -14,7 +25,11 @@ public:
void setColor(int level); void setColor(int level);
CConsoleHandler(); CConsoleHandler();
~CConsoleHandler(); ~CConsoleHandler();
#ifndef _WIN32
static void killConsole(pthread_t hThread); //for windows only, use native handle to the thread
#else
static void killConsole(void *hThread); //for windows only, use native handle to the thread static void killConsole(void *hThread); //for windows only, use native handle to the thread
#endif
template<typename T> void print(const T &data, int level) template<typename T> void print(const T &data, int level)
{ {
setColor(level); setColor(level);

88
CMT.cpp
View File

@ -51,14 +51,14 @@ extern SDL_Surface * CSDL_Ext::std32bppSurface;
std::queue<SDL_Event> events; std::queue<SDL_Event> events;
boost::mutex eventsM; boost::mutex eventsM;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
CLogger<0> log0; extern CLogger<0> _log0;
CLogger<1> log1; extern CLogger<1> _log1;
CLogger<2> log2; extern CLogger<2> _log2;
CLogger<3> log3; extern CLogger<3> _log3;
CLogger<4> log4; extern CLogger<4> _log4;
CLogger<5> log5; extern CLogger<5> _log5;
CConsoleHandler *console = NULL; extern CConsoleHandler *console;// = NULL;
std::ostream *logfile = NULL; extern std::ostream *logfile;// = NULL;
namespace intpr = boost::interprocess; namespace intpr = boost::interprocess;
void processCommand(const std::string &message); void processCommand(const std::string &message);
#ifndef __GNUC__ #ifndef __GNUC__
@ -79,7 +79,7 @@ int main(int argc, char** argv)
*::console->cb = &processCommand; *::console->cb = &processCommand;
console = new boost::thread(boost::bind(&CConsoleHandler::run,::console)); console = new boost::thread(boost::bind(&CConsoleHandler::run,::console));
} }
log0 << "\tConsole and logifle ready!" << std::endl; _log0 << "\tConsole and logifle ready!" << std::endl;
int port; int port;
if(argc > 1) if(argc > 1)
{ {
@ -92,10 +92,10 @@ int main(int argc, char** argv)
else else
{ {
port = 3030; port = 3030;
log0 << "Port " << port << " will be used." << std::endl; _log0 << "Port " << port << " will be used." << std::endl;
} }
std::cout.flags(ios::unitbuf); std::cout.flags(ios::unitbuf);
log0 << NAME << std::endl; _log0 << NAME << std::endl;
srand ( time(NULL) ); srand ( time(NULL) );
CPG=NULL; CPG=NULL;
atexit(SDL_Quit); atexit(SDL_Quit);
@ -104,13 +104,13 @@ int main(int argc, char** argv)
//luatest.test(); //luatest.test();
//CBIKHandler cb; //CBIKHandler cb;
//cb.open("CSECRET.BIK"); //cb.open("CSECRET.BIK");
log0 << "Starting... " << std::endl; _log0 << "Starting... " << std::endl;
THC timeHandler tmh, total, pomtime; THC timeHandler tmh, total, pomtime;
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO)==0) if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO)==0)
{ {
screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface
log0 <<"\tInitializing screen: "<<pomtime.getDif(); _log0 <<"\tInitializing screen: "<<pomtime.getDif();
log0 << std::endl; _log0 << std::endl;
SDL_WM_SetCaption(NAME.c_str(),""); //set window title SDL_WM_SetCaption(NAME.c_str(),""); //set window title
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff; int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff;
@ -118,7 +118,7 @@ int main(int argc, char** argv)
int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000; int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000;
#endif #endif
CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask); CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask);
log0 << "\tInitializing minors: " << pomtime.getDif() << std::endl; _log0 << "\tInitializing minors: " << pomtime.getDif() << std::endl;
TTF_Init(); TTF_Init();
TNRB16 = TTF_OpenFont("Fonts" PATHSEPARATOR "tnrb.ttf",16); TNRB16 = TTF_OpenFont("Fonts" PATHSEPARATOR "tnrb.ttf",16);
GEOR13 = TTF_OpenFont("Fonts" PATHSEPARATOR "georgia.ttf",13); GEOR13 = TTF_OpenFont("Fonts" PATHSEPARATOR "georgia.ttf",13);
@ -126,18 +126,18 @@ int main(int argc, char** argv)
GEORXX = TTF_OpenFont("Fonts" PATHSEPARATOR "tnrb.ttf",22); GEORXX = TTF_OpenFont("Fonts" PATHSEPARATOR "tnrb.ttf",22);
GEORM = TTF_OpenFont("Fonts" PATHSEPARATOR "georgia.ttf",10); GEORM = TTF_OpenFont("Fonts" PATHSEPARATOR "georgia.ttf",10);
atexit(TTF_Quit); atexit(TTF_Quit);
THC log0<<"\tInitializing fonts: "<<pomtime.getDif()<<std::endl; THC _log0<<"\tInitializing fonts: "<<pomtime.getDif()<<std::endl;
CMusicHandler * mush = new CMusicHandler; //initializing audio CMusicHandler * mush = new CMusicHandler; //initializing audio
mush->initMusics(); mush->initMusics();
//audio initialized //audio initialized
cgi->mush = mush; cgi->mush = mush;
THC log0<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl; THC _log0<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl;
THC log0<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl; THC _log0<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl;
CDefHandler::Spriteh = cgi->spriteh = new CLodHandler(); CDefHandler::Spriteh = cgi->spriteh = new CLodHandler();
cgi->spriteh->init("Data" PATHSEPARATOR "H3sprite.lod","Sprites"); cgi->spriteh->init("Data" PATHSEPARATOR "H3sprite.lod","Sprites");
BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler; BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler;
cgi->bitmaph->init("Data" PATHSEPARATOR "H3bitmap.lod","Data"); cgi->bitmaph->init("Data" PATHSEPARATOR "H3bitmap.lod","Data");
THC log0<<"Loading .lod files: "<<tmh.getDif()<<std::endl; THC _log0<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
initDLL(cgi->bitmaph,::console,logfile); initDLL(cgi->bitmaph,::console,logfile);
CGI->arth = VLC->arth; CGI->arth = VLC->arth;
CGI->creh = VLC->creh; CGI->creh = VLC->creh;
@ -147,7 +147,7 @@ int main(int argc, char** argv)
CGI->spellh = VLC->spellh; CGI->spellh = VLC->spellh;
CGI->dobjinfo = VLC->dobjinfo; CGI->dobjinfo = VLC->dobjinfo;
CGI->buildh = VLC->buildh; CGI->buildh = VLC->buildh;
log0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl; _log0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
//cgi->curh->initCursor(); //cgi->curh->initCursor();
//cgi->curh->showGraphicCursor(); //cgi->curh->showGraphicCursor();
pomtime.getDif(); pomtime.getDif();
@ -155,28 +155,28 @@ int main(int argc, char** argv)
cgi->curh->initCursor(); cgi->curh->initCursor();
//cgi->screenh = new CScreenHandler; //cgi->screenh = new CScreenHandler;
//cgi->screenh->initScreen(); //cgi->screenh->initScreen();
log0<<"\tScreen handler: "<<pomtime.getDif()<<std::endl; _log0<<"\tScreen handler: "<<pomtime.getDif()<<std::endl;
CAbilityHandler * abilh = new CAbilityHandler; CAbilityHandler * abilh = new CAbilityHandler;
abilh->loadAbilities(); abilh->loadAbilities();
cgi->abilh = abilh; cgi->abilh = abilh;
log0<<"\tAbility handler: "<<pomtime.getDif()<<std::endl; _log0<<"\tAbility handler: "<<pomtime.getDif()<<std::endl;
log0<<"Preparing first handlers: "<<tmh.getDif()<<std::endl; _log0<<"Preparing first handlers: "<<tmh.getDif()<<std::endl;
pomtime.getDif(); pomtime.getDif();
graphics = new Graphics(); graphics = new Graphics();
log0<<"\tMain graphics: "<<tmh.getDif()<<std::endl; _log0<<"\tMain graphics: "<<tmh.getDif()<<std::endl;
std::vector<CDefHandler **> animacje; std::vector<CDefHandler **> animacje;
for(std::vector<CHeroClass *>::iterator i = cgi->heroh->heroClasses.begin();i!=cgi->heroh->heroClasses.end();i++) for(std::vector<CHeroClass *>::iterator i = cgi->heroh->heroClasses.begin();i!=cgi->heroh->heroClasses.end();i++)
animacje.push_back(&((*i)->*(&CHeroClass::moveAnim))); animacje.push_back(&((*i)->*(&CHeroClass::moveAnim)));
graphics->loadHeroAnim(animacje); graphics->loadHeroAnim(animacje);
log0<<"\tHero animations: "<<tmh.getDif()<<std::endl; _log0<<"\tHero animations: "<<tmh.getDif()<<std::endl;
log0<<"Initializing game graphics: "<<tmh.getDif()<<std::endl; _log0<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
CMessage::init(); CMessage::init();
cgi->generaltexth = new CGeneralTextHandler; cgi->generaltexth = new CGeneralTextHandler;
cgi->generaltexth->load(); cgi->generaltexth->load();
log0<<"Preparing more handlers: "<<tmh.getDif()<<std::endl; _log0<<"Preparing more handlers: "<<tmh.getDif()<<std::endl;
CPreGame * cpg = new CPreGame(); //main menu and submenus CPreGame * cpg = new CPreGame(); //main menu and submenus
log0<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl; _log0<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
log0<<"Initialization of VCMI (togeter): "<<total.getDif()<<std::endl; _log0<<"Initialization of VCMI (togeter): "<<total.getDif()<<std::endl;
cpg->mush = mush; cpg->mush = mush;
StartInfo *options = new StartInfo(cpg->runLoop()); StartInfo *options = new StartInfo(cpg->runLoop());
@ -189,17 +189,17 @@ int main(int argc, char** argv)
ServerReady *sr = new(mr.get_address())ServerReady(); ServerReady *sr = new(mr.get_address())ServerReady();
std::string comm = std::string(SERVER_NAME) + " " + portc + " > server_log.txt"; std::string comm = std::string(SERVER_NAME) + " " + portc + " > server_log.txt";
boost::thread servthr(boost::bind(system,comm.c_str())); //runs server executable; //TODO: will it work on non-windows platforms? boost::thread servthr(boost::bind(system,comm.c_str())); //runs server executable; //TODO: will it work on non-windows platforms?
log0<<"Preparing shared memory and starting server: "<<tmh.getDif()<<std::endl; _log0<<"Preparing shared memory and starting server: "<<tmh.getDif()<<std::endl;
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
tmh.getDif();pomtime.getDif();//reset timers tmh.getDif();pomtime.getDif();//reset timers
cgi->pathf = new CPathfinder(); cgi->pathf = new CPathfinder();
log0<<"\tPathfinder: "<<pomtime.getDif()<<std::endl; _log0<<"\tPathfinder: "<<pomtime.getDif()<<std::endl;
log0<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl; _log0<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl;
std::ofstream lll("client_log.txt"); std::ofstream lll("client_log.txt");
CConnection *c=NULL; CConnection *c=NULL;
//wait until server is ready //wait until server is ready
log0<<"Waiting for server... "; _log0<<"Waiting for server... ";
{ {
intpr::scoped_lock<intpr::interprocess_mutex> slock(sr->mutex); intpr::scoped_lock<intpr::interprocess_mutex> slock(sr->mutex);
while(!sr->ready) while(!sr->ready)
@ -208,21 +208,21 @@ int main(int argc, char** argv)
} }
} }
intpr::shared_memory_object::remove("vcmi_memory"); intpr::shared_memory_object::remove("vcmi_memory");
log0 << tmh.getDif()<<std::endl; _log0 << tmh.getDif()<<std::endl;
while(!c) while(!c)
{ {
try try
{ {
log0 << "Establishing connection...\n"; _log0 << "Establishing connection...\n";
c = new CConnection("127.0.0.1",portc,NAME,lll); c = new CConnection("127.0.0.1",portc,NAME,lll);
} }
catch(...) catch(...)
{ {
log1 << "\nCannot establish connection! Retrying within 2 seconds" <<std::endl; _log1 << "\nCannot establish connection! Retrying within 2 seconds" <<std::endl;
SDL_Delay(2000); SDL_Delay(2000);
} }
} }
THC log0<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl; THC _log0<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl;
CClient cl(c,options); CClient cl(c,options);
boost::thread t(boost::bind(&CClient::run,&cl)); boost::thread t(boost::bind(&CClient::run,&cl));
SDL_Event ev; SDL_Event ev;
@ -232,9 +232,11 @@ int main(int argc, char** argv)
if(ev.type==SDL_QUIT) if(ev.type==SDL_QUIT)
{ {
cl.close(); cl.close();
#ifndef __unix__
::console->killConsole(console->native_handle()); ::console->killConsole(console->native_handle());
#endif
SDL_Delay(750); SDL_Delay(750);
log0 << "Ending...\n"; _log0 << "Ending...\n";
exit(0); exit(0);
} }
eventsM.lock(); eventsM.lock();
@ -244,7 +246,7 @@ int main(int argc, char** argv)
} }
else else
{ {
log1<<"Something was wrong: "<<SDL_GetError()<<std::endl; _log1<<"Something was wrong: "<<SDL_GetError()<<std::endl;
return -1; return -1;
} }
} }
@ -282,10 +284,10 @@ void processCommand(const std::string &message)
else if(message=="get txt") else if(message=="get txt")
{ {
boost::filesystem::create_directory("Extracted_txts"); boost::filesystem::create_directory("Extracted_txts");
log0<<"Command accepted. Opening .lod file...\t"; _log0<<"Command accepted. Opening .lod file...\t";
CLodHandler * txth = new CLodHandler; CLodHandler * txth = new CLodHandler;
txth->init(std::string(DATA_DIR "Data" PATHSEPARATOR "H3bitmap.lod"),"data"); txth->init(std::string(DATA_DIR "Data" PATHSEPARATOR "H3bitmap.lod"),"data");
log0<<"done.\nScanning .lod file\n"; _log0<<"done.\nScanning .lod file\n";
int curp=0; int curp=0;
std::string pattern = ".TXT"; std::string pattern = ".TXT";
for(int i=0;i<txth->entries.size(); i++) for(int i=0;i<txth->entries.size(); i++)
@ -300,9 +302,9 @@ void processCommand(const std::string &message)
if(p2!=curp) if(p2!=curp)
{ {
curp = p2; curp = p2;
log0<<"\r"<<curp<<"%"; _log0<<"\r"<<curp<<"%";
} }
} }
log0<<"\rExtracting done :)\n"; _log0<<"\rExtracting done :)\n";
} }
} }

View File

@ -1009,7 +1009,7 @@ void MapSel::processMaps(std::vector<std::string> &pliczkiTemp, int &index)
else break; else break;
} }
gzclose(tempf); gzclose(tempf);
if(iii<50) {log3<<"\t\tWarning: corrupted map file: "<<pliczkiTemp[pom]<<std::endl; continue;} if(iii<50) {_log3<<"\t\tWarning: corrupted map file: "<<pliczkiTemp[pom]<<std::endl; continue;}
if (!sss[4]) continue; //nie ma graczy? mapa niegrywalna //ju¿ to kiedyœ komentowa³em- - to bzdura //tu calkiem pasuje... if (!sss[4]) continue; //nie ma graczy? mapa niegrywalna //ju¿ to kiedyœ komentowa³em- - to bzdura //tu calkiem pasuje...
CMapInfo mi(pliczkiTemp[pom],sss); CMapInfo mi(pliczkiTemp[pom],sss);
mx.lock(); mx.lock();
@ -1393,19 +1393,19 @@ CPreGame::CPreGame()
preth = new CPreGameTextHandler; preth = new CPreGameTextHandler;
preth->loadTexts(); preth->loadTexts();
CGI->preth=preth; CGI->preth=preth;
log0<<"\tCPreGame: loading txts: "<<tmh.getDif()<<std::endl; _log0<<"\tCPreGame: loading txts: "<<tmh.getDif()<<std::endl;
currentMessage=NULL; currentMessage=NULL;
behindCurMes=NULL; behindCurMes=NULL;
initMainMenu(); initMainMenu();
log0<<"\tCPreGame: main menu initialization: "<<tmh.getDif()<<std::endl; _log0<<"\tCPreGame: main menu initialization: "<<tmh.getDif()<<std::endl;
initNewMenu(); initNewMenu();
log0<<"\tCPreGame: newgame menu initialization: "<<tmh.getDif()<<std::endl; _log0<<"\tCPreGame: newgame menu initialization: "<<tmh.getDif()<<std::endl;
initScenSel(); initScenSel();
log0<<"\tCPreGame: scenario choice initialization: "<<tmh.getDif()<<std::endl; _log0<<"\tCPreGame: scenario choice initialization: "<<tmh.getDif()<<std::endl;
initOptions(); initOptions();
log0<<"\tCPreGame: scenario options initialization: "<<tmh.getDif()<<std::endl; _log0<<"\tCPreGame: scenario options initialization: "<<tmh.getDif()<<std::endl;
showMainMenu(); showMainMenu();
log0<<"\tCPreGame: displaying main menu: "<<tmh.getDif()<<std::endl; _log0<<"\tCPreGame: displaying main menu: "<<tmh.getDif()<<std::endl;
CPG=this; CPG=this;
playerName="Player"; playerName="Player";
} }

View File

@ -101,7 +101,7 @@ CClient::CClient(CConnection *con, StartInfo *si)
{ {
timeHandler tmh; timeHandler tmh;
CGI->state = new CGameState(); CGI->state = new CGameState();
log0 <<"\tGamestate: "<<tmh.getDif()<<std::endl; _log0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
CConnection &c(*con); CConnection &c(*con);
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
ui8 pom8; ui8 pom8;
@ -116,34 +116,34 @@ CClient::CClient(CConnection *con, StartInfo *si)
ui32 seed, sum; ui32 seed, sum;
std::string mapname; std::string mapname;
c >> mapname >> sum >> seed; c >> mapname >> sum >> seed;
log0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl; _log0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl;
Mapa * mapa = new Mapa(mapname); Mapa * mapa = new Mapa(mapname);
log0 <<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl; _log0 <<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl;
log0 << "\tServer checksum for "<<mapname <<": "<<sum << std::endl; _log0 << "\tServer checksum for "<<mapname <<": "<<sum << std::endl;
log0 << "\tOur checksum for the map: "<< mapa->checksum << std::endl; _log0 << "\tOur checksum for the map: "<< mapa->checksum << std::endl;
if(mapa->checksum != sum) if(mapa->checksum != sum)
{ {
log1 << "Wrong map checksum!!!" << std::endl; _log1 << "Wrong map checksum!!!" << std::endl;
#ifndef __GNUC__ #ifndef __GNUC__
throw std::exception("Wrong checksum"); throw std::exception("Wrong checksum");
#else #else
throw std::exception(); throw std::exception();
#endif #endif
} }
log0 << "\tUsing random seed: "<<seed << std::endl; _log0 << "\tUsing random seed: "<<seed << std::endl;
gs = CGI->state; gs = CGI->state;
gs->scenarioOps = si; gs->scenarioOps = si;
gs->init(si,mapa,seed); gs->init(si,mapa,seed);
CGI->mh = new CMapHandler(); CGI->mh = new CMapHandler();
log0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl; _log0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
CGI->mh->map = mapa; CGI->mh->map = mapa;
log0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl; _log0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
CGI->mh->init(); CGI->mh->init();
log0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl; _log0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
for (int i=0; i<CGI->state->scenarioOps->playerInfos.size();i++) //initializing interfaces for (int i=0; i<CGI->state->scenarioOps->playerInfos.size();i++) //initializing interfaces
{ {
@ -173,7 +173,7 @@ void CClient::process(int what)
{ {
ui8 player; ui8 player;
*serv >> player;//who? *serv >> player;//who?
log5 << "It's turn of "<<(unsigned)player<<" player."<<std::endl; _log5 << "It's turn of "<<(unsigned)player<<" player."<<std::endl;
boost::thread(boost::bind(&CGameInterface::yourTurn,playerint[player])); boost::thread(boost::bind(&CGameInterface::yourTurn,playerint[player]));
break; break;
} }
@ -181,16 +181,16 @@ void CClient::process(int what)
{ {
NewTurn n; NewTurn n;
*serv >> n; *serv >> n;
log5 << "New day: "<<(unsigned)n.day<<". Applying changes... "; _log5 << "New day: "<<(unsigned)n.day<<". Applying changes... ";
gs->apply(&n); gs->apply(&n);
log5 << "done!"<<std::endl; _log5 << "done!"<<std::endl;
break; break;
} }
case 102: //set resource amount case 102: //set resource amount
{ {
SetResource sr; SetResource sr;
*serv >> sr; *serv >> sr;
log5 << "Set amount of "<<CGI->objh->restypes[sr.resid] _log5 << "Set amount of "<<CGI->objh->restypes[sr.resid]
<< " of player "<<(unsigned)sr.player <<" to "<<sr.val<<std::endl; << " of player "<<(unsigned)sr.player <<" to "<<sr.val<<std::endl;
gs->apply(&sr); gs->apply(&sr);
playerint[sr.player]->receivedResource(sr.resid,sr.val); playerint[sr.player]->receivedResource(sr.resid,sr.val);
@ -211,7 +211,7 @@ void CClient::process(int what)
{ {
SetResources sr; SetResources sr;
*serv >> sr; *serv >> sr;
log5 << "Set amount of resources of player "<<(unsigned)sr.player<<std::endl; _log5 << "Set amount of resources of player "<<(unsigned)sr.player<<std::endl;
gs->apply(&sr); gs->apply(&sr);
playerint[sr.player]->receivedResource(-1,-1); playerint[sr.player]->receivedResource(-1,-1);
break; break;
@ -220,7 +220,7 @@ void CClient::process(int what)
{ {
SetPrimSkill sps; SetPrimSkill sps;
*serv >> sps; *serv >> sps;
log5 << "Changing hero primary skill"<<std::endl; _log5 << "Changing hero primary skill"<<std::endl;
gs->apply(&sps); gs->apply(&sps);
playerint[gs->getHero(sps.id)->tempOwner]->heroPrimarySkillChanged(gs->getHero(sps.id),sps.which,sps.val); playerint[gs->getHero(sps.id)->tempOwner]->heroPrimarySkillChanged(gs->getHero(sps.id),sps.which,sps.val);
break; break;
@ -229,7 +229,7 @@ void CClient::process(int what)
{ {
SetSecSkill sr; SetSecSkill sr;
*serv >> sr; *serv >> sr;
log5 << "Changing hero secondary skill"<<std::endl; _log5 << "Changing hero secondary skill"<<std::endl;
gs->apply(&sr); gs->apply(&sr);
//TODO? - maybe inform interfaces //TODO? - maybe inform interfaces
break; break;
@ -259,7 +259,7 @@ void CClient::process(int what)
{ {
ChangeSpells vc; ChangeSpells vc;
*serv >> vc; *serv >> vc;
log5 << "Changing spells of hero "<<vc.hid<<std::endl; _log5 << "Changing spells of hero "<<vc.hid<<std::endl;
gs->apply(&vc); gs->apply(&vc);
break; break;
} }
@ -273,7 +273,7 @@ void CClient::process(int what)
if(obj->ID == 34) if(obj->ID == 34)
{ {
CGHeroInstance *h = static_cast<CGHeroInstance*>(obj); CGHeroInstance *h = static_cast<CGHeroInstance*>(obj);
log5 << "Removing hero with id = "<<(unsigned)rh.id<<std::endl; _log5 << "Removing hero with id = "<<(unsigned)rh.id<<std::endl;
playerint[h->tempOwner]->heroKilled(h); playerint[h->tempOwner]->heroKilled(h);
} }
break; break;
@ -282,7 +282,7 @@ void CClient::process(int what)
{ {
TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing
*serv >> *th; *serv >> *th;
log5 << "HeroMove: id="<<th->id<<"\tResult: "<<(unsigned)th->result<<"\tPosition "<<th->end<<std::endl; _log5 << "HeroMove: id="<<th->id<<"\tResult: "<<(unsigned)th->result<<"\tPosition "<<th->end<<std::endl;
gs->apply(th); gs->apply(th);
int player = gs->map->objects[th->id]->getOwner(); int player = gs->map->objects[th->id]->getOwner();
@ -317,7 +317,7 @@ void CClient::process(int what)
{ {
SetGarrisons sg; SetGarrisons sg;
*serv >> sg; *serv >> sg;
log5 << "Setting garrisons." << std::endl; _log5 << "Setting garrisons." << std::endl;
gs->apply(&sg); gs->apply(&sg);
for(std::map<ui32,CCreatureSet>::iterator i = sg.garrs.begin(); i!=sg.garrs.end(); i++) for(std::map<ui32,CCreatureSet>::iterator i = sg.garrs.begin(); i!=sg.garrs.end(); i++)
playerint[gs->map->objects[i->first]->tempOwner]->garrisonChanged(gs->map->objects[i->first]); playerint[gs->map->objects[i->first]->tempOwner]->garrisonChanged(gs->map->objects[i->first]);
@ -336,7 +336,7 @@ void CClient::process(int what)
NewStructures ns; NewStructures ns;
*serv >> ns; *serv >> ns;
CGTownInstance *town = static_cast<CGTownInstance*>(gs->map->objects[ns.tid]); CGTownInstance *town = static_cast<CGTownInstance*>(gs->map->objects[ns.tid]);
log5 << "New structure(s) in " << ns.tid <<" " << town->name << " - " << *ns.bid.begin() << std::endl; _log5 << "New structure(s) in " << ns.tid <<" " << town->name << " - " << *ns.bid.begin() << std::endl;
gs->apply(&ns); gs->apply(&ns);
BOOST_FOREACH(si32 bid, ns.bid) BOOST_FOREACH(si32 bid, ns.bid)
{ {
@ -356,7 +356,7 @@ void CClient::process(int what)
{ {
SetAvailableCreatures ns; SetAvailableCreatures ns;
*serv >> ns; *serv >> ns;
log5 << "Setting available creatures in " << ns.tid << std::endl; _log5 << "Setting available creatures in " << ns.tid << std::endl;
gs->apply(&ns); gs->apply(&ns);
CGTownInstance *t = gs->getTown(ns.tid); CGTownInstance *t = gs->getTown(ns.tid);
if(vstd::contains(playerint,t->tempOwner)) if(vstd::contains(playerint,t->tempOwner))
@ -367,7 +367,7 @@ void CClient::process(int what)
{ {
SetHeroesInTown inTown; SetHeroesInTown inTown;
*serv >> inTown; *serv >> inTown;
log5 << "Setting heroes in town " << inTown.tid << std::endl; _log5 << "Setting heroes in town " << inTown.tid << std::endl;
gs->apply(&inTown); gs->apply(&inTown);
CGTownInstance *t = gs->getTown(inTown.tid); CGTownInstance *t = gs->getTown(inTown.tid);
if(vstd::contains(playerint,t->tempOwner)) if(vstd::contains(playerint,t->tempOwner))
@ -378,7 +378,7 @@ void CClient::process(int what)
{ {
SetHeroArtifacts sha; SetHeroArtifacts sha;
*serv >> sha; *serv >> sha;
log5 << "Setting artifacts of hero " << sha.hid << std::endl; _log5 << "Setting artifacts of hero " << sha.hid << std::endl;
gs->apply(&sha); gs->apply(&sha);
CGHeroInstance *t = gs->getHero(sha.hid); CGHeroInstance *t = gs->getHero(sha.hid);
if(vstd::contains(playerint,t->tempOwner)) if(vstd::contains(playerint,t->tempOwner))
@ -389,7 +389,7 @@ void CClient::process(int what)
{ {
SetObjectProperty sop; SetObjectProperty sop;
*serv >> sop; *serv >> sop;
log5 << "Setting " << (unsigned)sop.what << " property of " << sop.id <<" object to "<<sop.val<<std::endl; _log5 << "Setting " << (unsigned)sop.what << " property of " << sop.id <<" object to "<<sop.val<<std::endl;
gs->apply(&sop); gs->apply(&sop);
break; break;
} }
@ -397,7 +397,7 @@ void CClient::process(int what)
{ {
SetHoverName shn; SetHoverName shn;
*serv >> shn; *serv >> shn;
log5 << "Setting a name of " << shn.id <<" object to "<< toString(shn.name) <<std::endl; _log5 << "Setting a name of " << shn.id <<" object to "<< toString(shn.name) <<std::endl;
gs->mx->lock(); gs->mx->lock();
gs->map->objects[shn.id]->hoverName = toString(shn.name); gs->map->objects[shn.id]->hoverName = toString(shn.name);
gs->mx->unlock(); gs->mx->unlock();
@ -407,7 +407,7 @@ void CClient::process(int what)
{ {
HeroLevelUp bs; HeroLevelUp bs;
*serv >> bs; *serv >> bs;
log5 << "Hero levels up!" <<std::endl; _log5 << "Hero levels up!" <<std::endl;
gs->apply(&bs); gs->apply(&bs);
CGHeroInstance *h = gs->getHero(bs.heroid); CGHeroInstance *h = gs->getHero(bs.heroid);
if(vstd::contains(playerint,h->tempOwner)) if(vstd::contains(playerint,h->tempOwner))
@ -421,7 +421,7 @@ void CClient::process(int what)
{ {
SelectionDialog sd; SelectionDialog sd;
*serv >> sd; *serv >> sd;
log5 << "Showing selection dialog " <<std::endl; _log5 << "Showing selection dialog " <<std::endl;
std::vector<Component*> comps; std::vector<Component*> comps;
for(int i=0;i<sd.components.size();i++) for(int i=0;i<sd.components.size();i++)
comps.push_back(&sd.components[i]); comps.push_back(&sd.components[i]);
@ -433,7 +433,7 @@ void CClient::process(int what)
{ {
YesNoDialog ynd; YesNoDialog ynd;
*serv >> ynd; *serv >> ynd;
log5 << "Showing yes/no dialog " <<std::endl; _log5 << "Showing yes/no dialog " <<std::endl;
std::vector<Component*> comps; std::vector<Component*> comps;
for(int i=0;i<ynd.components.size();i++) for(int i=0;i<ynd.components.size();i++)
comps.push_back(&ynd.components[i]); comps.push_back(&ynd.components[i]);
@ -445,7 +445,7 @@ void CClient::process(int what)
{ {
BattleStart bs; BattleStart bs;
*serv >> bs; //uses new to allocate memory for battleInfo - must be deleted when battle is over *serv >> bs; //uses new to allocate memory for battleInfo - must be deleted when battle is over
log5 << "Starting battle!" <<std::endl; _log5 << "Starting battle!" <<std::endl;
gs->apply(&bs); gs->apply(&bs);
if(playerint.find(gs->curB->side1) != playerint.end()) if(playerint.find(gs->curB->side1) != playerint.end())
@ -459,7 +459,7 @@ void CClient::process(int what)
{ {
BattleNextRound bnr; BattleNextRound bnr;
*serv >> bnr; *serv >> bnr;
log5 << "Round nr " << bnr.round <<std::endl; _log5 << "Round nr " << bnr.round <<std::endl;
gs->apply(&bnr); gs->apply(&bnr);
//tell players about next round //tell players about next round
@ -473,7 +473,7 @@ void CClient::process(int what)
{ {
BattleSetActiveStack sas; BattleSetActiveStack sas;
*serv >> sas; *serv >> sas;
log5 << "Active stack: " << sas.stack <<std::endl; _log5 << "Active stack: " << sas.stack <<std::endl;
gs->apply(&sas); gs->apply(&sas);
int owner = gs->curB->getStack(sas.stack)->owner; int owner = gs->curB->getStack(sas.stack)->owner;
if(owner >= PLAYER_LIMIT) //ugly workaround to skip neutral creatures - should be replaced with AI if(owner >= PLAYER_LIMIT) //ugly workaround to skip neutral creatures - should be replaced with AI
@ -493,7 +493,7 @@ void CClient::process(int what)
{ {
BattleResult br; BattleResult br;
*serv >> br; *serv >> br;
log5 << "Battle ends. Winner: " << (unsigned)br.winner<< ". Type of end: "<< (unsigned)br.result <<std::endl; _log5 << "Battle ends. Winner: " << (unsigned)br.winner<< ". Type of end: "<< (unsigned)br.result <<std::endl;
if(playerint.find(gs->curB->side1) != playerint.end()) if(playerint.find(gs->curB->side1) != playerint.end())
playerint[gs->curB->side1]->battleEnd(&br); playerint[gs->curB->side1]->battleEnd(&br);
@ -507,7 +507,7 @@ void CClient::process(int what)
{ {
BattleStackMoved br; BattleStackMoved br;
*serv >> br; *serv >> br;
log5 << "Stack "<<br.stack <<" moves to the tile "<<br.tile<<std::endl; _log5 << "Stack "<<br.stack <<" moves to the tile "<<br.tile<<std::endl;
if(playerint.find(gs->curB->side1) != playerint.end()) if(playerint.find(gs->curB->side1) != playerint.end())
playerint[gs->curB->side1]->battleStackMoved(br.stack,br.tile,br.flags&1,br.flags&2); playerint[gs->curB->side1]->battleStackMoved(br.stack,br.tile,br.flags&1,br.flags&2);
if(playerint.find(gs->curB->side2) != playerint.end()) if(playerint.find(gs->curB->side2) != playerint.end())
@ -519,7 +519,7 @@ void CClient::process(int what)
{ {
BattleAttack ba; BattleAttack ba;
*serv >> ba; *serv >> ba;
log5 << "Stack: " << ba.stackAttacking << " is attacking stack "<< ba.bsa.stackAttacked <<std::endl; _log5 << "Stack: " << ba.stackAttacking << " is attacking stack "<< ba.bsa.stackAttacked <<std::endl;
gs->apply(&ba); gs->apply(&ba);
LOCPLINT->battleAttack(&ba); LOCPLINT->battleAttack(&ba);
break; break;
@ -543,7 +543,7 @@ void CClient::waitForMoveAndSend(int color)
*serv << ui16(3002) << ba; *serv << ui16(3002) << ba;
return; return;
}HANDLE_EXCEPTION }HANDLE_EXCEPTION
log1 << "We should not be here!" << std::endl; _log1 << "We should not be here!" << std::endl;
} }
void CClient::run() void CClient::run()
{ {
@ -560,10 +560,10 @@ void CClient::run()
void CClient::close() void CClient::close()
{ {
log3 << "Connection has been requested to be closed.\n"; _log3 << "Connection has been requested to be closed.\n";
boost::unique_lock<boost::mutex>(*serv->wmx); boost::unique_lock<boost::mutex>(*serv->wmx);
*serv << ui16(99); *serv << ui16(99);
log3 << "Sended closing signal to the server\n"; _log3 << "Sended closing signal to the server\n";
serv->close(); serv->close();
log3 << "Our socket has been closed.\n"; _log3 << "Our socket has been closed.\n";
} }

View File

@ -396,7 +396,7 @@ void Graphics::loadHeroFlags()
grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[1]),false)); grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[1]),false));
grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[0]),false)); grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[0]),false));
grupa.join_all(); grupa.join_all();
log0 << "Loading and transforming heroes' flags: "<<th.getDif()<<std::endl; _log0 << "Loading and transforming heroes' flags: "<<th.getDif()<<std::endl;
} }
SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded) SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded)
{ {

View File

@ -14,7 +14,6 @@ vcmiclient_SOURCES = \
./CBitmapHandler.cpp \ ./CBitmapHandler.cpp \
../CCallback.cpp \ ../CCallback.cpp \
../CCastleInterface.cpp \ ../CCastleInterface.cpp \
../CConsoleHandler.cpp \
./CCreatureAnimation.cpp \ ./CCreatureAnimation.cpp \
../CCursorHandler.cpp \ ../CCursorHandler.cpp \
../hch/CDefHandler.cpp \ ../hch/CDefHandler.cpp \
@ -49,7 +48,6 @@ vcmiclient_SOURCES = \
../hch/CBuildingHandler.h \ ../hch/CBuildingHandler.h \
../CCallback.h \ ../CCallback.h \
../CCastleInterface.h \ ../CCastleInterface.h \
../CConsoleHandler.h \
./CCreatureAnimation.h \ ./CCreatureAnimation.h \
../hch/CCreatureHandler.h \ ../hch/CCreatureHandler.h \
../CCursorHandler.h \ ../CCursorHandler.h \

View File

@ -218,32 +218,32 @@ public:
} }
}; };
extern CLogger<0> log0; //green - standard progress info extern CLogger<0> _log0; //green - standard progress info
extern CLogger<1> log1; //red - big errors extern CLogger<1> _log1; //red - big errors
extern CLogger<2> log2; //magenta - major warnings extern CLogger<2> _log2; //magenta - major warnings
extern CLogger<3> log3; //yellow - minor warnings extern CLogger<3> _log3; //yellow - minor warnings
extern CLogger<4> log4; //white - detailed log info extern CLogger<4> _log4; //white - detailed log info
extern CLogger<5> log5; //gray - minor log info extern CLogger<5> _log5; //gray - minor log info
#define HANDLE_EXCEPTION \ #define HANDLE_EXCEPTION \
catch (const std::exception& e) { \ catch (const std::exception& e) { \
log1 << e.what() << std::endl; \ _log1 << e.what() << std::endl; \
} \ } \
catch (const std::exception * e) \ catch (const std::exception * e) \
{ \ { \
log1 << e->what()<< std::endl; \ _log1 << e->what()<< std::endl; \
delete e; \ delete e; \
} }
#define HANDLE_EXCEPTIONC(COMMAND) \ #define HANDLE_EXCEPTIONC(COMMAND) \
catch (const std::exception& e) { \ catch (const std::exception& e) { \
COMMAND; \ COMMAND; \
log1 << e.what() << std::endl; \ _log1 << e.what() << std::endl; \
} \ } \
catch (const std::exception * e) \ catch (const std::exception * e) \
{ \ { \
COMMAND; \ COMMAND; \
log1 << e->what()<< std::endl; \ _log1 << e->what()<< std::endl; \
delete e; \ delete e; \
} }

View File

@ -31,7 +31,7 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length)
Entry * ourEntry = entries.znajdz(Entry(defName)); Entry * ourEntry = entries.znajdz(Entry(defName));
if(!ourEntry) //nothing's been found if(!ourEntry) //nothing's been found
{ {
log1<<"Cannot find file: "<<defName; _log1<<"Cannot find file: "<<defName;
return NULL; return NULL;
} }
if(length) *length = ourEntry->realSize; if(length) *length = ourEntry->realSize;
@ -47,7 +47,7 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length)
FILE * f = fopen(name,"rb"); FILE * f = fopen(name,"rb");
int result = fread(outp,1,ourEntry->realSize,f); int result = fread(outp,1,ourEntry->realSize,f);
mutex->unlock(); mutex->unlock();
if(result<0) {log1<<"Error in file reading: "<<name<<std::endl;delete[] outp; return NULL;} if(result<0) {_log1<<"Error in file reading: "<<name<<std::endl;delete[] outp; return NULL;}
else else
return outp; return outp;
} }
@ -228,7 +228,7 @@ void CLodHandler::extract(std::string FName)
out.open(bufff.c_str(), std::ios::binary); out.open(bufff.c_str(), std::ios::binary);
if(!out.is_open()) if(!out.is_open())
{ {
log1<<"Unable to create "<<bufff; _log1<<"Unable to create "<<bufff;
} }
else else
{ {
@ -251,7 +251,7 @@ void CLodHandler::extract(std::string FName)
destin.close(); destin.close();
if(decRes!=0) if(decRes!=0)
{ {
log1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl; _log1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl;
} }
} }
delete[] outp; delete[] outp;
@ -279,7 +279,7 @@ void CLodHandler::extractFile(std::string FName, std::string name)
out.open(bufff.c_str(), std::ios::binary); out.open(bufff.c_str(), std::ios::binary);
if(!out.is_open()) if(!out.is_open())
{ {
log1<<"Unable to create "<<bufff; _log1<<"Unable to create "<<bufff;
} }
else else
{ {
@ -302,7 +302,7 @@ void CLodHandler::extractFile(std::string FName, std::string name)
destin.close(); destin.close();
if(decRes!=0) if(decRes!=0)
{ {
log1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl; _log1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl;
} }
} }
delete[] outp; delete[] outp;
@ -391,7 +391,7 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
} }
} }
else else
log1<<"Warning: No "+dirName+"/ folder!"<<std::endl; _log1<<"Warning: No "+dirName+"/ folder!"<<std::endl;
} }
std::string CLodHandler::getTextFile(std::string name) std::string CLodHandler::getTextFile(std::string name)
{ {

View File

@ -46,27 +46,27 @@ CConnection::CConnection(std::string host, std::string port, std::string Name, s
tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port),error); tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port),error);
if(error) if(error)
{ {
log1 << "Problem with resolving: " << std::endl << error <<std::endl; _log1 << "Problem with resolving: " << std::endl << error <<std::endl;
goto connerror1; goto connerror1;
} }
pom = endpoint_iterator; pom = endpoint_iterator;
if(pom != end) if(pom != end)
log0<<"Found endpoints:" << std::endl; _log0<<"Found endpoints:" << std::endl;
else else
{ {
log1 << "Critical problem: No endpoints found!" << std::endl; _log1 << "Critical problem: No endpoints found!" << std::endl;
goto connerror1; goto connerror1;
} }
i=0; i=0;
while(pom != end) while(pom != end)
{ {
log0 << "\t" << i << ": " << (boost::asio::ip::tcp::endpoint&)*pom << std::endl; _log0 << "\t" << i << ": " << (boost::asio::ip::tcp::endpoint&)*pom << std::endl;
pom++; pom++;
} }
i=0; i=0;
while(endpoint_iterator != end) while(endpoint_iterator != end)
{ {
log0 << "Trying connection to " << (boost::asio::ip::tcp::endpoint&)*endpoint_iterator << " (" << i++ << ")" << std::endl; _log0 << "Trying connection to " << (boost::asio::ip::tcp::endpoint&)*endpoint_iterator << " (" << i++ << ")" << std::endl;
socket->connect(*endpoint_iterator, error); socket->connect(*endpoint_iterator, error);
if(!error) if(!error)
{ {
@ -75,18 +75,18 @@ CConnection::CConnection(std::string host, std::string port, std::string Name, s
} }
else else
{ {
log1 << "Problem with connecting: " << std::endl << error << std::endl; _log1 << "Problem with connecting: " << std::endl << error << std::endl;
} }
endpoint_iterator++; endpoint_iterator++;
} }
//we shouldn't be here - error handling //we shouldn't be here - error handling
connerror1: connerror1:
log1 << "Something went wrong... checking for error info" << std::endl; _log1 << "Something went wrong... checking for error info" << std::endl;
if(error) if(error)
std::cout << error <<std::endl; std::cout << error <<std::endl;
else else
log1 << "No error info. " << std::endl; _log1 << "No error info. " << std::endl;
delete io_service; delete io_service;
//delete socket; //delete socket;
throw std::string("Can't establish connection :("); throw std::string("Can't establish connection :(");

View File

@ -16,6 +16,8 @@ libvcmi_a_SOURCES = \
../map.cpp \ ../map.cpp \
../stdafx.cpp \ ../stdafx.cpp \
./VCMI_Lib.cpp \ ./VCMI_Lib.cpp \
../hch/CSpellHandler.cpp \
../CConsoleHandler.cpp \
../hch/CAmbarCendamo.h \ ../hch/CAmbarCendamo.h \
../hch/CArtHandler.h \ ../hch/CArtHandler.h \
../hch/CBuildingHandler.h \ ../hch/CBuildingHandler.h \
@ -30,4 +32,4 @@ libvcmi_a_SOURCES = \
../map.h \ ../map.h \
./NetPacks.h \ ./NetPacks.h \
./VCMI_Lib.h \ ./VCMI_Lib.h \
../hch/CSpellHandler.cpp ../CConsoleHandler.h

View File

@ -12,12 +12,12 @@
class CLodHandler; class CLodHandler;
LibClasses * VLC = NULL; LibClasses * VLC = NULL;
CLodHandler * bitmaph=NULL; CLodHandler * bitmaph=NULL;
CLogger<0> log0; CLogger<0> _log0;
CLogger<1> log1; CLogger<1> _log1;
CLogger<2> log2; CLogger<2> _log2;
CLogger<3> log3; CLogger<3> _log3;
CLogger<4> log4; CLogger<4> _log4;
CLogger<5> log5; CLogger<5> _log5;
CConsoleHandler *console = NULL; CConsoleHandler *console = NULL;
std::ostream *logfile = NULL; std::ostream *logfile = NULL;
DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile) DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile)
@ -32,39 +32,39 @@ DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *
heroh->loadHeroes(); heroh->loadHeroes();
heroh->loadPortraits(); heroh->loadPortraits();
VLC->heroh = heroh; VLC->heroh = heroh;
log0 <<"\tHero handler: "<<pomtime.getDif()<<std::endl; _log0 <<"\tHero handler: "<<pomtime.getDif()<<std::endl;
CArtHandler * arth = new CArtHandler; CArtHandler * arth = new CArtHandler;
arth->loadArtifacts(); arth->loadArtifacts();
VLC->arth = arth; VLC->arth = arth;
log0<<"\tArtifact handler: "<<pomtime.getDif()<<std::endl; _log0<<"\tArtifact handler: "<<pomtime.getDif()<<std::endl;
CCreatureHandler * creh = new CCreatureHandler(); CCreatureHandler * creh = new CCreatureHandler();
creh->loadCreatures(); creh->loadCreatures();
VLC->creh = creh; VLC->creh = creh;
log0<<"\tCreature handler: "<<pomtime.getDif()<<std::endl; _log0<<"\tCreature handler: "<<pomtime.getDif()<<std::endl;
VLC->townh = new CTownHandler; VLC->townh = new CTownHandler;
VLC->townh->loadNames(); VLC->townh->loadNames();
log0<<"\tTown handler: "<<pomtime.getDif()<<std::endl; _log0<<"\tTown handler: "<<pomtime.getDif()<<std::endl;
CObjectHandler * objh = new CObjectHandler; CObjectHandler * objh = new CObjectHandler;
objh->loadObjects(); objh->loadObjects();
VLC->objh = objh; VLC->objh = objh;
log0<<"\tObject handler: "<<pomtime.getDif()<<std::endl; _log0<<"\tObject handler: "<<pomtime.getDif()<<std::endl;
VLC->dobjinfo = new CDefObjInfoHandler; VLC->dobjinfo = new CDefObjInfoHandler;
VLC->dobjinfo->load(); VLC->dobjinfo->load();
log0<<"\tDef information handler: "<<pomtime.getDif()<<std::endl; _log0<<"\tDef information handler: "<<pomtime.getDif()<<std::endl;
VLC->buildh = new CBuildingHandler; VLC->buildh = new CBuildingHandler;
VLC->buildh->loadBuildings(); VLC->buildh->loadBuildings();
log0<<"\tBuilding handler: "<<pomtime.getDif()<<std::endl; _log0<<"\tBuilding handler: "<<pomtime.getDif()<<std::endl;
CSpellHandler * spellh = new CSpellHandler; CSpellHandler * spellh = new CSpellHandler;
spellh->loadSpells(); spellh->loadSpells();
VLC->spellh = spellh; VLC->spellh = spellh;
log0<<"\tSpell handler: "<<pomtime.getDif()<<std::endl; _log0<<"\tSpell handler: "<<pomtime.getDif()<<std::endl;
} }
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode) DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode)

22
map.cpp
View File

@ -448,25 +448,25 @@ void Mapa::initFromBytes(unsigned char * bufor)
th.getDif(); th.getDif();
int i=0; int i=0;
readHeader(bufor, i); readHeader(bufor, i);
log0<<"\tReading header: "<<th.getDif()<<std::endl; _log0<<"\tReading header: "<<th.getDif()<<std::endl;
readRumors(bufor, i); readRumors(bufor, i);
log0<<"\tReading rumors: "<<th.getDif()<<std::endl; _log0<<"\tReading rumors: "<<th.getDif()<<std::endl;
readPredefinedHeroes(bufor, i); readPredefinedHeroes(bufor, i);
log0<<"\tReading predefined heroes: "<<th.getDif()<<std::endl; _log0<<"\tReading predefined heroes: "<<th.getDif()<<std::endl;
readTerrain(bufor, i); readTerrain(bufor, i);
log0<<"\tReading terrain: "<<th.getDif()<<std::endl; _log0<<"\tReading terrain: "<<th.getDif()<<std::endl;
readDefInfo(bufor, i); readDefInfo(bufor, i);
log0<<"\tReading defs info: "<<th.getDif()<<std::endl; _log0<<"\tReading defs info: "<<th.getDif()<<std::endl;
readObjects(bufor, i); readObjects(bufor, i);
log0<<"\tReading objects: "<<th.getDif()<<std::endl; _log0<<"\tReading objects: "<<th.getDif()<<std::endl;
readEvents(bufor, i); readEvents(bufor, i);
log0<<"\tReading events: "<<th.getDif()<<std::endl; _log0<<"\tReading events: "<<th.getDif()<<std::endl;
//map readed, bufor no longer needed //map readed, bufor no longer needed
delete[] bufor; bufor=NULL; delete[] bufor; bufor=NULL;
@ -478,7 +478,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
continue; continue;
addBlockVisTiles(objects[f]); addBlockVisTiles(objects[f]);
} }
log0<<"\tCalculating blocked/visitable tiles: "<<th.getDif()<<std::endl; _log0<<"\tCalculating blocked/visitable tiles: "<<th.getDif()<<std::endl;
} }
void Mapa::removeBlockVisTiles(CGObjectInstance * obj) void Mapa::removeBlockVisTiles(CGObjectInstance * obj)
{ {
@ -534,7 +534,7 @@ void Mapa::addBlockVisTiles(CGObjectInstance * obj)
} }
Mapa::Mapa(std::string filename) Mapa::Mapa(std::string filename)
{ {
log0<<"Opening map file: "<<filename<<"\t "<<std::flush; _log0<<"Opening map file: "<<filename<<"\t "<<std::flush;
gzFile map = gzopen(filename.c_str(),"rb"); gzFile map = gzopen(filename.c_str(),"rb");
std::vector<unsigned char> mapstr; int pom; std::vector<unsigned char> mapstr; int pom;
while((pom=gzgetc(map))>=0) while((pom=gzgetc(map))>=0)
@ -547,11 +547,11 @@ Mapa::Mapa(std::string filename)
{ {
initTable[ss] = mapstr[ss]; initTable[ss] = mapstr[ss];
} }
log0<<"done."<<std::endl; _log0<<"done."<<std::endl;
boost::crc_32_type result; boost::crc_32_type result;
result.process_bytes(initTable,mapstr.size()); result.process_bytes(initTable,mapstr.size());
checksum = result.checksum(); checksum = result.checksum();
log0 << "\tOur map checksum: "<<result.checksum() << std::endl; _log0 << "\tOur map checksum: "<<result.checksum() << std::endl;
initFromBytes(initTable); initFromBytes(initTable);
} }

View File

@ -469,7 +469,7 @@ void processDef (CGDefInfo* def)
pom->height = pom->handler->ourImages[0].bitmap->h/32; pom->height = pom->handler->ourImages[0].bitmap->h/32;
} }
else if(def->id != 34 && def->id != 98) else if(def->id != 34 && def->id != 98)
log3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl; _log3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl;
if(!def->handler->alphaTransformed) if(!def->handler->alphaTransformed)
{ {
for(int yy=0; yy<def->handler->ourImages.size(); ++yy) for(int yy=0; yy<def->handler->ourImages.size(); ++yy)
@ -484,7 +484,7 @@ void CMapHandler::init()
timeHandler th; timeHandler th;
th.getDif(); th.getDif();
loadDefs(); //loading castles' defs loadDefs(); //loading castles' defs
log0<<"Reading terrain defs: "<<th.getDif()<<std::endl; _log0<<"Reading terrain defs: "<<th.getDif()<<std::endl;
std::ifstream ifs("config/townsDefs.txt"); std::ifstream ifs("config/townsDefs.txt");
int ccc; int ccc;
@ -501,10 +501,10 @@ void CMapHandler::init()
n = CGI->state->capitols[i%ccc]; n = CGI->state->capitols[i%ccc];
ifs >> n->name; ifs >> n->name;
if(!n) if(!n)
log1 << "*HUGE* Warning - missing town def for " << i << std::endl; _log1 << "*HUGE* Warning - missing town def for " << i << std::endl;
map->defs.insert(n); map->defs.insert(n);
} }
log0<<"\tLoading town def info: "<<th.getDif()<<std::endl; _log0<<"\tLoading town def info: "<<th.getDif()<<std::endl;
for(int i=0;i<map->heroes.size();i++) for(int i=0;i<map->heroes.size();i++)
{ {
@ -518,7 +518,7 @@ void CMapHandler::init()
std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs
std::for_each(map->defs.begin(),map->defs.end(),processDef); //and non-h3m defs std::for_each(map->defs.begin(),map->defs.end(),processDef); //and non-h3m defs
log0<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl; _log0<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl;
for(int i=0;i<PLAYER_LIMIT;i++) for(int i=0;i<PLAYER_LIMIT;i++)
{ {
@ -527,20 +527,20 @@ void CMapHandler::init()
usedHeroes.insert(map->players[i].heroesNames[j].heroID); usedHeroes.insert(map->players[i].heroesNames[j].heroID);
} }
} }
log0<<"\tChecking used heroes: "<<th.getDif()<<std::endl; _log0<<"\tChecking used heroes: "<<th.getDif()<<std::endl;
for(int h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info { for(int h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info {
CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler)); CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler));
log0<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl; _log0<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
prepareFOWDefs(); prepareFOWDefs();
roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization
borderAndTerrainBitmapInit(); borderAndTerrainBitmapInit();
log0<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl; _log0<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl;
initObjectRects(); initObjectRects();
log0<<"\tMaking object rects: "<<th.getDif()<<std::endl; _log0<<"\tMaking object rects: "<<th.getDif()<<std::endl;
} }
SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect)

View File

@ -341,7 +341,7 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
{ {
case 99: //end! case 99: //end!
{ {
log0 << "We have been requested to close.\n"; _log0 << "We have been requested to close.\n";
exit(0); exit(0);
} }
case 100: //my interface ended its turn case 100: //my interface ended its turn
@ -967,12 +967,12 @@ upgend:
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
log1 << e.what() << std::endl; _log1 << e.what() << std::endl;
end2 = true; end2 = true;
} }
catch (const std::exception * e) catch (const std::exception * e)
{ {
log1 << e->what()<< std::endl; _log1 << e->what()<< std::endl;
end2 = true; end2 = true;
delete e; delete e;
} }
@ -1273,7 +1273,7 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, CCreatureSet &army
positions.open("config" PATHSEPARATOR "battleStartpos.txt", std::ios_base::in|std::ios_base::binary); positions.open("config" PATHSEPARATOR "battleStartpos.txt", std::ios_base::in|std::ios_base::binary);
if(!positions.is_open()) if(!positions.is_open())
{ {
log0<<"Unable to open battleStartpos.txt!"<<std::endl; _log0<<"Unable to open battleStartpos.txt!"<<std::endl;
} }
std::string dump; std::string dump;
positions>>dump; positions>>dump; positions>>dump; positions>>dump;

View File

@ -22,14 +22,14 @@ using namespace boost;
using namespace boost::asio; using namespace boost::asio;
using namespace boost::asio::ip; using namespace boost::asio::ip;
namespace intpr = boost::interprocess; namespace intpr = boost::interprocess;
CLogger<0> log0; extern CLogger<0> _log0;
CLogger<1> log1; extern CLogger<1> _log1;
CLogger<2> log2; extern CLogger<2> _log2;
CLogger<3> log3; extern CLogger<3> _log3;
CLogger<4> log4; extern CLogger<4> _log4;
CLogger<5> log5; extern CLogger<5> _log5;
CConsoleHandler *console = NULL; extern CConsoleHandler *console;// = NULL;
std::ostream *logfile = NULL; extern std::ostream *logfile;// = NULL;
bool end2 = false; bool end2 = false;
int port = 3030; int port = 3030;