cargo, a small library for managing assets

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
bjornbytes
Prole
Posts: 12
Joined: Sat Oct 10, 2015 8:17 pm
Contact:

cargo, a small library for managing assets

Post by bjornbytes » Wed Oct 28, 2015 12:08 am

Cargo is a simple library I made that automatically loads and caches assets in a LÖVE project. It maps a directory in your project to a Lua table and takes care of loading those assets the first time they are accessed. So if you have an "images" folder with several .png files in it, you can do the following:

Code: Select all

local assets = require('cargo').init('/')

function love.draw()
  love.graphics.draw(assets.images.monster)
  love.graphics.draw(assets.images.player)
  -- etc.
end
Notice that you don't have to call love.graphics.newImage on each image to get up and running. It supports nested folders and most common resource types, but you can also define custom resources if needed. The code and documentation are available here:

https://github.com/bjornbytes/cargo

User avatar
ArchAngel075
Party member
Posts: 317
Joined: Mon Jun 24, 2013 5:16 am

Re: cargo, a small library for managing assets

Post by ArchAngel075 » Wed Oct 28, 2015 6:08 am

I often coded such a setup whenever i worked on a project. It greatly improves workflow.
One thing I allways worked towards was dependencies support for files.
a File may have a .ini or other means of declaring dependency on another elsewhere in the mapping. The module would pause loading any dependency seeking files (adding to a queue) and then loop over the queue constantly until all files that can be loaded are loaded. A last loop over checks if a file cannot load because of missing dependency and then informs user. Was perfect for mod/addon implementation where each can depend on an external mod file.

User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: cargo, a small library for managing assets

Post by Roland_Yonaba » Wed Oct 28, 2015 8:06 am

I have a similar project, love2d-assets-loader. It was hell of a fun working on it. I also remember Kikito's awesome love-loader, which is threaded.
Your implementation is short and really neat, as far as I can see. Very nice!

padicao2010
Prole
Posts: 15
Joined: Wed Jan 15, 2014 8:38 am

Re: cargo, a small library for managing assets

Post by padicao2010 » Wed Oct 28, 2015 8:44 am

Does it release unused memory assets? Or it wiil keep all loaded assets in memory until the game exit?

User avatar
Luke100000
Party member
Posts: 231
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: cargo, a small library for managing assets

Post by Luke100000 » Wed Oct 28, 2015 6:36 pm

padicao2010 wrote:Does it release unused memory assets? Or it wiil keep all loaded assets in memory until the game exit?
If I understand the code: No, it keeps all resources loaded.

User avatar
bjornbytes
Prole
Posts: 12
Joined: Sat Oct 10, 2015 8:17 pm
Contact:

Re: cargo, a small library for managing assets

Post by bjornbytes » Thu Oct 29, 2015 1:25 am

Currently it will keep assets loaded. Cargo could use weak references but then you'd have to manually keep references to anything you want to keep loaded, which is kind of a pain. You may be able to get away with doing something like:

Code: Select all

local assets = require('cargo').init('/')
assets.some.folder = nil
To remove references to everything in /some/folder and have them collected. I haven't tested this though.

User avatar
Luke100000
Party member
Posts: 231
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: cargo, a small library for managing assets

Post by Luke100000 » Thu Oct 29, 2015 6:18 am

bjornbytes wrote:Currently it will keep assets loaded. Cargo could use weak references but then you'd have to manually keep references to anything you want to keep loaded, which is kind of a pain. You may be able to get away with doing something like:

Code: Select all

local assets = require('cargo').init('/')
assets.some.folder = nil
To remove references to everything in /some/folder and have them collected. I haven't tested this though.
Should work. If not try collectgarbage() after deleting.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Eric Matyas and 2 guests