Clone of Akilla's ac2d @ https://github.com/deregtd/AC2D

cInterface.cpp 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. #include "stdafx.h"
  2. #include "cInterface.h"
  3. DWORD dwAnim = 0x030000AC;//0x03000000 | 2128;
  4. DWORD dwTexBase = 0x06000000;
  5. cInterface::cInterface()
  6. {
  7. // cWObject *WO = new cWObject();
  8. m_fConnProgress = 0;
  9. m_vConsoleHistory.clear();
  10. strcpy(m_MOTD, "Waiting for MOTD...");
  11. ZeroMemory(&m_CharList, sizeof(m_CharList));
  12. m_dwSelChar = 0;
  13. m_dwLastAttacker = 0;
  14. m_vWMessages.clear();
  15. m_bFirstSize = true;
  16. m_fCamDist = 0.025f;
  17. m_fCamRotX = (float) M_PI;
  18. m_fCamRotY = (float) M_PI/3;
  19. bForward = false;
  20. bBack = false;
  21. bLeft = false;
  22. bRight = false;
  23. bStrLeft = false;
  24. bStrRight = false;
  25. bShift = false;
  26. bAnimUpdate = false;
  27. fSpeed = 32;
  28. FlyerCenter = cPoint3D(93.45f, -82.15f, 0.85f);
  29. // FlyerCenter = cPoint3D(0, 0, 5);
  30. bRotating = false;
  31. m_dwCurSelect = 0;
  32. m_mgChars[0] = 0;
  33. m_mgBZ = 0;
  34. m_iRenderRadius = 5;
  35. m_bShowConsole = false;
  36. // m_wStance = 0x3D;
  37. m_bCombatMode = false;
  38. QueryPerformanceFrequency(&liFreq);
  39. QueryPerformanceCounter(&liLast);
  40. InitializeCriticalSection(&csChat);
  41. //Initialize Interface
  42. m_WindowManager = new CWindowManager();
  43. m_WindowManager->AddWindow(*this);
  44. SetVisible(true);
  45. m_WindowManager->SetFocusedWindow(this);
  46. /* DWORD texes[] = {
  47. // 0x05001371,
  48. // 0x0500143E,
  49. // 0x0500143F,
  50. // 0x05001440,
  51. // 0x05001441,
  52. // 0x0500168E,
  53. // 0x0500168C,//alpha masks for blending
  54. // 0x0500168D,
  55. 0x0500145C,
  56. 0x05001459,
  57. 0x05001468,
  58. 0x05001456,
  59. 0x05001467,
  60. 0x05001462,
  61. 0x05001463,
  62. 0x05001465,
  63. 0x0500145B,
  64. 0x05001457,
  65. 0x0500145D,
  66. 0x0500145F,
  67. 0x0500145E,
  68. 0x050014A7,
  69. 0x0500145A,
  70. 0x05001464,
  71. 0x0500146A,
  72. 0x05001461,
  73. 0x0500146C,
  74. 0x05001469,
  75. 0x0500146B,
  76. 0x05001466,
  77. 0x0500146A,
  78. 0x05001827,
  79. 0x0500145C,
  80. 0x0500181F,
  81. 0x05001924,
  82. 0x05001900,
  83. 0x05001C3A,
  84. 0x05001C3B,
  85. 0x05001C3C,
  86. 0x0500145C,
  87. 0x05001458,
  88. 0x0600127D,
  89. 0x06000261
  90. };
  91. m_dwBaseTex = 0x3856;
  92. for (int y=0; y<6; y++)
  93. {
  94. for (int x=0; x<6; x++)
  95. {
  96. m_pbTex[y][x] = new cPictureBox();
  97. m_pbTex[y][x]->SetPicture(texes[y*6 + x]);//dwTexBase | (y*6 + x + m_dwBaseTex));
  98. m_pbTex[y][x]->SetSize(200,200);
  99. m_pbTex[y][x]->SetPosition(200*x,200*y);
  100. //m_pbTex[y][x]->SetVisible(true);
  101. AddChild(*m_pbTex[y][x]);
  102. }
  103. }
  104. */
  105. m_mwMinimap = new cMinimap();
  106. m_mwMinimap->SetSize(150, 166);
  107. m_mwMinimap->SetTransparency(0.6f);
  108. m_mwMinimap->SetTitle("Minimap");
  109. m_mwMinimap->SetIcon(0x06001065);
  110. AddChild(*m_mwMinimap);
  111. m_mwChat = new cChatWindow();
  112. m_mwChat->SetTransparency(0.6f);
  113. m_mwChat->SetTitle("Chat");
  114. m_mwChat->SetIcon(0x0600137D);
  115. AddChild(*m_mwChat);
  116. m_mwSpellBar = new cSpellBar();
  117. AddChild(*m_mwSpellBar);
  118. m_mwRadar = new cRadar();
  119. m_mwRadar->SetSize(110, 116);
  120. m_mwRadar->SetTransparency(0.7f);
  121. m_mwRadar->SetTitle("Radar");
  122. m_mwRadar->SetIcon(0x06001388);
  123. AddChild(*m_mwRadar);
  124. m_mwVitals = new cVitalsWindow();
  125. m_mwVitals->SetSize(150.0f, 60.0f+16);
  126. m_mwVitals->SetTransparency(0.7f);
  127. m_mwVitals->SetTitle("Vitals");
  128. m_mwVitals->SetIcon(0x060013B2);
  129. AddChild(*m_mwVitals);
  130. m_mwStats = new cStatWindow();
  131. m_mwStats->SetSize(150.0f, 20+16*9);
  132. m_mwStats->SetTransparency(0.7f);
  133. m_mwStats->SetTitle("Stats");
  134. m_mwStats->SetIcon(0x0600138C);
  135. AddChild(*m_mwStats);
  136. m_mwSkills = new cSkillWindow();
  137. m_mwSkills->SetSize(170.0f, 20+16*15);
  138. m_mwSkills->SetTransparency(0.7f);
  139. m_mwSkills->SetTitle("Skills");
  140. m_mwSkills->SetIcon(0x0600138E);
  141. AddChild(*m_mwSkills);
  142. m_mwWindowToolbar = new cWindowToolbar();
  143. m_mwWindowToolbar->AddWindow(m_mwMinimap);
  144. #ifndef TerrainOnly
  145. m_mwWindowToolbar->AddWindow(m_mwRadar);
  146. m_mwWindowToolbar->AddWindow(m_mwVitals);
  147. m_mwWindowToolbar->AddWindow(m_mwChat);
  148. m_mwWindowToolbar->AddWindow(m_mwStats);
  149. m_mwWindowToolbar->AddWindow(m_mwSkills);
  150. #endif
  151. AddChild(*m_mwWindowToolbar);
  152. #ifdef TerrainOnly
  153. m_mwMinimap->SetVisible(true);
  154. m_mwWindowToolbar->SetVisible(true);
  155. m_bShowConsole = true;
  156. #endif
  157. m_pbConnecting = new cProgressBar();
  158. m_pbConnecting->SetColor(0xFF0000);
  159. m_pbConnecting->SetLimits(0, 1.0f);
  160. m_pbConnecting->SetCurrent(0);
  161. AddChild(*m_pbConnecting);
  162. m_stConnecting = new cStaticText();
  163. m_stConnecting->SetTextColor(0xFFFFFF);
  164. m_stConnecting->SetTextHAlign(eCenter);
  165. AddChild(*m_stConnecting);
  166. m_picEnterGame = new cPictureBox();
  167. m_picEnterGame->SetPicture(0x06004CB2);
  168. m_picEnterGame->AddMouseEventHandler( *(MouseEventsAbstractor< cInterface > *)this );
  169. AddChild(*m_picEnterGame);
  170. m_picEnterGame->JumpToFront();
  171. // m_picMap = new cPictureBox();
  172. // m_picMap->SetPicture(0x06000261);
  173. // AddChild(*m_picMap);
  174. // m_picMap->JumpToFront();
  175. m_stMOTD = new cStaticText();
  176. m_stMOTD->SetTextColor(0xFFFFFF);
  177. m_stMOTD->SetText(m_MOTD);
  178. m_stMOTD->JumpToFront();
  179. AddChild(*m_stMOTD);
  180. for (int i=0;i<5;i++)
  181. {
  182. m_stCharList[i] = new cStaticText();
  183. m_stCharList[i]->SetTextColor(0xFFFFFF);
  184. m_stCharList[i]->SetTextHAlign(eCenter);
  185. m_stCharList[i]->JumpToFront();
  186. m_stCharList[i]->AddMouseEventHandler( *(MouseEventsAbstractor< cInterface > *)this );
  187. AddChild(*m_stCharList[i]);
  188. }
  189. m_picSelChar = new cPictureBox();
  190. m_picSelChar->JumpToBack();
  191. m_picSelChar->SetPicture(0x06001125);
  192. AddChild(*m_picSelChar);
  193. AddRenderEventHandler( *(RenderEventAbstractor< cInterface > *)this );
  194. AddMouseEventHandler( *(MouseEventsAbstractor< cInterface > *)this );
  195. AddKeyboardEventHandler( *(KeyboardEventsAbstractor< cInterface > *)this );
  196. SetInterfaceMode(eConnecting);
  197. }
  198. cInterface::~cInterface()
  199. {
  200. DeleteCriticalSection(&csChat);
  201. for (std::map<WORD, cLandblock *>::iterator i = m_mLandblocks.begin(); i != m_mLandblocks.end(); i++)
  202. delete i->second;
  203. //Clean up UI
  204. RemoveChild(*m_mwMinimap);
  205. delete m_mwMinimap;
  206. RemoveChild(*m_mwChat);
  207. delete m_mwChat;
  208. RemoveChild(*m_mwSpellBar);
  209. delete m_mwSpellBar;
  210. RemoveChild(*m_mwRadar);
  211. delete m_mwRadar;
  212. RemoveChild(*m_mwVitals);
  213. delete m_mwVitals;
  214. RemoveChild(*m_mwStats);
  215. delete m_mwStats;
  216. RemoveChild(*m_mwSkills);
  217. delete m_mwSkills;
  218. RemoveChild(*m_mwWindowToolbar);
  219. delete m_mwWindowToolbar;
  220. RemoveChild(*m_pbConnecting);
  221. delete m_pbConnecting;
  222. RemoveChild(*m_stConnecting);
  223. delete m_stConnecting;
  224. RemoveChild(*m_picEnterGame);
  225. delete m_picEnterGame;
  226. RemoveChild(*m_stMOTD);
  227. delete m_stMOTD;
  228. for (int i=0;i<5;i++)
  229. {
  230. RemoveChild(*m_stCharList[i]);
  231. delete m_stCharList[i];
  232. }
  233. RemoveChild(*m_picSelChar);
  234. delete m_picSelChar;
  235. m_WindowManager->RemoveWindow(*this);
  236. delete m_WindowManager;
  237. delete m_Cell;
  238. }
  239. void cInterface::SetNetwork(cNetwork *Network)
  240. {
  241. m_Network = Network;
  242. }
  243. void cInterface::SetObjectDB(cObjectDB *ObjectDB)
  244. {
  245. m_ObjectDB = ObjectDB;
  246. m_mwRadar->SetObjectDB(m_ObjectDB);
  247. }
  248. void cInterface::SetCharInfo(cCharInfo *CharInfo)
  249. {
  250. m_CharInfo = CharInfo;
  251. m_mwVitals->SetCharInfo(CharInfo);
  252. m_mwStats->SetCharInfo(CharInfo);
  253. m_mwSkills->SetCharInfo(CharInfo);
  254. m_mwSpellBar->SetCharInfo(CharInfo);
  255. }
  256. void cInterface::OutputConsoleString(char *format, ...)
  257. {
  258. va_list argPtr;
  259. static char output[1024];
  260. va_start(argPtr, format);
  261. vsprintf(output, format, argPtr);
  262. va_end(argPtr);
  263. OutputConsoleString((std::string)output);
  264. }
  265. void cInterface::OutputConsoleString(std::string & Output)
  266. {
  267. EnterCriticalSection(&csChat);
  268. m_vConsoleHistory.push_back(Output);
  269. OutputDebugString(Output.c_str());
  270. OutputDebugString(_T("\r\n"));
  271. FILE *out = fopen("AC2DConsole.txt","at");
  272. if (out)
  273. {
  274. fprintf(out, "%s\r\n", Output.c_str());
  275. fclose(out);
  276. }
  277. LeaveCriticalSection(&csChat);
  278. }
  279. void cInterface::OutputString(eColor Color, char *format, ...)
  280. {
  281. va_list argPtr;
  282. static char output[1024];
  283. va_start(argPtr, format);
  284. vsprintf(output, format, argPtr);
  285. va_end(argPtr);
  286. OutputString(Color, std::string(output));
  287. }
  288. void cInterface::OutputString(eColor Color, std::string & Output)
  289. {
  290. EnterCriticalSection(&csChat);
  291. m_mwChat->OutputString(Output, Color);
  292. LeaveCriticalSection(&csChat);
  293. }
  294. void cInterface::SetConnProgress(float NewProgress)
  295. {
  296. // Lock();
  297. m_fConnProgress = NewProgress;
  298. m_pbConnecting->SetCurrent(NewProgress);
  299. if (m_fConnProgress == 0.0f)
  300. m_stConnecting->SetText("Waiting for Connection to Establish...");
  301. else if (m_fConnProgress == 1.0f)
  302. m_stConnecting->SetText("Connected! Waiting for MOTD...");
  303. else
  304. {
  305. char Lele[50];
  306. sprintf(Lele, "Connecting: %i%%", (int) (m_fConnProgress*100));
  307. m_stConnecting->SetText(Lele);
  308. }
  309. // Unlock();
  310. }
  311. void cInterface::LoadLandblocks()
  312. {
  313. // OutputString(eYellow, "Loading Landblocks...");
  314. for (std::unordered_set<WORD>::iterator i = m_mNeedToLoadBlocks.begin(); i != m_mNeedToLoadBlocks.end(); i++)
  315. {
  316. cLandblock *pLB = new cLandblock();
  317. pLB->Load(*i);
  318. m_mLandblocks[*i] = pLB;
  319. }
  320. m_mNeedToLoadBlocks.clear();
  321. // OutputString(eYellow, "Done Loading.");
  322. }
  323. void cInterface::AddLandblock(cPortalFile *NewLB)
  324. {
  325. Lock();
  326. m_Cell->InsertEntry(NewLB);
  327. m_mNeedToLoadBlocks.insert(NewLB->id >> 16);
  328. Unlock();
  329. }
  330. int cInterface::Draw(RECT rRect, HDC hDC)
  331. {
  332. DispatchMessages();
  333. // Lock();
  334. m_iTriCount = 0;
  335. LARGE_INTEGER liTemp;
  336. QueryPerformanceCounter(&liTemp);
  337. float fTimeDiff = (float) (liTemp.QuadPart - liLast.QuadPart)/liFreq.QuadPart;
  338. liLast = liTemp;
  339. m_ObjectDB->UpdateObjects(fTimeDiff);
  340. //check for message sending
  341. //nuke this asap...
  342. while (m_mwChat->GetNeedSend())
  343. {
  344. //send message
  345. ParseEditInput( m_mwChat->GetTextLine() );
  346. }
  347. //Check for spell casting
  348. while (DWORD NextCast = m_mwSpellBar->GetNextCast())
  349. {
  350. stInternalSpell *IS = m_CharInfo->GetSpellInfo(NextCast);
  351. if (IS->dwFlags & 8)
  352. m_Network->CastSpell(m_dwSelChar, NextCast); //Self Spell
  353. else
  354. m_Network->CastSpell(m_dwCurSelect, NextCast); //Other Spell
  355. }
  356. if (m_InterfaceMode == eGame)
  357. {
  358. glClearColor( 107.0f/255, 178.0f/255, 255.0f/255, 1.0f );
  359. }
  360. if (bAnimUpdate)
  361. {
  362. bAnimUpdate = false;
  363. int iFB = 0, iStrafe = 0, iTurn = 0;
  364. if (bForward)
  365. iFB++;
  366. if (bBack)
  367. iFB--;
  368. if (bLeft)
  369. iTurn--;
  370. if (bRight)
  371. iTurn++;
  372. if (bStrLeft)
  373. iStrafe--;
  374. if (bStrRight)
  375. iStrafe++;
  376. m_Network->SendAnimUpdate(iFB, iStrafe, iTurn, !bShift);
  377. //Update velocity info
  378. cWObject *woMyself = m_ObjectDB->FindObject(m_dwSelChar);
  379. if (woMyself)
  380. {
  381. woMyself->SetMoveVelocities(iFB*3.0f, iStrafe*-1.0f, iTurn*1.5f);
  382. }
  383. }
  384. //Default to 2d mode
  385. glMatrixMode(GL_PROJECTION);
  386. glLoadIdentity();
  387. glOrtho(0, m_iWidth, m_iHeight, 0, 0.1, 100);
  388. gluLookAt(0, 0, 50, 0, 0, 0, 0, 1, 0);
  389. //Render all windows
  390. m_WindowManager->OnRender(fTimeDiff);
  391. //2d hacks for now until it's in the windowmanager
  392. {
  393. glListBase(0x01000000 + (12 << 8));
  394. glBindTexture( GL_TEXTURE_2D, 0);
  395. if (m_bShowConsole)
  396. {
  397. //draw console lines
  398. int iCount = 0;
  399. EnterCriticalSection(&csChat);
  400. for (std::vector<std::string>::reverse_iterator i = m_vConsoleHistory.rbegin(); (i != m_vConsoleHistory.rend()) && (iCount < 10); i++, iCount++)
  401. {
  402. glColor3f(1.0,1.0,1.0);
  403. glRasterPos2f(0, (GLfloat) ((3+(10-iCount)*13)));
  404. int iLen = (int) (*i).length();
  405. const char *Str = (*i).c_str();
  406. glCallLists(iLen, GL_UNSIGNED_BYTE, Str);
  407. }
  408. LeaveCriticalSection(&csChat);
  409. }
  410. }
  411. return m_iTriCount;
  412. // Unlock();
  413. }
  414. void cInterface::SetInterfaceMode(eInterfaceMode Mode)
  415. {
  416. Lock();
  417. //if ((Mode > eConnecting) && (m_fConnProgress < 1.0f))
  418. //{
  419. // Unlock();
  420. // return;
  421. //}
  422. m_InterfaceMode = Mode;
  423. #ifdef TerrainOnly
  424. Unlock();
  425. return;
  426. #endif
  427. switch (m_InterfaceMode)
  428. {
  429. case eConnecting:
  430. m_pbConnecting->SetVisible(true);
  431. m_stConnecting->SetVisible(true);
  432. // m_mwMinimap->SetVisible(true);
  433. m_mwWindowToolbar->SetVisible(true);
  434. // m_picMap->SetVisible(true);
  435. break;
  436. case eMOTD:
  437. m_pbConnecting->SetVisible(false);
  438. m_stConnecting->SetVisible(false);
  439. // m_picMap->SetVisible(false);
  440. m_mwMinimap->SetVisible(false);
  441. m_picEnterGame->SetVisible(true);
  442. m_stMOTD->SetVisible(true);
  443. m_picSelChar->SetVisible(true);
  444. for (int i=0;i<5;i++)
  445. m_stCharList[i]->SetVisible(true);
  446. break;
  447. case eEnteringGame:
  448. m_picEnterGame->SetVisible(false);
  449. m_stMOTD->SetVisible(true);
  450. m_picSelChar->SetVisible(true);
  451. for (int i = 0;i < 5;i++)
  452. m_stCharList[i]->SetVisible(true);
  453. break;
  454. case eGame:
  455. m_picEnterGame->SetVisible(false);
  456. m_stMOTD->SetVisible(false);
  457. for (int i=0;i<5;i++)
  458. m_stCharList[i]->SetVisible(false);
  459. m_picSelChar->SetVisible(false);
  460. m_mwRadar->SetVisible(true);
  461. m_mwChat->SetVisible(true);
  462. m_mwVitals->SetVisible(true);
  463. m_mwMinimap->SetVisible(true);
  464. m_mwStats->SetVisible(true);
  465. m_mwSkills->SetVisible(true);
  466. m_mwWindowToolbar->SetVisible(true);
  467. // m_mwSpellBar->SetVisible(true);
  468. m_WindowManager->SetFocusedWindow(this);
  469. break;
  470. }
  471. Unlock();
  472. }
  473. void cInterface::SetCharList(stCharList *CharList)
  474. {
  475. Lock();
  476. m_CharList = *CharList;
  477. if (m_CharList.CharCount)
  478. {
  479. m_dwSelChar = m_CharList.Chars[0].GUID;
  480. m_stCharList[0]->SetTextColor(0xFF);
  481. m_picSelChar->JumpToBack();
  482. m_picSelChar->SetPosition(m_stCharList[0]->GetLeft(), m_stCharList[0]->GetTop());
  483. }
  484. //Alphasort the char list now...
  485. Unlock();
  486. }
  487. void cInterface::SetMOTD(char *MOTD)
  488. {
  489. Lock();
  490. strcpy(m_MOTD, MOTD);
  491. m_stMOTD->SetText(m_MOTD);
  492. Unlock();
  493. }
  494. void cInterface::SetWorldPlayers(char *WorldName, DWORD Players, DWORD MaxPlayers)
  495. {
  496. m_dwNumPlayers = Players;
  497. strcpy(m_sWorldName, WorldName);
  498. char motdBuf[500];
  499. sprintf(motdBuf, "World: %s, Players: %i/%i", WorldName, Players, MaxPlayers);
  500. SetMOTD(motdBuf);
  501. }
  502. void cInterface::SetLastAttacker(DWORD GUID)
  503. {
  504. Lock();
  505. m_dwLastAttacker = GUID;
  506. Unlock();
  507. }
  508. void cInterface::WindowsMessage(UINT Message, WPARAM wParam, LPARAM lParam)
  509. {
  510. Lock();
  511. stWindowsMessage tpm = {Message, wParam, lParam};
  512. m_vWMessages.push_back(tpm);
  513. Unlock();
  514. }
  515. void cInterface::DispatchMessages()
  516. {
  517. Lock();
  518. std::list<stWindowsMessage>::iterator i = m_vWMessages.begin();
  519. bool MessagesLeft = (i != m_vWMessages.end());
  520. Unlock();
  521. while (MessagesLeft)
  522. {
  523. Lock();
  524. DWORD Message = (*i).Message;
  525. WPARAM wParam = (*i).wParam;
  526. LPARAM lParam = (*i).lParam;
  527. Unlock();
  528. switch (Message)
  529. {
  530. case WM_KEYUP:
  531. {
  532. m_WindowManager->OnKeyUp((DWORD) wParam);
  533. break;
  534. }
  535. case WM_CHAR:
  536. {
  537. m_WindowManager->OnKeyPress((DWORD) wParam);
  538. break;
  539. }
  540. case WM_KEYDOWN:
  541. {
  542. m_WindowManager->OnKeyDown((DWORD) wParam);
  543. break;
  544. }
  545. case WM_MOUSEMOVE:
  546. {
  547. int xPos = LOWORD(lParam);
  548. int yPos = HIWORD(lParam);
  549. m_WindowManager->OnMouseMove((float)xPos, (float)yPos, (DWORD) wParam);
  550. break;
  551. }
  552. case WM_MOUSEWHEEL:
  553. {
  554. //Mousewheel coords are screen coords for some reason... *shrug*
  555. POINT np = {LOWORD(lParam), HIWORD(lParam)};
  556. ScreenToClient(GetForegroundWindow(), &np);
  557. m_WindowManager->OnMouseWheel((float)np.x, (float)np.y, (DWORD) wParam);
  558. break;
  559. }
  560. case WM_RBUTTONUP:
  561. {
  562. int xPos = LOWORD(lParam);
  563. int yPos = HIWORD(lParam);
  564. m_WindowManager->OnMouseUp((float)xPos, (float)yPos, MK_RBUTTON);
  565. break;
  566. }
  567. case WM_RBUTTONDOWN:
  568. {
  569. int xPos = LOWORD(lParam);
  570. int yPos = HIWORD(lParam);
  571. m_WindowManager->OnMouseDown((float)xPos, (float)yPos, MK_RBUTTON);
  572. break;
  573. }
  574. case WM_LBUTTONUP:
  575. {
  576. int xPos = LOWORD(lParam);
  577. int yPos = HIWORD(lParam);
  578. m_WindowManager->OnMouseUp((float)xPos, (float)yPos, MK_LBUTTON);
  579. break;
  580. }
  581. case WM_LBUTTONDOWN:
  582. {
  583. int xPos = LOWORD(lParam);
  584. int yPos = HIWORD(lParam);
  585. m_WindowManager->OnMouseDown((float)xPos, (float)yPos, MK_LBUTTON);
  586. }
  587. break;
  588. case WM_LBUTTONDBLCLK:
  589. {
  590. int xPos = LOWORD(lParam);
  591. int yPos = HIWORD(lParam);
  592. m_WindowManager->OnDoubleClick((float)xPos, (float)yPos, MK_LBUTTON);
  593. }
  594. case WM_RBUTTONDBLCLK:
  595. {
  596. int xPos = LOWORD(lParam);
  597. int yPos = HIWORD(lParam);
  598. m_WindowManager->OnDoubleClick((float)xPos, (float)yPos, MK_RBUTTON);
  599. }
  600. break;
  601. }
  602. Lock();
  603. i++;
  604. MessagesLeft = (i != m_vWMessages.end());
  605. Unlock();
  606. }
  607. Lock();
  608. m_vWMessages.clear();
  609. Unlock();
  610. }
  611. void cInterface::ParseEditInput( std::string &szInput )
  612. {
  613. _ODS( "ParseEditInput(%d): %s", szInput.length(), szInput.c_str() );
  614. int iLen = (int) szInput.length();
  615. // Yelling at the user now would be fun, but oh well
  616. if( iLen < 1 )
  617. return;
  618. // people who use @ are dumb
  619. if( szInput[0] == '/' || szInput[0] == '@' )
  620. {
  621. char *Input = const_cast< char * >( szInput.c_str() ) + 1;
  622. if( ! strnicmp( Input, "sm", 2 ) )
  623. {
  624. m_Network->SendMaterialize();
  625. }
  626. if( ! strnicmp( Input, "tell ", 5 ) )
  627. {
  628. char *Name = Input + 5; // "tell "
  629. char *Comma = strstr( Name, "," );
  630. // yell here
  631. if( Comma == NULL )
  632. OutputString( eYellow2, "You need to enter a name, followed by a comma, then your message." );
  633. else
  634. {
  635. *Comma = 0;
  636. m_Network->SendTell( std::string( Name ), std::string( Comma + 1 ) );
  637. }
  638. }
  639. else if( ! strnicmp( Input, "cast ", 5 ) )
  640. {
  641. char *szAfterSpace = Input + 5; // "scast "
  642. if( *szAfterSpace == 0 )
  643. OutputString( eYellow2, "Type /cast and the spell id to cast a spell on something." );
  644. else
  645. {
  646. DWORD dwGUID = atoi( szAfterSpace );
  647. m_Network->CastSpell( m_dwCurSelect, dwGUID );
  648. }
  649. }
  650. else if( ! strnicmp( Input, "ar", sizeof("ar") ) )
  651. m_Network->SendAllegianceRecall();
  652. else if( ! strnicmp( Input, "hr", sizeof("hr") ) )
  653. m_Network->SendHouseRecall();
  654. else if( ! strnicmp( Input, "lr", sizeof("lr") ) )
  655. m_Network->SendLifestoneRecall();
  656. else if( ! strnicmp( Input, "mr", sizeof("mr") ) )
  657. m_Network->SendMarketplaceRecall();
  658. }
  659. else
  660. {
  661. _ODS( "Sending '%s' local broadcast...", szInput.c_str() );
  662. m_Network->SendPublicMessage( szInput );
  663. }
  664. }
  665. bool cInterface::OnMouseMove( IWindow & Window, float X, float Y, unsigned long Button )
  666. {
  667. if (bRotating)
  668. {
  669. m_fCamRotX = fStartX + (X - fLastX)/100;
  670. m_fCamRotY = fStartY - (Y - fLastY)/100;
  671. }
  672. return true;
  673. }
  674. bool cInterface::OnMouseWheel( IWindow & Window, float X, float Y, unsigned long Button )
  675. {
  676. int Delta = GET_WHEEL_DELTA_WPARAM(Button);
  677. if (Delta > 0)
  678. {
  679. m_fCamDist *= 0.9f;
  680. }
  681. if (Delta < 0)
  682. {
  683. m_fCamDist *= 1.1f;
  684. }
  685. return true;
  686. }
  687. bool cInterface::OnMouseDown( IWindow & Window, float X, float Y, unsigned long Button )
  688. {
  689. if (Button & 2)
  690. {
  691. bRotating = true;
  692. fLastX = X;
  693. fLastY = Y;
  694. fStartX = m_fCamRotX;
  695. fStartY = m_fCamRotY;
  696. }
  697. #ifdef TerrainOnly
  698. {
  699. DWORD *pbSelBuffer = new DWORD[500];
  700. ZeroMemory(pbSelBuffer, 500*4);
  701. glSelectBuffer(500, (GLuint *) pbSelBuffer);
  702. glRenderMode(GL_SELECT);
  703. glInitNames();
  704. DWORD dwX = (DWORD) (X), dwY = (DWORD) (Y);
  705. GLint viewport[4];
  706. glGetIntegerv (GL_VIEWPORT, viewport);
  707. glEnable(GL_DEPTH_TEST);
  708. glMatrixMode(GL_PROJECTION);
  709. glLoadIdentity();
  710. gluPickMatrix( dwX, (viewport[3] - dwY), 1.0, 1.0, viewport);
  711. gluPerspective(90,(float)m_iWidth/m_iHeight, 0.001, 100);
  712. cPoint3D MyPos = FlyerCenter;
  713. cPoint3D CamLoc = MyPos;
  714. CamLoc.z -= 1.0f;
  715. CamLoc.RotateAround(MyPos, cPoint3D(m_fCamRotY, 0, 0));
  716. CamLoc.RotateAround(MyPos, cPoint3D(0, 0, -m_fCamRotX));
  717. cPoint3D CamUp = cPoint3D(0, 1, 0);
  718. CamUp.RotateAround(cPoint3D(0,0,0), cPoint3D(m_fCamRotY, 0, 0));
  719. CamUp.RotateAround(cPoint3D(0,0,0), cPoint3D(0, 0, -m_fCamRotX));
  720. gluLookAt(MyPos.x, MyPos.y, MyPos.z, CamLoc.x, CamLoc.y, CamLoc.z, CamUp.x, CamUp.y, CamUp.z);
  721. // gluLookAt(CamLoc.x, CamLoc.y, CamLoc.z + 1.0f/240.0f, MyPos.x, MyPos.y, MyPos.z + 1.0f/240.0f, CamUp.x, CamUp.y, CamUp.z);
  722. int dwBlockX = 1.25f*(101.95+FlyerCenter.x);
  723. if (dwBlockX < 0) dwBlockX = 0;
  724. if (dwBlockX > 255) dwBlockX = 255;
  725. int dwBlockY = 1.25f*(101.95+FlyerCenter.y);
  726. if (dwBlockY < 0) dwBlockY = 0;
  727. if (dwBlockY > 255) dwBlockY = 255;
  728. DWORD LBX = dwBlockY;
  729. DWORD LBY = dwBlockX;
  730. m_mCurrentLandblocks.clear();
  731. int Y1 = LBY-m_iRenderRadius, Y2 = LBY+m_iRenderRadius;
  732. if (Y1 < 0) Y1 = 0; if (Y2 > 255) Y2 = 255;
  733. int X1 = LBX-m_iRenderRadius, X2 = LBX+m_iRenderRadius;
  734. if (X1 < 0) X1 = 0; if (X2 > 255) X2 = 255;
  735. for (DWORD y=Y1;y<=(DWORD)Y2;y++)
  736. {
  737. for (DWORD x=X1;x<=(DWORD)X2;x++)
  738. {
  739. WORD wLB = x | (y << 8);
  740. m_mCurrentLandblocks.insert(wLB);
  741. if (m_mLandblocks.find(wLB) == m_mLandblocks.end())
  742. if (m_mDownloadingLandblocks.find(wLB) == m_mDownloadingLandblocks.end())
  743. m_mNeedToLoadBlocks.insert(wLB);
  744. }
  745. }
  746. if (m_mNeedToLoadBlocks.size())
  747. LoadLandblocks();
  748. for (std::unordered_set<WORD>::iterator i = m_mCurrentLandblocks.begin(); i != m_mCurrentLandblocks.end(); i++)
  749. {
  750. if (m_mLandblocks.find(*i) != m_mLandblocks.end())
  751. {
  752. cLandblock *pLB = m_mLandblocks.find(*i)->second;
  753. pLB->Draw();
  754. }
  755. }
  756. glFlush();
  757. int iHits = glRenderMode(GL_RENDER);
  758. //i don't think this works right...
  759. float fLeast = 1.0;
  760. for (int i=0;i<iHits;i++)
  761. {
  762. float fNew = *((float *) &pbSelBuffer[4*i+2]);
  763. if (fNew <= fLeast)
  764. {
  765. fLeast = fNew;
  766. m_dwCurSelect = pbSelBuffer[4*i+3];
  767. }
  768. }
  769. char lele[500];
  770. sprintf(lele, "%08X\r\n", m_dwCurSelect);
  771. OutputDebugString(lele);
  772. delete []pbSelBuffer;
  773. }
  774. #endif
  775. if (m_InterfaceMode == eMOTD)
  776. {
  777. for (int i=0;i<m_CharList.CharCount;i++)
  778. {
  779. if (&Window == m_stCharList[i])
  780. {
  781. m_picSelChar->SetPosition(m_stCharList[i]->GetLeft(), m_stCharList[i]->GetTop());
  782. m_dwSelChar = m_CharList.Chars[i].GUID;
  783. for (int h=0;h<m_CharList.CharCount;h++)
  784. {
  785. m_mgChars[h]->SetDefaultAnim(0x03000002);
  786. m_stCharList[h]->SetTextColor(0xFFFFFF);
  787. }
  788. m_stCharList[i]->SetTextColor(0x0000FF);
  789. m_mgChars[i]->SetDefaultAnim(0);
  790. m_mgChars[i]->PlayAnimation( 0x03000853, 0, 0xFFFFFFFF, 30.0f );
  791. }
  792. }
  793. if (&Window == m_picEnterGame)
  794. {
  795. //Enter game
  796. m_picEnterGame->SetPicture(0x06004CB3);
  797. }
  798. }
  799. if (m_InterfaceMode == eGame)
  800. {
  801. cWObject *woMyself = m_ObjectDB->FindObject(m_dwSelChar);
  802. cPoint3D MyPos;
  803. float fMyHead = 0;
  804. if (woMyself)
  805. {
  806. woMyself->Lock();
  807. MyPos = woMyself->GetPosition();
  808. fMyHead = woMyself->GetHeading();
  809. woMyself->Unlock();
  810. }
  811. else
  812. return true;
  813. DWORD *pbSelBuffer = new DWORD[500];
  814. ZeroMemory(pbSelBuffer, 500*4);
  815. glSelectBuffer(500, (GLuint *) pbSelBuffer);
  816. glRenderMode(GL_SELECT);
  817. glInitNames();
  818. DWORD dwX = (DWORD) (X), dwY = (DWORD) (Y);
  819. GLint viewport[4];
  820. glGetIntegerv (GL_VIEWPORT, viewport);
  821. glEnable(GL_DEPTH_TEST);
  822. glMatrixMode(GL_PROJECTION);
  823. glLoadIdentity();
  824. gluPickMatrix( dwX, (viewport[3] - dwY), 1.0, 1.0, viewport);
  825. gluPerspective(90,(float)m_iWidth/m_iHeight, 0.001, 100);
  826. cPoint3D CamLoc = MyPos;
  827. CamLoc.z += m_fCamDist;
  828. CamLoc.RotateAround(MyPos, cPoint3D(m_fCamRotY, 0, 0));
  829. CamLoc.RotateAround(MyPos, cPoint3D(0, 0, m_fCamRotX+fMyHead));
  830. cPoint3D CamUp = cPoint3D(0, 1, 0);
  831. CamUp.RotateAround(cPoint3D(0,0,0), cPoint3D(m_fCamRotY, 0, 0));
  832. CamUp.RotateAround(cPoint3D(0,0,0), cPoint3D(0, 0, m_fCamRotX+fMyHead));
  833. gluLookAt(CamLoc.x, CamLoc.y, CamLoc.z + 1.0f/240.0f, MyPos.x, MyPos.y, MyPos.z + 1.0f/240.0f, CamUp.x, CamUp.y, CamUp.z);
  834. m_ObjectDB->Lock();
  835. std::list<cWObject *> * DrawList = m_ObjectDB->GetObjectsWithin(MyPos, 3.3f);
  836. for (std::list<cWObject *>::iterator i = DrawList->begin(); i != DrawList->end(); i++)
  837. {
  838. glPushName((*i)->GetGUID());
  839. (*i)->Draw();
  840. glPopName();
  841. }
  842. delete DrawList;
  843. m_ObjectDB->Unlock();
  844. glFlush();
  845. int iHits = glRenderMode(GL_RENDER);
  846. //i don't think this works right...
  847. float fLeast = 1.0;
  848. for (int i=0;i<iHits;i++)
  849. {
  850. if (*((float *) &pbSelBuffer[4*i+2]) <= fLeast)
  851. {
  852. fLeast = *((float *) &pbSelBuffer[4*i+2]);
  853. m_dwCurSelect = pbSelBuffer[4*i+3];
  854. }
  855. }
  856. delete []pbSelBuffer;
  857. }
  858. return true;
  859. }
  860. bool cInterface::OnMouseUp( IWindow & Window, float X, float Y, unsigned long Button )
  861. {
  862. bRotating = false;
  863. if (m_InterfaceMode == eMOTD)
  864. {
  865. //fix this
  866. float xPos = X;
  867. float yPos = Y;
  868. if (&Window == m_picEnterGame)
  869. {
  870. //Enter game
  871. OutputConsoleString("Trying to enter game...");
  872. m_mwRadar->SetChar(m_dwSelChar);
  873. m_picEnterGame->SetPicture(0x06004CB2);
  874. m_Network->SendEnterWorldRequest(m_dwSelChar);
  875. }
  876. }
  877. return true;
  878. }
  879. bool cInterface::OnKeyUp( IWindow & Window, unsigned long KeyCode )
  880. {
  881. if (KeyCode == 'W')
  882. {
  883. bForward = false;
  884. bAnimUpdate = true;
  885. }
  886. if (KeyCode == 'S')
  887. {
  888. bBack = false;
  889. bAnimUpdate = true;
  890. }
  891. if (KeyCode == 'A')
  892. {
  893. bLeft = false;
  894. bAnimUpdate = true;
  895. }
  896. if (KeyCode == 'D')
  897. {
  898. bRight = false;
  899. bAnimUpdate = true;
  900. }
  901. if (KeyCode == 'Z')
  902. {
  903. bStrLeft = false;
  904. bAnimUpdate = true;
  905. }
  906. if (KeyCode == 'C')
  907. {
  908. bStrRight = false;
  909. bAnimUpdate = true;
  910. }
  911. if (KeyCode == 'F')
  912. {
  913. if (fSpeed == 1)
  914. fSpeed = 2;
  915. else if (fSpeed == 2)
  916. fSpeed = 4;
  917. else if (fSpeed == 4)
  918. fSpeed = 8;
  919. else if (fSpeed == 8)
  920. fSpeed = 16;
  921. else if (fSpeed == 16)
  922. fSpeed = 32;
  923. else if (fSpeed == 32)
  924. fSpeed = 0.2f;
  925. else if (fSpeed == 0.2f)
  926. fSpeed = 0.5f;
  927. else if (fSpeed == 0.5f)
  928. fSpeed = 1;
  929. }
  930. return true;
  931. }
  932. bool cInterface::OnKeyDown( IWindow & Window, unsigned long KeyCode )
  933. {
  934. if ((KeyCode >= '1') && (KeyCode <= '9'))
  935. {
  936. m_iRenderRadius = 2*(int) (KeyCode - '1' + 1);
  937. }
  938. if (KeyCode == VK_OEM_3) //~
  939. {
  940. if (m_InterfaceMode == eGame)
  941. {
  942. m_bCombatMode ^= true;
  943. m_Network->SetCombatMode(m_bCombatMode);
  944. OutputString( eBlue, "Changing to %s mode!", m_bCombatMode ? "combat" : "peace" );
  945. //TODO: set this up to match to the new stance!
  946. m_mwSpellBar->SetVisible(m_bCombatMode);
  947. }
  948. }
  949. if (KeyCode == 'R')
  950. {
  951. if (m_InterfaceMode == eGame)
  952. m_Network->UseItem(m_dwCurSelect);
  953. }
  954. if (KeyCode == VK_ESCAPE)
  955. {
  956. m_bShowConsole ^= true;
  957. }
  958. if (KeyCode == VK_OEM_2) // forward slash and ?
  959. {
  960. if (m_InterfaceMode == eGame)
  961. {
  962. cWObject *woMyself = m_ObjectDB->FindObject(m_dwSelChar);
  963. if (woMyself)
  964. {
  965. m_ObjectDB->Lock();
  966. cPoint3D p3dMyself = woMyself->GetPosition();
  967. m_ObjectDB->Unlock();
  968. std::list<cWObject *> * SortList = m_ObjectDB->GetObjectsWithin(p3dMyself, 0.3f);
  969. m_ObjectDB->Lock();
  970. float fMaxDist = 100.0f;
  971. DWORD dwClosest = 0;
  972. for (std::list<cWObject *>::iterator i = SortList->begin(); i != SortList->end(); i++)
  973. {
  974. if (*i == woMyself)
  975. continue;
  976. cPoint3D p3dPos = (*i)->GetPosition();
  977. float fDist = (p3dMyself - p3dPos).Abs();
  978. if (fDist < fMaxDist)
  979. {
  980. dwClosest = (*i)->GetGUID();
  981. fMaxDist = fDist;
  982. }
  983. }
  984. m_dwCurSelect = dwClosest;
  985. m_ObjectDB->Unlock();
  986. delete SortList;
  987. }
  988. }
  989. }
  990. // if (KeyCode == VK_END)
  991. // {
  992. // m_Network->CastSpell(m_dwCurSelect, 27);
  993. // }
  994. if (KeyCode == 'W')
  995. {
  996. if (!bForward)
  997. {
  998. bForward = true;
  999. bAnimUpdate = true;
  1000. }
  1001. }
  1002. if (KeyCode == 'S')
  1003. {
  1004. if (!bBack)
  1005. {
  1006. bBack = true;
  1007. bAnimUpdate = true;
  1008. }
  1009. /* cWObject *woMyself = m_ObjectDB->FindObject(m_dwSelChar);
  1010. if (woMyself)
  1011. {
  1012. m_ObjectDB->Lock();
  1013. stLocation *lTemp = woMyself->GetLocation();
  1014. stMoveInfo mTemp = woMyself->GetMoveInfo();
  1015. float fHead = woMyself->GetHeading();
  1016. lTemp->xOffset -= -sin(fHead);
  1017. lTemp->yOffset += -cos(fHead);
  1018. m_ObjectDB->Unlock();
  1019. m_Network->SendPositionUpdate(lTemp, &mTemp);
  1020. stLocation *lTemp = woMyself->GetLocation();
  1021. stMoveInfo mTemp = woMyself->GetMoveInfo();
  1022. cPacket *CS = new cPacket();
  1023. CS->Add((DWORD) 0xF61C);
  1024. CS->Add((DWORD) 5);
  1025. CS->Add((DWORD) 2); //flag 1 - running
  1026. CS->Add((DWORD) 0x45000005); //flag 4 - forward
  1027. CS->Add(lTemp, sizeof(stLocation)); //full location
  1028. mTemp.moveCount = 0;
  1029. CS->Add(&mTemp, sizeof(stMoveInfo)); //movement info
  1030. CS->Add((DWORD) 1); //?
  1031. m_Network->SendWSGameEvent(CS, 5); //definitely group 5
  1032. }*/
  1033. }
  1034. if (KeyCode == 'A')
  1035. {
  1036. if (!bLeft)
  1037. {
  1038. bLeft = true;
  1039. bAnimUpdate = true;
  1040. }
  1041. }
  1042. if (KeyCode == 'D')
  1043. {
  1044. if (!bRight)
  1045. {
  1046. bRight = true;
  1047. bAnimUpdate = true;
  1048. }
  1049. }
  1050. if (KeyCode == 'Z')
  1051. {
  1052. if (!bStrLeft)
  1053. {
  1054. bStrLeft = true;
  1055. bAnimUpdate = true;
  1056. }
  1057. }
  1058. if (KeyCode == 'C')
  1059. {
  1060. if (!bStrRight)
  1061. {
  1062. bStrRight = true;
  1063. bAnimUpdate = true;
  1064. }
  1065. }
  1066. if (KeyCode == VK_UP)
  1067. {
  1068. m_fCamRotY -= (float) M_PI/20;
  1069. if (m_fCamRotY < 0) m_fCamRotY = 0;
  1070. }
  1071. if (KeyCode == VK_DOWN)
  1072. {
  1073. m_fCamRotY += (float) M_PI/20;
  1074. if (m_fCamRotY > M_PI) m_fCamRotY = (float) M_PI;
  1075. }
  1076. if (KeyCode == VK_LEFT)
  1077. {
  1078. /* m_dwBaseTex -= 36;
  1079. if (m_dwBaseTex < 0) m_dwBaseTex = 0;
  1080. for (int y=0; y<6; y++)
  1081. for (int x=0; x<6; x++)
  1082. m_pbTex[y][x]->SetPicture(dwTexBase | (y*6 + x + m_dwBaseTex));
  1083. */
  1084. if (m_InterfaceMode == eConnecting)
  1085. {
  1086. }
  1087. if (m_InterfaceMode == eMOTD)
  1088. {
  1089. dwAnim--;
  1090. for (int i=0;i<m_CharList.CharCount;i++)
  1091. m_mgChars[i]->PlayAnimation(dwAnim, 0, 0xFFFFFFFE, 30.0f),OutputConsoleString( "Playing animation %08x...", dwAnim );
  1092. }
  1093. m_fCamRotX -= (float) M_PI/20;
  1094. }
  1095. if (KeyCode == VK_RIGHT)
  1096. {
  1097. /* m_dwBaseTex += 36;
  1098. if (m_dwBaseTex < 0) m_dwBaseTex = 0;
  1099. for (int y=0; y<6; y++)
  1100. for (int x=0; x<6; x++)
  1101. m_pbTex[y][x]->SetPicture(dwTexBase | (y*6 + x + m_dwBaseTex));
  1102. */
  1103. if (m_InterfaceMode == eConnecting)
  1104. {
  1105. }
  1106. if (m_InterfaceMode == eMOTD)
  1107. {
  1108. dwAnim++;
  1109. for (int i=0;i<m_CharList.CharCount;i++)
  1110. m_mgChars[i]->PlayAnimation(dwAnim, 0, 0xFFFFFFFE, 30.0f),OutputConsoleString( "Playing animation %08x...", dwAnim );
  1111. }
  1112. m_fCamRotX += (float) M_PI/20;
  1113. }
  1114. if (KeyCode == VK_ADD)
  1115. {
  1116. m_fCamDist *= 0.9f;
  1117. }
  1118. if (KeyCode == VK_SUBTRACT)
  1119. {
  1120. m_fCamDist *= 1.1f;
  1121. }
  1122. if ((KeyCode == VK_NUMPAD0) || (KeyCode == VK_INSERT))
  1123. {
  1124. //reset to defs
  1125. m_fCamDist = 0.018f;
  1126. m_fCamRotX = 0;
  1127. m_fCamRotY = (float) M_PI/3;
  1128. }
  1129. return true;
  1130. }
  1131. void cInterface::Resize(int iWidth, int iHeight)
  1132. {
  1133. m_iWidth = iWidth;
  1134. m_iHeight = iHeight;
  1135. SetPosition(0, 0);
  1136. SetSize((float)m_iWidth, (float)m_iHeight);
  1137. m_mwWindowToolbar->SetPosition(iWidth/2 - (m_mwWindowToolbar->GetWidth()/2), 0);
  1138. //Connecting screen stuff...
  1139. m_pbConnecting->SetSize(0.8f*iWidth, 0.03f*iHeight);
  1140. m_pbConnecting->SetPosition(0.1f*iWidth, 0.75f*iHeight);
  1141. m_stConnecting->SetSize(0.8f*iWidth, 0.03f*iHeight);
  1142. m_stConnecting->SetPosition(0.1f*iWidth, (0.75f+0.03f)*iHeight);
  1143. m_picEnterGame->SetSize(iWidth/4.0f, iHeight/4.0f);
  1144. m_picEnterGame->SetPosition(3*iWidth/4.0f, iHeight/2.0f+20);
  1145. // m_picMap->SetSize(1*iWidth/2.0f, 1*iHeight/2.0f);
  1146. // m_picMap->SetPosition(2*iWidth/8.0f, 1*iHeight/8.0f);
  1147. m_stMOTD->SetSize(3*iWidth/4-10.0f, iHeight/2-30.0f);
  1148. m_stMOTD->SetPosition(10, iHeight/2+30.0f);
  1149. for (int i=0;i<5;i++)
  1150. {
  1151. m_stCharList[i]->SetSize(iWidth/5.0f, 15.0f);
  1152. m_stCharList[i]->SetPosition(iWidth*i/5.0f, iHeight/2.0f);
  1153. if (i < m_CharList.CharCount)
  1154. if (m_dwSelChar == m_CharList.Chars[i].GUID)
  1155. m_picSelChar->SetPosition(m_stCharList[i]->GetLeft(), m_stCharList[i]->GetTop());
  1156. }
  1157. m_picSelChar->SetSize(iWidth/5.0f, 15);
  1158. m_mwSpellBar->SetSize((float)0.9f*iWidth, 16+32+16);
  1159. m_mwSpellBar->SetPosition(0.05f*iWidth, iHeight-64);
  1160. if (m_bFirstSize)
  1161. {
  1162. m_bFirstSize = false;
  1163. m_mwChat->SetSize((float)iWidth - 190, 0.25f*iHeight);
  1164. m_mwChat->SetPosition(10, iHeight - m_mwChat->GetHeight() - m_mwSpellBar->GetHeight() - 10);
  1165. m_mwChat->SetAnchorTop(false);
  1166. m_mwChat->SetAnchorBottom(true);
  1167. m_mwChat->SetAnchorRight(true);
  1168. m_mwSpellBar->SetAnchorTop(false);
  1169. m_mwSpellBar->SetAnchorBottom(true);
  1170. m_mwSpellBar->SetAnchorRight(true);
  1171. m_mwRadar->SetPosition(iWidth-110.0f, 0);
  1172. m_mwRadar->SetAnchorLeft(false);
  1173. m_mwRadar->SetAnchorRight(true);
  1174. m_mwMinimap->SetPosition(iWidth-150.0f, m_mwRadar->GetHeight() + 10);
  1175. m_mwMinimap->SetAnchorLeft(false);
  1176. m_mwMinimap->SetAnchorRight(true);
  1177. m_mwStats->SetPosition(0, m_mwVitals->GetTop() + m_mwVitals->GetHeight() + 10);
  1178. m_mwSkills->SetPosition(iWidth-170.0f, m_mwMinimap->GetTop() + m_mwMinimap->GetHeight() + 10);
  1179. m_mwSkills->SetSize(170.0f, m_mwSpellBar->GetTop() - m_mwSkills->GetTop() - 10);
  1180. m_mwSkills->SetAnchorBottom(true);
  1181. m_mwSkills->SetAnchorLeft(false);
  1182. m_mwSkills->SetAnchorRight(true);
  1183. m_mwVitals->SetPosition(0, 0);
  1184. }
  1185. }
  1186. bool cInterface::OnRender( IWindow & Window, double TimeSlice )
  1187. {
  1188. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  1189. if (m_InterfaceMode == eConnecting)
  1190. {
  1191. glEnable(GL_DEPTH_TEST);
  1192. glMatrixMode(GL_PROJECTION);
  1193. glLoadIdentity();
  1194. glEnable(GL_BLEND);
  1195. //use this code to draw sanc on the connecting screen... for debugging only...
  1196. #ifdef TerrainOnly
  1197. // glEnable(GL_LIGHTING);
  1198. glEnable(GL_COLOR_MATERIAL);
  1199. gluPerspective(90,(float)m_iWidth/m_iHeight, 0.001, 100);
  1200. glViewport(0, 0, m_iWidth, m_iHeight);
  1201. if (bForward)
  1202. {
  1203. cPoint3D CamLoc = cPoint3D(0,0,-0.15f);
  1204. CamLoc.RotateAround(cPoint3D(0,0,0), cPoint3D(m_fCamRotY, 0, 0));
  1205. CamLoc.RotateAround(cPoint3D(0,0,0), cPoint3D(0, 0, -m_fCamRotX));
  1206. FlyerCenter += CamLoc*TimeSlice*fSpeed;
  1207. }
  1208. if (bBack)
  1209. {
  1210. cPoint3D CamLoc = cPoint3D(0,0,-0.15f);
  1211. CamLoc.RotateAround(cPoint3D(0,0,0), cPoint3D(m_fCamRotY, 0, 0));
  1212. CamLoc.RotateAround(cPoint3D(0,0,0), cPoint3D(0, 0, -m_fCamRotX));
  1213. FlyerCenter -= CamLoc*TimeSlice*fSpeed;
  1214. }
  1215. if (bLeft)
  1216. {
  1217. cPoint3D CamLoc = cPoint3D(-0.15f,0,0);
  1218. CamLoc.RotateAround(cPoint3D(0,0,0), cPoint3D(m_fCamRotY, 0, 0));
  1219. CamLoc.RotateAround(cPoint3D(0,0,0), cPoint3D(0, 0, -m_fCamRotX));
  1220. FlyerCenter += CamLoc*TimeSlice*fSpeed;
  1221. }
  1222. if (bRight)
  1223. {
  1224. cPoint3D CamLoc = cPoint3D(-0.15f,0,0);
  1225. CamLoc.RotateAround(cPoint3D(0,0,0), cPoint3D(m_fCamRotY, 0, 0));
  1226. CamLoc.RotateAround(cPoint3D(0,0,0), cPoint3D(0, 0, -m_fCamRotX));
  1227. FlyerCenter -= CamLoc*TimeSlice*fSpeed;
  1228. }
  1229. GLfloat pos0[4] = { FlyerCenter.x,FlyerCenter.y,FlyerCenter.z, 1.0 }; glLightfv(GL_LIGHT0,GL_POSITION,pos0);
  1230. POINTf tpP;
  1231. if (m_mwMinimap->GetClicked(&tpP))
  1232. {
  1233. FlyerCenter.x = tpP.x;
  1234. FlyerCenter.y = tpP.y;
  1235. }
  1236. m_mwMinimap->SetPlayerPosition(FlyerCenter, -m_fCamRotX);
  1237. cPoint3D MyPos = FlyerCenter;
  1238. cPoint3D CamLoc = MyPos;
  1239. CamLoc.z -= 1.0f;
  1240. CamLoc.RotateAround(MyPos, cPoint3D(m_fCamRotY, 0, 0));
  1241. CamLoc.RotateAround(MyPos, cPoint3D(0, 0, -m_fCamRotX));
  1242. cPoint3D CamUp = cPoint3D(0, 1, 0);
  1243. CamUp.RotateAround(cPoint3D(0,0,0), cPoint3D(m_fCamRotY, 0, 0));
  1244. CamUp.RotateAround(cPoint3D(0,0,0), cPoint3D(0, 0, -m_fCamRotX));
  1245. gluLookAt(MyPos.x, MyPos.y, MyPos.z, CamLoc.x, CamLoc.y, CamLoc.z, CamUp.x, CamUp.y, CamUp.z);
  1246. int dwBlockX = 1.25f*(101.95+FlyerCenter.x);
  1247. if (dwBlockX < 0) dwBlockX = 0;
  1248. if (dwBlockX > 255) dwBlockX = 255;
  1249. int dwBlockY = 1.25f*(101.95+FlyerCenter.y);
  1250. if (dwBlockY < 0) dwBlockY = 0;
  1251. if (dwBlockY > 255) dwBlockY = 255;
  1252. DWORD LBX = dwBlockX;
  1253. DWORD LBY = dwBlockY;
  1254. m_mCurrentLandblocks.clear();
  1255. int Y1 = LBY-m_iRenderRadius, Y2 = LBY+m_iRenderRadius;
  1256. if (Y1 < 0) Y1 = 0; if (Y2 > 255) Y2 = 255;
  1257. int X1 = LBX-m_iRenderRadius, X2 = LBX+m_iRenderRadius;
  1258. if (X1 < 0) X1 = 0; if (X2 > 255) X2 = 255;
  1259. for (DWORD y=Y1;y<=(DWORD)Y2;y++)
  1260. {
  1261. for (DWORD x=X1;x<=(DWORD)X2;x++)
  1262. {
  1263. WORD wLB = (x << 8) | y;
  1264. m_mCurrentLandblocks.insert(wLB);
  1265. if (m_mLandblocks.find(wLB) == m_mLandblocks.end())
  1266. if (m_mDownloadingLandblocks.find(wLB) == m_mDownloadingLandblocks.end())
  1267. m_mNeedToLoadBlocks.insert(wLB);
  1268. }
  1269. }
  1270. if (m_mNeedToLoadBlocks.size())
  1271. LoadLandblocks();
  1272. for (std::unordered_set<WORD>::iterator i = m_mCurrentLandblocks.begin(); i != m_mCurrentLandblocks.end(); i++)
  1273. {
  1274. if (m_mLandblocks.find(*i) != m_mLandblocks.end())
  1275. {
  1276. cLandblock *pLB = m_mLandblocks.find(*i)->second;
  1277. m_iTriCount += pLB->Draw();
  1278. }
  1279. }
  1280. glDisable(GL_LIGHTING);
  1281. //End landscape viewer here
  1282. #else
  1283. //bz/asheron here
  1284. glOrtho(-1.5, 1.5, -1.0f, 1.05f, 0.001, 100);
  1285. gluLookAt(0, 1.5f, 0.85f, 0, 0, 0.85f, 0, 0, 1);
  1286. glViewport(0, m_iHeight/4, m_iWidth, 3*m_iHeight/4);
  1287. if (!m_mgBZ)
  1288. {
  1289. m_mgBZ = new cModelGroup();
  1290. m_mgBZ->ReadModel(0x0200099E);
  1291. m_mgBZ->SetRotation(-(float)sqrt(2.0)/2, 0, 0, 0.5);
  1292. m_mgBZ->SetTranslation(cPoint3D(-0.7f, 0, 0));
  1293. m_mgBZ->SetScale(0.7f);
  1294. m_mgBZ->SetDefaultAnim(0x03000002);
  1295. //now load model cache
  1296. /* std::vector<stModelSwap> mod; mod.clear();
  1297. std::vector<stTextureSwap> tex; tex.clear();
  1298. std::vector<stPaletteSwap> pal; pal.clear();
  1299. char tpfn[80];
  1300. size_t iCount;
  1301. sprintf(tpfn, "C:\\program files\\Turbine\\Asheron's Call - Throne of Destiny\\5005AFB1.charcache");
  1302. FILE *tpo = fopen(tpfn, "rb");
  1303. if (tpo)
  1304. {
  1305. fread(&iCount, 4, 1, tpo);
  1306. for (DWORD i=0;i<iCount;i++)
  1307. {
  1308. stModelSwap tpm;
  1309. fread(&tpm, sizeof(stModelSwap), 1, tpo);
  1310. mod.push_back(tpm);
  1311. }
  1312. fread(&iCount, 4, 1, tpo);
  1313. for (DWORD i=0;i<iCount;i++)
  1314. {
  1315. stTextureSwap tpm;
  1316. fread(&tpm, sizeof(stTextureSwap), 1, tpo);
  1317. tex.push_back(tpm);
  1318. }
  1319. fread(&iCount, 4, 1, tpo);
  1320. for (DWORD i=0;i<iCount;i++)
  1321. {
  1322. stPaletteSwap tpm;
  1323. fread(&tpm, sizeof(stPaletteSwap), 1, tpo);
  1324. pal.push_back(tpm);
  1325. }
  1326. fclose(tpo);
  1327. }
  1328. m_mgBZ = new cModelGroup();
  1329. m_mgBZ->ReadModel(0x02000001, &pal, &tex, &mod);
  1330. m_mgBZ->SetRotation(-(float)sqrt(2.0)*0, 0, 0, 0.5);
  1331. m_mgBZ->SetTranslation(cPoint3D(-0.7f, 0, 0));
  1332. m_mgBZ->SetScale(1.0f);
  1333. m_mgBZ->SetDefaultAnim(0x03000002);
  1334. */
  1335. m_mgAsh = new cModelGroup();
  1336. m_mgAsh->ReadModel(0x020009C8);
  1337. m_mgAsh->SetRotation((float)sqrt(2.0)/2, 0, 0, 0.5);
  1338. m_mgAsh->SetTranslation(cPoint3D(0.7f, 0, 0));
  1339. m_mgAsh->SetScale(0.7f);
  1340. m_mgAsh->SetDefaultAnim(0x03000002);
  1341. }
  1342. m_mgBZ->UpdateAnim((float) TimeSlice);
  1343. m_mgAsh->UpdateAnim((float) TimeSlice);
  1344. m_mgBZ->Draw();
  1345. m_mgAsh->Draw();
  1346. //end bz/asheron
  1347. #endif
  1348. glViewport(0, 0, m_iWidth, m_iHeight);
  1349. gluPerspective(90,(float)m_iWidth/m_iHeight, 0.001, 100);
  1350. glDisable(GL_DEPTH_TEST);
  1351. glMatrixMode(GL_PROJECTION);
  1352. glLoadIdentity();
  1353. glOrtho(0, m_iWidth, m_iHeight, 0, 0.1, 100);
  1354. gluLookAt(0, 0, 50, 0, 0, 0, 0, 1, 0);
  1355. }
  1356. if (m_InterfaceMode == eMOTD)
  1357. {
  1358. if ((m_CharList.CharCount) && (!m_mgChars[0]))
  1359. {
  1360. for (int i=0;i<m_CharList.CharCount;i++)
  1361. {
  1362. m_stCharList[i]->SetText(m_CharList.Chars[i].Name);
  1363. //now load model cache
  1364. std::vector<stModelSwap> mod; mod.clear();
  1365. std::vector<stTextureSwap> tex; tex.clear();
  1366. std::vector<stPaletteSwap> pal; pal.clear();
  1367. char tpfn[80];
  1368. size_t iCount = 0;
  1369. sprintf(tpfn, "%08X.charcache", m_CharList.Chars[i].GUID);
  1370. FILE *tpo = fopen(tpfn, "rb");
  1371. if (tpo != NULL)
  1372. {
  1373. fread(&iCount, 4, 1, tpo);
  1374. for (DWORD i=0;i<iCount;i++)
  1375. {
  1376. stModelSwap tpm;
  1377. fread(&tpm, sizeof(stModelSwap), 1, tpo);
  1378. mod.push_back(tpm);
  1379. }
  1380. fread(&iCount, 4, 1, tpo);
  1381. for (DWORD i=0;i<iCount;i++)
  1382. {
  1383. stTextureSwap tpm;
  1384. fread(&tpm, sizeof(stTextureSwap), 1, tpo);
  1385. tex.push_back(tpm);
  1386. }
  1387. fread(&iCount, 4, 1, tpo);
  1388. for (DWORD i=0;i<iCount;i++)
  1389. {
  1390. stPaletteSwap tpm;
  1391. fread(&tpm, sizeof(stPaletteSwap), 1, tpo);
  1392. pal.push_back(tpm);
  1393. }
  1394. fclose(tpo);
  1395. }
  1396. m_mgChars[i] = new cModelGroup();
  1397. m_mgChars[i]->ReadModel(0x02000001, &pal, &tex, &mod);
  1398. m_mgChars[i]->SetRotation(0, 0, 0, 0);
  1399. m_mgChars[i]->SetTranslation(cPoint3D(2.0f-i, 0, 0));
  1400. m_mgChars[i]->SetScale(1.0f);
  1401. m_mgChars[i]->SetDefaultAnim(0x03000002);
  1402. m_mgChars[i]->UpdateAnim((float) rand()/RAND_MAX);
  1403. }
  1404. for (int h=0;h<m_CharList.CharCount;h++)
  1405. {
  1406. // m_mgChars[h]->SetDefaultAnim(0x03000002);
  1407. m_stCharList[h]->SetTextColor(0xFFFFFF);
  1408. }
  1409. m_stCharList[0]->SetTextColor(0x0000FF);
  1410. m_mgChars[0]->SetDefaultAnim(0);
  1411. m_mgChars[0]->PlayAnimation( 0x03000853, 0, 0xFFFFFFFF, 30.0f );
  1412. for (int i=0;i<5;i++)
  1413. {
  1414. m_mgPlatforms[i] = new cModelGroup();
  1415. m_mgPlatforms[i]->ReadModel(0x02000117);
  1416. m_mgPlatforms[i]->SetRotation(0, 0, 0, 0);
  1417. m_mgPlatforms[i]->SetTranslation(cPoint3D(2.00f-i, 0, -0.15f));
  1418. m_mgPlatforms[i]->SetScale(0.25f);
  1419. }
  1420. }
  1421. glEnable(GL_DEPTH_TEST);
  1422. glMatrixMode(GL_PROJECTION);
  1423. glLoadIdentity();
  1424. // gluPerspective(180,(float)m_iWidth/(m_iHeight/2), 0.001, 100);
  1425. glOrtho(-2.5f, 2.5f, -1.0f, 1.05f, 0.001, 100);
  1426. gluLookAt(0, 1.5f, 0.85f, 0, 0, 0.85f, 0, 0, 1);
  1427. glViewport(0, m_iHeight/2, m_iWidth, m_iHeight/2);
  1428. for (int i=0;i<m_CharList.CharCount;i++)
  1429. {
  1430. m_mgChars[i]->UpdateAnim((float) TimeSlice);
  1431. m_mgChars[i]->Draw();
  1432. }
  1433. for (int i=0;i<5;i++)
  1434. m_mgPlatforms[i]->Draw();
  1435. glViewport(0, 0, m_iWidth, m_iHeight);
  1436. gluPerspective(90,(float)m_iWidth/m_iHeight, 0.001, 100);
  1437. glDisable(GL_DEPTH_TEST);
  1438. glMatrixMode(GL_PROJECTION);
  1439. glLoadIdentity();
  1440. glOrtho(0, m_iWidth, m_iHeight, 0, 0.1, 100);
  1441. gluLookAt(0, 0, 50, 0, 0, 0, 0, 1, 0);
  1442. }
  1443. if (m_InterfaceMode == eGame)
  1444. {
  1445. glEnable(GL_DEPTH_TEST);
  1446. //Now for 3d shit (if any)
  1447. glMatrixMode(GL_PROJECTION);
  1448. glLoadIdentity();
  1449. gluPerspective(90,(float)m_iWidth/m_iHeight, 0.001, 100);
  1450. cWObject *woMyself = m_ObjectDB->FindObject(m_dwSelChar);
  1451. cPoint3D MyPos;
  1452. float fMyHead = 0;
  1453. if (woMyself)
  1454. {
  1455. woMyself->Lock();
  1456. MyPos = woMyself->GetPosition();
  1457. fMyHead = woMyself->GetHeading();
  1458. woMyself->Unlock();
  1459. }
  1460. else
  1461. MyPos = cPoint3D(0,0,0);
  1462. m_mwMinimap->SetPlayerPosition(MyPos, m_fCamRotX+fMyHead);
  1463. cPoint3D CamLoc = MyPos;
  1464. CamLoc.z += m_fCamDist;
  1465. CamLoc.RotateAround(MyPos, cPoint3D(m_fCamRotY, 0, 0));
  1466. CamLoc.RotateAround(MyPos, cPoint3D(0, 0, m_fCamRotX+fMyHead));
  1467. cPoint3D CamUp = cPoint3D(0, 1, 0);
  1468. CamUp.RotateAround(cPoint3D(0,0,0), cPoint3D(m_fCamRotY, 0, 0));
  1469. CamUp.RotateAround(cPoint3D(0,0,0), cPoint3D(0, 0, m_fCamRotX+fMyHead));
  1470. gluLookAt(CamLoc.x, CamLoc.y, CamLoc.z + 1.0f/240.0f, MyPos.x, MyPos.y, MyPos.z + 1.0f/240.0f, CamUp.x, CamUp.y, CamUp.z);
  1471. LARGE_INTEGER tpt1, tpt2, tpt3, tpf;
  1472. QueryPerformanceFrequency(&tpf);
  1473. QueryPerformanceCounter(&tpt1);
  1474. //draw landscape!
  1475. if (woMyself)
  1476. {
  1477. woMyself->Lock();
  1478. DWORD dwCurLB = woMyself->GetLandblock();
  1479. woMyself->Unlock();
  1480. DWORD LBX = (dwCurLB >> 24) & 0xFF;
  1481. DWORD LBY = (dwCurLB >> 16) & 0xFF;
  1482. m_mCurrentLandblocks.clear();
  1483. int Y1 = LBY-m_iRenderRadius, Y2 = LBY+m_iRenderRadius;
  1484. if (Y1 < 0) Y1 = 0; if (Y2 > 255) Y2 = 255;
  1485. int X1 = LBX-m_iRenderRadius, X2 = LBX+m_iRenderRadius;
  1486. if (X1 < 0) X1 = 0; if (X2 > 255) X2 = 255;
  1487. for (DWORD y=Y1;y<=(DWORD)Y2;y++)
  1488. {
  1489. for (DWORD x=X1;x<=(DWORD)X2;x++)
  1490. {
  1491. WORD wLB = (x << 8) | y;
  1492. m_mCurrentLandblocks.insert(wLB);
  1493. if (m_mLandblocks.find(wLB) == m_mLandblocks.end())
  1494. if (m_mDownloadingLandblocks.find(wLB) == m_mDownloadingLandblocks.end())
  1495. m_mNeedToLoadBlocks.insert(wLB);
  1496. }
  1497. }
  1498. if (m_mNeedToLoadBlocks.size())
  1499. LoadLandblocks();
  1500. for (std::unordered_set<WORD>::iterator i = m_mCurrentLandblocks.begin(); i != m_mCurrentLandblocks.end(); i++)
  1501. {
  1502. if (m_mLandblocks.find(*i) != m_mLandblocks.end())
  1503. {
  1504. cLandblock *pLB = m_mLandblocks.find(*i)->second;
  1505. m_iTriCount += pLB->Draw();
  1506. }
  1507. }
  1508. }
  1509. //draw all objects
  1510. m_ObjectDB->Lock();
  1511. std::list<cWObject *> * DrawList = m_ObjectDB->GetObjectsWithin(MyPos, 3.3f);
  1512. QueryPerformanceCounter(&tpt2);
  1513. glListBase(0x01000000 + (12 << 8));
  1514. for (std::list<cWObject *>::iterator i = DrawList->begin(); i != DrawList->end(); i++)
  1515. {
  1516. (*i)->Lock();
  1517. cPoint3D tpPos = (*i)->GetPosition();
  1518. float fHeading = (*i)->GetHeading();
  1519. m_iTriCount += (*i)->Draw();
  1520. if (m_dwCurSelect == (*i)->GetGUID())
  1521. {
  1522. glBindTexture( GL_TEXTURE_2D, 0);
  1523. glBegin(GL_LINES);
  1524. glColor3f(1,0,0);
  1525. glVertex3f(tpPos.x-0.003f,tpPos.y-0.003f,tpPos.z);
  1526. glVertex3f(tpPos.x-0.003f,tpPos.y-0.003f,tpPos.z+0.005f);
  1527. glVertex3f(tpPos.x+0.003f,tpPos.y-0.003f,tpPos.z);
  1528. glVertex3f(tpPos.x+0.003f,tpPos.y-0.003f,tpPos.z+0.005f);
  1529. glVertex3f(tpPos.x+0.003f,tpPos.y+0.003f,tpPos.z);
  1530. glVertex3f(tpPos.x+0.003f,tpPos.y+0.003f,tpPos.z+0.005f);
  1531. glVertex3f(tpPos.x-0.003f,tpPos.y+0.003f,tpPos.z);
  1532. glVertex3f(tpPos.x-0.003f,tpPos.y+0.003f,tpPos.z+0.005f);
  1533. glEnd();
  1534. }
  1535. glBindTexture( GL_TEXTURE_2D, 0);
  1536. glColor3f(1.0,1.0,1.0);
  1537. glRasterPos3f(tpPos.x, tpPos.y, tpPos.z+0.01f);
  1538. std::string sName = (*i)->GetName();
  1539. glCallLists((int) sName.length(), GL_UNSIGNED_BYTE, sName.c_str());
  1540. (*i)->Unlock();
  1541. }
  1542. QueryPerformanceCounter(&tpt3);
  1543. double ftp = (tpt2.QuadPart - tpt1.QuadPart)/(double) tpf.QuadPart;
  1544. double ftp2 = (tpt3.QuadPart - tpt2.QuadPart)/(double) tpf.QuadPart;
  1545. delete DrawList;
  1546. m_ObjectDB->Unlock();
  1547. glBindTexture( GL_TEXTURE_2D, 0);
  1548. glBegin(GL_LINES);
  1549. glColor3f(1,0,0);
  1550. glVertex3f(MyPos.x, MyPos.y-0.01f, MyPos.z);
  1551. glVertex3f(MyPos.x, MyPos.y+0.01f, MyPos.z);
  1552. glVertex3f(MyPos.x-0.01f, MyPos.y, MyPos.z);
  1553. glVertex3f(MyPos.x+0.01f, MyPos.y, MyPos.z);
  1554. glEnd();
  1555. glRasterPos3f(MyPos.x+0.01f, MyPos.y, MyPos.z);
  1556. glCallLists(1, GL_UNSIGNED_BYTE, "E");
  1557. glRasterPos3f(MyPos.x-0.01f, MyPos.y, MyPos.z);
  1558. glCallLists(1, GL_UNSIGNED_BYTE, "W");
  1559. glRasterPos3f(MyPos.x, MyPos.y+0.01f, MyPos.z);
  1560. glCallLists(1, GL_UNSIGNED_BYTE, "N");
  1561. glRasterPos3f(MyPos.x, MyPos.y-0.01f, MyPos.z);
  1562. glCallLists(1, GL_UNSIGNED_BYTE, "S");
  1563. //Back to 2D
  1564. glDisable(GL_DEPTH_TEST);
  1565. glMatrixMode(GL_PROJECTION);
  1566. glLoadIdentity();
  1567. glOrtho(0, m_iWidth, m_iHeight, 0, 0.1, 100);
  1568. gluLookAt(0, 0, 50, 0, 0, 0, 0, 1, 0);
  1569. }
  1570. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  1571. return true;
  1572. }
  1573. DWORD cInterface::GetCurrentSelection()
  1574. {
  1575. return m_dwCurSelect;
  1576. }
  1577. //void cInterface::SetStance(WORD NewStance)
  1578. //{
  1579. // m_wStance = NewStance;
  1580. //}
  1581. bool cInterface::OnClick( IWindow & Window, float X, float Y, unsigned long Button )
  1582. {
  1583. return true;
  1584. }
  1585. bool cInterface::OnDoubleClick( IWindow & Window, float X, float Y, unsigned long Button )
  1586. {
  1587. return true;
  1588. }
  1589. bool cInterface::OnMouseEnter( IWindow & Window, float X, float Y, unsigned long Button )
  1590. {
  1591. return true;
  1592. }
  1593. bool cInterface::OnMouseExit( IWindow & Window, float X, float Y, unsigned long Button )
  1594. {
  1595. return true;
  1596. }
  1597. bool cInterface::OnKeyPress( IWindow & Window, unsigned long KeyCode )
  1598. {
  1599. return true;
  1600. }