From b85f546e295e9da1542c4911ab2870d16a1fd5f6 Mon Sep 17 00:00:00 2001 From: triplefox Date: Thu, 20 Dec 2012 06:33:18 -0800 Subject: [PATCH] gui: some progress on input events and architecture planning, needs testcases now --- pkg/base/client_start.lua | 80 ++++++++++++++++++++++++++++++++++----- pkg/base/lib_gui.lua | 1 - pkg/base/lib_util.lua | 10 ++--- pkg/base/obj_player.lua | 2 + 4 files changed, 78 insertions(+), 15 deletions(-) diff --git a/pkg/base/client_start.lua b/pkg/base/client_start.lua index d2e74e8..91077c9 100644 --- a/pkg/base/client_start.lua +++ b/pkg/base/client_start.lua @@ -466,7 +466,11 @@ client.model_bone_set(mdl_bbox, mdl_bbox_bone2, "bbox_crouch", mdl_bbox_bone_dat -- set hooks 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 + + input_events = {} chat_prune(chat_text, sec_current) chat_prune(chat_killfeed, sec_current) @@ -789,7 +793,14 @@ input_events = {} 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 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) table.insert(input_events, {etype=GE_KEY, edata={key=key,state=state,modif=modif}}) @@ -798,17 +809,18 @@ local function push_keypress(key, state, modif) end end -local function push_mouse() - -- TODO look up how we are getting mouse now. -end - function h_key(key, state, modif) + + push_keypress(key, state, modif) + if state and key == SDLK_F5 then mouse_released = true client.mouse_lock_set(false) client.mouse_visible_set(true) end - + + -- disconnected ai + if not players[players.current] then if state and key == SDLK_ESCAPE then client.hook_tick = nil @@ -816,6 +828,9 @@ function h_key(key, state, modif) return end + + -- player entity ai + local plr = players[players.current] if typing_type then @@ -958,20 +973,57 @@ function h_key(key, state, modif) 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) + + if mouse_poll[button] ~= state then + mouse_poll[button] = state + push_mouse_button(button, state) + end + if mouse_released then mouse_released = false client.mouse_lock_set(true) client.mouse_visible_set(false) return end + + -- player entity ai + -- FIXME: no reassignable mouse button controls? local plr = players[players.current] 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 plr.wpn.click(button, state) end @@ -1004,6 +1056,16 @@ function h_mouse_button(button, state) end 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 mouse_released then return end if mouse_skip > 0 then diff --git a/pkg/base/lib_gui.lua b/pkg/base/lib_gui.lua index c2599e2..20b790e 100644 --- a/pkg/base/lib_gui.lua +++ b/pkg/base/lib_gui.lua @@ -496,7 +496,6 @@ function gui_create_scene(width, height, shared_rate) rawset(this, 'width', dim.width) rawset(this, 'height', dim.height) end - print("OK") this.dirty = true end diff --git a/pkg/base/lib_util.lua b/pkg/base/lib_util.lua index 990b572..8b98354 100644 --- a/pkg/base/lib_util.lua +++ b/pkg/base/lib_util.lua @@ -184,22 +184,22 @@ GE_SHARED_ALARM = 2 -- 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 -- 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 -- MOUSE: --- Per-frame mouse inputs: x, y, button status. --- (define result object) +-- Mouse movement: x, y, dx, dy. +-- callback passes in {x(number), y(number), dx(number), dy(number)} GE_MOUSE = 5 -- MOUSE_BUTTON: -- Mouse button is pressed or released. --- (define result object) +-- callback passes in {button(int), down(bool)} GE_MOUSE_BUTTON = 6 -- MOUSELOCK: diff --git a/pkg/base/obj_player.lua b/pkg/base/obj_player.lua index dd80f8a..c49725f 100644 --- a/pkg/base/obj_player.lua +++ b/pkg/base/obj_player.lua @@ -1133,6 +1133,8 @@ function new_player(settings) axs = math.sin(this.angx) axc = math.cos(this.angx) + --font_mini.print(64,8,0xFFFFFFFF,mouse_prettyprint()) + local w, h local i, j w, h = client.screen_get_dims()