Page 1 of 1

Very slow love.touchmoved

Posted: Sun Aug 14, 2016 8:34 pm
by roller
Hi,

i try to test touch events (on Android platform) and found big delay between finger moves and touchmoved events.
I think 1) there is some gap inside sdl-love2d or 2) love.touchmoved happens too frequently with little delta or 3) i make mistake inside my code

[youtube]https://www.youtube.com/watch?v=_NrupVLSSiA[/youtube]

My test code

Code: Select all

function love.conf(t)
  t.window.vsync = false
end

function love.load(arg)
  local font = love.graphics.newFont(25)
  love.graphics.setFont(font)
end

function love.keypressed(key,scancode,isrepeat)
  if key == "escape" then
    love.event.quit(0)
  end
end

local touches = {}

function love.draw()
  local x, y, dx, dy
  for _, data in pairs(touches) do
    if data then
      x, y, dx, dy = unpack(data)
      love.graphics.setLineWidth(5)
      love.graphics.setColor(255,255,255)
      love.graphics.circle("line", x, y,100)
      love.graphics.setColor(255,0,0)
      love.graphics.circle("line", x + dx or 0, y + dy or 0, 120)
    end
  end

  love.graphics.setColor(255,255,255)
  love.graphics.print("FPS: "..tostring(love.timer.getFPS( )), 10, 10)
  love.graphics.print("Time: "..tostring(love.timer.getAverageDelta()), 10, 30)
end

-- I need normal id of the touch, not system int64 aka "userdata 0x00000002"
function parse_touch_id(id)
--  str_id = tostring(id)
--  if string.sub(str_id, -4) == "NULL" then
--    return "a00"
--  else
--    return "a" .. string.sub(str_id, -2)
--  end  
  return tostring(id)
end

function love.touchpressed(id, x, y, dx, dy, pressure)
  local key = parse_touch_id(id)
  touches[key] = { x, y, dx, dy }
end

function love.touchmoved( id, x, y, dx, dy, pressure )
  local key = parse_touch_id(id)
  touches[key] = { x, y, dx, dy }
end

function love.touchreleased( id, x, y, dx, dy )
  local key = parse_touch_id(id)
  touches[key] = nil
end

Re: Very slow love.touchmoved

Posted: Mon Aug 15, 2016 4:29 am
by pgimeno
Note the FPS is 60. That's because love.conf isn't in a separate conf.lua file. I get a similar delay with the mouse (after adapting your program). After properly disabling vsync, it works fine.

Re: Very slow love.touchmoved

Posted: Mon Aug 15, 2016 5:06 am
by zorg
To add to this, you can specify the function that's usually in a conf.lua file inside main.lua, but the function only sets the fields inside the function to the given parameter; you'll need to set everything manually yourself (and this won't stop löve from creating a default window, and everything else either, also you can't disable modules after they have been loaded by default.) It's easier to just do it how you're supposed to.