BsEditorExec.cpp 2.1 KB

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