2
0

BsEditorExec.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5. #include <io.h>
  6. #include "BsEditorApplication.h"
  7. // DEBUG ONLY
  8. #include "BsDebug.h"
  9. using namespace BansheeEngine;
  10. #if BS_DEBUG_MODE
  11. void InitializeDebugConsole()
  12. {
  13. //Create a console for this application
  14. AllocConsole();
  15. //Redirect unbuffered STDOUT to the console
  16. HANDLE ConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  17. int SystemOutput = _open_osfhandle(intptr_t(ConsoleOutput), _O_TEXT);
  18. FILE *COutputHandle = _fdopen(SystemOutput, "w");
  19. *stdout = *COutputHandle;
  20. setvbuf(stdout, NULL, _IONBF, 0);
  21. //Redirect unbuffered STDERR to the console
  22. HANDLE ConsoleError = GetStdHandle(STD_ERROR_HANDLE);
  23. int SystemError = _open_osfhandle(intptr_t(ConsoleError), _O_TEXT);
  24. FILE *CErrorHandle = _fdopen(SystemError, "w");
  25. *stderr = *CErrorHandle;
  26. setvbuf(stderr, NULL, _IONBF, 0);
  27. //Redirect unbuffered STDIN to the console
  28. HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
  29. int SystemInput = _open_osfhandle(intptr_t(ConsoleInput), _O_TEXT);
  30. FILE *CInputHandle = _fdopen(SystemInput, "r");
  31. *stdin = *CInputHandle;
  32. setvbuf(stdin, NULL, _IONBF, 0);
  33. //make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
  34. std::ios::sync_with_stdio(true);
  35. }
  36. void ShutdownDebugConsole()
  37. {
  38. //Write "Press any key to exit"
  39. HANDLE ConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  40. DWORD CharsWritten;
  41. WriteConsole(ConsoleOutput, "\nPress any key to exit", 22, &CharsWritten, 0);
  42. //Disable line-based input mode so we can get a single character
  43. HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
  44. SetConsoleMode(ConsoleInput, 0);
  45. //Read a single character
  46. TCHAR InputBuffer;
  47. DWORD CharsRead;
  48. ReadConsole(ConsoleInput, &InputBuffer, 1, &CharsRead, 0);
  49. }
  50. #endif
  51. int CALLBACK WinMain(
  52. _In_ HINSTANCE hInstance,
  53. _In_ HINSTANCE hPrevInstance,
  54. _In_ LPSTR lpCmdLine,
  55. _In_ int nCmdShow
  56. )
  57. {
  58. #if BS_DEBUG_MODE
  59. InitializeDebugConsole();
  60. #endif
  61. try
  62. {
  63. EditorApplication::startUp(RenderAPIPlugin::DX11);
  64. EditorApplication::instance().runMainLoop();
  65. EditorApplication::shutDown();
  66. }
  67. catch(Exception& e)
  68. {
  69. LOGERR(e.getFullDescription());
  70. }
  71. #if BS_DEBUG_MODE
  72. ShutdownDebugConsole();
  73. #endif
  74. return 0;
  75. }