Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Getting the number of objects in a datafile?

Credits go to 23yrold3yrold and Niunio for helping out!
This thread is locked; no one can reply to it. rss feed Print
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
avatar

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;
   }

-----------------
Current projects: Allegro.pas | MinGRo

23yrold3yrold
Member #1,134
March 2001
avatar

There's a sizable and informative thread on this topic somewhere; try a search ...

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

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. ;D Methinks it's rather strange that the number of objects isn't stored somewhere in the datafile structure though...

Go to: