소스 검색

Splash screen functional

BearishSun 10 년 전
부모
커밋
9993f27e60

+ 9 - 0
BansheeCore/Include/BsImporter.h

@@ -65,6 +65,15 @@ namespace BansheeEngine
 		 */
 		ImportOptionsPtr createImportOptions(const Path& inputFilePath);
 
+		/**
+		 * @copydoc createImportOptions
+		 */
+		template<class T>
+		SPtr<T> createImportOptions(const Path& inputFilePath)
+		{
+			return std::static_pointer_cast<T>(createImportOptions(inputFilePath));
+		}
+
 		/**
 		 * @brief	Checks if we can import a file with the specified extension.
 		 *

+ 5 - 1
BansheeEditor/Source/BsEditorApplication.cpp

@@ -26,6 +26,7 @@
 #include "BsVirtualInput.h"
 #include "BsResources.h"
 #include "BsCoreSceneManager.h"
+#include "BsSplashScreen.h"
 
 // DEBUG ONLY
 #include "BsShader.h"
@@ -64,6 +65,7 @@ namespace BansheeEngine
 
 	void EditorApplication::onStartUp()
 	{
+		SplashScreen::show();
 		Application::onStartUp();
 
 		loadEditorSettings();
@@ -160,7 +162,9 @@ namespace BansheeEngine
 		Application::postUpdate();
 
 		gProjectLibrary().update();
-		EditorWindowManager::instance().update();	
+		EditorWindowManager::instance().update();
+
+		SplashScreen::hide();
 	}
 
 	Path EditorApplication::getEditorAssemblyPath() const

+ 0 - 27
BansheeEditorExec/BsEditorExec.cpp

@@ -8,7 +8,6 @@
 
 #if BS_PLATFORM == BS_PLATFORM_WIN32
 #include <windows.h>
-#include "Win32/BsWin32Window.h"
 
 using namespace BansheeEngine;
 
@@ -58,32 +57,6 @@ void ShutdownDebugConsole()
 }
 #endif // End BS_DEBUG_MODE
 
-void ShowSplashScreen()
-{
-	//WINDOW_DESC windowDesc;
-	//windowDesc.border = WindowBorder::None;
-	//windowDesc.width = 600;
-	//windowDesc.height = 662;
-	//windowDesc.left = -1;
-	//windowDesc.top = -1;
-	//windowDesc.title = "Banshee Splash";
-	//windowDesc.toolWindow = true;
-	//windowDesc.alphaBlending = true;
-
-	//Path splashTexturePath = "..\\..\\..\\Data\\Raw\\Engine\\BansheeLogo.png";
-
-	//auto textureIO = std::static_pointer_cast<TextureImportOptions>(gImporter().createImportOptions(splashTexturePath));
-	//textureIO->setCPUReadable(true);
-	//HTexture splashTexture = gImporter().import<Texture>(splashTexturePath, textureIO);
-
-	//PixelDataPtr splashPixelData = splashTexture->getProperties().allocateSubresourceBuffer(0);
-	//splashTexture->readData(*splashPixelData);
-
-	//windowDesc.background = splashPixelData;
-
-	//bs_new<Win32Window>(windowDesc);
-}
-
 int CALLBACK WinMain(
 	_In_  HINSTANCE hInstance,
 	_In_  HINSTANCE hPrevInstance,

+ 2 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -278,6 +278,7 @@
     <ClCompile Include="Source\BsScriptCodeImportOptions.cpp" />
     <ClCompile Include="Source\BsShortcutKey.cpp" />
     <ClCompile Include="Source\BsShortcutManager.cpp" />
+    <ClCompile Include="Source\BsSplashScreen.cpp" />
     <ClCompile Include="Source\BsVirtualInput.cpp" />
     <ClCompile Include="Source\BsLight.cpp" />
     <ClInclude Include="Include\BsApplication.h" />
@@ -374,6 +375,7 @@
     <ClInclude Include="Include\BsScriptManager.h" />
     <ClInclude Include="Include\BsShortcutKey.h" />
     <ClInclude Include="Include\BsShortcutManager.h" />
+    <ClInclude Include="Include\BsSplashScreen.h" />
     <ClInclude Include="Include\BsSpriteTextureRTTI.h" />
     <ClInclude Include="Include\BsSprite.h" />
     <ClInclude Include="Include\BsSpriteTexture.h" />

+ 6 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -353,6 +353,9 @@
     <ClInclude Include="Include\BsRendererMaterialManager.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsSplashScreen.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">
@@ -604,5 +607,8 @@
     <ClCompile Include="Source\BsRendererMaterial.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsSplashScreen.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 6 - 0
BansheeEngine/Include/BsBuiltinResources.h

@@ -128,6 +128,11 @@ namespace BansheeEngine
 		 */
 		static HShader getShader(const Path& path);
 
+		/**
+		 * @brief	Returns image data the Banshee Engine splash screen.
+		 */
+		static PixelDataPtr getSplashScreen();
+
 		static const Path BuiltinDataFolder;
 		static const Path EngineSkinFolder;
 		static const Path EngineCursorFolder;
@@ -209,6 +214,7 @@ namespace BansheeEngine
 
 		static const WString GUISkinFile;
 		static const WString WhiteTex;
+		static const wchar_t* SplashScreenName;
 
 		static const WString ButtonNormalTex;
 		static const WString ButtonHoverTex;

+ 29 - 0
BansheeEngine/Include/BsSplashScreen.h

