Make key_dest private to keys.c

This has the bonus feature of making nq pause the game when input focus is
lost (same conditions as dropping the console or bringing up the menu).
This commit is contained in:
Bill Currie 2013-01-16 13:18:54 +09:00
parent 5d8aab744f
commit ec6ba8a03c
13 changed files with 177 additions and 146 deletions

View file

@ -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);

View file

@ -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,

View file

@ -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)

View file

@ -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 ();

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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 ();

View file

@ -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));

View file

@ -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)
{

View file

@ -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 ();
}
}

View file

@ -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;
}
}

View file

@ -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));