Jump to content

[SOLVED] Issue with component system + plugins architecture


photo

Recommended Posts

Hi,

We're currently facing an issue, or let's say wondering if it is correct, using component system in tool architecture with plugins:

  • CIGI plugin
    • Based on / dealing with CIGIConnector
    • Optional business overlay using numerous setReceivePacketCallback, e.g. user defined packet
  • Core dll -> __declspec(dllexport)
    • Currently all data model, maybe used by other plugins or main
    • e.g. CameraComponent, RotorComponent, OtherPartComponent and associated controller
    • Here are ComponentSystem.h/cpp
  • VR plugin
    • Based on / dealing with AppVive
    • Using ComponentSystem.h macro e.g. for VRPlayerSpawner or ObjButton
  • Main
    • Can be started with different from above plugins

Only Core plugin exposes via dllexport only the class (singleton) ComponentSystem, other class / struct untouched.
CIGI plugin uses only what Core exposes, e.g. CameraController.
But VR plugin uses macro () of ComponentSystem.h to generate several classes for each VR components.. that would failed to link if files (ComponentSystem.h/cpp) are not duplicated in the project...
With all classes of ComponentSystem.h exposed with dllexport, there is still a link error from REGISTER_COMPONENT call.
At the end, Main AppSystemLogic to init the singleton ComponentSystem::get()->initialize();

Would you see the issue?
Would you suggest better/suitable approach?

Kind regards,
Charles

Edited by Lales.Charles
Link to comment

Hi,

Get it working as expected with few updates, feel free to check / comment / fix.

All classes are declared dllexport/import with following preproc bifurcation. Code compiles.

//////////// ComponentSystem.h ////////////

[...]

#ifdef DLL_EXPORT
#define DLLEI __declspec(dllexport)
#else
#define DLLEI __declspec(dllimport)
#endif
[...]

class DLLEI ComponentCreatorInterface

[...]

class DLLEI ComponentSystem : private Unigine::WorldLogic

[...]

Then to fix issue with singleton shared over mutliple dll, following updates are required.
Core dll singleton registers then properly components even from other dll, e.g. VR plugin. 

//////////// ComponentSystem.h ////////////

[...]

class DLLEI ComponentSystem : private Unigine::WorldLogic
{
public:
	// return pointer to singleton ComponentSystem
	/*static ComponentSystem *get()
	{
		static ComponentSystem instance;
		return &instance;
	}*/
	static ComponentSystem *get();

[...]

//////////// ComponentSystem.cpp ////////////

[...]

ComponentSystem *ComponentSystem::get() {
	static ComponentSystem instance;
	return &instance;
}

[...]

 

Kind regards,
Charles

PS: starting to wondering if we won't switch to C# API...

Edited by Lales.Charles
  • Like 3
Link to comment

Hi Charles,

Sorry for the delay. I was waiting for an opinion from my colleague.

Your solution looks really nice, and we probably would end up with something very similar you already made. The most important thing — it works :)

We have nothing to add at the moment.

Thank you.

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

Link to comment

Hi,

Ok thanks, then I proceed same way as well for the other controller singletons we discussed in other thread, e.g. CameraController or RotorController.

Kind regards,
Charles

Link to comment
  • morbid changed the title to [SOLVED] Issue with component system + plugins architecture
  • 2 months later...

Hi,

Regarding this point with update SDK 2.10, files ComponentSystem.h and ComponentSystem.cpp modifications have to be reported.

////  ComponentSystem.h ////

	static ComponentSystem *get()
	{
		static ComponentSystem instance;
		return &instance;
	}

replaced by

	static ComponentSystem *get();
	
//// ComponentSystem.cpp ////

ComponentSystem *ComponentSystem::get() {
	static ComponentSystem instance;
	return &instance;
}

Related to same plugin architecture, another requirement:

//// ComponentSystem.h

#ifdef DLL_EXPORT
#define DLLEI __declspec(dllexport)
#else
#define DLLEI __declspec(dllimport)
#endif

and multiple addition in class declarations

Is there a way / would it be useful to integrate it in sdk src for further update? 

Kind regards,
Charles

Link to comment
  • 4 months later...

Hello,

I would like Unigine to consider again this small modification. The way the singleton is currently created in the header is a source of problem in a multi-dll setup. On every engine update, we have to report the same modification, and in 2.12 the ComponentSystem.cpp/h have heavily changed!

Could it be possible to integrate this (or a variant) in the next version (the diff is really minor and attached here). If not, is there any rationale we have missed?

Thanks!

ComponentSystem_cpp_diff ComponentSystem_h_diff

  • Like 1
Link to comment

Dear Silent,

I have also changed the ComponentSystem.h to get access to PropertyWrapper and parameter. 

class ComponentVariable
{
public:
	ComponentVariable() = default;
	ComponentVariable(PropertyWrapper *component, const char *name, int type,
		const char *title, const char *tooltip, const char *group);
	virtual ~ComponentVariable();

	UNIGINE_INLINE int getID() const { return parameter->getID(); }
	UNIGINE_INLINE const char* getName() const { return name.get(); }
	UNIGINE_INLINE int getType() const { return type; }
	const char *getTypeName() const;
	UNIGINE_INLINE virtual Unigine::String getValueAsString() { return Unigine::String::null; }
	UNIGINE_INLINE virtual int nullCheck() { return 0; }

	/*********** [2020-07-06][Rohit Gonsalves][Added this getter to access property and PropertyParameter in Componment] **************/

	UNIGINE_INLINE PropertyWrapper* getPropertyWrapper() const { return holder; }
	UNIGINE_INLINE PropertyParameterPtr getPropertyParameter() const { return parameter; }

	/*********** [2020-07-06][Rohit Gonsalves][Added this getter to access property and PropertyParameter in Componment] **************/

	virtual void save(const Unigine::XmlPtr &parameter);

	virtual void setParameter(const Unigine::PropertyParameterPtr &param);

protected:
	int is_type_name(const char *name) const;

	PropertyWrapper *holder;

	Unigine::PropertyParameterPtr parameter;
	Unigine::String name;
	Unigine::String title;
	Unigine::String tooltip;
	Unigine::String group;
	int type;
};

Why it is important to me? The best part of ComponentVariable is you always have latest value in your object. You may directly use it in your code like in the pawn and spinner sample.

But sometimes few properties are expensive to change. Like I am generating texture based on YUV or RGBA selection. Now if I don't keep callback, I need to perform an update checking for value change of parameter. But with callback it is so simple and only happens once per value change. So please keep a scope to get property and parameter directly in upcoming versions. 

Regards.

Rohit

Link to comment
×
×
  • Create New...