PlatformWin32.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. #ifdef WIN32
  2. #include "Base.h"
  3. #include "Platform.h"
  4. #include "FileSystem.h"
  5. #include "Game.h"
  6. #include <GL/wglew.h>
  7. static long __timeTicksPerMillis;
  8. static long __timeStart;
  9. static long __timeAbsolute;
  10. static bool __vsync = WINDOW_VSYNC;
  11. static float __roll;
  12. static float __pitch;
  13. static HINSTANCE __hinstance = 0;
  14. static HWND __hwnd = 0;
  15. static HDC __hdc = 0;
  16. static HGLRC __hrc = 0;
  17. // Gets the gameplay::Input::Key enumeration constant that corresponds
  18. // to the given key and shift modifier combination.
  19. static gameplay::Input::Key getGameplayInputKey(WPARAM win32KeyCode, bool shiftDown)
  20. {
  21. // TODO: Handle the following keys
  22. //gameplay::Input::KEY_SYSREQ
  23. //gameplay::Input::KEY_BREAK
  24. //gameplay::Input::KEY_MENU
  25. //gameplay::Input::KEY_KP_ENTER
  26. switch (win32KeyCode)
  27. {
  28. case VK_PAUSE:
  29. return gameplay::Input::KEY_PAUSE;
  30. case VK_SCROLL:
  31. return gameplay::Input::KEY_SCROLL_LOCK;
  32. case VK_PRINT:
  33. return gameplay::Input::KEY_PRINT;
  34. case VK_ESCAPE:
  35. return gameplay::Input::KEY_ESCAPE;
  36. case VK_BACK:
  37. return gameplay::Input::KEY_BACKSPACE;
  38. case VK_TAB:
  39. return shiftDown ? gameplay::Input::KEY_BACK_TAB : gameplay::Input::KEY_TAB;
  40. case VK_RETURN:
  41. return gameplay::Input::KEY_RETURN;
  42. case VK_CAPITAL:
  43. return gameplay::Input::KEY_CAPS_LOCK;
  44. case VK_LSHIFT:
  45. return gameplay::Input::KEY_LEFT_SHIFT;
  46. case VK_RSHIFT:
  47. return gameplay::Input::KEY_RIGHT_SHIFT;
  48. case VK_LCONTROL:
  49. return gameplay::Input::KEY_LEFT_CTRL;
  50. case VK_RCONTROL:
  51. return gameplay::Input::KEY_RIGHT_CTRL;
  52. case VK_LMENU:
  53. return gameplay::Input::KEY_LEFT_ALT;
  54. case VK_RMENU:
  55. return gameplay::Input::KEY_RIGHT_ALT;
  56. case VK_LWIN:
  57. return gameplay::Input::KEY_LEFT_HYPER;
  58. case VK_RWIN:
  59. return gameplay::Input::KEY_RIGHT_HYPER;
  60. case VK_INSERT:
  61. return gameplay::Input::KEY_INSERT;
  62. case VK_HOME:
  63. return gameplay::Input::KEY_HOME;
  64. case VK_PRIOR:
  65. return gameplay::Input::KEY_PG_UP;
  66. case VK_DELETE:
  67. return gameplay::Input::KEY_DELETE;
  68. case VK_END:
  69. return gameplay::Input::KEY_END;
  70. case VK_NEXT:
  71. return gameplay::Input::KEY_PG_DOWN;
  72. case VK_LEFT:
  73. return gameplay::Input::KEY_LEFT_ARROW;
  74. case VK_RIGHT:
  75. return gameplay::Input::KEY_RIGHT_ARROW;
  76. case VK_UP:
  77. return gameplay::Input::KEY_UP_ARROW;
  78. case VK_DOWN:
  79. return gameplay::Input::KEY_DOWN_ARROW;
  80. case VK_NUMLOCK:
  81. return gameplay::Input::KEY_NUM_LOCK;
  82. case VK_ADD:
  83. return gameplay::Input::KEY_KP_PLUS;
  84. case VK_SUBTRACT:
  85. return gameplay::Input::KEY_KP_MINUS;
  86. case VK_MULTIPLY:
  87. return gameplay::Input::KEY_KP_MULTIPLY;
  88. case VK_DIVIDE:
  89. return gameplay::Input::KEY_KP_DIVIDE;
  90. case VK_NUMPAD7:
  91. return gameplay::Input::KEY_KP_HOME;
  92. case VK_NUMPAD8:
  93. return gameplay::Input::KEY_KP_UP;
  94. case VK_NUMPAD9:
  95. return gameplay::Input::KEY_KP_PG_UP;
  96. case VK_NUMPAD4:
  97. return gameplay::Input::KEY_KP_LEFT;
  98. case VK_NUMPAD5:
  99. return gameplay::Input::KEY_KP_FIVE;
  100. case VK_NUMPAD6:
  101. return gameplay::Input::KEY_KP_RIGHT;
  102. case VK_NUMPAD1:
  103. return gameplay::Input::KEY_KP_END;
  104. case VK_NUMPAD2:
  105. return gameplay::Input::KEY_KP_DOWN;
  106. case VK_NUMPAD3:
  107. return gameplay::Input::KEY_KP_PG_DOWN;
  108. case VK_NUMPAD0:
  109. return gameplay::Input::KEY_KP_INSERT;
  110. case VK_DECIMAL:
  111. return gameplay::Input::KEY_KP_DELETE;
  112. case VK_F1:
  113. return gameplay::Input::KEY_F1;
  114. case VK_F2:
  115. return gameplay::Input::KEY_F2;
  116. case VK_F3:
  117. return gameplay::Input::KEY_F3;
  118. case VK_F4:
  119. return gameplay::Input::KEY_F4;
  120. case VK_F5:
  121. return gameplay::Input::KEY_F5;
  122. case VK_F6:
  123. return gameplay::Input::KEY_F6;
  124. case VK_F7:
  125. return gameplay::Input::KEY_F7;
  126. case VK_F8:
  127. return gameplay::Input::KEY_F8;
  128. case VK_F9:
  129. return gameplay::Input::KEY_F9;
  130. case VK_F10:
  131. return gameplay::Input::KEY_F10;
  132. case VK_F11:
  133. return gameplay::Input::KEY_F11;
  134. case VK_F12:
  135. return gameplay::Input::KEY_F12;
  136. case VK_SPACE:
  137. return gameplay::Input::KEY_SPACE;
  138. case 0x30:
  139. return shiftDown ? gameplay::Input::KEY_RIGHT_PARENTHESIS : gameplay::Input::KEY_ZERO;
  140. case 0x31:
  141. return shiftDown ? gameplay::Input::KEY_EXCLAM : gameplay::Input::KEY_ONE;
  142. case 0x32:
  143. return shiftDown ? gameplay::Input::KEY_AT : gameplay::Input::KEY_TWO;
  144. case 0x33:
  145. return shiftDown ? gameplay::Input::KEY_NUMBER : gameplay::Input::KEY_THREE;
  146. case 0x34:
  147. return shiftDown ? gameplay::Input::KEY_DOLLAR : gameplay::Input::KEY_FOUR;
  148. case 0x35:
  149. return shiftDown ? gameplay::Input::KEY_PERCENT : gameplay::Input::KEY_FIVE;
  150. case 0x36:
  151. return shiftDown ? gameplay::Input::KEY_CIRCUMFLEX : gameplay::Input::KEY_SIX;
  152. case 0x37:
  153. return shiftDown ? gameplay::Input::KEY_AMPERSAND : gameplay::Input::KEY_SEVEN;
  154. case 0x38:
  155. return shiftDown ? gameplay::Input::KEY_ASTERISK : gameplay::Input::KEY_EIGHT;
  156. case 0x39:
  157. return shiftDown ? gameplay::Input::KEY_LEFT_PARENTHESIS : gameplay::Input::KEY_NINE;
  158. case VK_OEM_PLUS:
  159. return shiftDown ? gameplay::Input::KEY_EQUAL : gameplay::Input::KEY_PLUS;
  160. case VK_OEM_COMMA:
  161. return shiftDown ? gameplay::Input::KEY_LESS_THAN : gameplay::Input::KEY_COMMA;
  162. case VK_OEM_MINUS:
  163. return shiftDown ? gameplay::Input::KEY_UNDERSCORE : gameplay::Input::KEY_MINUS;
  164. case VK_OEM_PERIOD:
  165. return shiftDown ? gameplay::Input::KEY_GREATER_THAN : gameplay::Input::KEY_PERIOD;
  166. case VK_OEM_1:
  167. return shiftDown ? gameplay::Input::KEY_COLON : gameplay::Input::KEY_SEMICOLON;
  168. case VK_OEM_2:
  169. return shiftDown ? gameplay::Input::KEY_QUESTION : gameplay::Input::KEY_SLASH;
  170. case VK_OEM_3:
  171. return shiftDown ? gameplay::Input::KEY_GRAVE : gameplay::Input::KEY_TILDE;
  172. case VK_OEM_4:
  173. return shiftDown ? gameplay::Input::KEY_LEFT_BRACE : gameplay::Input::KEY_LEFT_BRACKET;
  174. case VK_OEM_5:
  175. return shiftDown ? gameplay::Input::KEY_BAR : gameplay::Input::KEY_BACK_SLASH;
  176. case VK_OEM_6:
  177. return shiftDown ? gameplay::Input::KEY_RIGHT_BRACE : gameplay::Input::KEY_RIGHT_BRACKET;
  178. case VK_OEM_7:
  179. return shiftDown ? gameplay::Input::KEY_QUOTE : gameplay::Input::KEY_APOSTROPHE;
  180. case 0x41:
  181. return shiftDown ? gameplay::Input::KEY_CAPITAL_A : gameplay::Input::KEY_A;
  182. case 0x42:
  183. return shiftDown ? gameplay::Input::KEY_CAPITAL_B : gameplay::Input::KEY_B;
  184. case 0x43:
  185. return shiftDown ? gameplay::Input::KEY_CAPITAL_C : gameplay::Input::KEY_C;
  186. case 0x44:
  187. return shiftDown ? gameplay::Input::KEY_CAPITAL_D : gameplay::Input::KEY_D;
  188. case 0x45:
  189. return shiftDown ? gameplay::Input::KEY_CAPITAL_E : gameplay::Input::KEY_E;
  190. case 0x46:
  191. return shiftDown ? gameplay::Input::KEY_CAPITAL_F : gameplay::Input::KEY_F;
  192. case 0x47:
  193. return shiftDown ? gameplay::Input::KEY_CAPITAL_G : gameplay::Input::KEY_G;
  194. case 0x48:
  195. return shiftDown ? gameplay::Input::KEY_CAPITAL_H : gameplay::Input::KEY_H;
  196. case 0x49:
  197. return shiftDown ? gameplay::Input::KEY_CAPITAL_I : gameplay::Input::KEY_I;
  198. case 0x4A:
  199. return shiftDown ? gameplay::Input::KEY_CAPITAL_J : gameplay::Input::KEY_J;
  200. case 0x4B:
  201. return shiftDown ? gameplay::Input::KEY_CAPITAL_K : gameplay::Input::KEY_K;
  202. case 0x4C:
  203. return shiftDown ? gameplay::Input::KEY_CAPITAL_L : gameplay::Input::KEY_L;
  204. case 0x4D:
  205. return shiftDown ? gameplay::Input::KEY_CAPITAL_M : gameplay::Input::KEY_M;
  206. case 0x4E:
  207. return shiftDown ? gameplay::Input::KEY_CAPITAL_N : gameplay::Input::KEY_N;
  208. case 0x4F:
  209. return shiftDown ? gameplay::Input::KEY_CAPITAL_O : gameplay::Input::KEY_O;
  210. case 0x50:
  211. return shiftDown ? gameplay::Input::KEY_CAPITAL_P : gameplay::Input::KEY_P;
  212. case 0x51:
  213. return shiftDown ? gameplay::Input::KEY_CAPITAL_Q : gameplay::Input::KEY_Q;
  214. case 0x52:
  215. return shiftDown ? gameplay::Input::KEY_CAPITAL_R : gameplay::Input::KEY_R;
  216. case 0x53:
  217. return shiftDown ? gameplay::Input::KEY_CAPITAL_S : gameplay::Input::KEY_S;
  218. case 0x54:
  219. return shiftDown ? gameplay::Input::KEY_CAPITAL_T : gameplay::Input::KEY_T;
  220. case 0x55:
  221. return shiftDown ? gameplay::Input::KEY_CAPITAL_U : gameplay::Input::KEY_U;
  222. case 0x56:
  223. return shiftDown ? gameplay::Input::KEY_CAPITAL_V : gameplay::Input::KEY_V;
  224. case 0x57:
  225. return shiftDown ? gameplay::Input::KEY_CAPITAL_W : gameplay::Input::KEY_W;
  226. case 0x58:
  227. return shiftDown ? gameplay::Input::KEY_CAPITAL_X : gameplay::Input::KEY_X;
  228. case 0x59:
  229. return shiftDown ? gameplay::Input::KEY_CAPITAL_Y : gameplay::Input::KEY_Y;
  230. case 0x5A:
  231. return shiftDown ? gameplay::Input::KEY_CAPITAL_Z : gameplay::Input::KEY_Z;
  232. default:
  233. return gameplay::Input::KEY_NONE;
  234. }
  235. }
  236. LRESULT CALLBACK __WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  237. {
  238. // Scale factors for the mouse movement used to simulate the accelerometer.
  239. static const float ACCELEROMETER_X_FACTOR = 90.0f / WINDOW_WIDTH;
  240. static const float ACCELEROMETER_Y_FACTOR = 90.0f / WINDOW_HEIGHT;
  241. static bool hasMouse = false;
  242. static bool lMouseDown = false;
  243. static bool rMouseDown = false;
  244. static int lx, ly;
  245. static bool shiftDown = false;
  246. switch (msg)
  247. {
  248. case WM_CLOSE:
  249. DestroyWindow(__hwnd);
  250. return 0;
  251. case WM_DESTROY:
  252. PostQuitMessage(0);
  253. return 0;
  254. case WM_LBUTTONDOWN:
  255. gameplay::Game::getInstance()->touch(LOWORD(lParam), HIWORD(lParam), gameplay::Input::TOUCHEVENT_PRESS);
  256. lMouseDown = true;
  257. return 0;
  258. case WM_LBUTTONUP:
  259. lMouseDown = false;
  260. gameplay::Game::getInstance()->touch(LOWORD(lParam), HIWORD(lParam), gameplay::Input::TOUCHEVENT_RELEASE);
  261. return 0;
  262. case WM_RBUTTONDOWN:
  263. rMouseDown = true;
  264. lx = LOWORD(lParam);
  265. ly = HIWORD(lParam);
  266. break;
  267. case WM_RBUTTONUP:
  268. rMouseDown = false;
  269. break;
  270. case WM_MOUSEMOVE:
  271. if (!hasMouse)
  272. {
  273. hasMouse = true;
  274. // Call TrackMouseEvent to detect the next WM_MOUSE_LEAVE.
  275. TRACKMOUSEEVENT tme;
  276. tme.cbSize = sizeof(TRACKMOUSEEVENT);
  277. tme.dwFlags = TME_LEAVE;
  278. tme.hwndTrack = __hwnd;
  279. TrackMouseEvent(&tme);
  280. }
  281. if (lMouseDown)
  282. {
  283. gameplay::Game::getInstance()->touch(LOWORD(lParam), HIWORD(lParam), gameplay::Input::TOUCHEVENT_MOVE);
  284. return 0;
  285. }
  286. else if (rMouseDown)
  287. {
  288. // Update the pitch and roll by adding the scaled deltas.
  289. __roll += -(float)(LOWORD(lParam) - lx) * ACCELEROMETER_X_FACTOR;
  290. __pitch += (float)(HIWORD(lParam) - ly) * ACCELEROMETER_Y_FACTOR;
  291. // Clamp the values to the valid range.
  292. __roll = max(min(__roll, 90.0f), -90.0f);
  293. __pitch = max(min(__pitch, 90.0f), -90.0f);
  294. // Update the last X/Y values.
  295. lx = LOWORD(lParam);
  296. ly = HIWORD(lParam);
  297. }
  298. break;
  299. case WM_MOUSELEAVE:
  300. hasMouse = false;
  301. lMouseDown = false;
  302. rMouseDown = false;
  303. break;
  304. case WM_KEYDOWN:
  305. if (wParam == VK_LSHIFT || wParam == VK_RSHIFT)
  306. shiftDown = true;
  307. gameplay::Game::getInstance()->keyPress(getGameplayInputKey(wParam, shiftDown), gameplay::Input::KEYEVENT_DOWN);
  308. break;
  309. case WM_KEYUP:
  310. if (wParam == VK_LSHIFT || wParam == VK_RSHIFT)
  311. shiftDown = false;
  312. gameplay::Game::getInstance()->keyPress(getGameplayInputKey(wParam, shiftDown), gameplay::Input::KEYEVENT_UP);
  313. break;
  314. case WM_SETFOCUS:
  315. break;
  316. case WM_KILLFOCUS:
  317. break;
  318. }
  319. return DefWindowProc(hwnd, msg, wParam, lParam);
  320. }
  321. namespace gameplay
  322. {
  323. extern void printError(const char* format, ...)
  324. {
  325. va_list argptr;
  326. va_start(argptr, format);
  327. fprintf(stderr, "\n");
  328. int sz = vfprintf(stderr, format, argptr);
  329. if (sz > 0)
  330. {
  331. char* buf = new char[sz + 2];
  332. vsprintf(buf, format, argptr);
  333. buf[sz] = '\n';
  334. buf[sz+1] = 0;
  335. OutputDebugStringA(buf);
  336. SAFE_DELETE_ARRAY(buf);
  337. }
  338. va_end(argptr);
  339. }
  340. Platform::Platform(Game* game)
  341. : _game(game)
  342. {
  343. }
  344. Platform::Platform(const Platform& copy)
  345. {
  346. // hidden
  347. }
  348. Platform::~Platform()
  349. {
  350. if (__hwnd)
  351. {
  352. DestroyWindow(__hwnd);
  353. __hwnd = 0;
  354. }
  355. }
  356. // TODO: Fix Fullscreen + More error handling.
  357. Platform* Platform::create(Game* game)
  358. {
  359. FileSystem::setResourcePath("./");
  360. Platform* platform = new Platform(game);
  361. // Get the application module handle.
  362. __hinstance = ::GetModuleHandle(NULL);
  363. LPCTSTR windowClass = L"gameplay";
  364. LPCTSTR windowName = L"";
  365. RECT rect = { 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT };
  366. // Register our window class.
  367. WNDCLASSEX wc;
  368. wc.cbSize = sizeof(WNDCLASSEX);
  369. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  370. wc.lpfnWndProc = (WNDPROC)__WndProc;
  371. wc.cbClsExtra = 0;
  372. wc.cbWndExtra = 0;
  373. wc.hInstance = __hinstance;
  374. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  375. wc.hIconSm = NULL;
  376. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  377. wc.hbrBackground = NULL; // No brush - we are going to paint our own background
  378. wc.lpszMenuName = NULL; // No default menu
  379. wc.lpszClassName = windowClass;
  380. if (!::RegisterClassEx(&wc))
  381. goto error;
  382. // Set the window style.
  383. DWORD style = ( WINDOW_FULLSCREEN ? WS_POPUP : WS_POPUP | WS_BORDER | WS_CAPTION | WS_SYSMENU) | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
  384. DWORD styleEx = (WINDOW_FULLSCREEN ? WS_EX_APPWINDOW : WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
  385. // Adjust the window rectangle so the client size is the requested size.
  386. AdjustWindowRectEx(&rect, style, FALSE, styleEx);
  387. // Create the native Windows window.
  388. __hwnd = CreateWindowEx(styleEx, windowClass, windowName, style, 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, __hinstance, NULL);
  389. // Get the drawing context.
  390. __hdc = GetDC(__hwnd);
  391. // Choose pixel format. 32-bit. RGBA.
  392. PIXELFORMATDESCRIPTOR pfd;
  393. memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
  394. pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  395. pfd.nVersion = 1;
  396. pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
  397. pfd.iPixelType = PFD_TYPE_RGBA;
  398. pfd.cColorBits = 32;
  399. pfd.cDepthBits = 32;
  400. pfd.iLayerType = PFD_MAIN_PLANE;
  401. int pixelFormat = ChoosePixelFormat(__hdc, &pfd);
  402. if (pixelFormat == 0 || !SetPixelFormat (__hdc, pixelFormat, &pfd))
  403. goto error;
  404. HGLRC tempContext = wglCreateContext(__hdc);
  405. wglMakeCurrent(__hdc, tempContext);
  406. if (GLEW_OK != glewInit())
  407. goto error;
  408. int attribs[] =
  409. {
  410. WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
  411. WGL_CONTEXT_MINOR_VERSION_ARB, 1,
  412. 0
  413. };
  414. if (!(__hrc = wglCreateContextAttribsARB(__hdc, 0, attribs) ) )
  415. {
  416. wglDeleteContext(tempContext);
  417. goto error;
  418. }
  419. wglDeleteContext(tempContext);
  420. if (!wglMakeCurrent(__hdc, __hrc) || !__hrc)
  421. goto error;
  422. // Vertical sync.
  423. wglSwapIntervalEXT(__vsync ? 1 : 0);
  424. // Show the window
  425. ShowWindow(__hwnd, SW_SHOW);
  426. return platform;
  427. error:
  428. // TODO: cleanup
  429. exit(0);
  430. return NULL;
  431. }
  432. int Platform::enterMessagePump()
  433. {
  434. int rc = 0;
  435. // Get the initial time.
  436. LARGE_INTEGER tps;
  437. QueryPerformanceFrequency(&tps);
  438. __timeTicksPerMillis = (long)(tps.QuadPart / 1000L);
  439. LARGE_INTEGER queryTime;
  440. QueryPerformanceCounter(&queryTime);
  441. __timeStart = queryTime.QuadPart / __timeTicksPerMillis;
  442. // Set the initial pitch and roll values.
  443. __pitch = 0.0;
  444. __roll = 0.0;
  445. SwapBuffers(__hdc);
  446. if (_game->getState() != Game::RUNNING)
  447. _game->run(WINDOW_WIDTH, WINDOW_HEIGHT);
  448. // Enter event dispatch loop.
  449. MSG msg;
  450. while (true)
  451. {
  452. if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  453. {
  454. TranslateMessage(&msg);
  455. DispatchMessage(&msg);
  456. if (msg.message == WM_QUIT)
  457. {
  458. _game->exit();
  459. break;
  460. }
  461. }
  462. if (_game->getState() != Game::PAUSED)
  463. {
  464. _game->frame();
  465. SwapBuffers(__hdc);
  466. }
  467. // If we are done, then exit.
  468. if (_game->getState() == Game::UNINITIALIZED)
  469. break;
  470. }
  471. return msg.wParam;
  472. }
  473. long Platform::getAbsoluteTime()
  474. {
  475. LARGE_INTEGER queryTime;
  476. QueryPerformanceCounter(&queryTime);
  477. __timeAbsolute = queryTime.QuadPart / __timeTicksPerMillis;
  478. return __timeAbsolute;
  479. }
  480. void Platform::setAbsoluteTime(long time)
  481. {
  482. __timeAbsolute = time;
  483. }
  484. bool Platform::isVsync()
  485. {
  486. return __vsync;
  487. }
  488. void Platform::setVsync(bool enable)
  489. {
  490. wglSwapIntervalEXT(enable ? 1 : 0);
  491. __vsync = enable;
  492. }
  493. int Platform::getOrientationAngle()
  494. {
  495. return 0;
  496. }
  497. bool Platform::isAccelerometerSupported()
  498. {
  499. return true;
  500. }
  501. void Platform::getAccelerometerPitchAndRoll(float* pitch, float* roll)
  502. {
  503. *pitch = __pitch;
  504. *roll = __roll;
  505. }
  506. void Platform::swapBuffers()
  507. {
  508. if (__hdc)
  509. SwapBuffers(__hdc);
  510. }
  511. }
  512. #endif