2
0

Main.cpp 4.1 KB

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