More Resource Loading

This week’s work revolved around loading resources from data files and developing the splash screen. I’ve previously discussed the splash screen in detail, so feel free to refer to my earlier blog post if you’re curious about my approach.

Loading the QML file

The first task was to load the QML file. Interestingly, the contents of the QML file are stored in a tree data structure. This tree contains all the necessary information required to load the game, ranging from screen sizes to resource file paths.

Re-writing qdFileManager and qdFilePackage Classes

The next task was to re-write the qdFileManager and qdFilePackage classes to use our zip utilities. These two classes are crucial for loading .pak files, which are frequently used in games to “pack” all the resources together. In this re-write, we changed the internal of the class methods to detect pack files and use are zip utilites to unpack them. Refer to these commits for a detailed understanding of the changes.

This led to the method qdFileManager::instance()::open_file(Common::SeekableReadStream *fh, const char *fname) working with Common::SeekableReadStream which made it easier to read buffers from here on.

Using readUint32LE() instead of read()

While making all these refactors, Sev explained the concept of Endianness and highlighted its importance in our codebase. Endianness in simple terms is the order in which multi-byte data is stored in memory. There are two systems in Endianness, Little Endian and Big Endian. In a system that follows Little Endian, the least significant byte is stored in the smallest address of memory, while in a Big Endian system, it is the complete opposite, the most significant byte is stored in the smallest address of memory. So let’s say you have a number 0x01. In the two systems it would look something like this.

  • Little Endian: 01 00 00 00
  • Big Endian: 00 00 00 01

Our files are written in Little Endian, but ScummVM works on many Big Endian systems. Thus, data could be misinterpreted, e.g., 0x01 might be read as 0x01000000 (16777216 in decimal), on a Big Endian system

Finishing things up

Following the initial commits, the subsequent tasks followed a straightforward pattern. They involved:

  1. Opening a file and getting the stream from it.
  2. Passing the stream as a parameter to qdFileManager::instance()::open_file.
  3. Reading from the stream and storing the required values as needed.
  4. Deleting the stream later on.

You can go through this commit to understand this change in greater detail.

This marked the end of my week, and we are now at the quarter mark of the program. There is still a lot of work to be done, and I am hopeful to show more exciting progress in the coming blogs. On a closing note, here is a picture of me displaying fonts on the screen to test if they were read accurately or not.

Stay tuned for more updates!


Leave a Reply

Your email address will not be published. Required fields are marked *