Main.cpp 3.3 KB

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