Jump to content

Intern class inheritance


photo

Recommended Posts

Posted

I don't know if it's possible, but it will be great to have the possibility to make your own class with inheritance of intern class of unigine, example, my own widget inheritance of Widget class.

 

Today, for do that, i make my class with an attribute Widget, and an function getWidget, work fine.

 

But, have a real inheritance will be very userful

 

 

Thanks.

Posted

This feature can be implemented with the following restrictions:

 

Inherited user class can't be obtained from the external class:

Node node = some node;
class MyNode : Node { };
node .addChild(new MyNode());
MyNode my_node = node.getChild();
// my_node can't be converted to the MyNode type after that.

 

User class should be presented in some variable or array to prevent automatic garbage collection.

Node node = some node;
class MyNode : Node { };
node .addChild(new MyNode());
// MyNode will be destroyed at the end of script system invocation.
// After that Node part of MyNode will be destroyed also and we will have a pointer on deleted node inside the node.
// Engine will crash.

Posted

New syntax for base class constructor:

class Foo {
Foo(int a,int :) { printf("Foo::Foo(): %d %d\n",a,B); }
};
class Bar : Foo {
Bar(int a,int B) : Foo(a + 3,b + 5) { }
};
Bar b = new Bar(1,2);
delete b;

 

External class inheritance:

class MyFile : File {
MyFile() : File() { }
};

MyFile file = new MyFile();
if(file.open("test.asm","rb")) {
printf("%s",file.readLine());
file.close();
}

printf("%s\n",typeinfo(file));
printf("%s\n",typeinfo(MyFile::cast(file.extern)));
printf("%s\n",typeinfo(MyFile::cast(new File())));

delete file;

0x00000000: jmp    	0x0000025c
MyFile 0x9f54170 (458752:0:0)
MyFile 0x9f54170 (458752:0:0)
int: 0

Posted

:) clap, clap clap ... nothing it's too hard for Frustrum, nop ????

Posted

Thankyou frustrum and team. This is a really big deal to me. Since this affects code that I am working on a lot - Is there an ETA on the next update?

Posted

Next SDK update is planned for the middle of September.

Posted

Ok I will try doing something else for the next 3 weeks

  • 3 weeks later...
Posted

I am having difficulty subclassing a Widget based object... Can we have an example of that.

 

my test case looks like this

class WidgetTest : WidgetVBox {
 WidgetTest (Gui gui) : WidgetVBox(gui){  }
} ;
int init() {
engine.game.setPlayer(new PlayerSpectator());
WidgetTest test = new WidgetTest(engine.getGui());
  engine.gui.addChild(test,GUI_ALIGN_TOP);
return 1;
}

 

to which I get the error can't convert user class to P6Widget

  • 2 weeks later...
Posted

You need to explicitly convert the inherited user class to the base widget before passing it to engine.gui.addChild(). This is done via extern:

 

// test.extern does the trick
engine.gui.addChild(test.extern,GUI_ALIGN_TOP);

It casts the child user class to the base extern class it was inherited from. Basically, what it does it returns the internal instance of WidgetVBox stored in WidgetTest object on its creation. The reverse casting from base class to the child one is done via cast().

Posted

Thankyou very much...

With regards to subclassing nodes how would one go about overriding/extending their serialisation functions. (Get them to write custom data in the world file?)

Posted

It is not possible to override serialization behavior for a node, because inherited classes do not have sufficient access level. When you call a base class method, it redirects the call to an "extern" instance (a base class one).

Posted

I would like to officially request that future versions of the engine allow a nodes serialization to be extended via subclassing it

Posted
I would like to officially request that future versions of the engine allow a nodes serialization to be extended via subclassing it

 

Maybe I am missunderstanding engine script/c++ interaction, but how should deserialization be handled on world load ? World file load is handled in engine core using c++ node class specific factories and loadXml() functions. UNIGINE world script with your overridden external script class definitions will be executed after world load when deserialization has already happened.

 

Not sure, but I would expect general property mechanism for custom node data world file storage the only possible approach

Posted

ahhh Thanks for your explaination. I use the property mechanism quite heavily. I was hoping for something a little cleaner.

×
×
  • Create New...