Main.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "BsApplication.h"
  2. #include "BsCrashHandler.h"
  3. #include "BsCoreThread.h"
  4. #include "BsFileSerializer.h"
  5. #include "BsGameSettings.h"
  6. #include "BsFileSystem.h"
  7. #include "BsResources.h"
  8. #include "BsResourceManifest.h"
  9. #include "BsPrefab.h"
  10. #include "BsSceneObject.h"
  11. #include "BsSceneManager.h"
  12. void runApplication();
  13. #if BS_PLATFORM == BS_PLATFORM_WIN32
  14. #include <windows.h>
  15. using namespace BansheeEngine;
  16. int CALLBACK WinMain(
  17. _In_ HINSTANCE hInstance,
  18. _In_ HINSTANCE hPrevInstance,
  19. _In_ LPSTR lpCmdLine,
  20. _In_ int nCmdShow
  21. )
  22. {
  23. CrashHandler::startUp();
  24. __try
  25. {
  26. runApplication();
  27. }
  28. __except (gCrashHandler().reportCrash(GetExceptionInformation()))
  29. {
  30. PlatformUtility::terminate(true);
  31. }
  32. CrashHandler::shutDown();
  33. return 0;
  34. }
  35. #endif // End BS_PLATFORM
  36. using namespace BansheeEngine;
  37. void runApplication()
  38. {
  39. FileDecoder fd(GAME_SETTINGS_PATH);
  40. SPtr<GameSettings> gameSettings = std::static_pointer_cast<GameSettings>(fd.decode());
  41. if (gameSettings == nullptr)
  42. gameSettings = bs_shared_ptr_new<GameSettings>();
  43. unsigned int resolutionWidth = 200;
  44. unsigned int resolutionHeight = 200;
  45. if (!gameSettings->fullscreen)
  46. {
  47. resolutionWidth = gameSettings->resolutionWidth;
  48. resolutionHeight = gameSettings->resolutionHeight;
  49. }
  50. RENDER_WINDOW_DESC renderWindowDesc;
  51. renderWindowDesc.videoMode = VideoMode(resolutionWidth, resolutionHeight);
  52. renderWindowDesc.title = toString(gameSettings->titleBarText);
  53. renderWindowDesc.fullscreen = false;
  54. renderWindowDesc.hideUntilSwap = true;
  55. Application::startUp(renderWindowDesc, RenderAPIPlugin::DX11);
  56. if (gameSettings->fullscreen)
  57. {
  58. if (gameSettings->useDesktopResolution)
  59. {
  60. const VideoModeInfo& videoModeInfo = RenderAPI::getVideoModeInfo();
  61. const VideoOutputInfo& primaryMonitorInfo = videoModeInfo.getOutputInfo(0);
  62. const VideoMode& selectedVideoMode = primaryMonitorInfo.getDesktopVideoMode();
  63. RenderWindowPtr window = gApplication().getPrimaryWindow();
  64. window->setFullscreen(gCoreAccessor(), selectedVideoMode);
  65. resolutionWidth = selectedVideoMode.getWidth();
  66. resolutionHeight = selectedVideoMode.getHeight();
  67. }
  68. else
  69. {
  70. VideoMode videoMode(resolutionWidth, resolutionHeight);
  71. RenderWindowPtr window = gApplication().getPrimaryWindow();
  72. window->setFullscreen(gCoreAccessor(), videoMode);
  73. }
  74. }
  75. gameSettings->useDesktopResolution = false; // Not relevant after first startup
  76. // TODO - Save full video mode
  77. gameSettings->resolutionWidth = resolutionWidth;
  78. gameSettings->resolutionHeight = resolutionHeight;
  79. FileEncoder fe(GAME_SETTINGS_PATH);
  80. fe.encode(gameSettings.get());
  81. Path resourceManifestPath = GAME_RESOURCES_PATH + GAME_RESOURCE_MANIFEST_NAME;
  82. ResourceManifestPtr manifest;
  83. if (FileSystem::exists(resourceManifestPath))
  84. {
  85. Path resourcesPath = FileSystem::getWorkingDirectoryPath();
  86. resourcesPath.append(GAME_RESOURCES_PATH);
  87. manifest = ResourceManifest::load(resourceManifestPath, resourcesPath);
  88. gResources().registerResourceManifest(manifest);
  89. }
  90. HPrefab mainScene = static_resource_cast<Prefab>(gResources().loadFromUUID(gameSettings->mainSceneUUID));
  91. if (mainScene != nullptr)
  92. {
  93. HSceneObject root = mainScene->instantiate();
  94. HSceneObject oldRoot = gSceneManager().getRootNode();
  95. gSceneManager()._setRootNode(root);
  96. oldRoot->destroy();
  97. }
  98. Application::instance().runMainLoop();
  99. Application::shutDown();
  100. }