fearless![]() Member Posts: 91 From: Romania, Tg Mures Registered: 11-26-2005 |
I'm working on my own Irrlicht - Lua binding and I'm having a number of C++ problems that are quite a challenge. I can do this in C# blind folded yet I feel lost in C++. I'm making a function that will get called from a script file. The function will create objects on the heap. It will allow me to define by scripting the objects that get loaded to the game. The object class will contain pointers to Irrlicht resources (textures, meshes, etc.) C++ has several containers (std, boost, etc) and in many cases people build their own linked lists. Which way should I go? Calin [Edit]I have to delete my fearless acc. Keep forgetting I stopped using it. My projects page: [This message has been edited by fearless (edited December 14, 2006).] |
|||
Jari![]() Member Posts: 1471 From: Helsinki, Finland Registered: 03-11-2005 |
No need to build anything of your own because like you said there are options. I'd use std's list and some smart pointers from boost if needed. I hope that little piece of info helps. Doesn't C++ something like auto pointer feature these days? I havent taken the time to learn that yet. ------------------ [VoHW] (Help needed) [Blog] - Truedisciple (mp3) |
|||
HanClinto![]() Administrator Posts: 1828 From: Indiana Registered: 10-11-2004 |
quote: You could try changing your password to something strange (or possibly just a random jumble of characters that you won't remember but have written down somewhere in case you really need it). |
|||
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
quick example of how you'd use the STL list container... don't know if this would compile, I just wrote it up in Notepad, and I haven't coded in C++ for about a week...
------------------ |
|||
Calin![]() Member Posts: 358 From: Moldova Registered: 12-04-2006 |
@HanClinto: I had same password for both accounts, I have a new pass to actually get me thinking. @DartsMan: Nice example. Problem is the number of objects to be added is unknown until runtime (the data is read from script). So I'm thinking at this version of addItem
[This message has been edited by Calin (edited December 16, 2006).] |
|||
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
You can still use mine at runtime... I don't see what the issue is... I was only passing in some temp variables to show an example of them being used.. Just in whatever you'd load the scripts through, you'd just keep adding those into the list... I think your not getting that you couldn't just cut/paste my example into your script loader (or whatever your doing). Your example is bad, very bad, Temp has not been defined. In debug it *might* be ok (as Debug will initialise uninitialised variables (set to 0)) but in release, Temp is pointing to some random location.
Sure, you could place your code into addItem() to allocate the new memory, that is also a good idea to have the same class allocating the memory as being the one which is destroying the memory too eg. Have a look into Object Factories (basic ones, as advanced ones will go well above what you would really need). Anywho, I could post up some stuff later on, time to eat some dinner... ------------------ |
|||
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
BTW, the number of objects doesn't matter... you could keep adding items into it as it's a linked list...
------------------ |
|||
Calin![]() Member Posts: 358 From: Moldova Registered: 12-04-2006 |
quote: Sorry, my bad. For some reason I had the impression you're doing something alone the lines:
quote: Thanks for pointing that out. I haven't done too much coding in C++ and pointers have always been my week spot. I've got it now =]. Your posts help qute a bit Dartsman. [This message has been edited by Calin (edited December 16, 2006).] |
|||
dartsman![]() Member Posts: 484 From: Queensland, Australia Registered: 03-16-2006 |
quote: It was... though it's just an example. You would want to extend that into some sort of Object Factory or Object Manager class. Heres a simple Object Manager example...
So that you could use that and do...
I believe that'll work, however again, wrote it in Notepad and haven't tried to compile n link it... ------------------ |