BsEditorExec.cpp 2.2 KB

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