entry.cpp 17 KB

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