Пример #1
0
/// Indexes all plugins found in /Plugins
void GameCore::loadPlugins()
{
	typedef PluginSDK::Types(*getPluginTypeFunc)();
	typedef ExtensionScripting*(*createScriptEnvironmentFunc)(GameCore*);
	typedef ExtensionAudio*(*createAudioEnvironmentFunc)(GameCore*);

	StringList dll_list = FileSystem::scanDirectory("Plugins", "dll", false);
	for (auto& dll_name : dll_list)
	{
		// Let's check what the plugin is and load immediately
		PluginLoader* plugin = new PluginLoader(dll_name);
		if (plugin)
		{
			Log("Plugin loaded: %s", dll_name.c_str());

			getPluginTypeFunc funptr = (getPluginTypeFunc)plugin->getFunctionAddress("getPluginType");
			if (funptr)
			{
				PluginSDK::Types pluginType = funptr();

				switch (pluginType)
				{
				case PluginSDK::Scripting:
					{
						 Log("THIS IS A SCRIPTING PLUGIN");
						 createScriptEnvironmentFunc funptr = (createScriptEnvironmentFunc)plugin->getFunctionAddress("createScriptingEnvironment");
						 if (funptr)
						 {
							 ExtensionScripting* scriptingEnvironment = funptr(this);
							 if (scriptingEnvironment)
							 {
								 Log("Got the scripting environment, Registered.");
								 scriptingEnvironments.push_back(scriptingEnvironment);
							 }
						 }
					}
					break;
				case PluginSDK::Audio:
					{
						 Log("THIS IS A AUDIO PLUGIN");
						 createAudioEnvironmentFunc funptr = (createAudioEnvironmentFunc)plugin->getFunctionAddress("createAudioEnvironment");
						 if (funptr)
						 {
							 ExtensionAudio* audioEnvironment = funptr(this);
							 if (audioEnvironment)
							 {
								 Log("Got the audio environment, Registered.");
								 gameAudio.audioEnvironments.push_back(audioEnvironment);
							 }
						 }
					}
					break;


				}
			}
		}
	}
}