entry.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
  414. if (!mouse->m_move)
  415. {
  416. inputSetMouseButtonState(mouse->m_button, mouse->m_down);
  417. }
  418. if (NULL != _mouse
  419. && !mouseLock)
  420. {
  421. _mouse->m_mx = mouse->m_mx;
  422. _mouse->m_my = mouse->m_my;
  423. _mouse->m_mz = mouse->m_mz;
  424. if (!mouse->m_move)
  425. {
  426. _mouse->m_buttons[mouse->m_button] = mouse->m_down;
  427. }
  428. }
  429. }
  430. break;
  431. case Event::Key:
  432. {
  433. const KeyEvent* key = static_cast<const KeyEvent*>(ev);
  434. handle = key->m_handle;
  435. inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
  436. }
  437. break;
  438. case Event::Size:
  439. {
  440. const SizeEvent* size = static_cast<const SizeEvent*>(ev);
  441. handle = size->m_handle;
  442. _width = size->m_width;
  443. _height = size->m_height;
  444. _reset = !s_reset; // force reset
  445. }
  446. break;
  447. case Event::Window:
  448. break;
  449. case Event::Suspend:
  450. break;
  451. default:
  452. break;
  453. }
  454. }
  455. inputProcess();
  456. } while (NULL != ev);
  457. if (handle.idx == 0
  458. && _reset != s_reset)
  459. {
  460. _reset = s_reset;
  461. bgfx::reset(_width, _height, _reset);
  462. inputSetMouseResolution(uint16_t(_width), uint16_t(_height) );
  463. }
  464. _debug = s_debug;
  465. return s_exit;
  466. }
  467. WindowState s_window[ENTRY_CONFIG_MAX_WINDOWS];
  468. bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset)
  469. {
  470. s_debug = _debug;
  471. s_reset = _reset;
  472. WindowHandle handle = { UINT16_MAX };
  473. bool mouseLock = inputIsMouseLocked();
  474. const Event* ev;
  475. do
  476. {
  477. struct SE
  478. {
  479. SE(WindowHandle _handle)
  480. : m_ev(poll(_handle) )
  481. {
  482. }
  483. ~SE()
  484. {
  485. if (NULL != m_ev)
  486. {
  487. release(m_ev);
  488. }
  489. }
  490. const Event* m_ev;
  491. } scopeEvent(handle);
  492. ev = scopeEvent.m_ev;
  493. if (NULL != ev)
  494. {
  495. handle = ev->m_handle;
  496. WindowState& win = s_window[handle.idx];
  497. switch (ev->m_type)
  498. {
  499. case Event::Axis:
  500. {
  501. const AxisEvent* axis = static_cast<const AxisEvent*>(ev);
  502. inputSetGamepadAxis(axis->m_gamepad, axis->m_axis, axis->m_value);
  503. }
  504. break;
  505. case Event::Char:
  506. {
  507. const CharEvent* chev = static_cast<const CharEvent*>(ev);
  508. win.m_handle = chev->m_handle;
  509. inputChar(chev->m_len, chev->m_char);
  510. }
  511. break;
  512. case Event::Exit:
  513. return true;
  514. case Event::Gamepad:
  515. {
  516. const GamepadEvent* gev = static_cast<const GamepadEvent*>(ev);
  517. DBG("gamepad %d, %d", gev->m_gamepad.idx, gev->m_connected);
  518. }
  519. break;
  520. case Event::Mouse:
  521. {
  522. const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
  523. win.m_handle = mouse->m_handle;
  524. if (mouse->m_move)
  525. {
  526. inputSetMousePos(mouse->m_mx, mouse->m_my, mouse->m_mz);
  527. }
  528. else
  529. {
  530. inputSetMouseButtonState(mouse->m_button, mouse->m_down);
  531. }
  532. if (!mouseLock)
  533. {
  534. if (mouse->m_move)
  535. {
  536. win.m_mouse.m_mx = mouse->m_mx;
  537. win.m_mouse.m_my = mouse->m_my;
  538. win.m_mouse.m_mz = mouse->m_mz;
  539. }
  540. else
  541. {
  542. win.m_mouse.m_buttons[mouse->m_button] = mouse->m_down;
  543. }
  544. }
  545. }
  546. break;
  547. case Event::Key:
  548. {
  549. const KeyEvent* key = static_cast<const KeyEvent*>(ev);
  550. win.m_handle = key->m_handle;
  551. inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
  552. }
  553. break;
  554. case Event::Size:
  555. {
  556. const SizeEvent* size = static_cast<const SizeEvent*>(ev);
  557. win.m_handle = size->m_handle;
  558. win.m_width = size->m_width;
  559. win.m_height = size->m_height;
  560. _reset = win.m_handle.idx == 0
  561. ? !s_reset
  562. : _reset
  563. ; // force reset
  564. }
  565. break;
  566. case Event::Window:
  567. {
  568. const WindowEvent* window = static_cast<const WindowEvent*>(ev);
  569. win.m_handle = window->m_handle;
  570. win.m_nwh = window->m_nwh;
  571. ev = NULL;
  572. }
  573. break;
  574. case Event::Suspend:
  575. break;
  576. default:
  577. break;
  578. }
  579. }
  580. inputProcess();
  581. } while (NULL != ev);
  582. if (isValid(handle) )
  583. {
  584. const WindowState& win = s_window[handle.idx];
  585. _state = win;
  586. if (handle.idx == 0)
  587. {
  588. inputSetMouseResolution(uint16_t(win.m_width), uint16_t(win.m_height) );
  589. }
  590. }
  591. if (_reset != s_reset)
  592. {
  593. _reset = s_reset;
  594. bgfx::reset(s_window[0].m_width, s_window[0].m_height, _reset);
  595. inputSetMouseResolution(uint16_t(s_window[0].m_width), uint16_t(s_window[0].m_height) );
  596. }
  597. _debug = s_debug;
  598. return s_exit;
  599. }
  600. bx::FileReaderI* getFileReader()
  601. {
  602. return s_fileReader;
  603. }
  604. bx::FileWriterI* getFileWriter()
  605. {
  606. return s_fileWriter;
  607. }
  608. bx::AllocatorI* getAllocator()
  609. {
  610. return s_allocator;
  611. }
  612. void* TinyStlAllocator::static_allocate(size_t _bytes)
  613. {
  614. return BX_ALLOC(getAllocator(), _bytes);
  615. }
  616. void TinyStlAllocator::static_deallocate(void* _ptr, size_t /*_bytes*/)
  617. {
  618. if (NULL != _ptr)
  619. {
  620. BX_FREE(getAllocator(), _ptr);
  621. }
  622. }
  623. } // namespace entry
  624. extern "C" bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32_t* _debug, uint32_t* _reset)
  625. {
  626. return entry::processEvents(*_width, *_height, *_debug, *_reset, NULL);
  627. }