kyleconroy/hawkthorne-journey — pull request #556 by campadrenalin (2012-11-07 01:21:43+00:00)
Title: Better loader design

Largely rewrites loader.lua, so that preloading can be done from the files that need it. For example, the levels are now loaded by a new "levels.lua" file.

The interface for this is the loader.preload(input_table, callback) function, which calls the callback function for each entry in input_table during the preload loop. Your callback can then populate a module-local cache. Again, using the example of levels.lua, you can get any level object from any module by importing "levels" and grabbing the appropriate object from that table. Nifty stuff, no?

While the interface makes all *uses* of preloading almost dangerously sexy, the loader module itself is not, thanks to the complexity of the internal queue structure. The complexity comes from being forward-compatible with specifying load order (a necessary feature if one thing depends on another being loaded first). Even so, it feels like it could have better variable names and such, so any feedback from other programmers on how to make loader.lua's guts a bit cleaner/more readable would be fantastic.