Lists & sort
BlitzMax Forums/BlitzMax Beginners Area/Lists & sort
| ||
Hi, I have a little problem with lists & sorting function. First of all: I have 2 lists that have in part the same object, Object_list and Blob_list. In the first list I add everything while the second is used only for checking events (collisions and so on...). So reading from the object_list permit to draw on the screen all the entities, while to check collision beetwen the current-entity and other possibilities I use the other list. My problem is: I need a z-order for the the blob/sprite drawing...and here I have problems. If I do SORTLIST (blob_list) It could be ok, but If I do SortList Object_list I sort ALL the objects...and this is wrong. I think to create a manual function to sort the entities in blob_list and (with the link) in object_list, but at the moment I melted my brain... I hope you understand the problem... Type Tentity'generic entity type field xpixel,ypixel field tipo' 0 - is a 'sprite, 1 is a basic element... field ogg_link:tlink ' the link to Object_list '... End Type My first approach was to use a personal Compare() function with tipo=0 specified, but it doesn't work. My second approach (current WIP...) is to create a Function Sort() to sort both the lists: I need to understand correctly the Link, Link._pred and Link._succ.... |
| ||
Sort bases on the Compare method which returns: -1: if the "other" object is larger (however you define largeron this object type) 0: if both object are assumed to be the same (this will also be used for remove so don't return 0 if they are the same from sorting view. In this case use -1 or 1. it won't destroy the ordering between objects that are assumed to be smaller or larger to each other). My compare method only returns 0 if the references are pointing to the same object. 1: if the other object is smaller (or vise versa with 1 / -1) |