entry.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /*
  2. * Copyright 2011-2016 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include <bx/bx.h>
  6. #include <bgfx/bgfx.h>
  7. #include <bx/string.h>
  8. #include <bx/crtimpl.h>
  9. #include <time.h>
  10. #if BX_PLATFORM_EMSCRIPTEN
  11. # include <emscripten.h>
  12. #endif // BX_PLATFORM_EMSCRIPTEN
  13. #include "entry_p.h"
  14. #include "cmd.h"
  15. #include "input.h"
  16. #define RMT_ENABLED ENTRY_CONFIG_PROFILER
  17. #include <remotery/lib/Remotery.h>
  18. extern "C" int _main_(int _argc, char** _argv);
  19. namespace entry
  20. {
  21. static uint32_t s_debug = BGFX_DEBUG_NONE;
  22. static uint32_t s_reset = BGFX_RESET_NONE;
  23. static bool s_exit = false;
  24. static Remotery* s_rmt = NULL;
  25. static bx::FileReaderI* s_fileReader = NULL;
  26. static bx::FileWriterI* s_fileWriter = NULL;
  27. extern bx::AllocatorI* getDefaultAllocator();
  28. static bx::AllocatorI* s_allocator = getDefaultAllocator();
  29. void* rmtMalloc(void* /*_context*/, rmtU32 _size)
  30. {
  31. return BX_ALLOC(s_allocator, _size);
  32. }
  33. void* rmtRealloc(void* /*_context*/, void* _ptr, rmtU32 _size)
  34. {
  35. return BX_REALLOC(s_allocator, _ptr, _size);
  36. }
  37. void rmtFree(void* /*_context*/, void* _ptr)
  38. {
  39. BX_FREE(s_allocator, _ptr);
  40. }
  41. #if ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR
  42. bx::AllocatorI* getDefaultAllocator()
  43. {
  44. BX_PRAGMA_DIAGNOSTIC_PUSH();
  45. BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4459); // warning C4459: declaration of 's_allocator' hides global declaration
  46. BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wshadow");
  47. static bx::CrtAllocator s_allocator;
  48. return &s_allocator;
  49. BX_PRAGMA_DIAGNOSTIC_POP();
  50. }
  51. #endif // ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR
  52. static const char* s_keyName[] =
  53. {
  54. "None",
  55. "Esc",
  56. "Return",
  57. "Tab",
  58. "Space",
  59. "Backspace",
  60. "Up",
  61. "Down",
  62. "Left",
  63. "Right",
  64. "Insert",
  65. "Delete",
  66. "Home",
  67. "End",
  68. "PageUp",
  69. "PageDown",
  70. "Print",
  71. "Plus",
  72. "Minus",
  73. "LeftBracket",
  74. "RightBracket",
  75. "Semicolon",
  76. "Quote",
  77. "Comma",
  78. "Period",
  79. "Slash",
  80. "Backslash",
  81. "Tilde",
  82. "F1",
  83. "F2",
  84. "F3",
  85. "F4",
  86. "F5",
  87. "F6",
  88. "F7",
  89. "F8",
  90. "F9",
  91. "F10",
  92. "F11",
  93. "F12",
  94. "NumPad0",
  95. "NumPad1",
  96. "NumPad2",
  97. "NumPad3",
  98. "NumPad4",
  99. "NumPad5",
  100. "NumPad6",
  101. "NumPad7",
  102. "NumPad8",
  103. "NumPad9",
  104. "Key0",
  105. "Key1",
  106. "Key2",
  107. "Key3",
  108. "Key4",
  109. "Key5",
  110. "Key6",
  111. "Key7",
  112. "Key8",
  113. "Key9",
  114. "KeyA",
  115. "KeyB",
  116. "KeyC",
  117. "KeyD",
  118. "KeyE",
  119. "KeyF",
  120. "KeyG",
  121. "KeyH",
  122. "KeyI",
  123. "KeyJ",
  124. "KeyK",
  125. "KeyL",
  126. "KeyM",
  127. "KeyN",
  128. "KeyO",
  129. "KeyP",
  130. "KeyQ",
  131. "KeyR",
  132. "KeyS",
  133. "KeyT",
  134. "KeyU",
  135. "KeyV",
  136. "KeyW",
  137. "KeyX",
  138. "KeyY",
  139. "KeyZ",
  140. "GamepadA",
  141. "GamepadB",
  142. "GamepadX",
  143. "GamepadY",
  144. "GamepadThumbL",
  145. "GamepadThumbR",
  146. "GamepadShoulderL",
  147. "GamepadShoulderR",
  148. "GamepadUp",
  149. "GamepadDown",
  150. "GamepadLeft",
  151. "GamepadRight",
  152. "GamepadBack",
  153. "GamepadStart",
  154. "GamepadGuide",
  155. };
  156. BX_STATIC_ASSERT(Key::Count == BX_COUNTOF(s_keyName) );
  157. const char* getName(Key::Enum _key)
  158. {
  159. BX_CHECK(_key < Key::Count, "Invalid key %d.", _key);
  160. return s_keyName[_key];
  161. }
  162. char keyToAscii(Key::Enum _key, uint8_t _modifiers)
  163. {
  164. const bool isAscii = (Key::Key0 <= _key && _key <= Key::KeyZ)
  165. || (Key::Esc <= _key && _key <= Key::Minus);
  166. if (!isAscii)
  167. {
  168. return '\0';
  169. }
  170. const bool isNumber = (Key::Key0 <= _key && _key <= Key::Key9);
  171. if (isNumber)
  172. {
  173. return '0' + char(_key - Key::Key0);
  174. }
  175. const bool isChar = (Key::KeyA <= _key && _key <= Key::KeyZ);
  176. if (isChar)
  177. {
  178. enum { ShiftMask = Modifier::LeftShift|Modifier::RightShift };
  179. const bool shift = !!(_modifiers&ShiftMask);
  180. return (shift ? 'A' : 'a') + char(_key - Key::KeyA);
  181. }
  182. switch (_key)
  183. {
  184. case Key::Esc: return 0x1b;
  185. case Key::Return: return '\n';
  186. case Key::Tab: return '\t';
  187. case Key::Space: return ' ';
  188. case Key::Backspace: return 0x08;
  189. case Key::Plus: return '+';
  190. case Key::Minus: return '-';
  191. default: break;
  192. }
  193. return '\0';
  194. }
  195. bool setOrToggle(uint32_t& _flags, const char* _name, uint32_t _bit, int _first, int _argc, char const* const* _argv)
  196. {
  197. if (0 == strcmp(_argv[_first], _name) )
  198. {
  199. int arg = _first+1;
  200. if (_argc > arg)
  201. {
  202. _flags &= ~_bit;
  203. _flags |= bx::toBool(_argv[arg]) ? _bit : 0;
  204. }
  205. else
  206. {
  207. _flags ^= _bit;
  208. }
  209. return true;
  210. }
  211. return false;
  212. }
  213. int cmdMouseLock(CmdContext* /*_context*/, void* /*_userData*/, int _argc, char const* const* _argv)
  214. {
  215. if (_argc > 1)
  216. {
  217. inputSetMouseLock(_argc > 1 ? bx::toBool(_argv[1]) : !inputIsMouseLocked() );
  218. return 0;
  219. }
  220. return 1;
  221. }
  222. int cmdGraphics(CmdContext* /*_context*/, void* /*_userData*/, int _argc, char const* const* _argv)
  223. {
  224. if (_argc > 1)
  225. {
  226. if (setOrToggle(s_reset, "vsync", BGFX_RESET_VSYNC, 1, _argc, _argv)
  227. || setOrToggle(s_reset, "maxaniso", BGFX_RESET_MAXANISOTROPY, 1, _argc, _argv)
  228. || setOrToggle(s_reset, "hmd", BGFX_RESET_HMD, 1, _argc, _argv)
  229. || setOrToggle(s_reset, "hmddbg", BGFX_RESET_HMD_DEBUG, 1, _argc, _argv)
  230. || setOrToggle(s_reset, "hmdrecenter", BGFX_RESET_HMD_RECENTER, 1, _argc, _argv)
  231. || setOrToggle(s_reset, "msaa", BGFX_RESET_MSAA_X16, 1, _argc, _argv)
  232. || setOrToggle(s_reset, "flush", BGFX_RESET_FLUSH_AFTER_RENDER, 1, _argc, _argv)
  233. || setOrToggle(s_reset, "flip", BGFX_RESET_FLIP_AFTER_RENDER, 1, _argc, _argv)
  234. || setOrToggle(s_reset, "hidpi", BGFX_RESET_HIDPI, 1, _argc, _argv)
  235. || setOrToggle(s_reset, "depthclamp", BGFX_RESET_DEPTH_CLAMP, 1, _argc, _argv)
  236. )
  237. {
  238. return 0;
  239. }
  240. else if (setOrToggle(s_debug, "stats", BGFX_DEBUG_STATS, 1, _argc, _argv)
  241. || setOrToggle(s_debug, "ifh", BGFX_DEBUG_IFH, 1, _argc, _argv)
  242. || setOrToggle(s_debug, "text", BGFX_DEBUG_TEXT, 1, _argc, _argv)
  243. || setOrToggle(s_debug, "wireframe", BGFX_DEBUG_WIREFRAME, 1, _argc, _argv) )
  244. {
  245. bgfx::setDebug(s_debug);
  246. return 0;
  247. }
  248. else if (0 == strcmp(_argv[1], "screenshot") )
  249. {
  250. if (_argc > 2)
  251. {
  252. bgfx::saveScreenShot(_argv[2]);
  253. }
  254. else
  255. {
  256. time_t tt;
  257. time(&tt);
  258. char filePath[256];
  259. bx::snprintf(filePath, sizeof(filePath), "temp/screenshot-%d", tt);
  260. bgfx::saveScreenShot(filePath);
  261. }
  262. return 0;
  263. }
  264. else if (0 == strcmp(_argv[1], "fullscreen") )
  265. {
  266. WindowHandle window = { 0 };
  267. toggleFullscreen(window);
  268. return 0;
  269. }
  270. }
  271. return 1;
  272. }
  273. int cmdExit(CmdContext* /*_context*/, void* /*_userData*/, int /*_argc*/, char const* const* /*_argv*/)
  274. {
  275. s_exit = true;
  276. return 0;
  277. }
  278. static const InputBinding s_bindings[] =
  279. {
  280. { entry::Key::KeyQ, entry::Modifier::LeftCtrl, 1, NULL, "exit" },
  281. { entry::Key::KeyQ, entry::Modifier::RightCtrl, 1, NULL, "exit" },
  282. { entry::Key::KeyF, entry::Modifier::LeftCtrl, 1, NULL, "graphics fullscreen" },
  283. { entry::Key::KeyF, entry::Modifier::RightCtrl, 1, NULL, "graphics fullscreen" },
  284. { entry::Key::Return, entry::Modifier::RightAlt, 1, NULL, "graphics fullscreen" },
  285. { entry::Key::F1, entry::Modifier::None, 1, NULL, "graphics stats" },
  286. { entry::Key::GamepadStart, entry::Modifier::None, 1, NULL, "graphics stats" },
  287. { entry::Key::F1, entry::Modifier::LeftShift, 1, NULL, "graphics stats 0\ngraphics text 0" },
  288. { entry::Key::F3, entry::Modifier::None, 1, NULL, "graphics wireframe" },
  289. { entry::Key::F4, entry::Modifier::None, 1, NULL, "graphics hmd" },
  290. { entry::Key::F4, entry::Modifier::LeftShift, 1, NULL, "graphics hmdrecenter" },
  291. { entry::Key::F4, entry::Modifier::LeftCtrl, 1, NULL, "graphics hmddbg" },
  292. { entry::Key::F7, entry::Modifier::None, 1, NULL, "graphics vsync" },
  293. { entry::Key::F8, entry::Modifier::None, 1, NULL, "graphics msaa" },
  294. { entry::Key::F9, entry::Modifier::None, 1, NULL, "graphics flush" },
  295. { entry::Key::F10, entry::Modifier::None, 1, NULL, "graphics hidpi" },
  296. { entry::Key::Print, entry::Modifier::None, 1, NULL, "graphics screenshot" },
  297. INPUT_BINDING_END
  298. };
  299. #if BX_PLATFORM_EMSCRIPTEN
  300. static AppI* s_app;
  301. static void updateApp()
  302. {
  303. s_app->update();
  304. }
  305. #endif // BX_PLATFORM_EMSCRIPTEN
  306. static App* s_apps = NULL;
  307. App::App(const char* _name)
  308. {
  309. m_name = _name;
  310. m_next = s_apps;
  311. s_apps = this;
  312. }
  313. App::~App()
  314. {
  315. }
  316. App* getFirstApp()
  317. {
  318. return s_apps;
  319. }
  320. int runApp(AppI* _app, int _argc, char** _argv)
  321. {
  322. _app->init(_argc, _argv);
  323. bgfx::frame();
  324. WindowHandle defaultWindow = { 0 };
  325. setWindowSize(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
  326. #if BX_PLATFORM_EMSCRIPTEN
  327. s_app = _app;
  328. emscripten_set_main_loop(&updateApp, -1, 1);
  329. #else
  330. while (_app->update() );
  331. #endif // BX_PLATFORM_EMSCRIPTEN
  332. return _app->shutdown();
  333. }
  334. int main(int _argc, char** _argv)
  335. {
  336. //DBG(BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME);
  337. if (BX_ENABLED(ENTRY_CONFIG_PROFILER) )
  338. {
  339. rmtSettings* settings = rmt_Settings();
  340. BX_WARN(NULL != settings, "Remotery is not enabled.");
  341. if (NULL != settings)
  342. {
  343. settings->malloc = rmtMalloc;
  344. settings->realloc = rmtRealloc;
  345. settings->free = rmtFree;
  346. rmtError err = rmt_CreateGlobalInstance(&s_rmt);
  347. BX_WARN(RMT_ERROR_NONE != err, "Remotery failed to create global instance.");
  348. if (RMT_ERROR_NONE == err)
  349. {
  350. rmt_SetCurrentThreadName("Main");
  351. }
  352. else
  353. {
  354. s_rmt = NULL;
  355. }
  356. }
  357. }
  358. #if BX_CONFIG_CRT_FILE_READER_WRITER
  359. s_fileReader = BX_NEW(s_allocator, bx::CrtFileReader);
  360. s_fileWriter = BX_NEW(s_allocator, bx::CrtFileWriter);
  361. #endif // BX_CONFIG_CRT_FILE_READER_WRITER
  362. cmdInit();
  363. cmdAdd("mouselock", cmdMouseLock);
  364. cmdAdd("graphics", cmdGraphics );
  365. cmdAdd("exit", cmdExit );
  366. inputInit();
  367. inputAddBindings("bindings", s_bindings);
  368. entry::WindowHandle defaultWindow = { 0 };
  369. entry::setWindowTitle(defaultWindow, bx::baseName(_argv[0]) );
  370. setWindowSize(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
  371. int32_t result = ::_main_(_argc, _argv);
  372. inputRemoveBindings("bindings");
  373. inputShutdown();
  374. cmdShutdown();
  375. #if BX_CONFIG_CRT_FILE_READER_WRITER
  376. BX_DELETE(s_allocator, s_fileReader);
  377. s_fileReader = NULL;
  378. BX_DELETE(s_allocator, s_fileWriter);
  379. s_fileWriter = NULL;
  380. #endif // BX_CONFIG_CRT_FILE_READER_WRITER
  381. if (BX_ENABLED(ENTRY_CONFIG_PROFILER)
  382. && NULL != s_rmt)
  383. {
  384. rmt_DestroyGlobalInstance(s_rmt);
  385. }
  386. return result;
  387. }
  388. bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse)
  389. {
  390. s_debug = _debug;
  391. s_reset = _reset;
  392. WindowHandle handle = { UINT16_MAX };
  393. bool mouseLock = inputIsMouseLocked();
  394. const Event* ev;
  395. do
  396. {
  397. struct SE { const Event* m_ev; SE() : m_ev(poll() ) {} ~SE() { if (NULL != m_ev) { release(m_ev); } } } scopeEvent;
  398. ev = scopeEvent.m_ev;
  399. if (NULL != ev)
  400. {
  401. switch (ev->m_type)
  402. {
  403. case Event::Axis:
  404. {
  405. const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
  406. inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
  407. }
  408. break;
  409. case Event::Char:
  410. {
  411. const CharEvent* chev = static_cast<const CharEvent*>(ev);
  412. inputChar(chev->m_len, chev->m_char);
  413. }
  414. break;
  415. case Event::Exit:
  416. return true;
  417. case Event::Gamepad:
  418. {
  419. // const GamepadEvent* gev = static_cast<const GamepadEvent*>(ev);
  420. // DBG("gamepad %d, %d", gev->m_gamepad.idx, gev->m_connected);
  421. }
  422. break;
  423. case Event::Mouse:
  424. {
  425. const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
  426. handle = mouse->m_handle;
  427. inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
  428. if (!mouse->m_move)
  429. {
  430. inputSetMouseButtonState(mouse->m_button, mouse->m_down);
  431. }
  432. if (NULL != _mouse
  433. && !mouseLock)
  434. {
  435. _mouse->m_mx = mouse->m_mx;
  436. _mouse->m_my = mouse->m_my;
  437. _mouse->m_mz = mouse->m_mz;
  438. if (!mouse->m_move)
  439. {
  440. _mouse->m_buttons[mouse->m_button] = mouse->m_down;
  441. }
  442. }
  443. }
  444. break;
  445. case Event::Key:
  446. {
  447. const KeyEvent* key = static_cast<const KeyEvent*>(ev);
  448. handle = key->m_handle;
  449. inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
  450. }
  451. break;
  452. case Event::Size:
  453. {
  454. const SizeEvent* size = static_cast<const SizeEvent*>(ev);
  455. handle = size->m_handle;
  456. _width = size->m_width;
  457. _height = size->m_height;
  458. _reset = !s_reset; // force reset
  459. }
  460. break;
  461. case Event::Window:
  462. break;
  463. case Event::Suspend:
  464. break;
  465. default:
  466. break;
  467. }
  468. }
  469. inputProcess();
  470. } while (NULL != ev);
  471. if (handle.idx == 0
  472. && _reset != s_reset)
  473. {
  474. _reset = s_reset;
  475. bgfx::reset(_width, _height, _reset);
  476. inputSetMouseResolution(uint16_t(_width), uint16_t(_height) );
  477. }
  478. _debug = s_debug;
  479. return s_exit;
  480. }
  481. WindowState s_window[ENTRY_CONFIG_MAX_WINDOWS];
  482. bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset)
  483. {
  484. s_debug = _debug;
  485. s_reset = _reset;
  486. WindowHandle handle = { UINT16_MAX };
  487. bool mouseLock = inputIsMouseLocked();
  488. const Event* ev;
  489. do
  490. {
  491. struct SE
  492. {
  493. SE(WindowHandle _handle)
  494. : m_ev(poll(_handle) )
  495. {
  496. }
  497. ~SE()
  498. {
  499. if (NULL != m_ev)
  500. {
  501. release(m_ev);
  502. }
  503. }
  504. const Event* m_ev;
  505. } scopeEvent(handle);
  506. ev = scopeEvent.m_ev;
  507. if (NULL != ev)
  508. {
  509. handle = ev->m_handle;
  510. WindowState& win = s_window[handle.idx];
  511. switch (ev->m_type)
  512. {
  513. case Event::Axis:
  514. {
  515. const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
  516. inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
  517. }
  518. break;
  519. case Event::Char:
  520. {
  521. const CharEvent* chev = static_cast<const CharEvent*>(ev);
  522. win.m_handle = chev->m_handle;
  523. inputChar(chev->m_len, chev->m_char);
  524. }
  525. break;
  526. case Event::Exit:
  527. return true;
  528. case Event::Gamepad:
  529. {
  530. const GamepadEvent* gev = static_cast<const GamepadEvent*>(ev);
  531. DBG("gamepad %d, %d", gev->m_gamepad.idx, gev->m_connected);
  532. }
  533. break;
  534. case Event::Mouse:
  535. {
  536. const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
  537. win.m_handle = mouse->m_handle;
  538. if (mouse->m_move)
  539. {
  540. inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
  541. }
  542. else
  543. {
  544. inputSetMouseButtonState(mouse->m_button, mouse->m_down);
  545. }
  546. if (!mouseLock)
  547. {
  548. if (mouse->m_move)
  549. {
  550. win.m_mouse.m_mx = mouse->m_mx;
  551. win.m_mouse.m_my = mouse->m_my;
  552. win.m_mouse.m_mz = mouse->m_mz;
  553. }
  554. else
  555. {
  556. win.m_mouse.m_buttons[mouse->m_button] = mouse->m_down;
  557. }
  558. }
  559. }
  560. break;
  561. case Event::Key:
  562. {
  563. const KeyEvent* key = static_cast<const KeyEvent*>(ev);
  564. win.m_handle = key->m_handle;
  565. inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
  566. }
  567. break;
  568. case Event::Size:
  569. {
  570. const SizeEvent* size = static_cast<const SizeEvent*>(ev);
  571. win.m_handle = size->m_handle;
  572. win.m_width = size->m_width;
  573. win.m_height = size->m_height;
  574. _reset = win.m_handle.idx == 0
  575. ? !s_reset
  576. : _reset
  577. ; // force reset
  578. }
  579. break;
  580. case Event::Window:
  581. {
  582. const WindowEvent* window = static_cast<const WindowEvent*>(ev);
  583. win.m_handle = window->m_handle;
  584. win.m_nwh = window->m_nwh;
  585. ev = NULL;
  586. }
  587. break;
  588. case Event::Suspend:
  589. break;
  590. default:
  591. break;
  592. }
  593. }
  594. inputProcess();
  595. } while (NULL != ev);
  596. if (isValid(handle) )
  597. {
  598. const WindowState& win = s_window[handle.idx];
  599. _state = win;
  600. if (handle.idx == 0)
  601. {
  602. inputSetMouseResolution(uint16_t(win.m_width), uint16_t(win.m_height) );
  603. }
  604. }
  605. if (_reset != s_reset)
  606. {
  607. _reset = s_reset;
  608. bgfx::reset(s_window[0].m_width, s_window[0].m_height, _reset);
  609. inputSetMouseResolution(uint16_t(s_window[0].m_width), uint16_t(s_window[0].m_height) );
  610. }
  611. _debug = s_debug;
  612. return s_exit;
  613. }
  614. bx::FileReaderI* getFileReader()
  615. {
  616. return s_fileReader;
  617. }
  618. bx::FileWriterI* getFileWriter()
  619. {
  620. return s_fileWriter;
  621. }
  622. bx::AllocatorI* getAllocator()
  623. {
  624. return s_allocator;
  625. }
  626. void* TinyStlAllocator::static_allocate(size_t _bytes)
  627. {
  628. return BX_ALLOC(getAllocator(), _bytes);
  629. }
  630. void TinyStlAllocator::static_deallocate(void* _ptr, size_t /*_bytes*/)
  631. {
  632. if (NULL != _ptr)
  633. {
  634. BX_FREE(getAllocator(), _ptr);
  635. }
  636. }
  637. } // namespace entry
  638. extern "C" bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32_t* _debug, uint32_t* _reset)
  639. {
  640. return entry::processEvents(*_width, *_height, *_debug, *_reset, NULL);
  641. }