mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Updated the new module changes to use more compile/link-time checking rather than runtime checking.
This commit is contained in:
+9
-17
@@ -60,11 +60,6 @@ namespace love
|
||||
|
||||
Module *Module::instances[] = {};
|
||||
|
||||
Module::Module()
|
||||
: moduleType(M_INVALID)
|
||||
{
|
||||
}
|
||||
|
||||
Module::~Module()
|
||||
{
|
||||
ModuleRegistry ®istry = registryInstance();
|
||||
@@ -79,15 +74,14 @@ Module::~Module()
|
||||
}
|
||||
}
|
||||
|
||||
// Same deal with Module::getModuleType().
|
||||
for (int i = 0; i < (int) M_MAX_ENUM; i++)
|
||||
{
|
||||
if (instances[i] == this)
|
||||
instances[i] = nullptr;
|
||||
}
|
||||
|
||||
freeEmptyRegistry();
|
||||
|
||||
if (instances[moduleType] == this)
|
||||
instances[moduleType] = nullptr;
|
||||
}
|
||||
|
||||
Module::ModuleType Module::getModuleType() const
|
||||
{
|
||||
return moduleType;
|
||||
}
|
||||
|
||||
void Module::registerInstance(Module *instance)
|
||||
@@ -108,12 +102,10 @@ void Module::registerInstance(Module *instance)
|
||||
throw Exception("Module %s already registered!", instance->getName());
|
||||
}
|
||||
|
||||
ModuleType moduletype = instance->getModuleType();
|
||||
if (moduletype == M_INVALID)
|
||||
throw love::Exception("Module %s has an invalid base module type.", instance->getName());
|
||||
|
||||
registry.insert(make_pair(name, instance));
|
||||
|
||||
ModuleType moduletype = instance->getModuleType();
|
||||
|
||||
if (instances[moduletype] != nullptr)
|
||||
{
|
||||
printf("Warning: overwriting module instance %s with new instance %s\n",
|
||||
|
||||
+4
-7
@@ -36,7 +36,6 @@ public:
|
||||
|
||||
enum ModuleType
|
||||
{
|
||||
M_INVALID = 0,
|
||||
M_AUDIO,
|
||||
M_EVENT,
|
||||
M_FILESYSTEM,
|
||||
@@ -56,10 +55,12 @@ public:
|
||||
M_MAX_ENUM
|
||||
};
|
||||
|
||||
Module();
|
||||
virtual ~Module();
|
||||
|
||||
ModuleType getModuleType() const;
|
||||
/**
|
||||
* Gets the base type of the module.
|
||||
**/
|
||||
virtual ModuleType getModuleType() const = 0;
|
||||
|
||||
/**
|
||||
* Gets the name of the module. This is used in case of errors
|
||||
@@ -95,10 +96,6 @@ public:
|
||||
return (T *) instances[type];
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
ModuleType moduleType;
|
||||
|
||||
private:
|
||||
|
||||
static Module *instances[M_MAX_ENUM];
|
||||
|
||||
Reference in New Issue
Block a user