Re: [AD] get_obj_count()

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Sorry for the late reply...

Joerg 'Sharky-X' Rueppel <sharky-x@xxxxxxxxxx> writes:
> while working with this function, I noticed that it sometimes returns 1 
> too much. After a little investigation, I found out that it also counts 
> an object with the name "GrabberInfo". I have changed my function to 
> work properly again by string-comparing the NAME property to 
> "GrabberInfo" and not counting it when it occurs. Is there a faster or 
> easier way to detect and avoid counting such invisible objects? Are 
> there any other similar extra-objects I need to be aware of?

Not that I can remember at the moment, but in theory there could be. In a 
chunk-based file format you should always assume there will be more data 
than you were expecting: that's the point of it being chunk based (makes 
it easy to expand in the future). Instead of taking out what you know you 
don't want, make your code only include what you do want, and ignore 
everything else. In other words it is a bad idea to have a function to 
count all the objects in a datafile, because that will trip up if 
new ones are added later. Instead, if this is say a list of sprite 
graphics, make it look for objects with type DAT_BITMAP, and then it 
won't need to care whatever else might be in the file as well.


-- 
Shawn Hargreaves - shawn@xxxxxxxxxx - http://www.talula.demon.co.uk/
"A binary is barely software: it's more like hardware on a floppy disk."



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/