Page 1 of 1

Images/sounds as tables?

Posted: Sat Jun 15, 2013 6:39 pm
by Santos
I was wondering what it would be like to be able to load images and sounds as tables, and create them from tables, basically replacing uses for ImageData and SoundData with editing tables. Related to this: https://bitbucket.org/rude/love/issue/3 ... a-2d-array

Something like this perhaps...

Code: Select all

imagetable = love.graphics.newImageTable('image.png')
imagetable[2][4] = {10, 200, 255, 255}

soundtable = love.sound.newSoundTable('sound.ogg')
for i = 1, #soundtable do soundtable[i] = soundtable[i] / 2 end

image = love.graphics.newImage(imagetable)
source = love.audio.newSource(soundtable)
I imagine this wouldn't be so good for some reason, but I'd be curious to know why.

Re: Images/sounds as tables?

Posted: Sat Jun 15, 2013 6:41 pm
by bartbes
Except for the performance reasons, this is really, really, really inconvenient for the engine which can't properly reference it and may need to do just that at any given time.

Re: Images/sounds as tables?

Posted: Sat Jun 15, 2013 6:59 pm
by Santos
Hehehehe, I see! :ultraglee:

So... why would the engine want to reference it exactly?

And out of curiosity, which part do you think would be slow, the "loading the file into a table", or the "creating the Image/Source from a table", or both?

Re: Images/sounds as tables?

Posted: Sat Jun 15, 2013 7:40 pm
by bartbes
Both, it's indirection, and there's also benefits to it being stored in a contiguous bit of memory, which tables really don't guarantee (or try to, don't get me wrong).
Also, it needs references to.. well, do anything at all with it.

Re: Images/sounds as tables?

Posted: Sat Jun 15, 2013 8:32 pm
by Santos
Ah, that's interesting about the contiguous memory.

I'm still confused about the reference thing though. If it was a table... wouldn't you just pass the reference of the table to whatever function you wanted? So it wouldn't need to be kept track of?

(In case I was unclear, I'm imagining functions which load up a image/sound file and translate it into a table of pixel/sample values, and then also functions which convert tables like these into Images/Sources.)

Re: Images/sounds as tables?

Posted: Sat Jun 15, 2013 8:54 pm
by bartbes
It's really hard to get it out of lua at random points, is what I mean.