Running a process to generate background images in realtime


I want to make a (Glulx) IF game using Inform 7 that has images of each location that are dynamically generated by a separate process running alongside the IF interpreter (e.g. to show the location background plus some things like current characters at that location).

The image will be presented when the player moves to a new location or performs particular actions such as waiting. How can I ensure that my game waits until the separate process has finished creating the required PNG/JPG before I move the player to the new location and draw the new scene?

I see from the Inform documentation that I can see if a file is ready to read, but it doesn’t look like I can loop until a file is ready (the separate process make take a little time to generate a new image).

I’m not sure how well Inform will cope with this, as it assumes that external images are packed into the blorb already. You’d probably have Inform open a separate file (in text mode), which your external process would mark as “ready to read” (see the documentation) when the image was ready. Then Inform would stop looping (“while the File of Program Status is not ready to read, do nothing.”) and display the image.

Another word of caution: I don’t think the standard prevents interpreters from caching images on startup, because there’s no way for a story file to change an image at run-time.

The Glulx spec is written with Blorb packages as the common case, but it offers a “simple filesystem” layout as an alternative. I don’t know if any interpreters have implemented it.

Assuming that can be made to work, the rest of the code can be made to work. I7’s API for accessing external files does indeed have a (very simple) model for marking the file as ready to read.

You don’t want to write a naive loop “while the … is not ready to read, do nothing”. That will busy-spin the CPU and slow down other processes. You should put a real-time delay inside the loop – perhaps check every quarter of a second.

Alternatively, you could have the external process display the image, which solves some problems while engaging others. (You might have to supply separate Mac / Win / Linux tools to do the image display.)

A surprising amount of cool stuff can be done with Glk, so don’t forget to give it a chance too.

Thanks for all the information and advice. I’ll let you know how I get on…

Maybe you could use Erik Temple’s Glimmr extensions to do the graphics - then you’d have an in-game solution. I haven’t used them myself yet, but composing images dynamically from backgrounds and sprites should be very doable. (Some links: home page, release announcement of the Canvas Animation component, an example.)

I just remembered: look at Alabaster by Emily Short. The code for the status window is unreleased, but I think it’s pure Inform.