Images/sounds as tables?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Images/sounds as tables?

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Images/sounds as tables?

Post 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.
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Images/sounds as tables?

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Images/sounds as tables?

Post 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.
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Images/sounds as tables?

Post 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.)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Images/sounds as tables?

Post by bartbes »

It's really hard to get it out of lua at random points, is what I mean.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests