entry.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * Copyright 2011-2015 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include <bx/bx.h>
  6. #include <bgfx/bgfx.h>
  7. #include <bx/string.h>
  8. #include <bx/readerwriter.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' + (_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') + (_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. )
  236. {
  237. return 0;
  238. }
  239. else if (setOrToggle(s_debug, "stats", BGFX_DEBUG_STATS, 1, _argc, _argv)
  240. || setOrToggle(s_debug, "ifh", BGFX_DEBUG_IFH, 1, _argc, _argv)
  241. || setOrToggle(s_debug, "text", BGFX_DEBUG_TEXT, 1, _argc, _argv)
  242. || setOrToggle(s_debug, "wireframe", BGFX_DEBUG_WIREFRAME, 1, _argc, _argv) )
  243. {
  244. bgfx::setDebug(s_debug);
  245. return 0;
  246. }
  247. else if (0 == strcmp(_argv[1], "screenshot") )
  248. {
  249. if (_argc > 2)
  250. {
  251. bgfx::saveScreenShot(_argv[2]);
  252. }
  253. else
  254. {
  255. time_t tt;
  256. time(&tt);
  257. char filePath[256];
  258. bx::snprintf(filePath, sizeof(filePath), "temp/screenshot-%d", tt);
  259. bgfx::saveScreenShot(filePath);
  260. }
  261. return 0;
  262. }
  263. else if (0 == strcmp(_argv[1], "fullscreen") )
  264. {
  265. WindowHandle window = { 0 };
  266. toggleFullscreen(window);
  267. return 0;
  268. }
  269. }
  270. return 1;
  271. }
  272. int cmdExit(CmdContext* /*_context*/, void* /*_userData*/, int /*_argc*/, char const* const* /*_argv*/)
  273. {
  274. s_exit = true;
  275. return 0;
  276. }
  277. static const InputBinding s_bindings[] =
  278. {
  279. { entry::Key::KeyQ, entry::Modifier::LeftCtrl, 1, NULL, "exit" },
  280. { entry::Key::KeyQ, entry::Modifier::RightCtrl, 1, NULL, "exit" },
  281. { entry::Key::KeyF, entry::Modifier::LeftCtrl, 1, NULL, "graphics fullscreen" },
  282. { entry::Key::KeyF, entry::Modifier::RightCtrl, 1, NULL, "graphics fullscreen" },
  283. { entry::Key::Return, entry::Modifier::RightAlt, 1, NULL, "graphics fullscreen" },
  284. { entry::Key::F1, entry::Modifier::None, 1, NULL, "graphics stats" },
  285. { entry::Key::GamepadStart, entry::Modifier::None, 1, NULL, "graphics stats" },
  286. { entry::Key::F1, entry::Modifier::LeftShift, 1, NULL, "graphics stats 0\ngraphics text 0" },
  287. { entry::Key::F3, entry::Modifier::None, 1, NULL, "graphics wireframe" },
  288. { entry::Key::F4, entry::Modifier::None, 1, NULL, "graphics hmd" },
  289. { entry::Key::F4, entry::Modifier::LeftShift, 1, NULL, "graphics hmdrecenter" },
  290. { entry::Key::F4, entry::Modifier::LeftCtrl, 1, NULL, "graphics hmddbg" },
  291. { entry::Key::F7, entry::Modifier::None, 1, NULL, "graphics vsync" },
  292. { entry::Key::F8, entry::Modifier::None, 1, NULL, "graphics msaa" },
  293. { entry::Key::F9, entry::Modifier::None, 1, NULL, "graphics flush" },
  294. { entry::Key::F10, entry::Modifier::None, 1, NULL, "graphics hidpi" },
  295. { entry::Key::Print, entry::Modifier::None, 1, NULL, "graphics screenshot" },
  296. INPUT_BINDING_END
  297. };
  298. #if BX_PLATFORM_EMSCRIPTEN
  299. static AppI* s_app;
  300. static void updateApp()
  301. {
  302. s_app->update();
  303. }
  304. #endif // BX_PLATFORM_EMSCRIPTEN
  305. int runApp(AppI* _app, int _argc, char** _argv)
  306. {
  307. _app->init(_argc, _argv);
  308. bgfx::frame();
  309. WindowHandle defaultWindow = { 0 };
  310. setWindowSize(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
  311. #if BX_PLATFORM_EMSCRIPTEN
  312. s_app = _app;
  313. emscripten_set_main_loop(&updateApp, -1, 1);
  314. #else
  315. while (_app->update() );
  316. #endif // BX_PLATFORM_EMSCRIPTEN
  317. return _app->shutdown();
  318. }
  319. int main(int _argc, char** _argv)
  320. {
  321. //DBG(BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME);
  322. if (BX_ENABLED(ENTRY_CONFIG_PROFILER) )
  323. {
  324. rmtSettings* settings = rmt_Settings();
  325. BX_WARN(NULL != settings, "Remotery is not enabled.");
  326. if (NULL != settings)
  327. {
  328. settings->malloc = rmtMalloc;
  329. settings->realloc = rmtRealloc;
  330. settings->free = rmtFree;
  331. rmtError err = rmt_CreateGlobalInstance(&s_rmt);
  332. BX_WARN(RMT_ERROR_NONE != err, "Remotery failed to create global instance.");
  333. if (RMT_ERROR_NONE == err)
  334. {
  335. rmt_SetCurrentThreadName("Main");
  336. }
  337. else
  338. {
  339. s_rmt = NULL;
  340. }
  341. }
  342. }
  343. #if BX_CONFIG_CRT_FILE_READER_WRITER
  344. s_fileReader = new bx::CrtFileReader;
  345. s_fileWriter = new bx::CrtFileWriter;
  346. #endif // BX_CONFIG_CRT_FILE_READER_WRITER
  347. cmdInit();
  348. cmdAdd("mouselock", cmdMouseLock);
  349. cmdAdd("graphics", cmdGraphics );
  350. cmdAdd("exit", cmdExit );
  351. inputInit();
  352. inputAddBindings("bindings", s_bindings);
  353. entry::WindowHandle defaultWindow = { 0 };
  354. entry::setWindowTitle(defaultWindow, bx::baseName(_argv[0]) );
  355. setWindowSize(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
  356. int32_t result = ::_main_(_argc, _argv);
  357. inputRemoveBindings("bindings");
  358. inputShutdown();
  359. cmdShutdown();
  360. #if BX_CONFIG_CRT_FILE_READER_WRITER
  361. delete s_fileReader;
  362. s_fileReader = NULL;
  363. delete s_fileWriter;
  364. s_fileWriter = NULL;
  365. #endif // BX_CONFIG_CRT_FILE_READER_WRITER
  366. if (BX_ENABLED(ENTRY_CONFIG_PROFILER)
  367. && NULL != s_rmt)
  368. {
  369. rmt_DestroyGlobalInstance(s_rmt);
  370. }
  371. return result;
  372. }
  373. bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse)
  374. {
  375. s_debug = _debug;
  376. s_reset = _reset;
  377. WindowHandle handle = { UINT16_MAX };
  378. bool mouseLock = inputIsMouseLocked();
  379. const Event* ev;
  380. do
  381. {
  382. struct SE { const Event* m_ev; SE() : m_ev(poll() ) {} ~SE() { if (NULL != m_ev) { release(m_ev); } } } scopeEvent;
  383. ev = scopeEvent.m_ev;
  384. if (NULL != ev)
  385. {
  386. switch (ev->m_type)
  387. {
  388. case Event::Axis:
  389. {
  390. const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
  391. inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
  392. }
  393. break;
  394. case Event::Char:
  395. {
  396. const CharEvent* chev = static_cast<const CharEvent*>(ev);
  397. inputChar(chev->m_len, chev->m_char);
  398. }
  399. break;
  400. case Event::Exit:
  401. return true;
  402. case Event::Gamepad:
  403. {
  404. const GamepadEvent* gev = static_cast<const GamepadEvent*>(ev);
  405. DBG("gamepad %d, %d", gev->m_gamepad.idx, gev->m_connected);
  406. }
  407. break;
  408. case Event::Mouse:
  409. {
  410. const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
  411. handle = mouse->m_handle;
  412. if (mouse->m_move)
  413. {
  414. inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
  415. }
  416. else
  417. {
  418. inputSetMouseButtonState(mouse->m_button, mouse->m_down);
  419. }
  420. if (NULL != _mouse
  421. && !mouseLock)
  422. {
  423. if (mouse->m_move)
  424. {
  425. _mouse->m_mx = mouse->m_mx;
  426. _mouse->m_my = mouse->m_my;
  427. _mouse->m_mz = mouse->m_mz;
  428. }
  429. else
  430. {
  431. _mouse->m_buttons[mouse->m_button] = mouse->m_down;
  432. }
  433. }
  434. }
  435. break;
  436. case Event::Key:
  437. {
  438. const KeyEvent* key = static_cast<const KeyEvent*>(ev);
  439. handle = key->m_handle;
  440. inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
  441. }
  442. break;
  443. case Event::Size:
  444. {
  445. const SizeEvent* size = static_cast<const SizeEvent*>(ev);
  446. handle = size->m_handle;
  447. _width = size->m_width;
  448. _height = size->m_height;
  449. _reset = !s_reset; // force reset
  450. }
  451. break;
  452. case Event::Window:
  453. break;
  454. case Event::Suspend:
  455. break;
  456. default:
  457. break;
  458. }
  459. }
  460. inputProcess();
  461. } while (NULL != ev);
  462. if (handle.idx == 0
  463. && _reset != s_reset)
  464. {
  465. _reset = s_reset;
  466. bgfx::reset(_width, _height, _reset);
  467. inputSetMouseResolution(_width, _height);
  468. }
  469. _debug = s_debug;
  470. return s_exit;
  471. }
  472. WindowState s_window[ENTRY_CONFIG_MAX_WINDOWS];
  473. bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset)
  474. {
  475. s_debug = _debug;
  476. s_reset = _reset;
  477. WindowHandle handle = { UINT16_MAX };
  478. bool mouseLock = inputIsMouseLocked();
  479. const Event* ev;
  480. do
  481. {
  482. struct SE
  483. {
  484. SE(WindowHandle _handle)
  485. : m_ev(poll(_handle) )
  486. {
  487. }
  488. ~SE()
  489. {
  490. if (NULL != m_ev)
  491. {
  492. release(m_ev);
  493. }
  494. }
  495. const Event* m_ev;
  496. } scopeEvent(handle);
  497. ev = scopeEvent.m_ev;
  498. if (NULL != ev)
  499. {
  500. handle = ev->m_handle;
  501. WindowState& win = s_window[handle.idx];
  502. switch (ev->m_type)
  503. {
  504. case Event::Axis:
  505. {
  506. const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
  507. inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
  508. }
  509. break;
  510. case Event::Char:
  511. {
  512. const CharEvent* chev = static_cast<const CharEvent*>(ev);
  513. win.m_handle = chev->m_handle;
  514. inputChar(chev->m_len, chev->m_char);
  515. }
  516. break;
  517. case Event::Exit:
  518. return true;
  519. case Event::Gamepad:
  520. {
  521. const GamepadEvent* gev = static_cast<const GamepadEvent*>(ev);
  522. DBG("gamepad %d, %d", gev->m_gamepad.idx, gev->m_connected);
  523. }
  524. break;
  525. case Event::Mouse:
  526. {
  527. const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
  528. win.m_handle = mouse->m_handle;
  529. if (mouse->m_move)
  530. {
  531. inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
  532. }
  533. else
  534. {
  535. inputSetMouseButtonState(mouse->m_button, mouse->m_down);
  536. }
  537. if (!mouseLock)
  538. {
  539. if (mouse->m_move)
  540. {
  541. win.m_mouse.m_mx = mouse->m_mx;
  542. win.m_mouse.m_my = mouse->m_my;
  543. win.m_mouse.m_mz = mouse->m_mz;
  544. }
  545. else
  546. {
  547. win.m_mouse.m_buttons[mouse->m_button] = mouse->m_down;
  548. }
  549. }
  550. }
  551. break;
  552. case Event::Key:
  553. {
  554. const KeyEvent* key = static_cast<const KeyEvent*>(ev);
  555. win.m_handle = key->m_handle;
  556. inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
  557. }
  558. break;
  559. case Event::Size:
  560. {
  561. const SizeEvent* size = static_cast<const SizeEvent*>(ev);
  562. win.m_handle = size->m_handle;
  563. win.m_width = size->m_width;
  564. win.m_height = size->m_height;
  565. _reset = win.m_handle.idx == 0
  566. ? !s_reset
  567. : _reset
  568. ; // force reset
  569. }
  570. break;
  571. case Event::Window:
  572. {
  573. const WindowEvent* window = static_cast<const WindowEvent*>(ev);
  574. win.m_handle = window->m_handle;
  575. win.m_nwh = window->m_nwh;
  576. ev = NULL;
  577. }
  578. break;
  579. case Event::Suspend:
  580. break;
  581. default:
  582. break;
  583. }
  584. }
  585. inputProcess();
  586. } while (NULL != ev);
  587. if (isValid(handle) )
  588. {
  589. const WindowState& win = s_window[handle.idx];
  590. _state = win;
  591. if (handle.idx == 0)
  592. {
  593. inputSetMouseResolution(win.m_width, win.m_height);
  594. }
  595. }
  596. if (_reset != s_reset)
  597. {
  598. _reset = s_reset;
  599. bgfx::reset(s_window[0].m_width, s_window[0].m_height, _reset);
  600. inputSetMouseResolution(s_window[0].m_width, s_window[0].m_height);
  601. }
  602. _debug = s_debug;
  603. return s_exit;
  604. }
  605. bx::FileReaderI* getFileReader()
  606. {
  607. return s_fileReader;
  608. }
  609. bx::FileWriterI* getFileWriter()
  610. {
  611. return s_fileWriter;
  612. }
  613. bx::AllocatorI* getAllocator()
  614. {
  615. return s_allocator;
  616. }
  617. void* TinyStlAllocator::static_allocate(size_t _bytes)
  618. {
  619. return BX_ALLOC(getAllocator(), _bytes);
  620. }
  621. void TinyStlAllocator::static_deallocate(void* _ptr, size_t /*_bytes*/)
  622. {
  623. if (NULL != _ptr)
  624. {
  625. BX_FREE(getAllocator(), _ptr);
  626. }
  627. }
  628. } // namespace entry
  629. extern "C" bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32_t* _debug, uint32_t* _reset)
  630. {
  631. return entry::processEvents(*_width, *_height, *_debug, *_reset, NULL);
  632. }