Sprites list optimisation..
In short here is my problem :
In the litle game that I whant to create I have all caninds of sprites that must be added and deleted from the screen. For that I am trying to use a dynamic alocated list but the problem is that if for example more than 7-8 sprites have to be deleted at the same time ( for example if they go out of the screen ) then my FPS get realy low and the program is bumpy. I tryed to use the list class that I made , one that I found on the net and finaly now i am using a STL list. ( "good" old Microsoft made ). But the problem remains : if more than 8-9 sprites have to be deleted simultaniosly the game gets realy bumpy and slow.
So how is overcomed this problem in all thouse action ghames where so MANY sprites apear and disapear every frame?
How can I solve my problem?
Thank you
MAD_Mask
Just adding another post so that this topic stays among the first on the page( in order to get a chase of someone replying ) .
So come on guys..... a little help here please
MAD_Mask
So come on guys..... a little help here please
MAD_Mask
If each delete is taking awhile, you could do something like putting the items to be deleted into a separate "DeleteMe" list after you remove them from your active list. Then, each game loop/second/interval/whatever, you could delete just a couple of these from this list if any are present. This will cause your deleting to be spread out over a period of time that you think is reasonable. Basically, you''d be writing a garbage collector.
Other options would be to recycle sprites if possible (by just reusing them as something else and not deleting) or only deleting sprites on a level or scene change when frame rate is not an issue.
Other options would be to recycle sprites if possible (by just reusing them as something else and not deleting) or only deleting sprites on a level or scene change when frame rate is not an issue.
So basicly you are saying that the actual deleteing takes much time and not the changes in the links ( the pointers to the next , previos sprite ).....
Hmmmm , I''ll try to do that but removing the sprite fgrom the main list doesn''t mean that I delete it? How can I do what you sugested using STL lists ?
MAD_Mask
Hmmmm , I''ll try to do that but removing the sprite fgrom the main list doesn''t mean that I delete it? How can I do what you sugested using STL lists ?
MAD_Mask
Well, I don''t know exactly how you are removing your sprites. If you are cycling through the entire list each time you remove a sprite, then you aren''t doing things as efficiently as you could. I was assuming from your original post that your slowdown was the actual object deletion and not just removing the item from the list.
In a doubly linked list, removing an item is extremely efficient as long as you have a pointer (or iterator) to the item you want to remove and don''t have to search through the list for it. I believe with the STL you can use erase() to remove either one item, or a range of items.
If you want to take an element out of one list and put it into another, assuming you already have an iterator pointing at the item you want to move, you''d do something like this:
Now you''d have a list of items that are ready to be deleted, that you can remove at your leisure by first getting an iterator pointed at the item (itrTemp below) and then deleting it. The easiest way is to take them off one of the ends.
itrTemp = list.begin();
delete *itrTemp;
list.pop_front();
Hopefully, that helps you out. (And hopefully, I didn''t put too many errors in my examples.)
In a doubly linked list, removing an item is extremely efficient as long as you have a pointer (or iterator) to the item you want to remove and don''t have to search through the list for it. I believe with the STL you can use erase() to remove either one item, or a range of items.
If you want to take an element out of one list and put it into another, assuming you already have an iterator pointing at the item you want to move, you''d do something like this:
// itrDelete is an iterator pointing at the element you wish// to movedeleteMeList.push_back(*itrDelete);activeList.erase(itrDelete);
Now you''d have a list of items that are ready to be deleted, that you can remove at your leisure by first getting an iterator pointed at the item (itrTemp below) and then deleting it. The easiest way is to take them off one of the ends.
itrTemp = list.begin();
delete *itrTemp;
list.pop_front();
Hopefully, that helps you out. (And hopefully, I didn''t put too many errors in my examples.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement