Group mouse move events from C API function

Groups together consecutive mouse move events like done in core.step()
lua function but on the C side.

It does not introduce any meaningful speedup but it theory is more efficient and
simplifies the Lua code.

The simplification of the Lua code alone is enough to justify this change?
This commit is contained in:
Francesco Abbate 2021-06-09 23:37:03 +02:00
parent 212e5e326c
commit 704a8dea09
2 changed files with 11 additions and 11 deletions

View File

@ -948,26 +948,18 @@ end
function core.step()
-- handle events
local did_keymap = false
local mouse_moved = false
local mouse = { x = 0, y = 0, dx = 0, dy = 0 }
for type, a,b,c,d in system.poll_event do
if type == "mousemoved" then
mouse_moved = true
mouse.x, mouse.y = a, b
mouse.dx, mouse.dy = mouse.dx + c, mouse.dy + d
elseif type == "textinput" and did_keymap then
if type == "textinput" and did_keymap then
did_keymap = false
elseif type == "mousemoved" then
core.try(core.on_event, type, a, b, c, d)
else
local _, res = core.try(core.on_event, type, a, b, c, d)
did_keymap = res or did_keymap
end
core.redraw = true
end
if mouse_moved then
core.try(core.on_event, "mousemoved", mouse.x, mouse.y, mouse.dx, mouse.dy)
end
local width, height = renderer.get_size()

View File

@ -201,6 +201,14 @@ top:
return 4;
case SDL_MOUSEMOTION:
SDL_PumpEvents();
SDL_Event event_plus;
while (SDL_PeepEvents(&event_plus, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) {
e.motion.x = event_plus.motion.x;
e.motion.y = event_plus.motion.y;
e.motion.xrel += event_plus.motion.xrel;
e.motion.yrel += event_plus.motion.yrel;
}
lua_pushstring(L, "mousemoved");
lua_pushnumber(L, e.motion.x);
lua_pushnumber(L, e.motion.y);