spingle/source/console.c

1314 lines
28 KiB
C
Raw Permalink Normal View History

2019-11-24 20:45:15 -08:00
/*
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2009 John Fitzgibbons and others
Copyright (C) 2010-2014 QuakeSpasm developers
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// console.c
2019-12-02 07:07:37 -08:00
#include "q_defs.h"
2019-11-24 20:45:15 -08:00
#include <sys/types.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
2019-12-02 04:24:20 -08:00
#if PLATFORM_IS(WINDOWS)
2019-11-24 20:45:15 -08:00
#include <io.h>
#else
#include <unistd.h>
#endif
2019-11-25 17:40:18 -08:00
int32_t con_linewidth;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
float con_cursorspeed = 4;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
#define CON_TEXTSIZE (1024 * 1024) //ericw -- was 65536. johnfitz -- new default size
#define CON_MINSIZE 16384 //johnfitz -- old default, now the minimum size
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
int32_t con_buffersize; //johnfitz -- user can now override default
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
bool con_forcedup; // because no entities to refresh
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
int32_t con_totallines; // total lines in console scrollback
int32_t con_backscroll; // lines up from bottom to display
int32_t con_current; // where next message will be printed
int32_t con_x; // offset in current line for next print
char *con_text = NULL;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
cvar_t con_notifytime = {"con_notifytime", "3", CVAR_NONE}; //seconds
cvar_t con_logcenterprint = {"con_logcenterprint", "1", CVAR_NONE}; //johnfitz
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
char con_lastcenterstring[1024]; //johnfitz
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
#define NUM_CON_TIMES 4
float con_times[NUM_CON_TIMES]; // realtime time the line was generated
// for transparent notify lines
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
int32_t con_vislines;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
bool con_debuglog = false;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
bool con_initialized;
2019-11-24 20:45:15 -08:00
/*
================
Con_Quakebar -- johnfitz -- returns a bar of the desired length, but never wider than the console
includes a newline, unless len >= con_linewidth.
================
*/
2019-11-25 17:40:18 -08:00
const char *Con_Quakebar(int32_t len)
2019-11-24 20:45:15 -08:00
{
static char bar[42];
2019-11-25 16:49:58 -08:00
int32_t i;
2019-11-24 20:45:15 -08:00
2019-11-25 16:49:58 -08:00
len = q_min(len, (int32_t)sizeof(bar) - 2);
2019-11-24 20:45:15 -08:00
len = q_min(len, con_linewidth);
bar[0] = '\35';
2019-11-25 17:40:18 -08:00
for(i = 1; i < len - 1; i++)
2019-11-24 20:45:15 -08:00
bar[i] = '\36';
2019-11-25 17:40:18 -08:00
bar[len - 1] = '\37';
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(len < con_linewidth)
2019-11-24 20:45:15 -08:00
{
bar[len] = '\n';
2019-11-25 17:40:18 -08:00
bar[len + 1] = 0;
2019-11-24 20:45:15 -08:00
}
else
bar[len] = 0;
return bar;
}
/*
================
Con_ToggleConsole_f
================
*/
2019-11-25 16:49:58 -08:00
extern int32_t history_line; //johnfitz
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
void Con_ToggleConsole_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(key_dest == key_console/* || (key_dest == key_game && con_forcedup)*/)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
key_lines[edit_line][1] = 0; // clear any typing
2019-11-24 20:45:15 -08:00
key_linepos = 1;
con_backscroll = 0; //johnfitz -- toggleconsole should return you to the bottom of the scrollback
history_line = edit_line; //johnfitz -- it should also return you to the bottom of the command history
2019-11-25 17:40:18 -08:00
if(cls.state == ca_connected)
2019-11-24 20:45:15 -08:00
{
IN_Activate();
key_dest = key_game;
}
else
{
2019-11-25 17:40:18 -08:00
M_Menu_Main_f();
2019-11-24 20:45:15 -08:00
}
}
else
{
IN_Deactivate(modestate == MS_WINDOWED);
key_dest = key_console;
}
2019-11-25 17:40:18 -08:00
SCR_EndLoadingPlaque();
memset(con_times, 0, sizeof(con_times));
2019-11-24 20:45:15 -08:00
}
/*
================
Con_Clear_f
================
*/
2019-11-25 17:40:18 -08:00
static void Con_Clear_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(con_text)
2019-12-07 09:27:26 -08:00
memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
2019-11-24 20:45:15 -08:00
con_backscroll = 0; //johnfitz -- if console is empty, being scrolled up is confusing
}
/*
================
Con_Dump_f -- johnfitz -- adapted from Q2 source
2019-11-24 20:45:15 -08:00
================
*/
2019-11-25 17:40:18 -08:00
static void Con_Dump_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t l, x;
const char *line;
FILE *f;
char buffer[1024];
char name[MAX_OSPATH];
q_snprintf(name, sizeof(name), "%s/condump.txt", com_gamedir);
COM_CreatePath(name);
f = fopen(name, "w");
if(!f)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("ERROR: couldn't open file %s.\n", name);
2019-11-24 20:45:15 -08:00
return;
}
// skip initial empty lines
2019-11-25 17:40:18 -08:00
for(l = con_current - con_totallines + 1; l <= con_current; l++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
line = con_text + (l % con_totallines) * con_linewidth;
for(x = 0; x < con_linewidth; x++)
if(line[x] != ' ')
2019-11-24 20:45:15 -08:00
break;
2019-11-25 17:40:18 -08:00
if(x != con_linewidth)
2019-11-24 20:45:15 -08:00
break;
}
// write the remaining lines
buffer[con_linewidth] = 0;
2019-11-25 17:40:18 -08:00
for(; l <= con_current; l++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
line = con_text + (l % con_totallines) * con_linewidth;
strncpy(buffer, line, con_linewidth);
for(x = con_linewidth - 1; x >= 0; x--)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(buffer[x] == ' ')
2019-11-24 20:45:15 -08:00
buffer[x] = 0;
else
break;
}
2019-11-25 17:40:18 -08:00
for(x = 0; buffer[x]; x++)
2019-11-24 20:45:15 -08:00
buffer[x] &= 0x7f;
2019-11-25 17:40:18 -08:00
fprintf(f, "%s\n", buffer);
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
fclose(f);
Con_Printf("Dumped console text to %s.\n", name);
2019-11-24 20:45:15 -08:00
}
/*
================
Con_ClearNotify
================
*/
2019-11-25 17:40:18 -08:00
void Con_ClearNotify(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(i = 0; i < NUM_CON_TIMES; i++)
2019-11-24 20:45:15 -08:00
con_times[i] = 0;
}
/*
================
Con_MessageMode_f
================
*/
2019-11-25 17:40:18 -08:00
static void Con_MessageMode_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cls.state != ca_connected || cls.demoplayback)
2019-11-24 20:45:15 -08:00
return;
chat_team = false;
key_dest = key_message;
}
/*
================
Con_MessageMode2_f
================
*/
2019-11-25 17:40:18 -08:00
static void Con_MessageMode2_f(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(cls.state != ca_connected || cls.demoplayback)
2019-11-24 20:45:15 -08:00
return;
chat_team = true;
key_dest = key_message;
}
/*
================
Con_CheckResize
If the line width has changed, reformat the buffer.
================
*/
2019-11-25 17:40:18 -08:00
void Con_CheckResize(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i, j, width, oldwidth, oldtotallines, numlines, numchars;
char *tbuf; //johnfitz -- tbuf no longer a static array
2019-11-25 16:49:58 -08:00
int32_t mark; //johnfitz
2019-11-24 20:45:15 -08:00
width = (vid.conwidth >> 3) - 2; //johnfitz -- use vid.conwidth instead of vid.width
2019-11-25 17:40:18 -08:00
if(width == con_linewidth)
2019-11-24 20:45:15 -08:00
return;
oldwidth = con_linewidth;
con_linewidth = width;
oldtotallines = con_totallines;
con_totallines = con_buffersize / con_linewidth; //johnfitz -- con_buffersize replaces CON_TEXTSIZE
numlines = oldtotallines;
2019-11-25 17:40:18 -08:00
if(con_totallines < numlines)
2019-11-24 20:45:15 -08:00
numlines = con_totallines;
numchars = oldwidth;
2019-11-25 17:40:18 -08:00
if(con_linewidth < numchars)
2019-11-24 20:45:15 -08:00
numchars = con_linewidth;
2019-11-25 17:40:18 -08:00
mark = Hunk_LowMark(); //johnfitz
tbuf = Hunk_AllocName(con_buffersize, __func__); //johnfitz
2019-11-24 20:45:15 -08:00
2019-12-07 09:27:26 -08:00
memcpy(tbuf, con_text, con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(i = 0; i < numlines; i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
for(j = 0; j < numchars; j++)
2019-11-24 20:45:15 -08:00
{
con_text[(con_totallines - 1 - i) * con_linewidth + j] =
2019-11-25 17:40:18 -08:00
tbuf[((con_current - i + oldtotallines) % oldtotallines) * oldwidth + j];
2019-11-24 20:45:15 -08:00
}
}
2019-11-25 17:40:18 -08:00
Hunk_FreeToLowMark(mark); //johnfitz
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
Con_ClearNotify();
2019-11-24 20:45:15 -08:00
con_backscroll = 0;
con_current = con_totallines - 1;
}
/*
================
Con_Init
================
*/
2019-11-25 17:40:18 -08:00
void Con_Init(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 16:49:58 -08:00
int32_t i;
2019-11-24 20:45:15 -08:00
//johnfitz -- user settable console buffer size
i = COM_CheckParm("-consize");
2019-11-25 17:40:18 -08:00
if(i && i < com_argc - 1)
2019-12-07 09:27:26 -08:00
con_buffersize = q_max(CON_MINSIZE, atoi(com_argv[i + 1]) * 1024);
2019-11-24 20:45:15 -08:00
else
con_buffersize = CON_TEXTSIZE;
//johnfitz
con_text = (char *)Hunk_AllocName(con_buffersize, "con_text"); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
2019-12-07 09:27:26 -08:00
memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
2019-11-24 20:45:15 -08:00
con_linewidth = -1;
//johnfitz -- no need to run Con_CheckResize here
con_linewidth = 38;
con_totallines = con_buffersize / con_linewidth;//johnfitz -- con_buffersize replaces CON_TEXTSIZE
con_backscroll = 0;
con_current = con_totallines - 1;
//johnfitz
2019-12-02 07:01:47 -08:00
Con_Printf("Console initialized\n");
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
Cvar_RegisterVariable(&con_notifytime);
Cvar_RegisterVariable(&con_logcenterprint); //johnfitz
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
Cmd_AddCommand("toggleconsole", Con_ToggleConsole_f);
Cmd_AddCommand("messagemode", Con_MessageMode_f);
Cmd_AddCommand("messagemode2", Con_MessageMode2_f);
Cmd_AddCommand("clear", Con_Clear_f);
Cmd_AddCommand("condump", Con_Dump_f); //johnfitz
2019-11-24 20:45:15 -08:00
con_initialized = true;
}
/*
===============
Con_Linefeed
===============
*/
2019-11-25 17:40:18 -08:00
static void Con_Linefeed(void)
2019-11-24 20:45:15 -08:00
{
//johnfitz -- improved scrolling
2019-11-25 17:40:18 -08:00
if(con_backscroll)
2019-11-24 20:45:15 -08:00
con_backscroll++;
2019-11-25 17:40:18 -08:00
if(con_backscroll > con_totallines - (glheight >> 3) - 1)
con_backscroll = con_totallines - (glheight >> 3) - 1;
2019-11-24 20:45:15 -08:00
//johnfitz
con_x = 0;
con_current++;
2019-12-07 09:27:26 -08:00
memset(&con_text[(con_current % con_totallines)*con_linewidth], ' ', con_linewidth);
2019-11-24 20:45:15 -08:00
}
/*
================
Con_Print
Handles cursor positioning, line wrapping, etc
All console printing must go through this in order to be logged to disk
If no console is visible, the notify window will pop up.
================
*/
2019-11-25 17:40:18 -08:00
static void Con_Print(const char *txt)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t y;
int32_t c, l;
static int32_t cr;
int32_t mask;
bool boundary;
2019-11-24 20:45:15 -08:00
//con_backscroll = 0; //johnfitz -- better console scrolling
2019-11-25 17:40:18 -08:00
if(txt[0] == 1)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
mask = 128; // go to colored text
S_LocalSound("misc/talk.wav"); // play talk wav
2019-11-24 20:45:15 -08:00
txt++;
}
2019-11-25 17:40:18 -08:00
else if(txt[0] == 2)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
mask = 128; // go to colored text
2019-11-24 20:45:15 -08:00
txt++;
}
else
mask = 0;
boundary = true;
2019-11-25 17:40:18 -08:00
while((c = *txt))
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(c <= ' ')
2019-11-24 20:45:15 -08:00
{
boundary = true;
}
2019-11-25 17:40:18 -08:00
else if(boundary)
2019-11-24 20:45:15 -08:00
{
// count word length
2019-11-25 17:40:18 -08:00
for(l = 0; l < con_linewidth; l++)
if(txt[l] <= ' ')
2019-11-24 20:45:15 -08:00
break;
// word wrap
2019-11-25 17:40:18 -08:00
if(l != con_linewidth && (con_x + l > con_linewidth))
2019-11-24 20:45:15 -08:00
con_x = 0;
boundary = false;
}
txt++;
2019-11-25 17:40:18 -08:00
if(cr)
2019-11-24 20:45:15 -08:00
{
con_current--;
cr = false;
}
2019-11-25 17:40:18 -08:00
if(!con_x)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Linefeed();
// mark time for transparent overlay
if(con_current >= 0)
2019-11-24 20:45:15 -08:00
con_times[con_current % NUM_CON_TIMES] = realtime;
}
2019-11-25 17:40:18 -08:00
switch(c)
2019-11-24 20:45:15 -08:00
{
case '\n':
con_x = 0;
break;
case '\r':
con_x = 0;
cr = 1;
break;
2019-11-25 17:40:18 -08:00
default: // display character and advance
2019-11-24 20:45:15 -08:00
y = con_current % con_totallines;
2019-11-25 17:40:18 -08:00
con_text[y * con_linewidth + con_x] = c | mask;
2019-11-24 20:45:15 -08:00
con_x++;
2019-11-25 17:40:18 -08:00
if(con_x >= con_linewidth)
2019-11-24 20:45:15 -08:00
con_x = 0;
break;
}
}
}
// borrowed from uhexen2 by S.A. for new procs, LOG_Init, LOG_Close
2019-11-25 17:40:18 -08:00
static char logfilename[MAX_OSPATH]; // current logfile name
static int32_t log_fd = -1; // log file descriptor
2019-11-24 20:45:15 -08:00
/*
================
Con_DebugLog
================
*/
void Con_DebugLog(const char *msg)
{
2019-11-25 17:40:18 -08:00
if(log_fd == -1)
2019-11-24 20:45:15 -08:00
return;
write(log_fd, msg, strlen(msg));
}
/*
================
Con_Printf
Handles cursor positioning, line wrapping, etc
================
*/
2019-11-25 17:40:18 -08:00
#define MAXPRINTMSG 4096
void Con_Printf(const char *fmt, ...)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
va_list argptr;
char msg[MAXPRINTMSG];
static bool inupdate;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
va_start(argptr, fmt);
q_vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr);
2019-11-24 20:45:15 -08:00
// also echo to debugging console
2019-11-25 17:40:18 -08:00
Sys_Printf("%s", msg);
2019-11-24 20:45:15 -08:00
// log all messages to file
2019-11-25 17:40:18 -08:00
if(con_debuglog)
2019-11-24 20:45:15 -08:00
Con_DebugLog(msg);
2019-11-25 17:40:18 -08:00
if(!con_initialized)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
if(cls.state == ca_dedicated)
return; // no graphics mode
2019-11-24 20:45:15 -08:00
// write it to the scrollable buffer
2019-11-25 17:40:18 -08:00
Con_Print(msg);
2019-11-24 20:45:15 -08:00
// update the screen if the console is displayed
2019-11-25 17:40:18 -08:00
if(cls.signon != SIGNONS && !scr_disabled_for_loading)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
// protect against infinite loop if something in SCR_UpdateScreen calls
// Con_Printd
if(!inupdate)
2019-11-24 20:45:15 -08:00
{
inupdate = true;
2019-11-25 17:40:18 -08:00
SCR_UpdateScreen();
2019-11-24 20:45:15 -08:00
inupdate = false;
}
}
}
/*
================
Con_DWarning -- ericw
2019-11-24 22:55:47 -08:00
2019-11-24 20:45:15 -08:00
same as Con_Warning, but only prints if "developer" cvar is set.
use for "exceeds standard limit of" messages, which are only relevant for developers
targetting vanilla engines
================
*/
2019-11-25 17:40:18 -08:00
void Con_DWarning(const char *fmt, ...)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
va_list argptr;
char msg[MAXPRINTMSG];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(!developer.value)
return; // don't confuse non-developers with techie stuff...
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
va_start(argptr, fmt);
q_vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
Con_SafePrintf("\x02Warning: ");
Con_Printf("%s", msg);
2019-11-24 20:45:15 -08:00
}
/*
================
Con_Warning -- johnfitz -- prints a warning to the console
================
*/
2019-11-25 17:40:18 -08:00
void Con_Warning(const char *fmt, ...)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
va_list argptr;
char msg[MAXPRINTMSG];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
va_start(argptr, fmt);
q_vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
Con_SafePrintf("\x02Warning: ");
Con_Printf("%s", msg);
2019-11-24 20:45:15 -08:00
}
/*
================
Con_DPrintf
A Con_Printf that only shows up if the "developer" cvar is set
================
*/
2019-11-25 17:40:18 -08:00
void Con_DPrintf(const char *fmt, ...)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
va_list argptr;
char msg[MAXPRINTMSG];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(!developer.value)
return; // don't confuse non-developers with techie stuff...
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
va_start(argptr, fmt);
q_vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
Con_SafePrintf("%s", msg); //johnfitz -- was Con_Printf
2019-11-24 20:45:15 -08:00
}
/*
================
Con_DPrintf2 -- johnfitz -- only prints if "developer" >= 2
currently not used
================
*/
2019-11-25 17:40:18 -08:00
void Con_DPrintf2(const char *fmt, ...)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
va_list argptr;
char msg[MAXPRINTMSG];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(developer.value >= 2)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
va_start(argptr, fmt);
q_vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr);
Con_Printf("%s", msg);
2019-11-24 20:45:15 -08:00
}
}
/*
==================
Con_SafePrintf
Okay to call even when the screen can't be updated
==================
*/
2019-11-25 17:40:18 -08:00
void Con_SafePrintf(const char *fmt, ...)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
va_list argptr;
char msg[1024];
int32_t temp;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
va_start(argptr, fmt);
q_vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr);
2019-11-24 20:45:15 -08:00
temp = scr_disabled_for_loading;
scr_disabled_for_loading = true;
2019-11-25 17:40:18 -08:00
Con_Printf("%s", msg);
2019-11-24 20:45:15 -08:00
scr_disabled_for_loading = temp;
}
/*
================
Con_CenterPrintf -- johnfitz -- pad each line with spaces to make it appear centered
================
*/
2019-11-25 17:40:18 -08:00
void Con_CenterPrintf(int32_t linewidth, const char *fmt, ...) FUNC_PRINTF(2, 3);
void Con_CenterPrintf(int32_t linewidth, const char *fmt, ...)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
va_list argptr;
char msg[MAXPRINTMSG]; //the original message
char line[MAXPRINTMSG]; //one line from the message
char spaces[21]; //buffer for spaces
char *src, *dst;
2019-12-07 09:27:26 -08:00
int32_t len, s;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
va_start(argptr, fmt);
q_vsnprintf(msg, sizeof(msg), fmt, argptr);
va_end(argptr);
2019-11-24 20:45:15 -08:00
linewidth = q_min(linewidth, con_linewidth);
2019-11-25 17:40:18 -08:00
for(src = msg; *src;)
2019-11-24 20:45:15 -08:00
{
dst = line;
2019-11-25 17:40:18 -08:00
while(*src && *src != '\n')
2019-11-24 20:45:15 -08:00
*dst++ = *src++;
*dst = 0;
2019-11-25 17:40:18 -08:00
if(*src == '\n')
2019-11-24 20:45:15 -08:00
src++;
len = strlen(line);
2019-11-25 17:40:18 -08:00
if(len < linewidth)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
s = (linewidth - len) / 2;
memset(spaces, ' ', s);
2019-11-24 20:45:15 -08:00
spaces[s] = 0;
2019-11-25 17:40:18 -08:00
Con_Printf("%s%s\n", spaces, line);
2019-11-24 20:45:15 -08:00
}
else
2019-11-25 17:40:18 -08:00
Con_Printf("%s\n", line);
2019-11-24 20:45:15 -08:00
}
}
/*
==================
Con_LogCenterPrint -- johnfitz -- echo centerprint message to the console
==================
*/
2019-11-25 17:40:18 -08:00
void Con_LogCenterPrint(const char *str)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!strcmp(str, con_lastcenterstring))
2019-11-24 20:45:15 -08:00
return; //ignore duplicates
2019-11-25 17:40:18 -08:00
if(cl.gametype == GAME_DEATHMATCH && con_logcenterprint.value != 2)
2019-11-24 20:45:15 -08:00
return; //don't log in deathmatch
strcpy(con_lastcenterstring, str);
2019-11-25 17:40:18 -08:00
if(con_logcenterprint.value)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Con_Printf("%s", Con_Quakebar(40));
Con_CenterPrintf(40, "%s\n", str);
Con_Printf("%s", Con_Quakebar(40));
Con_ClearNotify();
2019-11-24 20:45:15 -08:00
}
}
/*
==============================================================================
2019-11-25 17:40:18 -08:00
TAB COMPLETION
2019-11-24 20:45:15 -08:00
==============================================================================
*/
//johnfitz -- tab completion stuff
//unique defs
char key_tabpartial[MAXCMDLINE];
typedef struct tab_s
{
2019-11-25 17:40:18 -08:00
const char *name;
const char *type;
struct tab_s *next;
struct tab_s *prev;
2019-11-24 20:45:15 -08:00
} tab_t;
2019-11-25 17:40:18 -08:00
tab_t *tablist;
2019-11-24 20:45:15 -08:00
//defs from elsewhere
2019-11-25 17:40:18 -08:00
extern bool keydown[256];
2019-11-24 20:45:15 -08:00
typedef struct cmd_function_s
{
2019-11-25 17:40:18 -08:00
struct cmd_function_s *next;
const char *name;
xcommand_t function;
2019-11-24 20:45:15 -08:00
} cmd_function_t;
2019-11-25 17:40:18 -08:00
extern cmd_function_t *cmd_functions;
#define MAX_ALIAS_NAME 32
2019-11-24 20:45:15 -08:00
typedef struct cmdalias_s
{
2019-11-25 17:40:18 -08:00
struct cmdalias_s *next;
char name[MAX_ALIAS_NAME];
char *value;
2019-11-24 20:45:15 -08:00
} cmdalias_t;
2019-11-25 17:40:18 -08:00
extern cmdalias_t *cmd_alias;
2019-11-24 20:45:15 -08:00
/*
============
AddToTabList -- johnfitz
tablist is a doubly-linked loop, alphabetized by name
============
*/
// bash_partial is the string that can be expanded,
// aka Linux Bash shell. -- S.A.
2019-11-25 17:40:18 -08:00
static char bash_partial[80];
static bool bash_singlematch;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
void AddToTabList(const char *name, const char *type)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
tab_t *t, *insert;
char *i_bash;
2019-11-24 20:45:15 -08:00
const char *i_name;
2019-11-25 17:40:18 -08:00
if(!*bash_partial)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
strncpy(bash_partial, name, 79);
2019-11-24 20:45:15 -08:00
bash_partial[79] = '\0';
}
else
{
bash_singlematch = 0;
// find max common between bash_partial and name
i_bash = bash_partial;
i_name = name;
2019-11-25 17:40:18 -08:00
while(*i_bash && (*i_bash == *i_name))
2019-11-24 20:45:15 -08:00
{
i_bash++;
i_name++;
}
*i_bash = 0;
}
t = Hunk_AllocName(sizeof(tab_t), __func__);
2019-11-24 20:45:15 -08:00
t->name = name;
t->type = type;
2019-11-25 17:40:18 -08:00
if(!tablist) //create list
2019-11-24 20:45:15 -08:00
{
tablist = t;
t->next = t;
t->prev = t;
}
2019-11-25 17:40:18 -08:00
else if(strcmp(name, tablist->name) < 0) //insert at front
2019-11-24 20:45:15 -08:00
{
t->next = tablist;
t->prev = tablist->prev;
t->next->prev = t;
t->prev->next = t;
tablist = t;
}
else //insert later
{
insert = tablist;
do
{
2019-11-25 17:40:18 -08:00
if(strcmp(name, insert->name) < 0)
2019-11-24 20:45:15 -08:00
break;
insert = insert->next;
2019-11-25 17:40:18 -08:00
}
while(insert != tablist);
2019-11-24 20:45:15 -08:00
t->next = insert;
t->prev = insert->prev;
t->next->prev = t;
t->prev->next = t;
}
}
typedef struct arg_completion_type_s
{
2019-11-25 17:40:18 -08:00
const char *command;
filelist_item_t **filelist;
2019-11-24 20:45:15 -08:00
} arg_completion_type_t;
static const arg_completion_type_t arg_completion_types[] =
{
{ "map ", &extralevels },
{ "changelevel ", &extralevels },
{ "game ", &modlist },
{ "record ", &demolist },
{ "playdemo ", &demolist },
{ "timedemo ", &demolist }
};
2019-11-25 16:49:58 -08:00
static const int32_t num_arg_completion_types =
arraysizeof(arg_completion_types);
2019-11-24 20:45:15 -08:00
/*
============
FindCompletion -- stevenaaus
============
*/
2019-11-25 17:40:18 -08:00
const char *FindCompletion(const char *partial, filelist_item_t *filelist, int32_t *nummatches_out)
2019-11-24 20:45:15 -08:00
{
static char matched[32];
char *i_matched, *i_name;
2019-11-25 17:40:18 -08:00
filelist_item_t *file;
2019-12-07 09:27:26 -08:00
size_t init, match, plen;
2019-11-24 20:45:15 -08:00
memset(matched, 0, sizeof(matched));
plen = strlen(partial);
match = 0;
2019-11-25 17:40:18 -08:00
for(file = filelist, init = 0; file; file = file->next)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!strncmp(file->name, partial, plen))
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(init == 0)
2019-11-24 20:45:15 -08:00
{
init = 1;
strncpy(matched, file->name, strsizeof(matched));
matched[strsizeof(matched)] = '\0';
2019-11-24 20:45:15 -08:00
}
else
2019-11-25 17:40:18 -08:00
{
// find max common
2019-11-24 20:45:15 -08:00
i_matched = matched;
i_name = file->name;
2019-11-25 17:40:18 -08:00
while(*i_matched && (*i_matched == *i_name))
2019-11-24 20:45:15 -08:00
{
i_matched++;
i_name++;
}
*i_matched = 0;
}
match++;
}
}
*nummatches_out = match;
2019-11-25 17:40:18 -08:00
if(match > 1)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
for(file = filelist; file; file = file->next)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(!strncmp(file->name, partial, plen))
Con_SafePrintf(" %s\n", file->name);
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
Con_SafePrintf("\n");
2019-11-24 20:45:15 -08:00
}
return matched;
}
/*
============
BuildTabList -- johnfitz
============
*/
2019-11-25 17:40:18 -08:00
void BuildTabList(const char *partial)
2019-11-24 20:45:15 -08:00
{
2019-12-07 09:27:26 -08:00
cmdalias_t *alias;
cvar_t *cvar;
cmd_function_t *cmd;
size_t len;
2019-11-24 20:45:15 -08:00
tablist = NULL;
len = strlen(partial);
bash_partial[0] = 0;
bash_singlematch = 1;
2019-11-25 17:40:18 -08:00
cvar = Cvar_FindVarAfter("", CVAR_NONE);
for(; cvar ; cvar = cvar->next)
2019-12-07 09:27:26 -08:00
if(!strncmp(partial, cvar->name, len))
2019-11-25 17:40:18 -08:00
AddToTabList(cvar->name, "cvar");
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(cmd = cmd_functions ; cmd ; cmd = cmd->next)
2019-12-07 09:27:26 -08:00
if(!strncmp(partial, cmd->name, len))
2019-11-25 17:40:18 -08:00
AddToTabList(cmd->name, "command");
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(alias = cmd_alias ; alias ; alias = alias->next)
2019-12-07 09:27:26 -08:00
if(!strncmp(partial, alias->name, len))
2019-11-25 17:40:18 -08:00
AddToTabList(alias->name, "alias");
2019-11-24 20:45:15 -08:00
}
/*
============
Con_TabComplete -- johnfitz
============
*/
2019-11-25 17:40:18 -08:00
void Con_TabComplete(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
char partial[MAXCMDLINE];
const char *match;
static char *c;
tab_t *t;
int32_t mark, i, j;
2019-11-24 20:45:15 -08:00
// if editline is empty, return
2019-11-25 17:40:18 -08:00
if(key_lines[edit_line][1] == 0)
2019-11-24 20:45:15 -08:00
return;
// get partial string (space -> cursor)
2019-11-25 17:40:18 -08:00
if(!key_tabpartial[0]) //first time through, find new insert point. (Otherwise, use previous.)
2019-11-24 20:45:15 -08:00
{
//work back from cursor until you find a space, quote, semicolon, or prompt
c = key_lines[edit_line] + key_linepos - 1; //start one space left of cursor
2019-11-25 17:40:18 -08:00
while(*c != ' ' && *c != '\"' && *c != ';' && c != key_lines[edit_line])
2019-11-24 20:45:15 -08:00
c--;
c++; //start 1 char after the separator we just found
}
2019-11-25 17:40:18 -08:00
for(i = 0; c + i < key_lines[edit_line] + key_linepos; i++)
2019-11-24 20:45:15 -08:00
partial[i] = c[i];
partial[i] = 0;
// Map autocomplete function -- S.A
// Since we don't have argument completion, this hack will do for now...
2019-11-25 17:40:18 -08:00
for(j = 0; j < num_arg_completion_types; j++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
// arg_completion contains a command we can complete the arguments
// for (like "map ") and a list of all the maps.
2019-11-24 20:45:15 -08:00
arg_completion_type_t arg_completion = arg_completion_types[j];
const char *command_name = arg_completion.command;
2019-11-24 22:55:47 -08:00
2019-11-25 17:40:18 -08:00
if(!strncmp(key_lines[edit_line] + 1, command_name, strlen(command_name)))
2019-11-24 20:45:15 -08:00
{
2019-11-25 16:49:58 -08:00
int32_t nummatches = 0;
2019-11-24 20:45:15 -08:00
const char *matched_map = FindCompletion(partial, *arg_completion.filelist, &nummatches);
2019-11-25 17:40:18 -08:00
if(!*matched_map)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
q_strlcpy(partial, matched_map, MAXCMDLINE);
2019-11-24 20:45:15 -08:00
*c = '\0';
2019-11-25 17:40:18 -08:00
q_strlcat(key_lines[edit_line], partial, MAXCMDLINE);
2019-12-07 09:27:26 -08:00
key_linepos = c - key_lines[edit_line] + strlen(matched_map); //set new cursor position
2019-11-25 17:40:18 -08:00
if(key_linepos >= MAXCMDLINE)
2019-11-24 20:45:15 -08:00
key_linepos = MAXCMDLINE - 1;
// if only one match, append a space
2019-11-25 17:40:18 -08:00
if(key_linepos < MAXCMDLINE - 1 &&
key_lines[edit_line][key_linepos] == 0 && (nummatches == 1))
2019-11-24 20:45:15 -08:00
{
key_lines[edit_line][key_linepos] = ' ';
key_linepos++;
key_lines[edit_line][key_linepos] = 0;
}
c = key_lines[edit_line] + key_linepos;
return;
}
}
//if partial is empty, return
2019-11-25 17:40:18 -08:00
if(partial[0] == 0)
2019-11-24 20:45:15 -08:00
return;
//trim trailing space becuase it screws up string comparisons
2019-11-25 17:40:18 -08:00
if(i > 0 && partial[i - 1] == ' ')
partial[i - 1] = 0;
2019-11-24 20:45:15 -08:00
// find a match
mark = Hunk_LowMark();
2019-11-25 17:40:18 -08:00
if(!key_tabpartial[0]) //first time through
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
q_strlcpy(key_tabpartial, partial, MAXCMDLINE);
BuildTabList(key_tabpartial);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(!tablist)
2019-11-24 20:45:15 -08:00
return;
// print list if length > 1
2019-11-25 17:40:18 -08:00
if(tablist->next != tablist)
2019-11-24 20:45:15 -08:00
{
t = tablist;
Con_SafePrintf("\n");
do
{
Con_SafePrintf(" %s (%s)\n", t->name, t->type);
t = t->next;
2019-11-25 17:40:18 -08:00
}
while(t != tablist);
2019-11-24 20:45:15 -08:00
Con_SafePrintf("\n");
}
2019-11-25 17:40:18 -08:00
// match = tablist->name;
// First time, just show maximum matching chars -- S.A.
2019-11-24 20:45:15 -08:00
match = bash_partial;
}
else
{
2019-11-25 17:40:18 -08:00
BuildTabList(key_tabpartial);
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(!tablist)
2019-11-24 20:45:15 -08:00
return;
//find current match -- can't save a pointer because the list will be rebuilt each time
t = tablist;
match = keydown[K_SHIFT] ? t->prev->name : t->name;
do
{
2019-12-07 09:27:26 -08:00
if(!strcmp(t->name, partial))
2019-11-24 20:45:15 -08:00
{
match = keydown[K_SHIFT] ? t->prev->name : t->next->name;
break;
}
t = t->next;
2019-11-25 17:40:18 -08:00
}
while(t != tablist);
2019-11-24 20:45:15 -08:00
}
Hunk_FreeToLowMark(mark); //it's okay to free it here because match is a pointer to persistent data
// insert new match into edit line
2019-11-25 17:40:18 -08:00
q_strlcpy(partial, match, MAXCMDLINE); //first copy match string
q_strlcat(partial, key_lines[edit_line] + key_linepos, MAXCMDLINE); //then add chars after cursor
*c = '\0'; //now copy all of this into edit line
q_strlcat(key_lines[edit_line], partial, MAXCMDLINE);
2019-12-07 09:27:26 -08:00
key_linepos = c - key_lines[edit_line] + strlen(match); //set new cursor position
2019-11-25 17:40:18 -08:00
if(key_linepos >= MAXCMDLINE)
2019-11-24 20:45:15 -08:00
key_linepos = MAXCMDLINE - 1;
// if cursor is at end of string, let's append a space to make life easier
2019-11-25 17:40:18 -08:00
if(key_linepos < MAXCMDLINE - 1 &&
key_lines[edit_line][key_linepos] == 0 && bash_singlematch)
2019-11-24 20:45:15 -08:00
{
key_lines[edit_line][key_linepos] = ' ';
key_linepos++;
key_lines[edit_line][key_linepos] = 0;
2019-11-25 17:40:18 -08:00
// S.A.: the map argument completion (may be in combination with the bash-style
// display behavior changes, causes weirdness when completing the arguments for
// the changelevel command. the line below "fixes" it, although I'm not sure about
// the reason, yet, neither do I know any possible side effects of it:
2019-11-24 20:45:15 -08:00
c = key_lines[edit_line] + key_linepos;
}
}
/*
==============================================================================
DRAWING
==============================================================================
*/
/*
================
Con_DrawNotify
Draws the last few lines of output transparently over the game top
================
*/
2019-11-25 17:40:18 -08:00
void Con_DrawNotify(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i, x, v;
const char *text;
float time;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
GL_SetCanvas(CANVAS_CONSOLE); //johnfitz
2019-11-24 20:45:15 -08:00
v = vid.conheight; //johnfitz
2019-11-25 17:40:18 -08:00
for(i = con_current - NUM_CON_TIMES + 1; i <= con_current; i++)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(i < 0)
2019-11-24 20:45:15 -08:00
continue;
time = con_times[i % NUM_CON_TIMES];
2019-11-25 17:40:18 -08:00
if(time == 0)
2019-11-24 20:45:15 -08:00
continue;
time = realtime - time;
2019-11-25 17:40:18 -08:00
if(time > con_notifytime.value)
2019-11-24 20:45:15 -08:00
continue;
2019-11-25 17:40:18 -08:00
text = con_text + (i % con_totallines) * con_linewidth;
2019-11-24 20:45:15 -08:00
clearnotify = 0;
2019-11-25 17:40:18 -08:00
for(x = 0; x < con_linewidth; x++)
Draw_Character((x + 1) << 3, v, text[x]);
2019-11-24 20:45:15 -08:00
v += 8;
scr_tileclear_updates = 0; //johnfitz
}
2019-11-25 17:40:18 -08:00
if(key_dest == key_message)
2019-11-24 20:45:15 -08:00
{
clearnotify = 0;
2019-11-25 17:40:18 -08:00
if(chat_team)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Draw_String(8, v, "say_team:");
2019-11-24 20:45:15 -08:00
x = 11;
}
else
{
2019-11-25 17:40:18 -08:00
Draw_String(8, v, "say:");
2019-11-24 20:45:15 -08:00
x = 6;
}
text = Key_GetChatBuffer();
i = Key_GetChatMsgLen();
2019-11-25 17:40:18 -08:00
if(i > con_linewidth - x - 1)
2019-11-24 20:45:15 -08:00
text += i - con_linewidth + x + 1;
2019-11-25 17:40:18 -08:00
while(*text)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
Draw_Character(x << 3, v, *text);
2019-11-24 20:45:15 -08:00
x++;
text++;
}
2019-11-25 17:40:18 -08:00
Draw_Character(x << 3, v, 10 + ((int32_t)(realtime * con_cursorspeed) & 1));
2019-11-24 20:45:15 -08:00
v += 8;
scr_tileclear_updates = 0; //johnfitz
}
}
/*
================
Con_DrawInput -- johnfitz -- modified to allow insert editing
The input line scrolls horizontally if typing goes beyond the right edge
================
*/
2019-11-25 17:40:18 -08:00
extern qpic_t *pic_ovr, *pic_ins; //johnfitz -- new cursor handling
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
void Con_DrawInput(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
int32_t i, ofs;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(key_dest != key_console && !con_forcedup)
return; // don't draw anything
2019-11-24 20:45:15 -08:00
// prestep if horizontally scrolling
2019-11-25 17:40:18 -08:00
if(key_linepos >= con_linewidth)
2019-11-24 20:45:15 -08:00
ofs = 1 + key_linepos - con_linewidth;
else
ofs = 0;
// draw input string
2019-11-25 17:40:18 -08:00
for(i = 0; key_lines[edit_line][i + ofs] && i < con_linewidth; i++)
Draw_Character((i + 1) << 3, vid.conheight - 16, key_lines[edit_line][i + ofs]);
2019-11-24 20:45:15 -08:00
// johnfitz -- new cursor handling
2019-11-25 17:40:18 -08:00
if(!((int32_t)((realtime - key_blinktime)*con_cursorspeed) & 1))
2019-11-24 20:45:15 -08:00
{
i = key_linepos - ofs;
2019-11-25 17:40:18 -08:00
Draw_Pic((i + 1) << 3, vid.conheight - 16, key_insert ? pic_ins : pic_ovr);
2019-11-24 20:45:15 -08:00
}
}
/*
================
Con_DrawConsole -- johnfitz -- heavy revision
Draws the console with the solid background
The typing input line at the bottom should only be drawn if typing is allowed
================
*/
2019-11-25 17:40:18 -08:00
void Con_DrawConsole(int32_t lines, bool drawinput)
2019-11-24 20:45:15 -08:00
{
2019-12-02 07:01:47 -08:00
static char const ver[] = ENGINE_NAME " " VERSION;
2019-11-25 17:40:18 -08:00
int32_t i, x, y, j, sb, rows;
const char *text;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(lines <= 0)
2019-11-24 20:45:15 -08:00
return;
con_vislines = lines * vid.conheight / glheight;
2019-11-25 17:40:18 -08:00
GL_SetCanvas(CANVAS_CONSOLE);
2019-11-24 20:45:15 -08:00
// draw the background
2019-11-25 17:40:18 -08:00
Draw_ConsoleBackground();
2019-11-24 20:45:15 -08:00
// draw the buffer text
2019-11-25 17:40:18 -08:00
rows = (con_vislines + 7) / 8;
y = vid.conheight - rows * 8;
2019-11-24 20:45:15 -08:00
rows -= 2; //for input and version lines
sb = (con_backscroll) ? 2 : 0;
2019-11-25 17:40:18 -08:00
for(i = con_current - rows + 1; i <= con_current - sb; i++, y += 8)
2019-11-24 20:45:15 -08:00
{
j = i - con_backscroll;
2019-11-25 17:40:18 -08:00
if(j < 0)
2019-11-24 20:45:15 -08:00
j = 0;
2019-11-25 17:40:18 -08:00
text = con_text + (j % con_totallines) * con_linewidth;
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
for(x = 0; x < con_linewidth; x++)
Draw_Character((x + 1) << 3, y, text[x]);
2019-11-24 20:45:15 -08:00
}
// draw scrollback arrows
2019-11-25 17:40:18 -08:00
if(con_backscroll)
2019-11-24 20:45:15 -08:00
{
y += 8; // blank line
2019-11-25 17:40:18 -08:00
for(x = 0; x < con_linewidth; x += 4)
Draw_Character((x + 1) << 3, y, '^');
2019-11-24 20:45:15 -08:00
y += 8;
}
// draw the input prompt, user text, and cursor
2019-11-25 17:40:18 -08:00
if(drawinput)
Con_DrawInput();
2019-11-24 20:45:15 -08:00
//draw version number in bottom right
y += 8;
2019-12-02 07:01:47 -08:00
for(x = 0; x < (int32_t)strsizeof(ver); x++)
Draw_Character((con_linewidth - strsizeof(ver) + x + 2) << 3, y, ver[x] /*+ 128*/);
2019-11-24 20:45:15 -08:00
}
/*
==================
Con_NotifyBox
==================
*/
2019-11-25 17:40:18 -08:00
void Con_NotifyBox(const char *text)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
double t1, t2;
int32_t lastkey, lastchar;
2019-11-24 20:45:15 -08:00
// during startup for sound / cd warnings
2019-11-25 17:40:18 -08:00
Con_Printf("\n\n%s", Con_Quakebar(40)); //johnfitz
Con_Printf("%s", text);
Con_Printf("Press a key.\n");
Con_Printf("%s", Con_Quakebar(40)); //johnfitz
2019-11-24 20:45:15 -08:00
IN_Deactivate(modestate == MS_WINDOWED);
key_dest = key_console;
2019-11-25 17:40:18 -08:00
Key_BeginInputGrab();
2019-11-24 20:45:15 -08:00
do
{
2019-11-25 17:40:18 -08:00
t1 = Sys_DoubleTime();
SCR_UpdateScreen();
Sys_SendKeyEvents();
Key_GetGrabbedInput(&lastkey, &lastchar);
Sys_Sleep(16);
t2 = Sys_DoubleTime();
realtime += t2 - t1; // make the cursor blink
}
while(lastkey == -1 && lastchar == -1);
Key_EndInputGrab();
Con_Printf("\n");
2019-11-24 20:45:15 -08:00
IN_Activate();
key_dest = key_game;
2019-11-25 17:40:18 -08:00
realtime = 0; // put the cursor back to invisible
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
void LOG_Init(quakeparms_t *parms)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
time_t inittime;
char session[24];
2019-11-24 20:45:15 -08:00
2019-11-25 17:40:18 -08:00
if(!COM_CheckParm("-condebug"))
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
inittime = time(NULL);
2019-12-11 22:49:16 -08:00
strftime(session, sizeof(session), "%m/%u/%Y %H:%M:%S", localtime(&inittime));
2019-11-25 17:40:18 -08:00
q_snprintf(logfilename, sizeof(logfilename), "%s/qconsole.log", parms->basedir);
2019-11-24 20:45:15 -08:00
// unlink (logfilename);
2019-11-25 17:40:18 -08:00
log_fd = open(logfilename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if(log_fd == -1)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
fprintf(stderr, "Error: Unable to create log file %s\n", logfilename);
2019-11-24 20:45:15 -08:00
return;
}
con_debuglog = true;
2019-11-25 17:40:18 -08:00
Con_DebugLog(va("LOG started on: %s \n", session));
2019-11-24 20:45:15 -08:00
}
2019-11-25 17:40:18 -08:00
void LOG_Close(void)
2019-11-24 20:45:15 -08:00
{
2019-11-25 17:40:18 -08:00
if(log_fd == -1)
2019-11-24 20:45:15 -08:00
return;
2019-11-25 17:40:18 -08:00
close(log_fd);
2019-11-24 20:45:15 -08:00
log_fd = -1;
}