More file preloading

This is a bit of a follow up from my previous post.

In the end I decided to do preloading for Lua scripts too. This is because of the nature of my game – there are a number of times a Lua state (or interpreter instance) can be created. There is one for every “game”, plus a different one for configuration. When the executable loads, there is a dummy “game” playing behind the menu that creates a nice background animation. When the user selects “new game” – a new “game” instance is created.

Because most of the scripts are referenced dynamically from Lua via the “require” standard library function I wrote a function that replaces the vanilla require – it will look in the cache first and if it fails it falls back to the standard library function (which is saved in the Lua registry – a neat little hiding place for Lua values that the C API can access but the Lua scripts can’t. I haven’t tested it fully, but it appears to work well so far. Which obviously means there is something hideously wrong with it…

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: