2007-06-06 22:29:40 +03:00
|
|
|
// CMT.cpp : Defines the entry point for the console application.
|
|
|
|
//
|
2008-08-04 18:56:36 +03:00
|
|
|
#include "stdafx.h"
|
2007-06-06 22:29:40 +03:00
|
|
|
#include <cmath>
|
2007-06-20 15:00:18 +03:00
|
|
|
#include <string>
|
2007-06-06 22:29:40 +03:00
|
|
|
#include <vector>
|
2008-07-27 20:07:37 +03:00
|
|
|
#include <queue>
|
2007-06-06 22:29:40 +03:00
|
|
|
#include <cmath>
|
2008-07-25 20:28:28 +03:00
|
|
|
#include <boost/thread.hpp>
|
2008-08-04 12:05:52 +03:00
|
|
|
#include "SDL_ttf.h"
|
2008-07-25 20:28:28 +03:00
|
|
|
#include "SDL_mixer.h"
|
|
|
|
#include "SDL_Extensions.h"
|
2008-08-04 18:56:36 +03:00
|
|
|
#include "SDL_framerate.h"
|
|
|
|
#include "CGameInfo.h"
|
2007-07-07 19:04:15 +03:00
|
|
|
#include "mapHandler.h"
|
|
|
|
#include "global.h"
|
2008-08-04 18:56:36 +03:00
|
|
|
#include "CPreGame.h"
|
2007-08-15 18:13:11 +03:00
|
|
|
#include "CConsoleHandler.h"
|
2007-08-21 16:48:18 +03:00
|
|
|
#include "CCursorHandler.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CPathfinder.h"
|
|
|
|
#include "CGameState.h"
|
2007-09-14 16:11:10 +03:00
|
|
|
#include "CCallback.h"
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "CPlayerInterface.h"
|
2007-10-14 15:11:18 +03:00
|
|
|
#include "CLuaHandler.h"
|
2007-12-06 20:55:58 +02:00
|
|
|
#include "CAdvmapInterface.h"
|
2008-07-25 20:28:28 +03:00
|
|
|
#include "hch/CBuildingHandler.h"
|
|
|
|
#include "hch/CVideoHandler.h"
|
|
|
|
#include "hch/CAbilityHandler.h"
|
|
|
|
#include "hch/CHeroHandler.h"
|
|
|
|
#include "hch/CCreatureHandler.h"
|
|
|
|
#include "hch/CSpellHandler.h"
|
|
|
|
#include "hch/CMusicHandler.h"
|
|
|
|
#include "hch/CLodHandler.h"
|
|
|
|
#include "hch/CDefHandler.h"
|
|
|
|
#include "hch/CAmbarCendamo.h"
|
|
|
|
#include "hch/CGeneralTextHandler.h"
|
2008-07-01 11:01:02 +03:00
|
|
|
#include "client/Graphics.h"
|
2008-08-04 12:05:52 +03:00
|
|
|
#include "client/Client.h"
|
2008-07-03 18:03:32 +03:00
|
|
|
#include "lib/Connection.h"
|
2008-07-25 20:28:28 +03:00
|
|
|
#include "lib/VCMI_Lib.h"
|
2008-06-30 03:06:41 +03:00
|
|
|
std::string NAME = NAME_VER + std::string(" (client)");
|
2008-06-13 00:08:04 +03:00
|
|
|
DLL_EXPORT void initDLL(CLodHandler *b);
|
2008-04-25 12:25:59 +03:00
|
|
|
SDL_Surface * screen, * screen2;
|
2008-08-04 18:56:36 +03:00
|
|
|
extern SDL_Surface * CSDL_Ext::std32bppSurface;
|
2008-07-27 20:07:37 +03:00
|
|
|
std::queue<SDL_Event> events;
|
2008-08-04 18:56:36 +03:00
|
|
|
boost::mutex eventsM;
|
|
|
|
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
|
2008-08-04 12:05:52 +03:00
|
|
|
#ifndef __GNUC__
|
2008-06-30 03:06:41 +03:00
|
|
|
int _tmain(int argc, _TCHAR* argv[])
|
2008-08-04 18:56:36 +03:00
|
|
|
#else
|
2008-08-04 12:05:52 +03:00
|
|
|
int main(int argc, _TCHAR* argv[])
|
2008-08-04 18:56:36 +03:00
|
|
|
#endif
|
2008-07-01 11:01:02 +03:00
|
|
|
{
|
2008-07-27 20:07:37 +03:00
|
|
|
std::cout.flags(ios::unitbuf);
|
2008-07-03 18:03:32 +03:00
|
|
|
std::cout << NAME << std::endl;
|
2008-06-16 13:51:14 +03:00
|
|
|
srand ( time(NULL) );
|
|
|
|
CPG=NULL;
|
|
|
|
atexit(SDL_Quit);
|
|
|
|
CGameInfo * cgi = CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.)
|
2007-11-19 00:58:28 +02:00
|
|
|
//CLuaHandler luatest;
|
2008-08-04 18:56:36 +03:00
|
|
|
//luatest.test();
|
2007-08-17 20:42:21 +03:00
|
|
|
//CBIKHandler cb;
|
|
|
|
//cb.open("CSECRET.BIK");
|
2008-06-16 13:51:14 +03:00
|
|
|
std::cout << "Starting... " << std::endl;
|
2008-06-14 13:20:18 +03:00
|
|
|
THC timeHandler tmh, total, pomtime;
|
2007-06-19 17:41:03 +03:00
|
|
|
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO/*|SDL_INIT_EVENTTHREAD*/)==0)
|
2007-06-06 22:29:40 +03:00
|
|
|
{
|
2008-06-16 13:51:14 +03:00
|
|
|
screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface
|
|
|
|
THC std::cout<<"\tInitializing screen: "<<pomtime.getDif()<<std::endl;
|
2008-06-30 03:06:41 +03:00
|
|
|
SDL_WM_SetCaption(NAME.c_str(),""); //set window title
|
2008-06-16 13:51:14 +03:00
|
|
|
#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;
|
2008-08-04 18:56:36 +03:00
|
|
|
#endif
|
2008-02-06 15:50:40 +02:00
|
|
|
CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask);
|
2008-06-16 13:51:14 +03:00
|
|
|
THC std::cout<<"\tInitializing minors: "<<pomtime.getDif()<<std::endl;
|
2007-06-12 12:33:20 +03:00
|
|
|
TTF_Init();
|
2007-06-19 18:25:42 +03:00
|
|
|
TNRB16 = TTF_OpenFont("Fonts\\tnrb.ttf",16);
|
|
|
|
GEOR13 = TTF_OpenFont("Fonts\\georgia.ttf",13);
|
2008-01-15 20:50:52 +02:00
|
|
|
GEOR16 = TTF_OpenFont("Fonts\\georgia.ttf",16);
|
2007-06-28 13:47:28 +03:00
|
|
|
GEORXX = TTF_OpenFont("Fonts\\tnrb.ttf",22);
|
2008-08-04 18:56:36 +03:00
|
|
|
GEORM = TTF_OpenFont("Fonts\\georgia.ttf",10);
|
2008-06-16 13:51:14 +03:00
|
|
|
atexit(TTF_Quit);
|
|
|
|
THC std::cout<<"\tInitializing fonts: "<<pomtime.getDif()<<std::endl;
|
2007-09-18 16:30:26 +03:00
|
|
|
CMusicHandler * mush = new CMusicHandler; //initializing audio
|
2007-06-20 15:00:18 +03:00
|
|
|
mush->initMusics();
|
2008-08-04 18:56:36 +03:00
|
|
|
//audio initialized
|
2007-08-15 18:13:11 +03:00
|
|
|
cgi->consoleh = new CConsoleHandler;
|
2007-07-09 08:57:30 +03:00
|
|
|
cgi->mush = mush;
|
2008-08-04 18:56:36 +03:00
|
|
|
THC std::cout<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl;
|
2007-07-09 14:40:39 +03:00
|
|
|
THC std::cout<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl;
|
2008-06-14 13:20:18 +03:00
|
|
|
CDefHandler::Spriteh = cgi->spriteh = new CLodHandler();
|
|
|
|
cgi->spriteh->init("Data\\H3sprite.lod","Sprites");
|
2008-06-12 09:45:51 +03:00
|
|
|
BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler;
|
2008-06-14 13:20:18 +03:00
|
|
|
cgi->bitmaph->init("Data\\H3bitmap.lod","Data");
|
2007-08-24 11:27:32 +03:00
|
|
|
THC std::cout<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
|
2008-08-04 18:56:36 +03:00
|
|
|
initDLL(cgi->bitmaph);
|
2008-07-25 20:28:28 +03:00
|
|
|
CGI->arth = VLC->arth;
|
2008-07-27 23:00:41 +03:00
|
|
|
CGI->creh = VLC->creh;
|
2008-07-25 20:28:28 +03:00
|
|
|
CGI->townh = VLC->townh;
|
|
|
|
CGI->heroh = VLC->heroh;
|
|
|
|
CGI->objh = VLC->objh;
|
|
|
|
CGI->dobjinfo = VLC->dobjinfo;
|
2008-08-04 18:56:36 +03:00
|
|
|
CGI->buildh = VLC->buildh;
|
|
|
|
THC std::cout<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
|
2008-06-14 13:20:18 +03:00
|
|
|
//cgi->curh->initCursor();
|
|
|
|
//cgi->curh->showGraphicCursor();
|
|
|
|
pomtime.getDif();
|
2008-08-01 21:13:33 +03:00
|
|
|
cgi->curh = new CCursorHandler;
|
|
|
|
cgi->curh->initCursor();
|
|
|
|
//cgi->screenh = new CScreenHandler;
|
|
|
|
//cgi->screenh->initScreen();
|
2008-08-04 18:56:36 +03:00
|
|
|
THC std::cout<<"\tScreen handler: "<<pomtime.getDif()<<std::endl;
|
2008-06-14 13:20:18 +03:00
|
|
|
CAbilityHandler * abilh = new CAbilityHandler;
|
|
|
|
abilh->loadAbilities();
|
|
|
|
cgi->abilh = abilh;
|
2008-08-04 18:56:36 +03:00
|
|
|
THC std::cout<<"\tAbility handler: "<<pomtime.getDif()<<std::endl;
|
2007-11-24 00:33:55 +02:00
|
|
|
THC std::cout<<"Preparing first handlers: "<<tmh.getDif()<<std::endl;
|
2008-06-16 13:51:14 +03:00
|
|
|
pomtime.getDif();
|
2008-06-14 13:20:18 +03:00
|
|
|
graphics = new Graphics();
|
2008-06-16 13:51:14 +03:00
|
|
|
THC std::cout<<"\tMain graphics: "<<tmh.getDif()<<std::endl;
|
|
|
|
std::vector<CDefHandler **> animacje;
|
|
|
|
for(std::vector<CHeroClass *>::iterator i = cgi->heroh->heroClasses.begin();i!=cgi->heroh->heroClasses.end();i++)
|
|
|
|
animacje.push_back(&((*i)->*(&CHeroClass::moveAnim)));
|
|
|
|
graphics->loadHeroAnim(animacje);
|
|
|
|
THC std::cout<<"\tHero animations: "<<tmh.getDif()<<std::endl;
|
2008-06-14 13:20:18 +03:00
|
|
|
THC std::cout<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
|
2007-10-13 23:31:50 +03:00
|
|
|
CMessage::init();
|
2007-08-24 11:27:32 +03:00
|
|
|
cgi->generaltexth = new CGeneralTextHandler;
|
|
|
|
cgi->generaltexth->load();
|
2008-08-04 18:56:36 +03:00
|
|
|
THC std::cout<<"Preparing more handlers: "<<tmh.getDif()<<std::endl;
|
2007-07-09 14:40:39 +03:00
|
|
|
CPreGame * cpg = new CPreGame(); //main menu and submenus
|
|
|
|
THC std::cout<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
|
2008-06-14 13:20:18 +03:00
|
|
|
THC std::cout<<"Initialization of VCMI (togeter): "<<total.getDif()<<std::endl;
|
2007-06-20 15:00:18 +03:00
|
|
|
cpg->mush = mush;
|
2008-06-30 03:06:41 +03:00
|
|
|
StartInfo *options = new StartInfo(cpg->runLoop());
|
2008-08-04 18:56:36 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
2008-07-27 20:07:37 +03:00
|
|
|
boost::thread servthr(boost::bind(system,"VCMI_server.exe > server_log.txt")); //runs server executable;
|
|
|
|
//TODO: will it work on non-windows platforms?
|
2008-08-04 18:56:36 +03:00
|
|
|
THC tmh.getDif();pomtime.getDif();//reset timers
|
2007-06-09 16:28:03 +03:00
|
|
|
CSpellHandler * spellh = new CSpellHandler;
|
2007-06-10 21:04:15 +03:00
|
|
|
spellh->loadSpells();
|
2008-02-26 01:26:50 +02:00
|
|
|
cgi->spellh = spellh;
|
2008-08-04 18:56:36 +03:00
|
|
|
THC std::cout<<"\tSpell handler: "<<pomtime.getDif()<<std::endl;
|
2007-08-17 20:42:21 +03:00
|
|
|
cgi->pathf = new CPathfinder();
|
2008-02-26 01:26:50 +02:00
|
|
|
THC std::cout<<"\tPathfinder: "<<pomtime.getDif()<<std::endl;
|
2007-09-30 19:16:00 +03:00
|
|
|
cgi->consoleh->runConsole();
|
2008-02-26 01:26:50 +02:00
|
|
|
THC std::cout<<"\tCallback and console: "<<pomtime.getDif()<<std::endl;
|
2008-08-04 18:56:36 +03:00
|
|
|
THC std::cout<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl;
|
2008-07-25 20:28:28 +03:00
|
|
|
std::ofstream lll("client_log.txt");
|
2008-08-09 02:02:32 +03:00
|
|
|
|
|
|
|
CConnection *c=NULL;
|
|
|
|
while(!c)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::cout << "Establishing connection...\t";
|
|
|
|
c = new CConnection("localhost","3030",NAME,lll);
|
|
|
|
std::cout << "done!" <<std::endl;
|
|
|
|
}
|
|
|
|
catch(...)
|
|
|
|
{
|
|
|
|
std::cout << "\nCannot establish connection! Retrying within 3 seconds" <<std::endl;
|
|
|
|
SDL_Delay(3000);
|
|
|
|
}
|
|
|
|
}
|
2008-08-04 18:56:36 +03:00
|
|
|
THC std::cout<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl;
|
2008-08-04 12:05:52 +03:00
|
|
|
CClient cl(c,options);
|
2008-08-04 18:56:36 +03:00
|
|
|
boost::thread t(boost::bind(&CClient::run,&cl));
|
2008-07-27 20:07:37 +03:00
|
|
|
SDL_Event ev;
|
|
|
|
while(1) //main SDL events loop
|
|
|
|
{
|
|
|
|
SDL_WaitEvent(&ev);
|
2008-08-04 18:56:36 +03:00
|
|
|
if(ev.type==SDL_QUIT)
|
2008-07-27 20:07:37 +03:00
|
|
|
{
|
|
|
|
t.interrupt();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
eventsM.lock();
|
|
|
|
events.push(ev);
|
|
|
|
eventsM.unlock();
|
2008-08-04 18:56:36 +03:00
|
|
|
}
|
2007-06-06 22:29:40 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-07-09 14:40:39 +03:00
|
|
|
printf("Something was wrong: %s/n", SDL_GetError());
|
2007-06-06 22:29:40 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2007-06-07 20:45:56 +03:00
|
|
|
}
|