anthony.liot Posted August 22, 2011 Share Posted August 22, 2011 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. Link to comment
ulf.schroeter Posted August 22, 2011 Share Posted August 22, 2011 There doesn't seems to be an easy solution. See this older post. Link to comment
frustum Posted August 25, 2011 Share Posted August 25, 2011 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. Link to comment
frustum Posted August 25, 2011 Share Posted August 25, 2011 Almost done, without restrictions. Link to comment
frustum Posted August 25, 2011 Share Posted August 25, 2011 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 Link to comment
anthony.liot Posted August 25, 2011 Author Share Posted August 25, 2011 :) clap, clap clap ... nothing it's too hard for Frustrum, nop ???? Link to comment
danni.coy Posted August 25, 2011 Share Posted August 25, 2011 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? Link to comment
binstream Posted August 25, 2011 Share Posted August 25, 2011 Next SDK update is planned for the middle of September. Link to comment
danni.coy Posted August 25, 2011 Share Posted August 25, 2011 Ok I will try doing something else for the next 3 weeks Link to comment
ivan.cuevas Posted August 26, 2011 Share Posted August 26, 2011 Incredible! very nice feature! Link to comment
danni.coy Posted September 14, 2011 Share Posted September 14, 2011 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 Link to comment
manguste Posted September 22, 2011 Share Posted September 22, 2011 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(). Link to comment
danni.coy Posted September 23, 2011 Share Posted September 23, 2011 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?) Link to comment
manguste Posted September 28, 2011 Share Posted September 28, 2011 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). Link to comment
danni.coy Posted September 28, 2011 Share Posted September 28, 2011 I would like to officially request that future versions of the engine allow a nodes serialization to be extended via subclassing it Link to comment
ulf.schroeter Posted September 28, 2011 Share Posted September 28, 2011 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 Link to comment
danni.coy Posted September 29, 2011 Share Posted September 29, 2011 ahhh Thanks for your explaination. I use the property mechanism quite heavily. I was hoping for something a little cleaner. Link to comment
Recommended Posts