Return to “Technical”

Post

Node based progamming

#1
I've been watching LT for a long time now and have been very interested in the node based technology behind it. I've been teaching myself C++ and have tried to (unsuccessfully) reproduce a similar system. I remember Josh mentioned at one point that he was able to cut Boost out of the game, does anyone know if he was using shared pointers from Boost? I've tried creating Node objects that contain Property objects. Each Property object can hold a primitive data type and each Node contains an unordered map of Property objects that can be accessed by name. I then have a list of Node pointers so objects that inherit from Node can be inserted into this list. However, I found that maintaining this list was difficult due to multiple inheritance destructors and the pointers. Another solution I tried was creating things with their own containers but then having a generic Node list that only references to objects in order to see what properties they have. With both of these methods I had trouble with creating functions for children of the Node class since only the virtual functions of Node could be called from the Node container. Finally, unless a method for sorting the Node container was added it always felt disorganize and bloated.

Anyways, I probably went about this the wrong way, but does anyone (Josh?) have any ideas/comments on how this is done in LT?
Post

Re: Node based progamming

#2
Hey there,
I've read your post and am right now trying to do something similar.. at least in theory, because I can't really visualize the nice node based hierarchy like Josh does. Frankly I'm not a graphics programmer..
Because of your problem with destructors I *think* smart-pointers might be a good solution. If I undestand you correctly (I tried to reproduce the issue) shared-pointers should work. If you want to cut out boost, assuming you only use the smart-pointers from it, I guess std::shared_ptr is also an alternative. I have to admit I don't have much experience with smart-pointers, just recently read about them the first time :)

And to the overall hierarchy of your program, I'm wondering if you really want to inherit from node and what use it has?
I went for an approach where I have basically 2 classes, structured like this: (Pseudo code)

Code: Select all

class node
{
   list< shared_pointer< node > > m_child_nodes;
   list< shared_pointer< property > > m_properties;
   string m_name;
};

class base_property
{
  // Few virtual functions
  virtual void echo(void); // Do something with the node
};

class text_property: public base_property
{
  string m_text;
  void echo(void) { cout << text << endl; };
};
And I also have a container class which holds the actual node and property objects and offers functions to create nodes and so on.. I am only inheriting from property and all the functionality of the node also lies here.
Not sure if this is the best approach...I still struggle with them pointers and proper deletion too. From what I read smart-pointers should solve all my problems, but atm they aren't :) I guess I made some mistake in the code, too lazy to find it just now :ghost: :ghost:

I hope what I said makes any sense to you ?? oO (because of my limited skill to express my thoughts and english skill, not your skill to undestand it i mean :oops: ), if so I'm happy.
And please feel free to post any code of yours...that might help, I'm also very interested to see what others came up with! If someone is interested I can post the actual C++ code I'm (still) writing later.

Edit:
Forgot to ask: What sequence containers are you using to store your 'node' / 'node*' ?
I'm right now using a std::list because it's guaranteed( :think: ) to not invalidate pointers due to reallocation when calling std::list::insert, I always forget about this and it ends with a mess :ghost:

Edit2:
I probably misunderstood you. I read it a second time, I first thought you wanted to recreate the node-based UI from the video-updates. AFAIK Josh hasn't implemented anything further than the UI based on the node tech, could be wrong tho. Can't remember all those dev-logs. If you didn't, I'm afraid I can't help you :lol:

Online Now

Users browsing this forum: No registered users and 7 guests

cron