Преглед на файлове

Making C++ framework startup simpler

BearishSun преди 9 години
родител
ревизия
9ac01d6431

+ 5 - 2
Source/BansheeCore/Include/BsCoreApplication.h

@@ -26,6 +26,9 @@ namespace BansheeEngine
 		RENDER_WINDOW_DESC primaryWindowDesc; /**< Describes the window to create during start-up. */
 		RENDER_WINDOW_DESC primaryWindowDesc; /**< Describes the window to create during start-up. */
 
 
 		Vector<String> importers; /**< A list of importer plugins to load. */
 		Vector<String> importers; /**< A list of importer plugins to load. */
+
+		/** Optional callback function to be called every frame while the application is running. */
+		std::function<void()> updateCallback; 
 	};
 	};
 
 
 	/**
 	/**
@@ -88,7 +91,7 @@ namespace BansheeEngine
 
 
 	protected:
 	protected:
 		/** @copydoc Module::onStartUp */
 		/** @copydoc Module::onStartUp */
-		virtual void onStartUp() override;
+		void onStartUp() override;
 
 
 		/**	Called for each iteration of the main loop. Called before any game objects or plugins are updated. */
 		/**	Called for each iteration of the main loop. Called before any game objects or plugins are updated. */
 		virtual void preUpdate();
 		virtual void preUpdate();
@@ -112,7 +115,7 @@ namespace BansheeEngine
 		/**	Called by the core thread to end profiling. */
 		/**	Called by the core thread to end profiling. */
 		void endCoreProfiling();
 		void endCoreProfiling();
 
 
-	private:
+	protected:
 		typedef void(*UpdatePluginFunc)();
 		typedef void(*UpdatePluginFunc)();
 
 
 		SPtr<RenderWindow> mPrimaryWindow;
 		SPtr<RenderWindow> mPrimaryWindow;

+ 3 - 0
Source/BansheeCore/Source/BsCoreApplication.cpp

@@ -221,6 +221,9 @@ namespace BansheeEngine
 
 
 			preUpdate();
 			preUpdate();
 
 
+			if (mStartUpDesc.updateCallback != nullptr)
+				mStartUpDesc.updateCallback();
+
 			PROFILE_CALL(gCoreSceneManager()._update(), "SceneManager");
 			PROFILE_CALL(gCoreSceneManager()._update(), "SceneManager");
 			gAudio()._update();
 			gAudio()._update();
 			gPhysics().update();
 			gPhysics().update();

+ 2 - 0
Source/BansheeEngine/Include/BsApplication.h

@@ -18,6 +18,8 @@ namespace BansheeEngine
 	{
 	{
 	public:
 	public:
 		Application(const START_UP_DESC& desc);
 		Application(const START_UP_DESC& desc);
+		Application(VideoMode videoMode, const String& title, bool fullscreen, 
+			std::function<void()> updateCallback = nullptr);
 		virtual ~Application();
 		virtual ~Application();
 
 
 		/** Starts the Banshee engine. */
 		/** Starts the Banshee engine. */

+ 22 - 0
Source/BansheeEngine/Source/BsApplication.cpp

@@ -29,6 +29,28 @@ namespace BansheeEngine
 
 
 	}
 	}
 
 
+	Application::Application(VideoMode videoMode, const String& title, bool fullscreen, std::function<void()> updateCallback)
+		: CoreApplication(START_UP_DESC()), mMonoPlugin(nullptr), mSBansheeEnginePlugin(nullptr)
+	{
+		// Set up default plugins
+		mStartUpDesc.renderAPI = BS_RENDER_API_MODULE;
+		mStartUpDesc.renderer = BS_RENDERER_MODULE;
+		mStartUpDesc.audio = BS_AUDIO_MODULE;
+		mStartUpDesc.physics = BS_PHYSICS_MODULE;
+		mStartUpDesc.input = BS_INPUT_MODULE;
+
+		mStartUpDesc.importers.push_back("BansheeFreeImgImporter");
+		mStartUpDesc.importers.push_back("BansheeFBXImporter");
+		mStartUpDesc.importers.push_back("BansheeFontImporter");
+		mStartUpDesc.importers.push_back("BansheeSL");
+
+		mStartUpDesc.primaryWindowDesc.videoMode = videoMode;
+		mStartUpDesc.primaryWindowDesc.fullscreen = fullscreen;
+		mStartUpDesc.primaryWindowDesc.title = title;
+
+		mStartUpDesc.updateCallback = updateCallback;
+	}
+
 	Application::~Application()
 	Application::~Application()
 	{
 	{
 		// Cleanup any new objects queued for destruction by unloaded scripts
 		// Cleanup any new objects queued for destruction by unloaded scripts