|
Getting the number of objects in a datafile? |
Erik Grahn
Member #3,914
October 2003
|
I have an Allegro datafile with a number of BMP objects (tiles) in it being loaded in my program, and am trying to figure out an easy way to figure out how many objects total are in the datafile, is there an easy/clever way to do this? |
Niunio
Member #1,975
March 2002
|
int NumObjs = 0;; DATAFILE *DataFile = NULL; if ((DataFile = load_datafile ("file.dat")!=NULL) { while (DataFile[NumObjs]->type != DAT_END) ++NumObjs; } unload_datafile (DataFile); Didn't tested. Note that will count the number of objects. To count only bitmaps (no palette): int NumBitmaps = 0; (...) while (DataFile[NumObjs]->type != DAT_END) { if (DataFile[NumObjs]->type == DAT_BITMAP) ++NumBitmaps; ++NumObjs; }
----------------- |
23yrold3yrold
Member #1,134
March 2001
|
There's a sizable and informative thread on this topic somewhere; try a search ... -- |
Erik Grahn
Member #3,914
October 2003
|
Yes, cool, thanks both. Actually, Niunio, I saw your first post before you added the checking for BITMAP objects but I came up with something similar myself, this should work now. Methinks it's rather strange that the number of objects isn't stored somewhere in the datafile structure though... |
|