Browse Source

Add internal module type enum value for use with out-of-tree third party modules.

https://bitbucket.org/rude/love/pull-requests/79/add-pluggable-modules-to-the-build-system/
Alex Szpakowski 5 years ago
parent
commit
9ebb6a5c44
2 changed files with 11 additions and 7 deletions
  1. 9 6
      src/common/Module.cpp
  2. 2 1
      src/common/Module.h

+ 9 - 6
src/common/Module.cpp

@@ -113,15 +113,18 @@ void Module::registerInstance(Module *instance)
 
 
 	registry.insert(make_pair(name, instance));
 	registry.insert(make_pair(name, instance));
 
 
-	ModuleType moduletype = instance->getModuleType();
+	ModuleType mtype = instance->getModuleType();
 
 
-	if (instances[moduletype] != nullptr)
+	if (mtype != M_UNKNOWN)
 	{
 	{
-		printf("Warning: overwriting module instance %s with new instance %s\n",
-			   instances[moduletype]->getName(), instance->getName());
-	}
+		if (instances[mtype] != nullptr)
+		{
+			printf("Warning: overwriting module instance %s with new instance %s\n",
+				   instances[mtype]->getName(), instance->getName());
+		}
 
 
-	instances[moduletype] = instance;
+		instances[mtype] = instance;
+	}
 }
 }
 
 
 Module *Module::getInstance(const std::string &name)
 Module *Module::getInstance(const std::string &name)

+ 2 - 1
src/common/Module.h

@@ -38,6 +38,7 @@ public:
 
 
 	enum ModuleType
 	enum ModuleType
 	{
 	{
+		M_UNKNOWN = -1, // Use this for modules outside of LOVE's source code.
 		M_AUDIO,
 		M_AUDIO,
 		M_DATA,
 		M_DATA,
 		M_EVENT,
 		M_EVENT,
@@ -99,7 +100,7 @@ public:
 	template <typename T>
 	template <typename T>
 	static T *getInstance(ModuleType type)
 	static T *getInstance(ModuleType type)
 	{
 	{
-		return (T *) instances[type];
+		return type != M_UNKNOWN ? (T *) instances[type] : nullptr;
 	}
 	}
 
 
 private:
 private: