diff --git a/include/QF/keys.h b/include/QF/keys.h index 68cd462e3..eee2d7f54 100644 --- a/include/QF/keys.h +++ b/include/QF/keys.h @@ -439,6 +439,7 @@ typedef enum { } imt_t; // Input Mapping Table typedef enum { + key_unfocused, // engine has lost input focus key_game, key_console, key_message, @@ -451,7 +452,6 @@ typedef struct { int state; // low bit is down state } kbutton_t; -extern keydest_t key_dest; extern imt_t key_game_target; extern knum_t key_togglemenu; extern knum_t key_toggleconsole; @@ -463,6 +463,7 @@ extern int keydown[QFK_LAST]; struct cbuf_s; void Key_Event (knum_t key, short unicode, qboolean down); +void Key_FocusEvent (int gain); void Key_Init (struct cbuf_s *cb); void Key_Init_Cvars (void); void Key_WriteBindings (QFile *f); diff --git a/libs/console/client.c b/libs/console/client.c index 24ba57612..bd2fc4b29 100644 --- a/libs/console/client.c +++ b/libs/console/client.c @@ -103,6 +103,7 @@ static view_t *hud_view; static qboolean con_initialized; +static keydest_t con_keydest; static void ClearNotify (void) @@ -119,7 +120,7 @@ ToggleConsole_f (void) { Con_ClearTyping (input_line, 0); - if (key_dest == key_console && !con_data.force_commandline) { + if (con_keydest == key_console && !con_data.force_commandline) { Key_SetKeyDest (key_game); } else { Key_SetKeyDest (key_console); @@ -133,7 +134,7 @@ ToggleChat_f (void) { Con_ClearTyping (input_line, 0); - if (key_dest == key_console && !con_data.force_commandline) { + if (con_keydest == key_console && !con_data.force_commandline) { Key_SetKeyDest (key_game); } else { Key_SetKeyDest (key_console); @@ -448,14 +449,14 @@ C_KeyEvent (knum_t key, short unicode, qboolean down) if (!down) return; - if (key_dest == key_menu) { + if (con_keydest == key_menu) { if (Menu_KeyEvent (key, unicode, down)) return; } if (down) { if (key == key_togglemenu) { - switch (key_dest) { + switch (con_keydest) { case key_menu: Menu_Leave (); return; @@ -476,7 +477,7 @@ C_KeyEvent (knum_t key, short unicode, qboolean down) Menu_Enter (); return; default: - Sys_Error ("Bad key_dest"); + Sys_Error ("Bad con_keydest"); } } else if (key == key_toggleconsole) { ToggleConsole_f (); @@ -484,9 +485,9 @@ C_KeyEvent (knum_t key, short unicode, qboolean down) } } - if (key_dest == key_menu) { + if (con_keydest == key_menu) { return; - } else if (key_dest == key_message) { + } else if (con_keydest == key_message) { if (chat_team) { il = say_team_line; } else { @@ -570,7 +571,7 @@ C_DrawInputLine (inputline_t *il) static void draw_input (view_t *view) { - if (key_dest != key_console)// && !con_data.force_commandline) + if (con_keydest != key_console)// && !con_data.force_commandline) return; // don't draw anything (always draw if not active) DrawInputLine (view->xabs + 8, view->yabs, 1, input_line); @@ -725,7 +726,7 @@ setup_console (void) if (con_data.force_commandline) { lines = con_data.lines = r_data->vid->conheight; - } else if (key_dest == key_console) { + } else if (con_keydest == key_console) { lines = r_data->vid->conheight * bound (0.2, con_size->value, 1); } else { lines = 0; @@ -754,9 +755,9 @@ C_DrawConsole (void) if (console_view->ylen != con_data.lines) view_resize (console_view, console_view->xlen, con_data.lines); - say_view->visible = key_dest == key_message; + say_view->visible = con_keydest == key_message; console_view->visible = con_data.lines != 0; - menu_view->visible = key_dest == key_menu; + menu_view->visible = con_keydest == key_menu; con_data.view->draw (con_data.view); } @@ -796,6 +797,13 @@ exec_line (inputline_t *il) Con_ExecLine (il->line); } +static void +con_keydest_callback (keydest_t kd) +{ + // simply cache the value + con_keydest = kd; +} + static void C_Init (void) { @@ -805,6 +813,7 @@ C_Init (void) setlocale (LC_ALL, "C-TRADITIONAL"); #endif + Key_KeydestCallback (con_keydest_callback); Menu_Init (); con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL, diff --git a/libs/models/iqm/model_iqm.c b/libs/models/iqm/model_iqm.c index cbf56bc4e..6eabf7117 100644 --- a/libs/models/iqm/model_iqm.c +++ b/libs/models/iqm/model_iqm.c @@ -167,6 +167,7 @@ load_iqm_vertex_arrays (model_t *mod, const iqmheader *hdr, byte *buffer) for (i = 0; i < hdr->num_vertexarrays; i++) { va = vas + i; + Sys_MaskPrintf (SYS_MODEL, "%u %u %u %u %u %u\n", i, va->type, va->flags, va->format, va->size, va->offset); switch (va->type) { case IQM_POSITION: if (position) diff --git a/libs/video/targets/in_x11.c b/libs/video/targets/in_x11.c index 76eb9f048..dc689a7d5 100644 --- a/libs/video/targets/in_x11.c +++ b/libs/video/targets/in_x11.c @@ -597,7 +597,7 @@ XLateKey (XKeyEvent * ev, int *k, int *u) } static void -x11_keydest_callback (keydest_t key_dst) +x11_keydest_callback (keydest_t key_dest) { if (key_dest == key_game) { XAutoRepeatOff (x_disp); @@ -646,9 +646,9 @@ event_button (XEvent *event) static void event_focusout (XEvent *event) { + Key_FocusEvent (0); if (x_have_focus) { x_have_focus = false; - XAutoRepeatOn (x_disp); if (in_snd_block->int_val) { S_BlockSound (); CDAudio_Pause (); @@ -661,8 +661,7 @@ static void event_focusin (XEvent *event) { x_have_focus = true; - if (key_dest == key_game) - XAutoRepeatOff (x_disp); + Key_FocusEvent (1); if (in_snd_block->int_val) { S_UnblockSound (); CDAudio_Resume (); diff --git a/libs/video/targets/keys.c b/libs/video/targets/keys.c index 494f82c9c..91f9627cb 100644 --- a/libs/video/targets/keys.c +++ b/libs/video/targets/keys.c @@ -59,7 +59,7 @@ static U void (*const key_progs_init)(struct progs_s *) = Key_Progs_Init; /* key up events are sent even if in console mode */ -VISIBLE keydest_t key_dest = key_console; +VISIBLE keydest_t key_dest = key_unfocused; VISIBLE imt_t key_game_target = IMT_0; VISIBLE knum_t key_togglemenu = QFK_ESCAPE; VISIBLE knum_t key_toggleconsole = QFK_BACKQUOTE; @@ -464,6 +464,14 @@ keyname_t keynames[] = { {NULL, 0} }; +static void +Key_CallDestCallbacks (keydest_t kd) +{ + int i; + + for (i = 0; i < num_keydest_callbacks; i++) + keydest_callbacks[i] (kd); +} static void process_binding (knum_t key, const char *kb) @@ -949,6 +957,16 @@ Key_Event (knum_t key, short unicode, qboolean down) } } +VISIBLE void +Key_FocusEvent (int gain) +{ + if (gain) { + Key_CallDestCallbacks (key_dest); + } else { + Key_CallDestCallbacks (key_unfocused); + } +} + void Key_ClearStates (void) { @@ -1030,8 +1048,6 @@ Key_SetBinding (imt_t target, knum_t keynum, const char *binding) VISIBLE void Key_SetKeyDest(keydest_t kd) { - int i; - key_dest = kd; switch (key_dest) { default: @@ -1047,8 +1063,7 @@ Key_SetKeyDest(keydest_t kd) key_target = IMT_MENU; break; } - for (i = 0; i < num_keydest_callbacks; i++) - keydest_callbacks[i] (key_dest); + Key_CallDestCallbacks (key_dest); } VISIBLE void diff --git a/nq/include/host.h b/nq/include/host.h index 0963d6fcb..2e17ca341 100644 --- a/nq/include/host.h +++ b/nq/include/host.h @@ -51,6 +51,7 @@ extern int viewentity; extern qboolean host_initialized; // true if into command execution extern double host_frametime; extern int host_framecount; // incremented every frame, never reset +extern int host_in_game; // input focus goes to the game extern double realtime; // not bounded in any way, changed at // start of every frame, never reset diff --git a/nq/source/host.c b/nq/source/host.c index 2f614beab..f25562e2c 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -94,6 +94,7 @@ double oldcon_realtime; int host_framecount; int host_hunklevel; +int host_in_game; int minimum_memory; client_t *host_client; // current client @@ -562,7 +563,7 @@ Host_ServerFrame (void) // move things around and think // always pause in single player if in console or menus - if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game)) { + if (!sv.paused && (svs.maxclients > 1 || host_in_game)) { SV_Physics (); sv.time += host_frametime; } @@ -871,6 +872,12 @@ Host_Init_Memory (void) Sys_Printf ("%4.1f megabyte heap\n", host_mem_size->value); } +static void +host_keydest_callback (keydest_t kd) +{ + host_in_game = kd == key_game; +} + void Host_Init (void) { @@ -909,6 +916,8 @@ Host_Init (void) Mod_Init (); + Key_KeydestCallback (host_keydest_callback); + SV_Init (); if (cls.state != ca_dedicated) diff --git a/nq/source/host_cmd.c b/nq/source/host_cmd.c index 06acaa823..3327cb57f 100644 --- a/nq/source/host_cmd.c +++ b/nq/source/host_cmd.c @@ -62,10 +62,6 @@ int current_skill; void Host_Quit_f (void) { -// if (key_dest != key_console && cls.state != ca_dedicated) { -// M_Menu_Quit_f (); -// return; -// } if (!con_module) Sys_Printf ("I hope you wanted to quit\n"); CL_Disconnect (); diff --git a/nq/source/sbar.c b/nq/source/sbar.c index 339907876..e77ff103a 100644 --- a/nq/source/sbar.c +++ b/nq/source/sbar.c @@ -1253,10 +1253,6 @@ Sbar_FinaleOverlay (void) { int remaining; - //FIXME cleaner test - if (key_dest != key_game) - return; - r_data->scr_copyeverything = 1; draw_cachepic (overlay_view, 0, 16, "gfx/finale.lmp", 1); @@ -1274,10 +1270,6 @@ Sbar_DrawCenterPrint (void) if (centertime_off <= 0) return; - //FIXME cleaner test - if (key_dest != key_game) - return; - Sbar_DrawCenterString (overlay_view, -1); } @@ -1639,6 +1631,12 @@ Sbar_GIB_Print_Center_f (void) Sbar_CenterPrint (GIB_Argv(1)); } +static void +sbar_keydest_callback (keydest_t kd) +{ + overlay_view->visible = kd == key_game; +} + void Sbar_Init (void) { @@ -1646,6 +1644,8 @@ Sbar_Init (void) init_views (); + Key_KeydestCallback (sbar_keydest_callback); + for (i = 0; i < 10; i++) { sb_nums[0][i] = r_funcs->Draw_PicFromWad (va ("num_%i", i)); sb_nums[1][i] = r_funcs->Draw_PicFromWad (va ("anum_%i", i)); diff --git a/nq/source/sv_ded.c b/nq/source/sv_ded.c index b6b8072f6..37fd93f2b 100644 --- a/nq/source/sv_ded.c +++ b/nq/source/sv_ded.c @@ -30,6 +30,7 @@ #include "QF/cdaudio.h" #include "QF/cvar.h" +#include "QF/keys.h" #include "QF/plugin.h" #include "QF/screen.h" @@ -41,8 +42,6 @@ client_state_t cl; client_static_t cls; -keydest_t key_dest = key_game; - cvar_t *cl_name; cvar_t *cl_writecfg; cvar_t *demo_speed; @@ -54,6 +53,11 @@ int viewentity; vid_render_data_t *r_data; vid_render_funcs_t *r_funcs; +void +Key_KeydestCallback (keydest_callback_t *callback) +{ +} + void CL_SetState (cactive_t state) { diff --git a/nq/source/sv_user.c b/nq/source/sv_user.c index 5677171a4..c1db350a8 100644 --- a/nq/source/sv_user.c +++ b/nq/source/sv_user.c @@ -603,7 +603,7 @@ SV_RunClients (void) continue; } // always pause in single player if in console or menus - if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game)) + if (!sv.paused && (svs.maxclients > 1 || host_in_game)) SV_ClientThink (); } } diff --git a/qw/source/cl_chat.c b/qw/source/cl_chat.c index 795e56a4e..ac8826a9a 100644 --- a/qw/source/cl_chat.c +++ b/qw/source/cl_chat.c @@ -249,7 +249,8 @@ cl_chat_keydest (keydest_t keydest) break; case key_console: case key_menu: - CL_ChatInfo (2); // supposed to be for loss of focus... + case key_unfocused: + CL_ChatInfo (2); break; } } diff --git a/qw/source/sbar.c b/qw/source/sbar.c index d333de415..7234c7f51 100644 --- a/qw/source/sbar.c +++ b/qw/source/sbar.c @@ -115,8 +115,6 @@ static view_t *stuff_view; static view_t *main_view; static void (*Sbar_Draw_DMO_func) (view_t *view, int l, int y, int skip); -static void Sbar_TeamOverlay (view_t *view); -static void Sbar_DeathmatchOverlay (view_t *view, int start); static void hud_swap_f (cvar_t *var) @@ -892,65 +890,52 @@ draw_status (view_t *view) draw_num (view, 248, 0, cl.stats[STAT_AMMO], 3, cl.stats[STAT_AMMO] <= 10); } +/* + Sbar_DeathmatchOverlay + + ping time frags name +*/ static void -draw_overlay (view_t *view) +Sbar_DeathmatchOverlay (view_t *view, int start) { - // main screen deathmatch rankings - // if we're dead show team scores in team games - if (cl.stats[STAT_HEALTH] <= 0 && !cl.spectator) - if (cl.teamplay > 0 && !sb_showscores) - Sbar_TeamOverlay (view); - else - Sbar_DeathmatchOverlay (view, 0); - else if (sb_showscores) - Sbar_DeathmatchOverlay (view, 0); - else if (sb_showteamscores) - Sbar_TeamOverlay (view); -} + int l, y; + int skip = 10; -static void -sbar_update_vis (void) -{ - qboolean headsup; - - if (r_data->scr_copyeverything) - Sbar_Changed (); - - sbar_view->visible = 0; - - headsup = !(hud_sbar->int_val || r_data->scr_viewsize->int_val < 100); - - if ((sb_updates >= r_data->vid->numpages) && !headsup) + if (r_data->vid->conwidth < 244) // FIXME: magic number, gained through experimentation return; - if (con_module - && con_module->data->console->lines == r_data->vid->conheight) - return; // console is full screen + if (largegame) + skip = 8; - if (cls.state == ca_active - && ((cl.stats[STAT_HEALTH] <= 0 && !cl.spectator) - || sb_showscores || sb_showteamscores)) - overlay_view->visible = 1; - else - overlay_view->visible = 0; - - if (!sb_lines) - return; - - sbar_view->visible = 1; + // request new ping times every two second + if (realtime - cl.last_ping_request > 2.0) { + cl.last_ping_request = realtime; + if (!cls.demoplayback) { + MSG_WriteByte (&cls.netchan.message, clc_stringcmd); + SZ_Print (&cls.netchan.message, "pings"); + } + } r_data->scr_copyeverything = 1; - sb_updates++; + r_data->scr_fullupdate = 0; - if (sb_showscores || sb_showteamscores || cl.stats[STAT_HEALTH] <= 0) - sb_updates = 0; -} + if (!start) { + draw_cachepic (view, 0, 0, "gfx/ranking.lmp", 1); + y = 24; + } else + y = start; -void -Sbar_Draw (void) -{ - sbar_update_vis (); - main_view->draw (main_view); + // scores + Sbar_SortFrags (true); + + // draw the text + l = scoreboardlines; + + // func ptr, avoids absurd if testing + Sbar_Draw_DMO_func (view, l, y, skip); + + if (y >= view->ylen - 10) // we ran over the screen size, squish + largegame = true; } /* @@ -959,7 +944,7 @@ Sbar_Draw (void) team frags added by Zoid */ -void +static void Sbar_TeamOverlay (view_t *view) { char num[20]; @@ -1033,6 +1018,64 @@ Sbar_TeamOverlay (view_t *view) Sbar_DeathmatchOverlay (view, y); } +static void +draw_overlay (view_t *view) +{ + if (cls.state != ca_active + || !((cl.stats[STAT_HEALTH] <= 0 && !cl.spectator) + || sb_showscores || sb_showteamscores)) + return; + // main screen deathmatch rankings + // if we're dead show team scores in team games + if (cl.stats[STAT_HEALTH] <= 0 && !cl.spectator) + if (cl.teamplay > 0 && !sb_showscores) + Sbar_TeamOverlay (view); + else + Sbar_DeathmatchOverlay (view, 0); + else if (sb_showscores) + Sbar_DeathmatchOverlay (view, 0); + else if (sb_showteamscores) + Sbar_TeamOverlay (view); +} + +static void +sbar_update_vis (void) +{ + qboolean headsup; + + if (r_data->scr_copyeverything) + Sbar_Changed (); + + sbar_view->visible = 0; + + headsup = !(hud_sbar->int_val || r_data->scr_viewsize->int_val < 100); + + if ((sb_updates >= r_data->vid->numpages) && !headsup) + return; + + if (con_module + && con_module->data->console->lines == r_data->vid->conheight) + return; // console is full screen + + if (!sb_lines) + return; + + sbar_view->visible = 1; + + r_data->scr_copyeverything = 1; + sb_updates++; + + if (sb_showscores || sb_showteamscores || cl.stats[STAT_HEALTH] <= 0) + sb_updates = 0; +} + +void +Sbar_Draw (void) +{ + sbar_update_vis (); + main_view->draw (main_view); +} + /* Sbar_LogFrags @@ -1394,54 +1437,6 @@ Sbar_DMO_Init_f (cvar_t *var) Sbar_Draw_DMO_func = Sbar_Draw_DMO_Ping; } -/* - Sbar_DeathmatchOverlay - - ping time frags name -*/ -void -Sbar_DeathmatchOverlay (view_t *view, int start) -{ - int l, y; - int skip = 10; - - if (r_data->vid->conwidth < 244) // FIXME: magic number, gained through experimentation - return; - - if (largegame) - skip = 8; - - // request new ping times every two second - if (realtime - cl.last_ping_request > 2.0) { - cl.last_ping_request = realtime; - if (!cls.demoplayback) { - MSG_WriteByte (&cls.netchan.message, clc_stringcmd); - SZ_Print (&cls.netchan.message, "pings"); - } - } - - r_data->scr_copyeverything = 1; - r_data->scr_fullupdate = 0; - - if (!start) { - draw_cachepic (view, 0, 0, "gfx/ranking.lmp", 1); - y = 24; - } else - y = start; - - // scores - Sbar_SortFrags (true); - - // draw the text - l = scoreboardlines; - - // func ptr, avoids absurd if testing - Sbar_Draw_DMO_func (view, l, y, skip); - - if (y >= view->ylen - 10) // we ran over the screen size, squish - largegame = true; -} - /* draw_minifrags @@ -1719,10 +1714,6 @@ Sbar_FinaleOverlay (void) { int remaining; - //FIXME cleaner test - if (key_dest != key_game) - return; - r_data->scr_copyeverything = 1; draw_cachepic (overlay_view, 0, 16, "gfx/finale.lmp", 1); @@ -1740,10 +1731,6 @@ Sbar_DrawCenterPrint (void) if (centertime_off <= 0) return; - //FIXME cleaner test - if (key_dest != key_game) - return; - Sbar_DrawCenterString (overlay_view, -1); } @@ -1946,6 +1933,12 @@ Sbar_GIB_Print_Center_f (void) Sbar_CenterPrint (GIB_Argv(1)); } +static void +sbar_keydest_callback (keydest_t kd) +{ + overlay_view->visible = kd == key_game; +} + void Sbar_Init (void) { @@ -1953,6 +1946,8 @@ Sbar_Init (void) init_views (); + Key_KeydestCallback (sbar_keydest_callback); + for (i = 0; i < 10; i++) { sb_nums[0][i] = r_funcs->Draw_PicFromWad (va ("num_%i", i)); sb_nums[1][i] = r_funcs->Draw_PicFromWad (va ("anum_%i", i));