Jump to content

Custom plugin loading


photo

Recommended Posts

Hi there

 

I'm thinking about loading i.e. the AppWall plugin from our code base. Is there something provided by Unigine without involving the scripting. I'd like to get an instance of the AppWall in C++.

 

Best regards,

Renato

Link to comment

Hi Renato,

 

You can use Reflection class to do that:

Interpreter interpreter = (Interpreter*)Engine::get()->getSystemInterpreter();

Reflection PLUGIN_reflection(interpreter, Variable("engine.wall")); //make sure that you have AppWall loaded here
Variable res = PLUGIN_reflection.callExternFunction("getWidth");
Log::message("engine.wall.getWidth(): %d\n", res.getInt());

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Hi Andrey

 

This approach is working. Do you know the performance impact due to the casting and calling back and forth? Calling exported functions seems to be a bit of a workaround. You don't plan to offer the interface of to the factory functions of the plugins?

 

Best regards,

Renato

Link to comment

Hi Renato,

 

You can check how Interface plugin is done (it has InterfaceBase.h header with all methods). We plan to add such interfaces for all plugins (probably, in 2.4). At the meantime, I guess, you can do it manually or continue to use Reflection.

 

Performance of the Reflection class is high enough for the production use, don't worry :)

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Thanks Andrey

 

I made some few test with custom loading of the AppWall Plugin. But even if I'm loading the dll before I initialize engine, I get an error that an instance of the "App" is already created. Does Unigine imports dll's and calls CreatePlugin for all dll lying in the executable folder?

/** TRY WITH LOADLIBRARY CALL */
HINSTANCE dllHandle = NULL;
AppWallPluginType AppWallPluginPtr = NULL;

dllHandle = LoadLibrary("AppWall_x64.dll");

if (dllHandle)
{
	AppWallPluginPtr = (AppWallPluginType)(GetProcAddress(dllHandle, "CreatePlugin"));

	if (AppWallPluginPtr)
	{
		Unigine::Plugin* appWall = (Unigine::Plugin*)AppWallPluginPtr();
		Unigine::Log::message("working so far...\n");
	}
}

Unigine::EnginePtr engine(UNIGINE_VERSION,  myArgc, myArgv);

engine->main(&system_logic, &world_logic, NULL);

/** RESULTS IN A ERROR MESSAGE:
 *
 *  AppWallPlugin::AppWallPlugin(): App is no NULL
 *
 */

Due to the message, I assume the engine is creating an instance of the underlying AppWindow class inside the AppWallPlugin.

 

Another remark: Even if I can load the dll successfull, shouldn't I be able to pass an instances of the App to the engine call?

	Unigine::EnginePtr engine(UNIGINE_VERSION, &myApp, myArgc, myArgv);

Best regards,

Renato

Link to comment

Hmmm...

 

I have removed all of these configurations. 

 

Since the AppWall is realizing the Unigine::App interface, I suppose that the engine is also creating such an instance without the AppWall plugin loaded, right?

Link to comment

Hi Renato,

 

Is there any specific reasons why you are not using the addPlugin() method from the Engine Class to load plugin? All the manipulations with plugins should be done only after engine is initialized. This article also might be useful in your case: https://developer.unigine.com/en/docs/2.3/code/cpp/plugin

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Hi Andrey

 

I'd like to rebuild an plugin working as the AppWall plugin. For that I'm analyzing the AppWall plugin for more insight know-how. But all I get is always the already initialized App singleton.

 

Thanks, Renato

Link to comment

Hi Renato,

 

Only single App* plugin can be loaded into the engine instance. This means that if you already have some App* plugin loaded (for example, AppProjection) you can't load any other  App* plugin because they are both have custom App logic.

 

Probably that's why you are having such issues.

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

"Is there any specific reasons why you are not using the addPlugin() method from the Engine Class to load plugin?"

 

Hi Silent as i ve said in another post i am using the above functions to load my custom plugins and i would like to use the same to load AppProjection, but i need to define the parameters for instance -width 3 and i am not sure how to do it....trying to do that in the launcher.bat is not actually working... prob there is something i am not doing right there, but in any case using the addPlugin() method seems the way to go.... 

Link to comment
×
×
  • Create New...