BsEditorExec.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #include "Win32/BsWin32Window.h"
  11. using namespace BansheeEngine;
  12. #if BS_DEBUG_MODE
  13. void InitializeDebugConsole()
  14. {
  15. //Create a console for this application
  16. AllocConsole();
  17. //Redirect unbuffered STDOUT to the console
  18. HANDLE ConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  19. int SystemOutput = _open_osfhandle(intptr_t(ConsoleOutput), _O_TEXT);
  20. FILE *COutputHandle = _fdopen(SystemOutput, "w");
  21. *stdout = *COutputHandle;
  22. setvbuf(stdout, NULL, _IONBF, 0);
  23. //Redirect unbuffered STDERR to the console
  24. HANDLE ConsoleError = GetStdHandle(STD_ERROR_HANDLE);
  25. int SystemError = _open_osfhandle(intptr_t(ConsoleError), _O_TEXT);
  26. FILE *CErrorHandle = _fdopen(SystemError, "w");
  27. *stderr = *CErrorHandle;
  28. setvbuf(stderr, NULL, _IONBF, 0);
  29. //Redirect unbuffered STDIN to the console
  30. HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
  31. int SystemInput = _open_osfhandle(intptr_t(ConsoleInput), _O_TEXT);
  32. FILE *CInputHandle = _fdopen(SystemInput, "r");
  33. *stdin = *CInputHandle;
  34. setvbuf(stdin, NULL, _IONBF, 0);
  35. //make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
  36. std::ios::sync_with_stdio(true);
  37. }
  38. void ShutdownDebugConsole()
  39. {
  40. //Write "Press any key to exit"
  41. HANDLE ConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  42. DWORD CharsWritten;
  43. WriteConsole(ConsoleOutput, "\nPress any key to exit", 22, &CharsWritten, 0);
  44. //Disable line-based input mode so we can get a single character
  45. HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
  46. SetConsoleMode(ConsoleInput, 0);
  47. //Read a single character
  48. TCHAR InputBuffer;
  49. DWORD CharsRead;
  50. ReadConsole(ConsoleInput, &InputBuffer, 1, &CharsRead, 0);
  51. }
  52. #endif // End BS_DEBUG_MODE
  53. void ShowSplashScreen()
  54. {
  55. //WINDOW_DESC windowDesc;
  56. //windowDesc.border = WindowBorder::None;
  57. //windowDesc.width = 600;
  58. //windowDesc.height = 662;
  59. //windowDesc.left = -1;
  60. //windowDesc.top = -1;
  61. //windowDesc.title = "Banshee Splash";
  62. //windowDesc.toolWindow = true;
  63. //windowDesc.alphaBlending = true;
  64. //Path splashTexturePath = "..\\..\\..\\Data\\Raw\\Engine\\BansheeLogo.png";
  65. //auto textureIO = std::static_pointer_cast<TextureImportOptions>(gImporter().createImportOptions(splashTexturePath));
  66. //textureIO->setCPUReadable(true);
  67. //HTexture splashTexture = gImporter().import<Texture>(splashTexturePath, textureIO);
  68. //PixelDataPtr splashPixelData = splashTexture->getProperties().allocateSubresourceBuffer(0);
  69. //splashTexture->readData(*splashPixelData);
  70. //windowDesc.background = splashPixelData;
  71. //bs_new<Win32Window>(windowDesc);
  72. }
  73. int CALLBACK WinMain(
  74. _In_ HINSTANCE hInstance,
  75. _In_ HINSTANCE hPrevInstance,
  76. _In_ LPSTR lpCmdLine,
  77. _In_ int nCmdShow
  78. )
  79. {
  80. #if BS_DEBUG_MODE
  81. InitializeDebugConsole();
  82. #endif
  83. CrashHandler::startUp();
  84. __try
  85. {
  86. EditorApplication::startUp(RenderAPIPlugin::DX11);
  87. EditorApplication::instance().runMainLoop();
  88. EditorApplication::shutDown();
  89. }
  90. __except (gCrashHandler().reportCrash(GetExceptionInformation()))
  91. {
  92. PlatformUtility::terminate(true);
  93. }
  94. #if BS_DEBUG_MODE
  95. ShutdownDebugConsole();
  96. #endif
  97. CrashHandler::shutDown();
  98. return 0;
  99. }
  100. #endif // End BS_PLATFORM