gui: some progress on input events and architecture planning, needs testcases now

This commit is contained in:
triplefox 2012-12-20 06:33:18 -08:00
parent a0d0d564c1
commit b85f546e29
4 changed files with 78 additions and 15 deletions

View File

@ -466,8 +466,12 @@ client.model_bone_set(mdl_bbox, mdl_bbox_bone2, "bbox_crouch", mdl_bbox_bone_dat
-- set hooks -- set hooks
function h_tick_main(sec_current, sec_delta) function h_tick_main(sec_current, sec_delta)
--FIXME: why is this POS prototyping variable still here, it is being used to control the player model's leg swing >:(
rotpos = rotpos + sec_delta*120.0 rotpos = rotpos + sec_delta*120.0
input_events = {}
chat_prune(chat_text, sec_current) chat_prune(chat_text, sec_current)
chat_prune(chat_killfeed, sec_current) chat_prune(chat_killfeed, sec_current)
@ -789,6 +793,13 @@ input_events = {}
As it's currently architected, the hooks each take in stuff immediately and drive polling constants. As it's currently architected, the hooks each take in stuff immediately and drive polling constants.
the SDL events are similar to icegui events, but not exactly the same. the SDL events are similar to icegui events, but not exactly the same.
The push_mouse and push_keypress are intended to be inlined in the hook functions eventually. The push_mouse and push_keypress are intended to be inlined in the hook functions eventually.
Triplefox:
GM wired everything directly to the first-person view when building these hooks,
and we need to get some distance from that model to let the gui - or any alternate control schemes like vehicles/spectate - breathe.
Migrating the view stuff into the player object would help keep the client-global focused on just being infrastructure.
I've marked the points where it becomes an "ai controller" to help guide this.
]] ]]
local function push_keypress(key, state, modif) local function push_keypress(key, state, modif)
@ -798,17 +809,18 @@ local function push_keypress(key, state, modif)
end end
end end
local function push_mouse()
-- TODO look up how we are getting mouse now.
end
function h_key(key, state, modif) function h_key(key, state, modif)
push_keypress(key, state, modif)
if state and key == SDLK_F5 then if state and key == SDLK_F5 then
mouse_released = true mouse_released = true
client.mouse_lock_set(false) client.mouse_lock_set(false)
client.mouse_visible_set(true) client.mouse_visible_set(true)
end end
-- disconnected ai
if not players[players.current] then if not players[players.current] then
if state and key == SDLK_ESCAPE then if state and key == SDLK_ESCAPE then
client.hook_tick = nil client.hook_tick = nil
@ -816,6 +828,9 @@ function h_key(key, state, modif)
return return
end end
-- player entity ai
local plr = players[players.current] local plr = players[players.current]
if typing_type then if typing_type then
@ -958,7 +973,44 @@ function h_key(key, state, modif)
end end
end end
local function push_mouse_button(button, state)
table.insert(input_events, {etype=GE_MOUSE_BUTTON, edata={button=button,down=state}})
end
local function push_mouse(x, y, dx, dy)
table.insert(input_events, {etype=GE_MOUSE, edata={x=x, y=y, dx=dx, dy=dy}})
end
-- a nice little tool for checking the mouse state
function mouse_prettyprint()
local function xyp(n)
local s = tostring(mouse_xy[n])
if #s == 1 then return n..s.." "
elseif #s == 2 then return n..s.." "
elseif #s == 3 then return n..s.." "
elseif #s == 4 then return n..s.." "
else return n..s end
end
local function pollp(n)
if mouse_poll[n] then return n..'X ' else return n..' ' end
end
return xyp('x')..xyp('y')..xyp('dx')..xyp('dy')..
" "..pollp(1)..pollp(2)..pollp(3)..pollp(4)..pollp(5)
end
mouse_poll = {false,false,false,false,false}
mouse_xy = {x=0,y=0,dx=0,dy=0}
function h_mouse_button(button, state) function h_mouse_button(button, state)
if mouse_poll[button] ~= state then
mouse_poll[button] = state
push_mouse_button(button, state)
end
if mouse_released then if mouse_released then
mouse_released = false mouse_released = false
client.mouse_lock_set(true) client.mouse_lock_set(true)
@ -966,12 +1018,12 @@ function h_mouse_button(button, state)
return return
end end
-- player entity ai
-- FIXME: no reassignable mouse button controls?
local plr = players[players.current] local plr = players[players.current]
if not plr then return end if not plr then return end
local xlen, ylen, zlen
xlen, ylen, zlen = common.map_get_dims()
if plr.tool == TOOL_GUN and plr.alive then if plr.tool == TOOL_GUN and plr.alive then
plr.wpn.click(button, state) plr.wpn.click(button, state)
end end
@ -1004,6 +1056,16 @@ function h_mouse_button(button, state)
end end
function h_mouse_motion(x, y, dx, dy) function h_mouse_motion(x, y, dx, dy)
mouse_xy.x = x
mouse_xy.y = y
mouse_xy.dx = dx
mouse_xy.dy = dy
push_mouse(x, y, dx, dy)
-- player entity ai
if not players[players.current] then return end if not players[players.current] then return end
if mouse_released then return end if mouse_released then return end
if mouse_skip > 0 then if mouse_skip > 0 then

View File

@ -496,7 +496,6 @@ function gui_create_scene(width, height, shared_rate)
rawset(this, 'width', dim.width) rawset(this, 'width', dim.width)
rawset(this, 'height', dim.height) rawset(this, 'height', dim.height)
end end
print("OK")
this.dirty = true this.dirty = true
end end

View File

@ -184,22 +184,22 @@ GE_SHARED_ALARM = 2
-- KEY: -- KEY:
-- User pressed or released a key. -- User pressed or released a key.
-- callback passes in the binding and modifiers. -- callback passes in {key(int), state(bool), modif(int bitmask)}
GE_KEY = 3 GE_KEY = 3
-- BUTTON: -- BUTTON:
-- User pressed or released a mapped button. -- User pressed or released a mapped button.
-- callback passes in the binding and modifiers. -- callback passes in {key(int), button{button(string), desc(string)}, state(bool), modif(int bitmask)}
GE_BUTTON = 4 GE_BUTTON = 4
-- MOUSE: -- MOUSE:
-- Per-frame mouse inputs: x, y, button status. -- Mouse movement: x, y, dx, dy.
-- (define result object) -- callback passes in {x(number), y(number), dx(number), dy(number)}
GE_MOUSE = 5 GE_MOUSE = 5
-- MOUSE_BUTTON: -- MOUSE_BUTTON:
-- Mouse button is pressed or released. -- Mouse button is pressed or released.
-- (define result object) -- callback passes in {button(int), down(bool)}
GE_MOUSE_BUTTON = 6 GE_MOUSE_BUTTON = 6
-- MOUSELOCK: -- MOUSELOCK:

View File

@ -1133,6 +1133,8 @@ function new_player(settings)
axs = math.sin(this.angx) axs = math.sin(this.angx)
axc = math.cos(this.angx) axc = math.cos(this.angx)
--font_mini.print(64,8,0xFFFFFFFF,mouse_prettyprint())
local w, h local w, h
local i, j local i, j
w, h = client.screen_get_dims() w, h = client.screen_get_dims()