Przeglądaj źródła

Added GameSettings asset used for loading the standalone game application

BearishSun 10 lat temu
rodzic
commit
1c8785769a

+ 1 - 1
BansheeEditor/Include/BsProjectLibrary.h

@@ -204,7 +204,7 @@ namespace BansheeEngine
 		void setIncludeInBuild(const Path& path, bool force);
 
 		/**
-		 * @brief	Finds all resource entries that should be included in a build.
+		 * @brief	Finds all top-level resource entries that should be included in a build.
 		 *			Values returned by this method are transient, they may be destroyed
 		 *			on any following ProjectLibrary call.
 		 */

+ 3 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -281,12 +281,15 @@
     <ClCompile Include="Source\BsSplashScreen.cpp" />
     <ClCompile Include="Source\BsVirtualInput.cpp" />
     <ClCompile Include="Source\BsLight.cpp" />
+    <ClCompile Include="Source\BsGameSettings.cpp" />
     <ClInclude Include="Include\BsApplication.h" />
     <ClInclude Include="Include\BsCamera.h" />
     <ClInclude Include="Include\BsCameraRTTI.h" />
     <ClInclude Include="Include\BsCursor.h" />
     <ClInclude Include="Include\BsDrawHelper.h" />
     <ClInclude Include="Include\BsDropDownAreaPlacement.h" />
+    <ClInclude Include="Include\BsGameSettings.h" />
+    <ClInclude Include="Include\BsGameSettingsRTTI.h" />
     <ClInclude Include="Include\BsGUIDropDownContent.h" />
     <ClInclude Include="Include\BsGUIElementStyleRTTI.h" />
     <ClInclude Include="Include\BsGUILayoutData.h" />

+ 9 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -356,6 +356,12 @@
     <ClInclude Include="Include\BsSplashScreen.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsGameSettings.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Include\BsGameSettingsRTTI.h">
+      <Filter>Header Files\RTTI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">
@@ -610,5 +616,8 @@
     <ClCompile Include="Source\BsSplashScreen.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsGameSettings.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 30 - 0
BansheeEngine/Include/BsGameSettings.h

@@ -0,0 +1,30 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+#include "BsIReflectable.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Contains settings used for controlling game start-up, as well as persisting various other properties
+	 * 			through game sessions.
+	 */
+	class BS_EXPORT GameSettings : public IReflectable
+	{
+	public:
+		String mainSceneUUID; /**< Resource UUID of the default scene that is loaded when the application is started. */
+		bool fullscreen = true; /**< If true the application will be started in fullscreen using user's desktop resolution. */
+		bool useDesktopResolution = true; /**< If running in fullscreen should the user's desktop resolution be used instead of the specified resolution. */
+		UINT32 resolutionWidth = 1280; /**< Width of the window. */
+		UINT32 resolutionHeight = 720; /**< Height of the window. */
+		WString titleBarText; /**< Text displayed in window's titlebar. */
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+	public:
+		friend class GameSettingsRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const override;
+	};
+}

+ 57 - 0
BansheeEngine/Include/BsGameSettingsRTTI.h

