entry.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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. int runApp(AppI* _app, int _argc, char** _argv)
  307. {
  308. _app->init(_argc, _argv);
  309. bgfx::frame();
  310. WindowHandle defaultWindow = { 0 };
  311. setWindowSize(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
  312. #if BX_PLATFORM_EMSCRIPTEN
  313. s_app = _app;
  314. emscripten_set_main_loop(&updateApp, -1, 1);
  315. #else
  316. while (_app->update() );
  317. #endif // BX_PLATFORM_EMSCRIPTEN
  318. return _app->shutdown();
  319. }
  320. int main(int _argc, char** _argv)
  321. {
  322. //DBG(BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME);
  323. if (BX_ENABLED(ENTRY_CONFIG_PROFILER) )
  324. {
  325. rmtSettings* settings = rmt_Settings();
  326. BX_WARN(NULL != settings, "Remotery is not enabled.");
  327. if (NULL != settings)
  328. {
  329. settings->malloc = rmtMalloc;
  330. settings->realloc = rmtRealloc;
  331. settings->free = rmtFree;
  332. rmtError err = rmt_CreateGlobalInstance(&s_rmt);
  333. BX_WARN(RMT_ERROR_NONE != err, "Remotery failed to create global instance.");
  334. if (RMT_ERROR_NONE == err)
  335. {
  336. rmt_SetCurrentThreadName("Main");
  337. }
  338. else
  339. {
  340. s_rmt = NULL;
  341. }
  342. }
  343. }
  344. #if BX_CONFIG_CRT_FILE_READER_WRITER
  345. s_fileReader = new bx::CrtFileReader;
  346. s_fileWriter = new bx::CrtFileWriter;
  347. #endif // BX_CONFIG_CRT_FILE_READER_WRITER
  348. cmdInit();
  349. cmdAdd("mouselock", cmdMouseLock);
  350. cmdAdd("graphics", cmdGraphics );
  351. cmdAdd("exit", cmdExit );
  352. inputInit();
  353. inputAddBindings("bindings", s_bindings);
  354. entry::WindowHandle defaultWindow = { 0 };
  355. entry::setWindowTitle(defaultWindow, bx::baseName(_argv[0]) );
  356. setWindowSize(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
  357. int32_t result = ::_main_(_argc, _argv);
  358. inputRemoveBindings("bindings");
  359. inputShutdown();
  360. cmdShutdown();
  361. #if BX_CONFIG_CRT_FILE_READER_WRITER
  362. delete s_fileReader;
  363. s_fileReader = NULL;
  364. delete s_fileWriter;
  365. s_fileWriter = NULL;
  366. #endif // BX_CONFIG_CRT_FILE_READER_WRITER
  367. if (BX_ENABLED(ENTRY_CONFIG_PROFILER)
  368. && NULL != s_rmt)
  369. {
  370. rmt_DestroyGlobalInstance(s_rmt);
  371. }
  372. return result;
  373. }
  374. bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse)
  375. {
  376. s_debug = _debug;
  377. s_reset = _reset;
  378. WindowHandle handle = { UINT16_MAX };
  379. bool mouseLock = inputIsMouseLocked();
  380. const Event* ev;
  381. do
  382. {
  383. struct SE { const Event* m_ev; SE() : m_ev(poll() ) {} ~SE() { if (NULL != m_ev) { release(m_ev); } } } scopeEvent;
  384. ev = scopeEvent.m_ev;
  385. if (NULL != ev)
  386. {
  387. switch (ev->m_type)
  388. {
  389. case Event::Axis:
  390. {
  391. const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
  392. inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
  393. }
  394. break;
  395. case Event::Char:
  396. {
  397. const CharEvent* chev = static_cast<const CharEvent*>(ev);
  398. inputChar(chev->m_len, chev->m_char);
  399. }
  400. break;
  401. case Event::Exit:
  402. return true;
  403. case Event::Gamepad:
  404. {
  405. // const GamepadEvent* gev = static_cast<const GamepadEvent*>(ev);
  406. // DBG("gamepad %d, %d", gev->m_gamepad.idx, gev->m_connected);
  407. }
  408. break;
  409. case Event::Mouse:
  410. {
  411. const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
  412. handle = mouse->m_handle;
  413. if (mouse->m_move)
  414. {
  415. inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
  416. }
  417. else
  418. {
  419. inputSetMouseButtonState(mouse->m_button, mouse->m_down);
  420. }
  421. if (NULL != _mouse
  422. && !mouseLock)
  423. {
  424. if (mouse->m_move)
  425. {
  426. _mouse->m_mx = mouse->m_mx;
  427. _mouse->m_my = mouse->m_my;
  428. _mouse->m_mz = mouse->m_mz;
  429. }
  430. else
  431. {
  432. _mouse->m_buttons[mouse->m_button] = mouse->m_down;
  433. }
  434. }
  435. }
  436. break;
  437. case Event::Key:
  438. {
  439. const KeyEvent* key = static_cast<const KeyEvent*>(ev);
  440. handle = key->m_handle;
  441. inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
  442. }
  443. break;
  444. case Event::Size:
  445. {
  446. const SizeEvent* size = static_cast<const SizeEvent*>(ev);
  447. handle = size->m_handle;
  448. _width = size->m_width;
  449. _height = size->m_height;
  450. _reset = !s_reset; // force reset
  451. }
  452. break;
  453. case Event::Window:
  454. break;
  455. case Event::Suspend:
  456. break;
  457. default:
  458. break;
  459. }
  460. }
  461. inputProcess();
  462. } while (NULL != ev);
  463. if (handle.idx == 0
  464. && _reset != s_reset)
  465. {
  466. _reset = s_reset;
  467. bgfx::reset(_width, _height, _reset);
  468. inputSetMouseResolution(uint16_t(_width), uint16_t(_height) );
  469. }
  470. _debug = s_debug;
  471. return s_exit;
  472. }
  473. WindowState s_window[ENTRY_CONFIG_MAX_WINDOWS];
  474. bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset)
  475. {
  476. s_debug = _debug;
  477. s_reset = _reset;
  478. WindowHandle handle = { UINT16_MAX };
  479. bool mouseLock = inputIsMouseLocked();
  480. const Event* ev;
  481. do
  482. {
  483. struct SE
  484. {
  485. SE(WindowHandle _handle)
  486. : m_ev(poll(_handle) )
  487. {
  488. }
  489. ~SE()
  490. {
  491. if (NULL != m_ev)
  492. {
  493. release(m_ev);
  494. }
  495. }
  496. const Event* m_ev;
  497. } scopeEvent(handle);
  498. ev = scopeEvent.m_ev;
  499. if (NULL != ev)
  500. {
  501. handle = ev->m_handle;
  502. WindowState& win = s_window[handle.idx];
  503. switch (ev->m_type)
  504. {
  505. case Event::Axis:
  506. {
  507. const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
  508. inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
  509. }
  510. break;
  511. case Event::Char:
  512. {
  513. const CharEvent* chev = static_cast<const CharEvent*>(ev);
  514. win.m_handle = chev->m_handle;
  515. inputChar(chev->m_len, chev->m_char);
  516. }
  517. break;
  518. case Event::Exit:
  519. return true;
  520. case Event::Gamepad:
  521. {
  522. const GamepadEvent* gev = static_cast<const GamepadEvent*>(ev);
  523. DBG("gamepad %d, %d", gev->m_gamepad.idx, gev->m_connected);
  524. }
  525. break;
  526. case Event::Mouse:
  527. {
  528. const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
  529. win.m_handle = mouse->m_handle;
  530. if (mouse->m_move)
  531. {
  532. inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
  533. }
  534. else
  535. {
  536. inputSetMouseButtonState(mouse->m_button, mouse->m_down);
  537. }
  538. if (!mouseLock)
  539. {
  540. if (mouse->m_move)
  541. {
  542. win.m_mouse.m_mx = mouse->m_mx;
  543. win.m_mouse.m_my = mouse->m_my;
  544. win.m_mouse.m_mz = mouse->m_mz;
  545. }
  546. else
  547. {
  548. win.m_mouse.m_buttons[mouse->m_button] = mouse->m_down;
  549. }
  550. }
  551. }
  552. break;
  553. case Event::Key:
  554. {
  555. const KeyEvent* key = static_cast<const KeyEvent*>(ev);
  556. win.m_handle = key->m_handle;
  557. inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
  558. }
  559. break;
  560. case Event::Size:
  561. {
  562. const SizeEvent* size = static_cast<const SizeEvent*>(ev);
  563. win.m_handle = size->m_handle;
  564. win.m_width = size->m_width;
  565. win.m_height = size->m_height;
  566. _reset = win.m_handle.idx == 0
  567. ? !s_reset
  568. : _reset
  569. ; // force reset
  570. }
  571. break;
  572. case Event::Window:
  573. {
  574. const WindowEvent* window = static_cast<const WindowEvent*>(ev);
  575. win.m_handle = window->m_handle;
  576. win.m_nwh = window->m_nwh;
  577. ev = NULL;
  578. }
  579. break;
  580. case Event::Suspend:
  581. break;
  582. default:
  583. break;
  584. }
  585. }
  586. inputProcess();
  587. } while (NULL != ev);
  588. if (isValid(handle) )
  589. {
  590. const WindowState& win = s_window[handle.idx];
  591. _state = win;
  592. if (handle.idx == 0)
  593. {
  594. inputSetMouseResolution(uint16_t(win.m_width), uint16_t(win.m_height) );
  595. }
  596. }
  597. if (_reset != s_reset)
  598. {
  599. _reset = s_reset;
  600. bgfx::reset(s_window[0].m_width, s_window[0].m_height, _reset);
  601. inputSetMouseResolution(uint16_t(s_window[0].m_width), uint16_t(s_window[0].m_height) );
  602. }
  603. _debug = s_debug;
  604. return s_exit;
  605. }
  606. bx::FileReaderI* getFileReader()
  607. {
  608. return s_fileReader;
  609. }
  610. bx::FileWriterI* getFileWriter()
  611. {
  612. return s_fileWriter;
  613. }
  614. bx::AllocatorI* getAllocator()
  615. {
  616. return s_allocator;
  617. }
  618. void* TinyStlAllocator::static_allocate(size_t _bytes)
  619. {
  620. return BX_ALLOC(getAllocator(), _bytes);
  621. }
  622. void TinyStlAllocator::static_deallocate(void* _ptr, size_t /*_bytes*/)
  623. {
  624. if (NULL != _ptr)
  625. {
  626. BX_FREE(getAllocator(), _ptr);
  627. }
  628. }
  629. } // namespace entry
  630. extern "C" bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32_t* _debug, uint32_t* _reset)
  631. {
  632. return entry::processEvents(*_width, *_height, *_debug, *_reset, NULL);
  633. }