BsEditorExec.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <io.h>
  5. #include "BsEditorApplication.h"
  6. #include "BsPlatform.h"
  7. #include "BsCrashHandler.h"
  8. #if BS_PLATFORM == BS_PLATFORM_WIN32
  9. #include <windows.h>
  10. using namespace BansheeEngine;
  11. #if BS_DEBUG_MODE
  12. void InitializeDebugConsole()
  13. {
  14. //Create a console for this application
  15. AllocConsole();
  16. // Redirect standard output to console
  17. freopen("CONIN$", "r", stdin);
  18. freopen("CONOUT$", "w", stdout);
  19. freopen("CONOUT$", "w", stderr);
  20. // Clear streams to ensure they aren't in an error state
  21. std::wcout.clear();
  22. std::cout.clear();
  23. std::wcerr.clear();
  24. std::cerr.clear();
  25. std::wcin.clear();
  26. std::cin.clear();
  27. }
  28. void ShutdownDebugConsole()
  29. {
  30. //Write "Press any key to exit"
  31. HANDLE ConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  32. DWORD CharsWritten;
  33. WriteConsole(ConsoleOutput, "\nPress any key to exit", 22, &CharsWritten, 0);
  34. //Disable line-based input mode so we can get a single character
  35. HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
  36. SetConsoleMode(ConsoleInput, 0);
  37. //Read a single character
  38. TCHAR InputBuffer;
  39. DWORD CharsRead;
  40. ReadConsole(ConsoleInput, &InputBuffer, 1, &CharsRead, 0);
  41. }
  42. #endif // End BS_DEBUG_MODE
  43. int CALLBACK WinMain(
  44. _In_ HINSTANCE hInstance,
  45. _In_ HINSTANCE hPrevInstance,
  46. _In_ LPSTR lpCmdLine,
  47. _In_ int nCmdShow
  48. )
  49. {
  50. #if BS_DEBUG_MODE
  51. InitializeDebugConsole();
  52. #endif
  53. CrashHandler::startUp();
  54. __try
  55. {
  56. EditorApplication::startUp(EditorRenderAPI::DX11);
  57. EditorApplication::instance().runMainLoop();
  58. EditorApplication::shutDown();
  59. }
  60. __except (gCrashHandler().reportCrash(GetExceptionInformation()))
  61. {
  62. PlatformUtility::terminate(true);
  63. }
  64. #if BS_DEBUG_MODE
  65. ShutdownDebugConsole();
  66. #endif
  67. CrashHandler::shutDown();
  68. return 0;
  69. }
  70. #endif // End BS_PLATFORM