PolyWinCore.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #include "PolyWinCore.h"
  20. #include "PolyCoreInput.h"
  21. #include "PolyCoreServices.h"
  22. #include "PolyInputEvent.h"
  23. #include "PolyGLRenderer.h"
  24. #include "PolyGLSLShaderModule.h"
  25. #include "PolyLogger.h"
  26. #include "PolyThreaded.h"
  27. #include <GL/gl.h>
  28. #include <GL/glext.h>
  29. #include <GL/wglext.h>
  30. using namespace Polycode;
  31. long getThreadID() {
  32. return 0;
  33. }
  34. extern Win32Core *core;
  35. void ClientResize(HWND hWnd, int nWidth, int nHeight)
  36. {
  37. RECT rcClient, rcWindow;
  38. POINT ptDiff;
  39. GetClientRect(hWnd, &rcClient);
  40. GetWindowRect(hWnd, &rcWindow);
  41. ptDiff.x = (rcWindow.right - rcWindow.left) - rcClient.right;
  42. ptDiff.y = (rcWindow.bottom - rcWindow.top) - rcClient.bottom;
  43. MoveWindow(hWnd,rcWindow.left, rcWindow.top, nWidth + ptDiff.x, nHeight + ptDiff.y, TRUE);
  44. }
  45. Win32Core::Win32Core(PolycodeViewBase *view, int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate)
  46. : Core(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate) {
  47. hWnd = *((HWND*)view->windowData);
  48. core = this;
  49. initKeymap();
  50. hDC = NULL;
  51. hRC = NULL;
  52. PixelFormat = 0;
  53. lastMouseX = -1;
  54. lastMouseY = -1;
  55. eventMutex = createMutex();
  56. isFullScreen = fullScreen;
  57. renderer = new OpenGLRenderer();
  58. services->setRenderer(renderer);
  59. setVideoMode(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel);
  60. WSADATA WsaData;
  61. if(WSAStartup( MAKEWORD(2,2), &WsaData ) != NO_ERROR ){
  62. Logger::log("Error initializing sockets!\n");
  63. }
  64. ((OpenGLRenderer*)renderer)->initOSSpecific();
  65. CoreServices::getInstance()->installModule(new GLSLShaderModule());
  66. }
  67. Win32Core::~Win32Core() {
  68. destroyContext();
  69. }
  70. void Win32Core::enableMouse(bool newval) {
  71. ShowCursor(newval);
  72. }
  73. unsigned int Win32Core::getTicks() {
  74. return GetTickCount();
  75. }
  76. bool Win32Core::Update() {
  77. if(!running)
  78. return false;
  79. checkEvents();
  80. renderer->BeginRender();
  81. updateCore();
  82. renderer->EndRender();
  83. SwapBuffers(hDC);
  84. doSleep();
  85. return running;
  86. }
  87. void Win32Core::setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel) {
  88. if(fullScreen) {
  89. SetWindowLong(hWnd, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP);
  90. ShowWindow(hWnd, SW_SHOW);
  91. DEVMODE dmScreenSettings; // Device Mode
  92. memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
  93. dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
  94. dmScreenSettings.dmPelsWidth = xRes; // Selected Screen Width
  95. dmScreenSettings.dmPelsHeight = yRes; // Selected Screen Height
  96. dmScreenSettings.dmBitsPerPel = 32; // Selected Bits Per Pixel
  97. dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
  98. ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN);
  99. SetWindowPos(hWnd, NULL, 0, 0, xRes, yRes, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  100. } else {
  101. if(isFullScreen) {
  102. ChangeDisplaySettings(NULL,0);
  103. }
  104. // SetWindowLong(hWnd, GWL_STYLE, WS_OVERLAPPED|WS_SYSMENU);
  105. // ShowWindow(hWnd, SW_SHOW);
  106. ClientResize(hWnd, xRes, yRes);
  107. }
  108. isFullScreen = fullScreen;
  109. initContext(false, 0);
  110. if(aaLevel > 0) {
  111. initMultisample(aaLevel);
  112. }
  113. renderer->Resize(xRes, yRes);
  114. }
  115. void Win32Core::initContext(bool usePixelFormat, unsigned int pixelFormat) {
  116. destroyContext();
  117. memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)) ;
  118. pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  119. pfd.nVersion = 1 ;
  120. pfd.dwFlags = PFD_DOUBLEBUFFER |
  121. PFD_SUPPORT_OPENGL |
  122. PFD_DRAW_TO_WINDOW ;
  123. pfd.iPixelType = PFD_TYPE_RGBA ;
  124. pfd.cColorBits = 24;
  125. pfd.cDepthBits = 16;
  126. pfd.cAccumBlueBits = 8;
  127. pfd.cAccumRedBits = 8;
  128. pfd.cAccumGreenBits = 8;
  129. pfd.cAccumAlphaBits = 8;
  130. pfd.cAccumBits = 24;
  131. pfd.iLayerType = PFD_MAIN_PLANE ;
  132. if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context?
  133. {
  134. Logger::log("Can't Create A GL Device Context.\n");
  135. return; // Return FALSE
  136. }
  137. if(usePixelFormat) {
  138. PixelFormat = pixelFormat;
  139. } else {
  140. if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
  141. {
  142. Logger::log("Can't Find A Suitable PixelFormat.\n");
  143. return; // Return FALSE
  144. }
  145. }
  146. Logger::log("Setting format: %d\n", PixelFormat);
  147. if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
  148. {
  149. Logger::log("Can't Set The PixelFormat: %d.\n", PixelFormat);
  150. return; // Return FALSE
  151. }
  152. if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?
  153. {
  154. Logger::log("Can't Create A GL Rendering Context.\n");
  155. return; // Return FALSE
  156. }
  157. if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context
  158. {
  159. Logger::log("Can't Activate The GL Rendering Context.\n");
  160. return; // Return FALSE
  161. }
  162. }
  163. void Win32Core::destroyContext() {
  164. if(hDC == NULL)
  165. return;
  166. wglMakeCurrent (hDC, 0);
  167. wglDeleteContext(hRC);
  168. hRC = 0;
  169. ReleaseDC (hWnd, hDC);
  170. hDC = 0;
  171. if (isFullScreen)
  172. ChangeDisplaySettings (NULL,0);
  173. }
  174. void Win32Core::initMultisample(int numSamples) {
  175. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB =
  176. (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
  177. if (!wglChoosePixelFormatARB) {
  178. Logger::log("Multisampling not supported!\n");
  179. return;
  180. }
  181. int pixelFormat;
  182. bool valid;
  183. UINT numFormats;
  184. float fAttributes[] = {0,0};
  185. int iAttributes[] = { WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
  186. WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
  187. WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
  188. WGL_COLOR_BITS_ARB,24,
  189. WGL_DEPTH_BITS_ARB,24,
  190. WGL_DOUBLE_BUFFER_ARB,GL_TRUE,
  191. WGL_ACCUM_GREEN_BITS_ARB, 8,
  192. WGL_ACCUM_RED_BITS_ARB, 8,
  193. WGL_ACCUM_BLUE_BITS_ARB, 8,
  194. WGL_ACCUM_ALPHA_BITS_ARB, 8,
  195. WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
  196. WGL_SAMPLES_ARB, numSamples ,
  197. 0,0};
  198. if(!wglChoosePixelFormatARB(hDC,iAttributes,fAttributes,1,&pixelFormat,&numFormats)) {
  199. Logger::log("Invalid pixel format chosen\n");
  200. return;
  201. }
  202. // initContext(true, pixelFormat);
  203. glEnable(GL_MULTISAMPLE_ARB);
  204. }
  205. void Win32Core::initKeymap() {
  206. for (int i=0; i<1024; ++i )
  207. keyMap[i] = KEY_UNKNOWN;
  208. keyMap[VK_BACK] = KEY_BACKSPACE;
  209. keyMap[VK_TAB] = KEY_TAB;
  210. keyMap[VK_CLEAR] = KEY_CLEAR;
  211. keyMap[VK_RETURN] = KEY_RETURN;
  212. keyMap[VK_PAUSE] = KEY_PAUSE;
  213. keyMap[VK_ESCAPE] = KEY_ESCAPE;
  214. keyMap[VK_SPACE] = KEY_SPACE;
  215. keyMap[VK_APOSTROPHE] = KEY_QUOTE;
  216. keyMap[VK_COMMA] = KEY_COMMA;
  217. keyMap[VK_MINUS] = KEY_MINUS;
  218. keyMap[VK_PERIOD] = KEY_PERIOD;
  219. keyMap[VK_SLASH] = KEY_SLASH;
  220. keyMap[VK_0] = KEY_0;
  221. keyMap[VK_1] = KEY_1;
  222. keyMap[VK_2] = KEY_2;
  223. keyMap[VK_3] = KEY_3;
  224. keyMap[VK_4] = KEY_4;
  225. keyMap[VK_5] = KEY_5;
  226. keyMap[VK_6] = KEY_6;
  227. keyMap[VK_7] = KEY_7;
  228. keyMap[VK_8] = KEY_8;
  229. keyMap[VK_9] = KEY_9;
  230. keyMap[VK_SEMICOLON] = KEY_SEMICOLON;
  231. keyMap[VK_EQUALS] = KEY_EQUALS;
  232. keyMap[VK_LBRACKET] = KEY_LEFTBRACKET;
  233. keyMap[VK_BACKSLASH] = KEY_BACKSLASH;
  234. keyMap[VK_OEM_102] = KEY_LESS;
  235. keyMap[VK_RBRACKET] = KEY_RIGHTBRACKET;
  236. keyMap[VK_GRAVE] = KEY_BACKQUOTE;
  237. keyMap[VK_BACKTICK] = KEY_BACKQUOTE;
  238. keyMap[VK_A] = KEY_a;
  239. keyMap[VK_B] = KEY_b;
  240. keyMap[VK_C] = KEY_c;
  241. keyMap[VK_D] = KEY_d;
  242. keyMap[VK_E] = KEY_e;
  243. keyMap[VK_F] = KEY_f;
  244. keyMap[VK_G] = KEY_g;
  245. keyMap[VK_H] = KEY_h;
  246. keyMap[VK_I] = KEY_i;
  247. keyMap[VK_J] = KEY_j;
  248. keyMap[VK_K] = KEY_k;
  249. keyMap[VK_L] = KEY_l;
  250. keyMap[VK_M] = KEY_m;
  251. keyMap[VK_N] = KEY_n;
  252. keyMap[VK_O] = KEY_o;
  253. keyMap[VK_P] = KEY_p;
  254. keyMap[VK_Q] = KEY_q;
  255. keyMap[VK_R] = KEY_r;
  256. keyMap[VK_S] = KEY_s;
  257. keyMap[VK_T] = KEY_t;
  258. keyMap[VK_U] = KEY_u;
  259. keyMap[VK_V] = KEY_v;
  260. keyMap[VK_W] = KEY_w;
  261. keyMap[VK_X] = KEY_x;
  262. keyMap[VK_Y] = KEY_y;
  263. keyMap[VK_Z] = KEY_z;
  264. keyMap[VK_DELETE] = KEY_DELETE;
  265. keyMap[VK_NUMPAD0] = KEY_KP0;
  266. keyMap[VK_NUMPAD1] = KEY_KP1;
  267. keyMap[VK_NUMPAD2] = KEY_KP2;
  268. keyMap[VK_NUMPAD3] = KEY_KP3;
  269. keyMap[VK_NUMPAD4] = KEY_KP4;
  270. keyMap[VK_NUMPAD5] = KEY_KP5;
  271. keyMap[VK_NUMPAD6] = KEY_KP6;
  272. keyMap[VK_NUMPAD7] = KEY_KP7;
  273. keyMap[VK_NUMPAD8] = KEY_KP8;
  274. keyMap[VK_NUMPAD9] = KEY_KP9;
  275. keyMap[VK_DECIMAL] = KEY_KP_PERIOD;
  276. keyMap[VK_DIVIDE] = KEY_KP_DIVIDE;
  277. keyMap[VK_MULTIPLY] = KEY_KP_MULTIPLY;
  278. keyMap[VK_SUBTRACT] = KEY_KP_MINUS;
  279. keyMap[VK_ADD] = KEY_KP_PLUS;
  280. keyMap[VK_UP] = KEY_UP;
  281. keyMap[VK_DOWN] = KEY_DOWN;
  282. keyMap[VK_RIGHT] = KEY_RIGHT;
  283. keyMap[VK_LEFT] = KEY_LEFT;
  284. keyMap[VK_INSERT] = KEY_INSERT;
  285. keyMap[VK_HOME] = KEY_HOME;
  286. keyMap[VK_END] = KEY_END;
  287. keyMap[VK_PRIOR] = KEY_PAGEUP;
  288. keyMap[VK_NEXT] = KEY_PAGEDOWN;
  289. keyMap[VK_F1] = KEY_F1;
  290. keyMap[VK_F2] = KEY_F2;
  291. keyMap[VK_F3] = KEY_F3;
  292. keyMap[VK_F4] = KEY_F4;
  293. keyMap[VK_F5] = KEY_F5;
  294. keyMap[VK_F6] = KEY_F6;
  295. keyMap[VK_F7] = KEY_F7;
  296. keyMap[VK_F8] = KEY_F8;
  297. keyMap[VK_F9] = KEY_F9;
  298. keyMap[VK_F10] = KEY_F10;
  299. keyMap[VK_F11] = KEY_F11;
  300. keyMap[VK_F12] = KEY_F12;
  301. keyMap[VK_F13] = KEY_F13;
  302. keyMap[VK_F14] = KEY_F14;
  303. keyMap[VK_F15] = KEY_F15;
  304. keyMap[VK_NUMLOCK] = KEY_NUMLOCK;
  305. keyMap[VK_CAPITAL] = KEY_CAPSLOCK;
  306. keyMap[VK_SCROLL] = KEY_SCROLLOCK;
  307. keyMap[VK_RSHIFT] = KEY_RSHIFT;
  308. keyMap[VK_LSHIFT] = KEY_LSHIFT;
  309. keyMap[VK_RCONTROL] = KEY_RCTRL;
  310. keyMap[VK_LCONTROL] = KEY_LCTRL;
  311. keyMap[VK_RMENU] = KEY_RALT;
  312. keyMap[VK_LMENU] = KEY_LALT;
  313. keyMap[VK_RWIN] = KEY_RSUPER;
  314. keyMap[VK_LWIN] = KEY_LSUPER;
  315. keyMap[VK_HELP] = KEY_HELP;
  316. keyMap[VK_SNAPSHOT] = KEY_PRINT;
  317. keyMap[VK_CANCEL] = KEY_BREAK;
  318. keyMap[VK_APPS] = KEY_MENU;
  319. }
  320. PolyKEY Win32Core::mapKey(LPARAM lParam, WPARAM wParam) {
  321. switch (wParam) {
  322. case VK_CONTROL:
  323. if ( lParam&EXTENDED_KEYMASK )
  324. wParam = VK_RCONTROL;
  325. else
  326. wParam = VK_LCONTROL;
  327. break;
  328. case 33:
  329. if ( lParam&EXTENDED_KEYMASK )
  330. wParam = VK_RMENU;
  331. else
  332. wParam = VK_LMENU;
  333. break;
  334. }
  335. return keyMap[(unsigned int)wParam];
  336. }
  337. void Win32Core::handleKeyDown(LPARAM lParam, WPARAM wParam) {
  338. lockMutex(eventMutex);
  339. Win32Event newEvent;
  340. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  341. newEvent.eventCode = InputEvent::EVENT_KEYDOWN;
  342. newEvent.keyCode = mapKey(lParam, wParam);
  343. newEvent.unicodeChar = ' ';
  344. win32Events.push_back(newEvent);
  345. unlockMutex(eventMutex);
  346. }
  347. void Win32Core::handleKeyUp(LPARAM lParam, WPARAM wParam) {
  348. lockMutex(eventMutex);
  349. Win32Event newEvent;
  350. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  351. newEvent.eventCode = InputEvent::EVENT_KEYUP;
  352. newEvent.keyCode = mapKey(lParam, wParam);
  353. newEvent.unicodeChar = ' ';
  354. win32Events.push_back(newEvent);
  355. unlockMutex(eventMutex);
  356. }
  357. void Win32Core::handleMouseMove(LPARAM lParam, WPARAM wParam) {
  358. lockMutex(eventMutex);
  359. Win32Event newEvent;
  360. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  361. newEvent.eventCode = InputEvent::EVENT_MOUSEMOVE;
  362. newEvent.mouseX = GET_X_LPARAM(lParam);
  363. newEvent.mouseY = GET_Y_LPARAM(lParam);
  364. win32Events.push_back(newEvent);
  365. unlockMutex(eventMutex);
  366. }
  367. void Win32Core::handleMouseWheel(LPARAM lParam, WPARAM wParam) {
  368. lockMutex(eventMutex);
  369. Win32Event newEvent;
  370. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  371. newEvent.mouseX = GET_X_LPARAM(lParam);
  372. newEvent.mouseY = GET_Y_LPARAM(lParam);
  373. int zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
  374. if(zDelta < 0)
  375. newEvent.eventCode = InputEvent::EVENT_MOUSEWHEEL_DOWN;
  376. else
  377. newEvent.eventCode = InputEvent::EVENT_MOUSEWHEEL_UP;
  378. win32Events.push_back(newEvent);
  379. unlockMutex(eventMutex);
  380. }
  381. void Win32Core::handleMouseDown(int mouseCode,LPARAM lParam, WPARAM wParam) {
  382. lockMutex(eventMutex);
  383. Win32Event newEvent;
  384. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  385. newEvent.mouseX = GET_X_LPARAM(lParam);
  386. newEvent.mouseY = GET_Y_LPARAM(lParam);
  387. newEvent.eventCode = InputEvent::EVENT_MOUSEDOWN;
  388. newEvent.mouseButton = mouseCode;
  389. win32Events.push_back(newEvent);
  390. unlockMutex(eventMutex);
  391. }
  392. void Win32Core::handleMouseUp(int mouseCode,LPARAM lParam, WPARAM wParam) {
  393. lockMutex(eventMutex);
  394. Win32Event newEvent;
  395. newEvent.eventGroup = Win32Event::INPUT_EVENT;
  396. newEvent.mouseX = GET_X_LPARAM(lParam);
  397. newEvent.mouseY = GET_Y_LPARAM(lParam);
  398. newEvent.eventCode = InputEvent::EVENT_MOUSEUP;
  399. newEvent.mouseButton = mouseCode;
  400. win32Events.push_back(newEvent);
  401. unlockMutex(eventMutex);
  402. }
  403. void Win32Core::checkEvents() {
  404. lockMutex(eventMutex);
  405. Win32Event event;
  406. for(int i=0; i < win32Events.size(); i++) {
  407. event = win32Events[i];
  408. switch(event.eventGroup) {
  409. case Win32Event::INPUT_EVENT:
  410. switch(event.eventCode) {
  411. case InputEvent::EVENT_MOUSEMOVE:
  412. input->setDeltaPosition(event.mouseX - lastMouseX , event.mouseY - lastMouseY);
  413. lastMouseX = event.mouseX;
  414. lastMouseY = event.mouseY;
  415. input->setMousePosition(event.mouseX, event.mouseY, getTicks());
  416. break;
  417. case InputEvent::EVENT_MOUSEDOWN:
  418. input->setMouseButtonState(event.mouseButton, true, getTicks());
  419. break;
  420. case InputEvent::EVENT_MOUSEUP:
  421. input->setMouseButtonState(event.mouseButton, false, getTicks());
  422. break;
  423. case InputEvent::EVENT_KEYDOWN:
  424. input->setKeyState(event.keyCode, (char)event.unicodeChar, true, getTicks());
  425. break;
  426. case InputEvent::EVENT_KEYUP:
  427. input->setKeyState(event.keyCode, (char)event.unicodeChar, false, getTicks());
  428. break;
  429. }
  430. break;
  431. }
  432. }
  433. win32Events.clear();
  434. unlockMutex(eventMutex);
  435. }
  436. DWORD WINAPI Win32LaunchThread(LPVOID data) {
  437. Threaded *threaded = (Threaded*)data;
  438. threaded->runThread();
  439. return 1;
  440. }
  441. void Win32Core::createThread(Threaded *target) {
  442. DWORD dwGenericThread;
  443. HANDLE handle = CreateThread(NULL,0,Win32LaunchThread,target,0,&dwGenericThread);
  444. }
  445. void Win32Core::lockMutex(CoreMutex *mutex) {
  446. WaitForSingleObject(((Win32Mutex*)mutex)->winMutex,INFINITE);
  447. }
  448. void Win32Core::unlockMutex(CoreMutex *mutex) {
  449. ReleaseMutex(((Win32Mutex*)mutex)->winMutex);
  450. }
  451. void Win32Core::platformSleep(int msecs) {
  452. Sleep(msecs);
  453. }
  454. CoreMutex *Win32Core::createMutex() {
  455. Win32Mutex *newMutex = new Win32Mutex();
  456. newMutex->winMutex = CreateMutex( NULL, FALSE, NULL);
  457. return newMutex;
  458. }
  459. std::vector<Polycode::Rectangle> Win32Core::getVideoModes() {
  460. std::vector<Polycode::Rectangle> retVector;
  461. return retVector;
  462. }