Jump to content

call order AppXxxLogic / plugins


photo

Recommended Posts

Dear Unigine team,

Is there any way to control order of AppXxxLogic::init/update/shutdown?

Usually main.cpp starts engine as follow:

#ifdef _WIN32
int wmain(int argc, wchar_t* argv[])
#else
int main(int argc, char* argv[])
#endif
{
	// init engine
	Unigine::EnginePtr engine(UNIGINE_VERSION, argc, argv);

	// UnigineLogic
	AppSystemLogic system_logic;
	AppWorldLogic  world_logic;
	AppEditorLogic editor_logic;

	// enter main loop
	engine->main(&system_logic, &world_logic, &editor_logic);

	return 0;
}

 It is possible to declare multiple AppXxxLogic, call order will then follow add order.

#ifdef _WIN32
int wmain(int argc, wchar_t* argv[])
#else
int main(int argc, char* argv[])
#endif
{
	// init engine
	Unigine::EnginePtr engine(UNIGINE_VERSION, argc, argv);

	// UnigineLogic
	AppSystemLogic system_logic;
	AppSystemLogic2 system_logic2;
	AppWorldLogic  world_logic;
	AppWorldLogic2  world_logic2;
	AppEditorLogic editor_logic;

	// enter main loop
	engine->addSystemLogic(&system_logic);
	engine->addSystemLogic(&system_logic2);
	engine->addWorldLogic(&world_logic);
	engine->addWorldLogic(&world_logic2);
	engine->addEditorLogic(&editor_logic);
	engine->main();

	return 0;
}

Then come in the game AppXxxLogic added through plugins.

class InteractivePlugin : public Plugin
{
public:
	InteractivePlugin()
	{
		Log::message("InteractivePlugin::InteractivePlugin(): called\n");
	}
	virtual ~InteractivePlugin()
	{
		Log::message("InteractivePlugin::~InteractivePlugin(): called\n");
	}

	// plugin data
	virtual void* get_data()
	{
		return this;
	}

	virtual int  init();
	virtual int  shutdown();
	virtual void destroy();

private:
	InteractiveWorldLogic wl;
};

int InteractivePlugin::init()
{
	Log::message("InteractivePlugin::init(): called\n");

	// add C++ callbacks
	Engine* engine = Engine::get();
	engine->addWorldLogic(&wl);

	return 1;
}

I observed that InteractiveWorldLogic::init() is called before AppWorldLogic::init()...

Is there a way to change that?

Kind regards,
Charles

Link to comment

Hi Charles!

Is there a way to change that?
Unfortunately, there is no way to change the order. I mean, there are no specific methods for this.
All you can do is:
1) Add plugins in the AppSystemLogic::init() method via API (Engine::addPlugin), not the command line argument "extern_plugin".
or
2) In the AppSystemLogic::init() use something like this:

#include <Unigine.h>

using namespace Unigine;

int AppSystemLogic::init()
{
	// world logic that needs to be pushed to the end of the queue
	WorldLogic *target_world;

	Engine *engine = Engine::get();
	engine->removeWorldLogic(target_world); // remove from the middle
	engine->addWorldLogic(target_world);	// add to the end

	return 1;
}

Best regards,
Alexander

Link to comment

Hi,

Thanks for feedback.

In fact, the context was:

  • AppWorldLogic::init -> create some players
  • InteractiveWorldLogic::init -> use them (but null ptr)

I solved it with kind of delayed init fired by event from camera controller...

  • AppWorldLogic::init -> create some players
  • InteractiveWorldLogic::init -> listen to cameraCtrl playerCollectionChanged
  • InteractiveWorldLogic::playerCollectionChanged_callback -> use them

But it fact, was simpler to move all players creation and usage in the same plugin init.

Kind regards,
Charles

Link to comment
×
×
  • Create New...