Generate a binary file to manage the pre-rendered backgrounds
A pre-rendered background is not just a simple image used as a backdrop — the 3D space is fully present, and each screen can involve various interactions:
objects and NPCs to interact with, wall collisions, walkable and non-walkable paths, doors, various obstacles, etc.
You can understand that something is needed to define what is present in the scene for each individual screen — where you come from, where you exit,
what can happen and what cannot.
There are several ways to do this. For a simple game, we could definitely define a data structure to store all the necessary data for each scene.
But to do things properly, we would need to allocate the data structure on the heap — defining everything on the stack would be impossible.
The PS1 only has 2MB of RAM, and even though we can define how much stack to use when initializing memory,
we can't afford to use 100–500 KB just to define the screens.
And that's only for a game that might have just a few dozen screens — but think about games like Final Fantasy VII or VIII; they have hundreds of backgrounds.
So even if we load all the data into the heap, the problem remains — memory is limited.
We need something that can be saved on the CD-ROM and read when needed, loading into memory only the parts of the screen that interest us.
We could use a JSON or XML file to define each scene with its properties, and then create a function that reads the file, understands its syntax, and extracts the necessary values.
Today, JSON and XML files are overused — parsers for these types of files have become standard.
But we're in the '90s — the CPU and RAM are certainly capable of handling something like this, but it's a less efficient operation.
And since it's the '90s, we still like to optimize as much as possible — so we’ll use a binary file.
In the video below (it's in italian), I’ll explain in detail how I implemented reading (on the PS1 side) from a binary file, as well as writing to it.