Ejemplo n.º 1
0
MPlugin* MEngine::loadPlugin(const char* name)
{
    M_PROFILE_SCOPE(MEngine::loadPlugin);
    MPlugin* plugin = new MPlugin;
    plugin->load(name);
    if(plugin->isLoaded())
    {
	m_Plugins.push_back(plugin);
	return plugin;
    }
    delete plugin;
    return 0;
}
Ejemplo n.º 2
0
void MaratisPlayer::loadGamePlugin(void)
{
	char gameFile[256];
	MWindow * window = MWindow::getInstance();

	#ifdef WIN32
		getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.dll");
	#elif __APPLE__
		getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.dylib");
	#elif linux
		getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.so");
	#endif

	// try to load any other plugins in the game directory first
	// as the game may expect these to be loaded
	vector<string> files;
	readDirectory(window->getWorkingDirectory(), &files);
	for(vector<string>::iterator iFile = files.begin();
		iFile != files.end();
		iFile++)
	{
		if(*iFile == gameFile)
			continue;

		#ifdef WIN32
			if(iFile->find(".dll") != string::npos)
		#elif __APPLE__
			if(iFile->find(".dylib") != string::npos)
		#elif linux
			if(iFile->find(".so") != string::npos)
		#endif
			{
				char pluginPath[256];

				getGlobalFilename(pluginPath, window->getWorkingDirectory(), iFile->c_str());
				MPlugin* plugin = new MPlugin();
				plugin->load(pluginPath);
				if(plugin->getFilename())
					m_plugins.push_back(plugin);
				else
					SAFE_DELETE(plugin);
			}
	}

	// After all other plugins are loaded, we can load the game
	// as we assume all prerequisites are loaded
	SAFE_DELETE(m_gamePlugin);
	m_gamePlugin = new MPlugin();
	m_gamePlugin->load(gameFile);
}
Ejemplo n.º 3
0
mBOOL MPluginList::refresh(PLUG_LOADTIME now) {
	int i, ndone=0, nkept=0, nloaded=0, nunloaded=0, nreloaded=0, ndelayed=0;
	MPlugin *iplug;

	if (!ini_refresh()) {
		META_ERROR("dll: Problem reloading plugins.ini: %s", inifile);
		// meta_errno should be already set in ini_refresh()
		return(mFALSE);
	}

	META_LOG("dll: Updating plugins...");
	for(i=0; i < endlist; i++) {
		iplug=&plist[i];
		if(iplug->status < PL_VALID)
			continue;
		switch(iplug->action) {
			case PA_KEEP:
				META_DEBUG(1, ("Keeping plugin '%s'", iplug->desc));
				iplug->action=PA_NONE;
				nkept++;
				break;
			case PA_LOAD:
				META_DEBUG(1, ("Loading plugin '%s'", iplug->desc));
				if(iplug->load(now))
					nloaded++;
				else if(meta_errno==ME_DELAYED)
					ndelayed++;
				break;
			case PA_RELOAD:
				META_DEBUG(1, ("Reloading plugin '%s'", iplug->desc));
				if(iplug->reload(now, PNL_FILE_NEWER))
					nreloaded++;
				else if(meta_errno==ME_DELAYED)
					ndelayed++;
				break;
			case PA_NONE:
				// If previously loaded from ini, but apparently removed from new ini.
				if(iplug->source==PS_INI && iplug->status >= PL_RUNNING) {
					META_DEBUG(1, ("Unloading plugin '%s'", iplug->desc));
					iplug->action=PA_UNLOAD;
					if(iplug->unload(now, PNL_INI_DELETED, PNL_INI_DELETED))
						nunloaded++;
					else if(meta_errno==ME_DELAYED)
						ndelayed++;
				}
				break;
			case PA_ATTACH:
				// Previously requested attach, but was delayed?
				META_DEBUG(1, ("Retrying attach plugin '%s'", iplug->desc));
				if(iplug->retry(now, PNL_DELAYED))
					nloaded++;
				else if(meta_errno==ME_DELAYED)
					ndelayed++;
				break;
			case PA_UNLOAD:
				// Previously requested unload, but was delayed?
				META_DEBUG(1, ("Retrying unload plugin '%s'", iplug->desc));
				if(iplug->retry(now, PNL_DELAYED))
					nunloaded++;
				else if(meta_errno==ME_DELAYED)
					ndelayed++;
				break;
			case PA_NULL:
				META_ERROR("dll: Unexpected action for plugin '%s': '%s'", iplug->desc, iplug->str_action());
				break;
			default:
				META_ERROR("dll: Unrecognized action for plugin '%s': '%s'", iplug->desc, iplug->str_action());
				break;
		}
		ndone++;
	}
	META_LOG("dll: Finished updating %d plugins; kept %d, loaded %d, unloaded %d, reloaded %d, delayed %d", 
			ndone, nkept, nloaded, nunloaded, nreloaded, ndelayed);
	return(mTRUE);
}