@@ -0,0 +1,57 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsGameSettings.h"
+
+namespace BansheeEngine
+{
+	class BS_EXPORT GameSettingsRTTI : public RTTIType <GameSettings, IReflectable, GameSettingsRTTI>
+	{
+	private:
+		String& getMainSceneUUID(GameSettings* obj) { return obj->mainSceneUUID; }
+		void setMainSceneUUID(GameSettings* obj, String& val) { obj->mainSceneUUID = val; }
+
+		bool& getFullscreen(GameSettings* obj) { return obj->fullscreen; }
+		void setFullscreen(GameSettings* obj, bool& val) { obj->fullscreen = val; }
+
+		bool& getUseDesktopResolution(GameSettings* obj) { return obj->useDesktopResolution; }
+		void setUseDesktopResolution(GameSettings* obj, bool& val) { obj->useDesktopResolution = val; }
+
+		UINT32& getResolutionWidth(GameSettings* obj) { return obj->resolutionWidth; }
+		void setResolutionWidth(GameSettings* obj, UINT32& val) { obj->resolutionWidth = val; }
+
+		UINT32& getResolutionHeight(GameSettings* obj) { return obj->resolutionHeight; }
+		void setResolutionHeight(GameSettings* obj, UINT32& val) { obj->resolutionHeight = val; }
+
+		WString& getTitlebarText(GameSettings* obj) { return obj->titleBarText; }
+		void setTitlebarText(GameSettings* obj, WString& val) { obj->titleBarText = val; }
+
+	public:
+		GameSettingsRTTI()
+		{
+			addPlainField("mainSceneUUID", 0, &GameSettingsRTTI::getMainSceneUUID, &GameSettingsRTTI::setMainSceneUUID);
+			addPlainField("fullscreen", 1, &GameSettingsRTTI::getFullscreen, &GameSettingsRTTI::setFullscreen);
+			addPlainField("useDesktopResolution", 2, &GameSettingsRTTI::getUseDesktopResolution, &GameSettingsRTTI::setUseDesktopResolution);
+			addPlainField("resolutionWidth", 3, &GameSettingsRTTI::getResolutionWidth, &GameSettingsRTTI::setResolutionWidth);
+			addPlainField("resolutionHeight", 4, &GameSettingsRTTI::getResolutionHeight, &GameSettingsRTTI::setResolutionHeight);
+			addPlainField("titleBarText", 5, &GameSettingsRTTI::getTitlebarText, &GameSettingsRTTI::setTitlebarText);
+		}
+
+		virtual const String& getRTTIName() override
+		{
+			static String name = "GameSettings";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId() override
+		{
+			return TID_GameSettings;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject() override
+		{
+			return bs_shared_ptr_new<GameSettings>();
+		}
+	};
+}

+ 4 - 1
BansheeEngine/Include/BsPrerequisites.h

@@ -135,6 +135,8 @@ namespace BansheeEngine
 	static const Path ASSEMBLY_PATH = "..\\..\\Assemblies\\";
 	static const Path GAME_RESOURCES_PATH = "..\\..\\..\\Resources\\";
 	static const Path RUNTIME_DATA_PATH = L"..\\..\\..\\Data\\";
+	static const char* GAME_SETTINGS_NAME = "GameSettings.asset";
+	static const char* GAME_RESOURCE_MANIFEST_NAME = "ResourceManifest.asset";
 
 	/**
 	 * @brief	RTTI types.
@@ -153,6 +155,7 @@ namespace BansheeEngine
 		TID_GUISkin = 30009,
 		TID_GUISkinEntry = 30010,
 		TID_Light = 30011,
-		TID_CLight = 30012
+		TID_CLight = 30012,
+		TID_GameSettings = 30013
 	};
 }

+ 4 - 4
BansheeEngine/Source/BsBuiltinResources.cpp

@@ -288,11 +288,11 @@ namespace BansheeEngine
 		/* 								ICON		                     		*/
 		/************************************************************************/
 
-		Path cursorPath = FileSystem::getWorkingDirectoryPath();
-		cursorPath.append(EngineIconFolder);
-		cursorPath.append(IconTex + L".asset");
+		Path iconPath = FileSystem::getWorkingDirectoryPath();
+		iconPath.append(EngineIconFolder);
+		iconPath.append(IconTex + L".asset");
 
-		HTexture iconTex = gResources().load<Texture>(cursorPath);
+		HTexture iconTex = gResources().load<Texture>(iconPath);
 
 		mBansheeIcon = iconTex->getProperties().allocateSubresourceBuffer(0);
 		iconTex->readSubresource(gCoreAccessor(), 0, mBansheeIcon);

+ 16 - 0
BansheeEngine/Source/BsGameSettings.cpp

@@ -0,0 +1,16 @@
+#include "BsGameSettings.h"
+#include "BsGameSettingsRTTI.h"
+
+namespace BansheeEngine
+{
+	RTTITypeBase* GameSettings::getRTTIStatic()
+	{
+		return GameSettingsRTTI::instance();
+	}
+
+	RTTITypeBase* GameSettings::getRTTI() const
+	{
+		return GameSettings::getRTTIStatic();
+	}
+
+}

+ 96 - 26
Game/Source/Main.cpp

@@ -1,12 +1,105 @@
 #include "BsApplication.h"
 #include "BsCrashHandler.h"
 #include "BsCoreThread.h"
+#include "BsFileSerializer.h"
+#include "BsGameSettings.h"
+#include "BsFileSystem.h"
+#include "BsResources.h"
+#include "BsResourceManifest.h"
+#include "BsPrefab.h"
+#include "BsSceneObject.h"
+#include "BsSceneManager.h"
+
+using namespace BansheeEngine;
+
+void runApplication()
+{
+	Path gameSettingsPath = RUNTIME_DATA_PATH + GAME_SETTINGS_NAME;
+	FileDecoder fd(gameSettingsPath);
+	SPtr<GameSettings> gameSettings = std::static_pointer_cast<GameSettings>(fd.decode());
+
+	if (gameSettings == nullptr)
+		gameSettings = bs_shared_ptr_new<GameSettings>();
+
+	unsigned int resolutionWidth = 200;
+	unsigned int resolutionHeight = 200;
+
+	if (!gameSettings->fullscreen)
+	{
+		resolutionWidth = gameSettings->resolutionWidth;
+		resolutionHeight = gameSettings->resolutionHeight;
+	}
+
+	RENDER_WINDOW_DESC renderWindowDesc;
+	renderWindowDesc.videoMode = VideoMode(resolutionWidth, resolutionHeight);
+	renderWindowDesc.title = toString(gameSettings->titleBarText);
+	renderWindowDesc.fullscreen = false;
+	renderWindowDesc.hideUntilSwap = true;
+
+	Application::startUp(renderWindowDesc, RenderAPIPlugin::DX11);
+
+	if (gameSettings->fullscreen)
+	{
+		if (gameSettings->useDesktopResolution)
+		{
+			const VideoModeInfo& videoModeInfo = RenderAPI::getVideoModeInfo();
+			const VideoOutputInfo& primaryMonitorInfo = videoModeInfo.getOutputInfo(0);
+			const VideoMode& selectedVideoMode = primaryMonitorInfo.getDesktopVideoMode();
+
+			RenderWindowPtr window = gApplication().getPrimaryWindow();
+			window->setFullscreen(gCoreAccessor(), selectedVideoMode);
+
+			resolutionWidth = selectedVideoMode.getWidth();
+			resolutionHeight = selectedVideoMode.getHeight();
+		}
+		else
+		{
+			VideoMode videoMode(resolutionWidth, resolutionHeight);
+
+			RenderWindowPtr window = gApplication().getPrimaryWindow();
+			window->setFullscreen(gCoreAccessor(), videoMode);
+		}
+	}
+
+	gameSettings->useDesktopResolution = false; // Not relevant after first startup
+
+	// TODO - Save full video mode
+	gameSettings->resolutionWidth = resolutionWidth;
+	gameSettings->resolutionHeight = resolutionHeight;
+
+	FileEncoder fe(gameSettingsPath);
+	fe.encode(gameSettings.get());
+
+	Path resourceManifestPath = GAME_RESOURCES_PATH + GAME_RESOURCE_MANIFEST_NAME;
+
+	ResourceManifestPtr manifest;
+	if (FileSystem::exists(resourceManifestPath))
+	{
+		Path resourcesPath = FileSystem::getWorkingDirectoryPath();
+		resourcesPath.append(GAME_RESOURCES_PATH);
+
+		manifest = ResourceManifest::load(resourceManifestPath, resourcesPath);
+
+		gResources().registerResourceManifest(manifest);
+	}
+
+	HPrefab mainScene = static_resource_cast<Prefab>(gResources().loadFromUUID(gameSettings->mainSceneUUID));
+	if (mainScene != nullptr)
+	{
+		HSceneObject root = mainScene->instantiate();
+		HSceneObject oldRoot = gSceneManager().getRootNode();
+
+		gSceneManager()._setRootNode(root);
+		oldRoot->destroy();
+	}
+
+	Application::instance().runMainLoop();
+	Application::shutDown();
+}
 
 #if BS_PLATFORM == BS_PLATFORM_WIN32
 #include <windows.h>
 
-using namespace BansheeEngine;
-
 int CALLBACK WinMain(
 	_In_  HINSTANCE hInstance,
 	_In_  HINSTANCE hPrevInstance,
@@ -18,30 +111,7 @@ int CALLBACK WinMain(
 
 	__try
 	{
-		RENDER_WINDOW_DESC renderWindowDesc;
-		renderWindowDesc.videoMode = VideoMode(200, 200); // TODO - Get desktop resolution
-		renderWindowDesc.title = "Banshee Game"; // TODO - Get this from game settings
-		renderWindowDesc.fullscreen = false; // TODO - Get this from game settings
-		renderWindowDesc.hideUntilSwap = true;
-
-		RenderAPIPlugin renderAPI = RenderAPIPlugin::DX11; // TODO - Get this from game settings
-
-		Application::startUp(renderWindowDesc, renderAPI);
-
-		// TODO - Apply icon
-
-		// TODO - If on first run start in fullscreen (perhaps Build settings controlled) at desktop resolution
-		const VideoModeInfo& videoModeInfo = RenderAPI::getVideoModeInfo();
-		const VideoOutputInfo& primaryMonitorInfo = videoModeInfo.getOutputInfo(0);
-		const VideoMode& selectedVideoMode = primaryMonitorInfo.getDesktopVideoMode();
-
-		RenderWindowPtr window = gApplication().getPrimaryWindow();
-		window->setFullscreen(gCoreAccessor(), selectedVideoMode);
-
-		// TODO - Load main scene
-
-		Application::instance().runMainLoop();
-		Application::shutDown();
+		runApplication();
 	}
 	__except (gCrashHandler().reportCrash(GetExceptionInformation()))
 	{

+ 1 - 0
TODO.txt

@@ -31,6 +31,7 @@ Optional:
  - Drag and dropping a prefab onto the scene (or hierarchy) should work the same as with meshes
  - Add tooltips to toolbar items and other buttons with icons
  - Either disable light tool icons before release or make them functional (With gizmos)
+ - Test VS 2015 Community as code editor (possibly also move the code to VS 2015)
 
  More optional:
  - When starting drag from hierarchy tree view it tends to select another object (can't repro)