Jump to content

Component system and inheritance - issue with VR


photo

Recommended Posts

Hi,

It is remark / question related to previous post / component system in fact. 

You solved the sync issue between CIGI and VR by moving some update to post-update as follow:

class VRPlayerVive : public VRPlayerVR
{
public:
	COMPONENT(VRPlayerVive, VRPlayerVR);
	COMPONENT_INIT(init);
	COMPONENT_POST_UPDATE(post_update); //instead of COMPONENT_UPDATE thanks to cash-metall from Unigine
	COMPONENT_SHUTDOWN(shutdown);

But this induce another bug / collateral effect on interaction between controller and button -> click not working anymore :-/

Before, VRPlayer::postUpdate() called update_button_states() and then following VRPlayerVive::update() called grab_update(...) with proper buttons_prev_state...
After, VRPlayerVive::post_update() mismatches the call order and buttons_prev_state where always wrong.

I fixed it as follow

class VRPlayer : public Unigine::ComponentBase
{
public:
	COMPONENT(VRPlayer, Unigine::ComponentBase);
	//COMPONENT_INIT(init); //since inheritance deal with it
	//COMPONENT_POST_UPDATE(postUpdate); //since inheritance deal with it, here call order mater..
	//COMPONENT_SHUTDOWN(shutdown); //since inheritance deal with it

and with explicit base class calls

void VRPlayerVive::init()
{
	VRPlayer::init(); //already the case in fact.. and VRPlayer COMPONENT_INIT(init) seems ignored :-o
}

void VRPlayerVive::post_update()
{
	[...]
	VRPlayer::postUpdate();
}

void VRPlayerVive::shutdown()
{
	[...]
	VRPlayer::shutdown();
}

Surprisingly, VRPlayerPC (when VR not available) implements a bit this

void VRPlayerPC::update()
{
	[...]
	//nothing here... 
}

void VRPlayerPC::postUpdate()
{
	[...]
	VRPlayer::postUpdate();
}

void VRPlayerPC::shutdown()
{
	[...]
	VRPlayer::shutdown();
}

So, could you check / suggest a clean way to proceed?
In fact, how are we supposed to proceed with inheritance and component system (C++ / macro based)?
E.g. I'm not sure COMPONENT_INIT(init) do as the other COMPONENT_POST_UPDATE & co...

As reminder, we kept the VR sample relation:
class VRPlayerVive : public VRPlayerVR
class VRPlayerVR : public VRPlayer
class VRPlayer : public Unigine::ComponentBase

Kind regards,
Charles

 

Link to comment

Hi Charles,

So, could you check / suggest a clean way to proceed?
It's good. But you can also use method ordering to control the order of execution. To change the order use the second argument in the COMPONENT_INIT/COMPONENT_UPDATE/... macros.
For example:

COMPONENT_POST_UPDATE(post_update, 100);

After this post_update() will be executed after all "post updates" in all components of any type.
Default order is 0.
Use negative numbers if you want to execute the method before others.
Use positive numbers to run the method after others.

Sequence of execution looks like this:
A::update(order = -5);
B::update(order = 0);
C::update(order = 5);
A::postUpdate(order = 0);
C::postUpdate(order = 0);
B::postUpdate(order = 2);
Where A, B, C are three different components.

In fact, how are we supposed to proceed with inheritance and component system (C++ / macro based)?
As you want. But I recommend not to mix the pipeline within the same project.
Use C++ inheritance if your base classes are not components.
Macro-based inheritance gives you more control:
1) You can override the base class method (only B::update() will be executed):

class A
{
	COMPONENT_UPDATE(update);
	void update();
};

class B: public class A
{
	COMPONENT_UPDATE(update);
	void update();
};

In this case it doesn't matter that the A::update() is not virtual.

2) You can run base class method before derived (A::update(), then B::update()):

class A
{
	COMPONENT_UPDATE(update, -1);
	void update();
};

class B: public class A
{
	COMPONENT_UPDATE(update);
	void update();
};

3) You can run derived class method before base (B::update(), then A::update());

class A
{
	COMPONENT_UPDATE(update);
	void update();
};

class B: public class A
{
	COMPONENT_UPDATE(update, -1);
	void update();
};

 

Best regards,
Alexander

Link to comment
×
×
  • Create New...