So, first I tried with a canvas and getImageData. Alas, even with a 1x1 canvas, getImageData causes 100% CPU usage:
Code: Select all
function love.load()
canvas = love.graphics.newCanvas(1, 1)
end
function love.update(dt)
canvas:getImageData()
end
Maybe ImageData is a view of the canvas that gets updated in real time? Nope, it's a snapshot. That road is closed too.
I haven't tried using tables with the collision bitmap data and bit manipulation, as I figure it would be too slow to do it several times per frame, depending on the tile sizes. So I thought of using strings, since they are binary byte arrays. But I've searched all places I could imagine, and I didn't see any bitwise string manipulation library for Lua: all of them were for numbers, not strings. In PHP (and in Perl, I think) you can do string|string, string^string and string&string. It would be nice if LÖVE included functions to do that, plus bit shift left/right of strings. That would enable me to do the necessary bit manipulation that would probably provide the speed I need.
But since there's currently no such thing, I wonder if there's any other fast alternative that I'm missing.
[EDIT: I've created it as a loadable module now: https://github.com/pgimeno/lua-strbit - see testsuite.lua for sample usage]
Is it possible, without using ImageData, to check if a canvas is a solid color? Perhaps some clever use of setShader?
Is there any other fast enough method?