2
0

CMT.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. // CMT.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <cmath>
  5. #include <string>
  6. #include <vector>
  7. #include <queue>
  8. #include <cmath>
  9. #include <boost/thread.hpp>
  10. #include "SDL_TTF.h"
  11. #include "SDL_mixer.h"
  12. #include "SDL_Extensions.h"
  13. #include "SDL_framerate.h"
  14. #include "CGameInfo.h"
  15. #include "mapHandler.h"
  16. #include "global.h"
  17. #include "CPreGame.h"
  18. #include "CConsoleHandler.h"
  19. #include "CCursorHandler.h"
  20. #include "CScreenHandler.h"
  21. #include "CPathfinder.h"
  22. #include "CGameState.h"
  23. #include "CCallback.h"
  24. #include "CPlayerInterface.h"
  25. #include "CLuaHandler.h"
  26. #include "CLua.h"
  27. #include "CAdvmapInterface.h"
  28. #include "hch/CBuildingHandler.h"
  29. #include "hch/CVideoHandler.h"
  30. #include "hch/CAbilityHandler.h"
  31. #include "hch/CHeroHandler.h"
  32. #include "hch/CCreatureHandler.h"
  33. #include "hch/CSpellHandler.h"
  34. #include "hch/CMusicHandler.h"
  35. #include "hch/CLodHandler.h"
  36. #include "hch/CDefHandler.h"
  37. #include "hch/CAmbarCendamo.h"
  38. #include "hch/CGeneralTextHandler.h"
  39. #include "client/Graphics.h"
  40. #include "Client/Client.h"
  41. #include "lib/Connection.h"
  42. #include "lib/VCMI_Lib.h"
  43. std::string NAME = NAME_VER + std::string(" (client)");
  44. DLL_EXPORT void initDLL(CLodHandler *b);
  45. SDL_Surface * screen, * screen2;
  46. extern SDL_Surface * CSDL_Ext::std32bppSurface;
  47. std::queue<SDL_Event> events;
  48. boost::mutex eventsM;
  49. TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
  50. int _tmain(int argc, _TCHAR* argv[])
  51. {
  52. std::cout.flags(ios::unitbuf);
  53. std::cout << NAME << std::endl;
  54. srand ( time(NULL) );
  55. CPG=NULL;
  56. atexit(SDL_Quit);
  57. CGameInfo * cgi = CGI = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.)
  58. //CLuaHandler luatest;
  59. //luatest.test();
  60. //CBIKHandler cb;
  61. //cb.open("CSECRET.BIK");
  62. std::cout << "Starting... " << std::endl;
  63. THC timeHandler tmh, total, pomtime;
  64. if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO/*|SDL_INIT_EVENTTHREAD*/)==0)
  65. {
  66. screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface
  67. THC std::cout<<"\tInitializing screen: "<<pomtime.getDif()<<std::endl;
  68. SDL_WM_SetCaption(NAME.c_str(),""); //set window title
  69. #if SDL_BYTEORDER == SDL_BIG_ENDIAN
  70. int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff;
  71. #else
  72. int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000;
  73. #endif
  74. CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask);
  75. THC std::cout<<"\tInitializing minors: "<<pomtime.getDif()<<std::endl;
  76. TTF_Init();
  77. TNRB16 = TTF_OpenFont("Fonts\\tnrb.ttf",16);
  78. GEOR13 = TTF_OpenFont("Fonts\\georgia.ttf",13);
  79. GEOR16 = TTF_OpenFont("Fonts\\georgia.ttf",16);
  80. GEORXX = TTF_OpenFont("Fonts\\tnrb.ttf",22);
  81. GEORM = TTF_OpenFont("Fonts\\georgia.ttf",10);
  82. atexit(TTF_Quit);
  83. THC std::cout<<"\tInitializing fonts: "<<pomtime.getDif()<<std::endl;
  84. CMusicHandler * mush = new CMusicHandler; //initializing audio
  85. mush->initMusics();
  86. //audio initialized
  87. cgi->consoleh = new CConsoleHandler;
  88. cgi->mush = mush;
  89. cgi->curh = new CCursorHandler;
  90. THC std::cout<<"\tInitializing sound and cursor: "<<pomtime.getDif()<<std::endl;
  91. THC std::cout<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl;
  92. CDefHandler::Spriteh = cgi->spriteh = new CLodHandler();
  93. cgi->spriteh->init("Data\\H3sprite.lod","Sprites");
  94. BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler;
  95. cgi->bitmaph->init("Data\\H3bitmap.lod","Data");
  96. THC std::cout<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
  97. initDLL(cgi->bitmaph);
  98. CGI->arth = VLC->arth;
  99. CGI->creh = VLC->creh;
  100. CGI->townh = VLC->townh;
  101. CGI->heroh = VLC->heroh;
  102. CGI->objh = VLC->objh;
  103. CGI->dobjinfo = VLC->dobjinfo;
  104. CGI->buildh = VLC->buildh;
  105. THC std::cout<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
  106. //cgi->curh->initCursor();
  107. //cgi->curh->showGraphicCursor();
  108. pomtime.getDif();
  109. cgi->screenh = new CScreenHandler;
  110. cgi->screenh->initScreen();
  111. THC std::cout<<"\tScreen handler: "<<pomtime.getDif()<<std::endl;
  112. CAbilityHandler * abilh = new CAbilityHandler;
  113. abilh->loadAbilities();
  114. cgi->abilh = abilh;
  115. THC std::cout<<"\tAbility handler: "<<pomtime.getDif()<<std::endl;
  116. THC std::cout<<"Preparing first handlers: "<<tmh.getDif()<<std::endl;
  117. pomtime.getDif();
  118. graphics = new Graphics();
  119. THC std::cout<<"\tMain graphics: "<<tmh.getDif()<<std::endl;
  120. std::vector<CDefHandler **> animacje;
  121. for(std::vector<CHeroClass *>::iterator i = cgi->heroh->heroClasses.begin();i!=cgi->heroh->heroClasses.end();i++)
  122. animacje.push_back(&((*i)->*(&CHeroClass::moveAnim)));
  123. graphics->loadHeroAnim(animacje);
  124. THC std::cout<<"\tHero animations: "<<tmh.getDif()<<std::endl;
  125. THC std::cout<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
  126. CMessage::init();
  127. cgi->generaltexth = new CGeneralTextHandler;
  128. cgi->generaltexth->load();
  129. THC std::cout<<"Preparing more handlers: "<<tmh.getDif()<<std::endl;
  130. CPreGame * cpg = new CPreGame(); //main menu and submenus
  131. THC std::cout<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
  132. THC std::cout<<"Initialization of VCMI (togeter): "<<total.getDif()<<std::endl;
  133. cpg->mush = mush;
  134. StartInfo *options = new StartInfo(cpg->runLoop());
  135. ///////////////////////////////////////////////////////////////////////////////////////
  136. boost::thread servthr(boost::bind(system,"VCMI_server.exe > server_log.txt")); //runs server executable;
  137. //TODO: will it work on non-windows platforms?
  138. THC tmh.getDif();pomtime.getDif();//reset timers
  139. CSpellHandler * spellh = new CSpellHandler;
  140. spellh->loadSpells();
  141. cgi->spellh = spellh;
  142. THC std::cout<<"\tSpell handler: "<<pomtime.getDif()<<std::endl;
  143. cgi->pathf = new CPathfinder();
  144. THC std::cout<<"\tPathfinder: "<<pomtime.getDif()<<std::endl;
  145. cgi->consoleh->runConsole();
  146. THC std::cout<<"\tCallback and console: "<<pomtime.getDif()<<std::endl;
  147. THC std::cout<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl;
  148. std::ofstream lll("client_log.txt");
  149. CConnection c("localhost","3030",NAME,lll);
  150. THC std::cout<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl;
  151. CClient cl(&c,options);
  152. boost::thread t(boost::bind(&CClient::run,&cl));
  153. SDL_Event ev;
  154. while(1) //main SDL events loop
  155. {
  156. SDL_WaitEvent(&ev);
  157. if(ev.type==SDL_QUIT)
  158. {
  159. t.interrupt();
  160. exit(0);
  161. }
  162. eventsM.lock();
  163. events.push(ev);
  164. eventsM.unlock();
  165. }
  166. ///claculating FoWs for minimap
  167. /****************************Minimaps' FoW******************************************/
  168. //for(int g=0; g<cgi->playerint.size(); ++g)
  169. //{
  170. // if(!cgi->playerint[g]->human)
  171. // continue;
  172. // CMinimap & mm = ((CPlayerInterface*)cgi->playerint[g])->adventureInt->minimap;
  173. // int mw = mm.map[0]->w, mh = mm.map[0]->h,
  174. // wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
  175. // for(int d=0; d<cgi->mh->map->twoLevel+1; ++d)
  176. // {
  177. // SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface);
  178. // for (int i=0; i<mw; i++)
  179. // {
  180. // for (int j=0; j<mh; j++)
  181. // {
  182. // int3 pp( ((i*CGI->mh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d );
  183. // if ( !((CPlayerInterface*)cgi->playerint[g])->cb->isVisible(pp) )
  184. // {
  185. // CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0);
  186. // }
  187. // }
  188. // }
  189. // CSDL_Ext::update(pt);
  190. // mm.FoW.push_back(pt);
  191. // }
  192. //}
  193. }
  194. else
  195. {
  196. printf("Something was wrong: %s/n", SDL_GetError());
  197. return -1;
  198. }
  199. }