#174374 - relminator - Sat Jun 05, 2010 11:59 am
Hi, I'm developing a bullet-hell game for the DS.
http://forum.gbadev.org/viewtopic.php?p=174373#174373
I am now in the stage where I need to port a Freebasic code to C++. What I did with Freebasic was to make my own linked-list that processes the parameters of the turret(bullet spawner) object.
Here's the designer:
http://rel.betterwebber.com/junk.php?id=92
It uses my own implementation of a circular linked-list since Freebasic had no access to templates (so no STL).
Now I am in the crossroads of whether I would use STL (vector or list ) or stay with my own list class.
I really don't want to stay with my list class since STL is available to me.
Vectors should be faster (easy on the cache) since the data is stored in contiguous memory. However since vectors uses more memory(heap killer), I'm thinking of using list. Less cache hits but smaller in memory usage.
Any thoughts of what to use?
The data would be accessed sequentially.
Thanks!!!
_________________
http://rel.betterwebber.com
#174375 - sajiimori - Sun Jun 06, 2010 2:25 am
When you're just starting out, use std::vector until you encounter an actual, visible problem with it. :)
#174376 - relminator - Sun Jun 06, 2010 2:52 am
sajiimori wrote: |
When you're just starting out, use std::vector until you encounter an actual, visible problem with it. :) |
Possible problem when using vectors would not be visible. Vectors allocate more elements that what is apparent on your code (speed and contiguous memory). This is the DS where memory is scarce and I'm going to attach about 8(8 x 32 to 64 bullets) instances per enemy(128 enemies max) in real-time.
Thanks.
Anyone else have a take on this?
_________________
http://rel.betterwebber.com
#174378 - Jinroh - Sun Jun 06, 2010 8:07 am
Personally I usually go with the "Your own class" approach since you have more control over everything that goes on.
The template classes are nice, but on embedded systems I don't like to leave anything to chance.
_________________
The lone Wolf howls, driven by pride he presses on. Knowing not where he goes, but only where he wants to be.
~Me~
#174384 - Miked0801 - Mon Jun 07, 2010 1:11 am
And rolling your own classes are going to be bug free and tested? Not usually for quite a while! No, if you are coding in C++, you use what C++ supplies and that is the template library and the wonderful tools it supplies. I used to buy into the argument that the bloat would kill you in embedded land, but after a few years, I've found this to be either overstatement or outright falicy.
Back to the problem at hand. If you are emulating a list and need list-like performance, then use a list. If you want random access, use a vector. But, please do use the STL if you have it available to you. It really does solve many more problems then it sometimes creates.
#174389 - Jinroh - Mon Jun 07, 2010 7:25 am
Relminator mentioned that he already has a management system coded with Linked Lists. From when he did the FreeBasic version of his game.
Relminator being a smart guy, I would think it would be well designed enough to be fine to use.
_________________
The lone Wolf howls, driven by pride he presses on. Knowing not where he goes, but only where he wants to be.
~Me~
#174391 - ant512 - Mon Jun 07, 2010 9:23 am
Rolling your own will result in smaller binaries, mostly because the STL container classes haul in a lot of other junk you probably won't need - exceptions, etc.
#174393 - Miked0801 - Mon Jun 07, 2010 2:49 pm
One more question for you here:
You are mentioning performance as a concern with this list structure. A 128 entry list, accessed sequentially per tic is only 128 accesses. List<>, Vector<>, or List() are all going to access this in roughly the same amount of time. Lists have ever so slightly more overhead, but overall that should be nothing. The question being, is accessing 128 elements going to make or break or even slightly effect your game? This does not seem like a top 10 type operation in terms of overall CPU usage. Therefore, code for ease of maintainablity and extendability.
Smaller binaries are nice, if that turns out to be the case. Speeding up an operation that takes 0.001% of overall CPU usage is nothing. Having to spend anytime whatsoever trying to debug your data structure because its signature changed slightly is unacceptable. Having to change the internals of a management structure like a list is also a complete waste of time if there is a better solution already available.
If this does not apply to you, then do what you will. As a very experienced C/Asm programmer who has finally stopped coding with the digital equivilent of sticks and rocks, I cannot overstate the ease of use and robustness of code that proper C++ programming gives. That includes smart pointer usage and C++ design patterns. Good luck on your endevour.
#174394 - vuurrobin - Mon Jun 07, 2010 3:27 pm
I made an (bugfree AFAIK) vector class when I was coding DSOL, you can try to remove the vector class from the rest of the code, modify it as you want and use that, if you want.
http://vuurrobin.100webcustomers.com/index.php/dsol
other than that, you can just try stl and modify it later if it turns out to slow.
_________________
my blog:
http://vuurrobin.100webcustomers.com/
#174398 - sajiimori - Mon Jun 07, 2010 8:01 pm
I stand by what I said. Worrying about the future is a waste of brain power. :)
When there is a problem - a real one that is preventing you from making the game you want - then think about the correct solution. Maybe it will be replacing std::vector, or maybe not.
#174405 - headspin - Tue Jun 08, 2010 10:39 am
Why not just use a standard array with a size of MAX_BULLETS?
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game
#174406 - ant512 - Tue Jun 08, 2010 10:41 am
You could have a look at the DynamicArray struct/functions offered by libnds.
#174408 - relminator - Tue Jun 08, 2010 1:36 pm
Thanks for the suggestion guys. Sorry for not replying soon enough as my dad is going for an operation tomorrow.
So far this are some suggestions:
*Static array of MAX_BULLETS
Sorry for making a vague question but I won't use lists for that. In fact I'm using a static arrays for bullets. *;) I'll be using lists/vectors for turret behavior.
* My own list class
Although I have a robust list class (bugfree and memleak free as I've tested it and ran it on a mem leak detector), I'm not too happy with the gain in code size after reading this:
http://www.coranac.com/2009/11/sizeof-new/
* std vectors or std list
I'm leaning more into lists as I'm not going to access the elements randomly but sequentially. Though memory would get fragmented using lists, I don't think that would be a hit speed wise as the main bottleneck in my engine so far has been fillrate rather than DS clock speed.
Again, thanks for the replies guys! After my dad gets better, I could get back to coding again.
_________________
http://rel.betterwebber.com