Prechádzať zdrojové kódy

Merge pull request #68 from Tassim/patch-1

Rename Module::isShutDown to Module::isStartedUp
Marko Pintera 8 rokov pred
rodič
commit
0da8e5772e
1 zmenil súbory, kde vykonal 17 pridanie a 11 odobranie
  1. 17 11
      Source/BansheeUtility/Include/BsModule.h

+ 17 - 11
Source/BansheeUtility/Include/BsModule.h

@@ -25,7 +25,7 @@ namespace bs
 		 */
 		 */
 		static T& instance()
 		static T& instance()
 		{
 		{
-			if(isShutDown())
+			if (!isStartedUp())
 			{
 			{
 				BS_EXCEPT(InternalErrorException, 
 				BS_EXCEPT(InternalErrorException, 
 					"Trying to access a module but it hasn't been started up yet.");
 					"Trying to access a module but it hasn't been started up yet.");
@@ -46,7 +46,7 @@ namespace bs
 		 */
 		 */
 		static T* instancePtr()
 		static T* instancePtr()
 		{
 		{
-			if (isShutDown())
+			if (!isStartedUp())
 			{
 			{
 				BS_EXCEPT(InternalErrorException, 
 				BS_EXCEPT(InternalErrorException, 
 					"Trying to access a module but it hasn't been started up yet.");
 					"Trying to access a module but it hasn't been started up yet.");
@@ -65,11 +65,11 @@ namespace bs
 		template<class ...Args>
 		template<class ...Args>
 		static void startUp(Args &&...args)
 		static void startUp(Args &&...args)
 		{
 		{
-			if (!isShutDown())
+			if (isStartedUp())
 				BS_EXCEPT(InternalErrorException, "Trying to start an already started module.");
 				BS_EXCEPT(InternalErrorException, "Trying to start an already started module.");
 
 
 			_instance() = bs_new<T>(std::forward<Args>(args)...);
 			_instance() = bs_new<T>(std::forward<Args>(args)...);
-			isShutDown() = false;
+			isStartedUp() = true;
 
 
 			((Module*)_instance())->onStartUp();
 			((Module*)_instance())->onStartUp();
 		}
 		}
@@ -83,11 +83,11 @@ namespace bs
 		{
 		{
 			static_assert(std::is_base_of<T, SubType>::value, "Provided type is not derived from type the Module is initialized with.");
 			static_assert(std::is_base_of<T, SubType>::value, "Provided type is not derived from type the Module is initialized with.");
 
 
-			if (!isShutDown())
+			if (isStartedUp())
 				BS_EXCEPT(InternalErrorException, "Trying to start an already started module.");
 				BS_EXCEPT(InternalErrorException, "Trying to start an already started module.");
 
 
 			_instance() = bs_new<SubType>(std::forward<Args>(args)...);
 			_instance() = bs_new<SubType>(std::forward<Args>(args)...);
-			isShutDown() = false;
+			isStartedUp() = true;
 
 
 			((Module*)_instance())->onStartUp();
 			((Module*)_instance())->onStartUp();
 		}
 		}
@@ -95,11 +95,17 @@ namespace bs
 		/** Shuts down this module and frees any resources it is using. */
 		/** Shuts down this module and frees any resources it is using. */
 		static void shutDown()
 		static void shutDown()
 		{
 		{
-			if (isShutDown() || isDestroyed())
+			if (isDestroyed())
 			{
 			{
 				BS_EXCEPT(InternalErrorException, 
 				BS_EXCEPT(InternalErrorException, 
 					"Trying to shut down an already shut down module.");
 					"Trying to shut down an already shut down module.");
 			}
 			}
+			
+			if (!isStartedUp()) 
+			{
+				BS_EXCEPT(InternalErrorException, 
+					"Trying to shut down a module which was never started.");
+			}
 
 
 			((Module*)_instance())->onShutDown();
 			((Module*)_instance())->onShutDown();
 
 
@@ -110,7 +116,7 @@ namespace bs
 		/** Query if the module has been started. */
 		/** Query if the module has been started. */
 		static bool isStarted()
 		static bool isStarted()
 		{
 		{
-			return !isShutDown() && !isDestroyed();
+			return isStartedUp() && !isDestroyed();
 		}
 		}
 
 
 	protected:
 	protected:
@@ -162,12 +168,12 @@ namespace bs
 		}
 		}
 
 
 		/** Checks has the Module been started up. */
 		/** Checks has the Module been started up. */
-		static bool& isShutDown()
+		static bool& isStartedUp()
 		{
 		{
-			static bool inst = true;
+			static bool inst = false;
 			return inst;
 			return inst;
 		}
 		}
 	};
 	};
 
 
 	/** @} */
 	/** @} */
-}
+}