Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Let's try this. If you have a question, but don't think it deserves it's own thread, post it here and get help from fellow forum members.

I'll start. When using sprite batches, if I need to change all of it's sprites, which would be cheaper: clearing + readding or setting the sprite in the spritebatch? If the latter, how much cheaper is it?
slime
Solid Snayke
Posts: 2932
Joined: Mon Aug 23, 2010 6:45 am
Contact:

Whatthefuck wrote:I'll start. When using sprite batches, if I need to change all of it's sprites, which would be cheaper: clearing + readding or setting the sprite in the spritebatch? If the latter, how much cheaper is it?

Something like this:

Code: Select all

function love.draw()
spritebatch:clear()
spritebatch:bind()

for i,v in ipairs(sprites) do
end

spritebatch:unbind()

love.graphics.draw(spritebatch, 0, 0)
end

(SpriteBatch:bind/unbind will be made obsolete in the next LÖVE version, but only because SpriteBatches will essentially automatically do the same thing under the hood. Until then, use them!)

If you're going to be adding/changing the sprites every frame then you should also use the 'stream' SpriteBatch usage hint when creating the spritebatch (i.e. love.graphics.newSpriteBatch(image, maxsprites, "stream")). If you aren't modifying the spritebatch every frame, 'static' might be the best to use.
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

slime wrote:If you're going to be adding/changing the sprites every frame then you should also use the 'stream' SpriteBatch usage hint when creating the spritebatch (i.e. love.graphics.newSpriteBatch(image, maxsprites, "stream")). If you aren't modifying the spritebatch every frame, 'static' might be the best to use.
I'm using spritebatches for baking the lighting into canvases which I then draw over everything.
The problem is that if I need to update the lighting often (I have added a time of day system with day and night cycles), it creates a slight stutter, and considering that I have a i5 4670, I expect it to be even worse on lower end CPUs. I'm using a single sprite batch (which has a maximum of 256 sprites) which I clear + re-add everything to and then draw it to a canvas. The canvas is not a single one, but plenty of 16x16 canvases. (to avoid having to re-render unnecessary stuff)

Are there any better solutions to this?

The reason why I bake the lighting into canvases, is because when I upscale them to match the screen resolution, I get smooth lighting as a result of linear filtering kicking in.

Edit: just realized I had power options set to 'balanced' which increased CPU clocks gradually as CPU load increased. Setting it to high performance yields constant 60 fps with no fps drops. Ugh.
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

I have a question:
Is there any way to make images smaller (memory wise) ?
I have loads of PNGs that I need to load but in the game they are going to be resized quite a lot (they'll be smaller) so I was thinking if there was a way to make resized images smaller in termes of memory.

Would canvas do the trick ?
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping

bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Ranguna259 wrote: I have loads of PNGs that I need to load but in the game they are going to be resized quite a lot (they'll be smaller) so I was thinking if there was a way to make resized images smaller in termes of memory.
Actually make them smaller?
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Ranguna259 wrote:I have a question:
Is there any way to make images smaller (memory wise) ?
I have loads of PNGs that I need to load but in the game they are going to be resized quite a lot (they'll be smaller) so I was thinking if there was a way to make resized images smaller in termes of memory.

Would canvas do the trick ?
Search for 'optipng' on google. That thing removes unnecessary data, as told by my friend, and preserves the same quality.

Also, the threading system in love2d's wiki says that you can send flat tables to threads. What is a 'flat' table? Table with no indexes? Table with numeric indexes only?
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Whatthefuck wrote:What is a 'flat' table? Table with no indexes? Table with numeric indexes only?
Tables that contain no other tables.
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

bartbes wrote: Actually make them smaller?
Yeah, make the space they use in the memory smaller, I shrink them by scalling them down but that just changes it size while keeping it's space the same.
Imagine a hella huge image, arround 1MG that's 4096x4096, I load it by using love.graphics.newImage() and then scale it down by, say, 0.25 and it becomes 1024x1024, but in the RAM that image is still taking the same space as the 4096x4096 one, so I wanted a way to make the space that the 1024 image uses smaller in the memory. Is that even possible ?
Whatthefuck wrote:Search for 'optipng' on google. That thing removes unnecessary data, as told by my friend, and preserves the same quality.

Also, the threading system in love2d's wiki says that you can send flat tables to threads. What is a 'flat' table? Table with no indexes? Table with numeric indexes only?
I'm not looking for an external program, I'm looking way to do this in LOVE (if possible)
bartbes wrote:Tables that contain no other tables.
Aren't flat tables, tables in strings, exemple:

Code: Select all

tbl = loadstring('return {1,2,3}')()
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping

Jasoco
Inner party member
Posts: 3655
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

No, bartbes was actually saying to just make the image smaller. Is there a reason you'd want a 4096x4096 image if you're just going to shrink it? Just include a smaller 1024x1024 version and load that.
slime
Solid Snayke
Posts: 2932
Joined: Mon Aug 23, 2010 6:45 am
Contact:

Ranguna259 wrote:I have a question:
Is there any way to make images smaller (memory wise) ?
I have loads of PNGs that I need to load but in the game they are going to be resized quite a lot (they'll be smaller) so I was thinking if there was a way to make resized images smaller in termes of memory.
Downscale the image files on your computer using an image editing tool (maybe combined with a script if you want to automate it). You could include all the images in the .love and only load the ones which have an appropriate size for the system the game is running on, if you want.

If you want to use LÖVE as your image processing tool, you could create a canvas at the final size you want, draw the image to the canvas, and use [wiki]Canvas:getImageData[/wiki] and [wiki]ImageData:encode[/wiki] to re-save the downscaled image to a new file.

For even more RAM/VRAM usage optimization, you could convert the textures to DXT1 or DXT5 (depending on if they're fully opaque or not). DXT-compressed textures stay compressed in RAM and in VRAM, unlike regular image formats. LÖVE can't save to DXT though, it can only load them.
Whatthefuck wrote:Search for 'optipng' on google. That thing removes unnecessary data, as told by my friend, and preserves the same quality.
PNG/jpeg/etc. are always decompressed into raw pixel data when they're loaded into RAM, so that'll only help with filesizes rather than the amount of RAM/VRAM used.

### Who is online

Users browsing this forum: No registered users and 48 guests