@@ -0,0 +1,29 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+
+namespace BansheeEngine
+{
+	/**
+	 * @brief	Displays a splash screen with Banshee Engine logo.
+	 */
+	class BS_EXPORT SplashScreen
+	{
+	public:
+		/**
+		 * @brief	Displays a splash screen with Banshee Engine logo.
+		 */
+		static void show();
+
+		/**
+		 * @brief	Hides the splash screen.
+		 */
+		static void hide();
+
+	private:
+		struct Pimpl;
+		static Pimpl* m;
+
+		static const UINT32 SPLASH_SCREEN_DURATION_MS;
+	};
+}

+ 27 - 0
BansheeEngine/Source/BsBuiltinResources.cpp

@@ -32,6 +32,8 @@
 #include "BsVertexDataDesc.h"
 #include "BsShapeMeshes3D.h"
 #include "BsMesh.h"
+#include "BsFileSerializer.h"
+#include "BsTextureImportOptions.h"
 
 namespace BansheeEngine
 {
@@ -69,6 +71,7 @@ namespace BansheeEngine
 	/************************************************************************/
 
 	const WString BuiltinResources::WhiteTex = L"White.psd";
+	const wchar_t* BuiltinResources::SplashScreenName = L"SplashScreen.png";
 
 	const WString BuiltinResources::ButtonNormalTex = L"ButtonNormal.png";
 	const WString BuiltinResources::ButtonHoverTex = L"ButtonHover.png";
@@ -287,6 +290,22 @@ namespace BansheeEngine
 		BuiltinResourcesHelper::importFont(BuiltinRawDataFolder + DefaultFontFilename, DefaultFontFilename, BuiltinDataFolder,
 			{ DefaultFontSize }, false, mResourceManifest);
 
+		// Import splash screen
+		{
+			Path inputPath = BuiltinRawDataFolder + WString(SplashScreenName);
+			Path outputPath = BuiltinRawDataFolder + (WString(SplashScreenName) + L".asset");
+
+			auto textureIO = gImporter().createImportOptions<TextureImportOptions>(inputPath);
+			textureIO->setCPUReadable(true);
+			HTexture splashTexture = gImporter().import<Texture>(inputPath, textureIO);
+
+			PixelDataPtr splashPixelData = splashTexture->getProperties().allocateSubresourceBuffer(0);
+			splashTexture->readData(*splashPixelData);
+
+			FileEncoder fe(outputPath);
+			fe.encode(splashPixelData.get());
+		}
+
 		// Generate & save GUI sprite textures
 		BuiltinResourcesHelper::generateSpriteTextures(EngineSkinFolder, mResourceManifest);
 
@@ -874,6 +893,14 @@ namespace BansheeEngine
 		return *mCursorArrowLeftRight.get();
 	}
 
+	PixelDataPtr BuiltinResources::getSplashScreen()
+	{
+		Path splashScreenPath = BuiltinRawDataFolder + (WString(SplashScreenName) + L".asset");
+		FileDecoder fd(splashScreenPath);
+
+		return std::static_pointer_cast<PixelData>(fd.decode());
+	}
+
 	HMesh BuiltinResources::getMesh(BuiltinMesh mesh) const
 	{
 		Path meshPath = FileSystem::getWorkingDirectoryPath();

+ 59 - 0
BansheeEngine/Source/BsSplashScreen.cpp

@@ -0,0 +1,59 @@
+#include "BsSplashScreen.h"
+#include "BsBuiltinResources.h"
+#include "BsTimer.h"
+
+#if BS_PLATFORM == BS_PLATFORM_WIN32
+#include "Win32/BsWin32Window.h"
+
+namespace BansheeEngine
+{
+	struct SplashScreen::Pimpl
+	{
+		Win32Window* window = nullptr;
+		Timer timer;
+	};
+
+	// Note: Never freed, but that's fine
+	SplashScreen::Pimpl* SplashScreen::m = bs_new<Pimpl>();
+	const UINT32 SplashScreen::SPLASH_SCREEN_DURATION_MS = 3000;
+
+	void SplashScreen::show()
+	{
+		if (m->window != nullptr)
+			return;
+
+		WINDOW_DESC windowDesc;
+		windowDesc.border = WindowBorder::None;
+		windowDesc.width = 600;
+		windowDesc.height = 662;
+		windowDesc.left = -1;
+		windowDesc.top = -1;
+		windowDesc.title = "Banshee Splash";
+		windowDesc.toolWindow = true;
+		windowDesc.alphaBlending = true;
+
+		PixelDataPtr splashPixelData = BuiltinResources::getSplashScreen();
+		if (splashPixelData == nullptr)
+			return;
+
+		windowDesc.background = splashPixelData;
+
+		m->window = bs_new<Win32Window>(windowDesc);
+		m->timer.reset();
+	}
+
+	void SplashScreen::hide()
+	{
+		if (m->window == nullptr || m->timer.getMilliseconds() < SPLASH_SCREEN_DURATION_MS)
+			return;
+
+		bs_delete(m->window);
+		m->window = nullptr;
+	}
+}
+
+#else
+
+static_assert("Missing SplashScreen implementation.");
+
+#endif

+ 4 - 0
MBansheeEditor/UnitTests.cs

@@ -218,6 +218,8 @@ namespace BansheeEditor
         /// </summary>
         private static void UnitTest4_Prefabs()
         {
+            return;
+
             if (EditorApplication.IsProjectLoaded)
             {
                 Debug.LogWarning("Skipping unit test as no project is loaded.");
@@ -517,6 +519,8 @@ namespace BansheeEditor
                 Scene.Clear();
 
             ProjectLibrary.Delete("unitTest4Scene_0");
+            ProjectLibrary.Delete("unitTest4Scene_1");
+            ProjectLibrary.Delete("unitTest4Scene_2");
         }
 
         /// <summary>