Freedom

Long time no post. Well, I am finished my degree now, so that – theoretically – should leave time for some projects.

Content for once

So, I made a little progress during the week. I was playing my Asteroids game from a USB pen and it really showed me how my dynamic loading of files was slowing me down. Due to the way I wrote the game, nothing is preloaded (because all graphics and audio files are referenced from external scripts). They are loaded on demand. They were cached once loaded however. On my laptop hard drive, the delay is slight, but still perceptible. I must have gotten immune to it somehow – but since the USB pen thing I started to notice it more and it irritated me.

I wrote a little function that can be called from Lua (a running theme) that takes a directory and a function. It applies the function to every file in the directory and its subdirectories. The function is called with two arguments, the path to the file and a file size. The code for doing this is quite simple – I used the opendir() and readdir() POSIX functions, along with stat() to determine whether to recurse into a directory or to get the byte size of a regular file.

From Lua then I just loop across the data directory, and preload files that look like images or sound files. I haven’t yet implemented preloading lua files, and I’m not sure if I will (given that the majority of the are referenced by the script running the preloader). I’m thinking of breaking the script in two – one that is run at program launch and another that is run at “new game”. At the moment the same script handles a bit of both. I might consider using file watches (or listeners, or whatever they’re called) so I can be notified when a Lua script changes and reload the data, but that is far less likely.

Next up, some kind of graphical progress bar, rather than just using the window title text…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: