Removes the scattered loadImage, loadAudio, loadFont etc. throughout love2d modules
Prevents accidentally loading the same resource twice / allows things to share a resource
Very common use case, all of my games have a file like this
Provides clear ownership of resources
Abstracts method of storage away from game code
Resource dependency management? e.g. resource X depends on Y and Z; loading X will automatically load Y and Z
Problems that would need to be solved:
Resource lifetime: no need to keep all resources in memory all the time, e.g. on level change now-unused resources should probably be unloaded
ephemeron tables not implemented in luajit
manual refcounting - awful, refcounting works best with RAII anyways
C module that hides the resource manager's reference from the Lua state so it can be collected - black magic and also probably awful
manual purging of resources - acceptable in cases where this behavior is wanted
Are resources immutable? Probably?
How do we handle the case where someone loads an image and wants to modify it at runtime? There should probably be a way to bypass caching functionality so shared resources don't get modified.
Cool features:
Resource specification DSL
can be tied in with animation DSL
Ability to register custom resource loaders
could do REALLY cool things with this, e.g. have an "rtimage" resource type that allows images to be generated at runtime via some factory function parameterized by keys in the resource script
Ideas:
Multithreaded resource loading?
Mountable sources with priority and mergable resource scripts - facilitates patching and modding
Resource sets - imagine you know all the resources required for a level in advance - you could preload that level's resource set so everything is already in memory.
Misc.
No global state allowed; if the user wants a global resource manager he can create one himself
Example usage
resource 'block' {
type = 'image', filename = 'assets/block.png'
}
-- maybe this would be better? it adds to the overall implementation complexity though
image 'block' {
filename = 'assets/block.png'
}
...
-- perhaps something like this to load resource scripts
local resources = resource.dofile('resource_list.lua')
-- though as with animation DSL this could be done without loading a file:
local resources = resource.dsl(function()
resource 'block' {
type = 'image', filename = 'assets/block.png'
}
end)
-- indexing this theoretical table would automatically load the image and return it, probably via
-- the lazy module
local x = resources['block']
-- Without DSL:
local rcm = rcmanager.new()
local block = rcm:addresource('block')
block:attribute('type', 'image')
block:attribute('filename', 'assets/block.png')
local x = rcm['block'] ?
-- there probably needs to be an additional layer between creation and access to facilitate
-- resource chains
Concepts
Resources: images, audio, text, and so on
Singular: resource owned by one consumer
Shared: resource shared between multiple consumers (programatically this shouldn't be different from a singular resource)
Resource script: specifies a set of resources using a DSL
Resource manager (bad name): owns resources, provides ways to specify resources programmatically and via resource scripts similar to the animation API
Problems this would solve:
Problems that would need to be solved:
ephemeron tablesnot implemented in luajitCool features:
Ideas:
Misc.
Example usage
Concepts