2006-04-13 20:47:06 +00:00
// On-screen Display (ie. console)
// for the Build Engine
2012-03-12 04:47:04 +00:00
// by Jonathon Fowler (jf@jonof.id.au)
2006-04-13 20:47:06 +00:00
# include "build.h"
# include "osd.h"
# include "compat.h"
# include "baselayer.h"
2008-06-30 07:30:48 +00:00
# include "cache1d.h"
2008-07-20 05:31:23 +00:00
# include "pragmas.h"
2010-05-02 23:27:30 +00:00
# include "scancodes.h"
2010-05-09 22:12:29 +00:00
# include "crc32.h"
2014-03-22 09:26:39 +00:00
# include "xxhash.h"
2014-10-25 03:29:53 +00:00
# include "common.h"
2015-01-11 04:52:15 +00:00
# include "editor.h"
2013-12-24 09:44:24 +00:00
static symbol_t * symbols = NULL ;
2006-04-13 20:47:06 +00:00
static symbol_t * addnewsymbol ( const char * name ) ;
static symbol_t * findsymbol ( const char * name , symbol_t * startingat ) ;
static symbol_t * findexactsymbol ( const char * name ) ;
2009-01-09 09:29:17 +00:00
// static int32_t _validate_osdlines(void *);
static int32_t _internal_osdfunc_listsymbols ( const osdfuncparm_t * ) ;
static int32_t _internal_osdfunc_help ( const osdfuncparm_t * ) ;
static int32_t _internal_osdfunc_alias ( const osdfuncparm_t * ) ;
// static int32_t _internal_osdfunc_dumpbuildinfo(const osdfuncparm_t *);
// static int32_t _internal_osdfunc_setrendermode(const osdfuncparm_t *);
static int32_t white = - 1 ; // colour of white (used by default display routines)
static void _internal_drawosdchar ( int32_t , int32_t , char , int32_t , int32_t ) ;
2012-12-25 16:13:50 +00:00
static void _internal_drawosdstr ( int32_t , int32_t , const char * , int32_t , int32_t , int32_t ) ;
2009-01-09 09:29:17 +00:00
static void _internal_drawosdcursor ( int32_t , int32_t , int32_t , int32_t ) ;
static int32_t _internal_getcolumnwidth ( int32_t ) ;
static int32_t _internal_getrowheight ( int32_t ) ;
static void _internal_clearbackground ( int32_t , int32_t ) ;
static int32_t _internal_gettime ( void ) ;
static void _internal_onshowosd ( int32_t ) ;
2006-04-13 20:47:06 +00:00
2014-07-06 00:12:25 +00:00
osdmain_t * osd = NULL ;
2009-01-09 09:29:17 +00:00
static int32_t osdrowscur = - 1 ;
static int32_t osdscroll = 0 ;
static int32_t osdmaxrows = 20 ; // maximum number of lines which can fit on the screen
2014-12-17 13:02:21 +00:00
BFILE * osdlog ; // log filehandle
const char * osdlogfn ;
2009-01-09 09:29:17 +00:00
static int32_t keytime = 0 ;
static int32_t osdscrtime = 0 ;
2006-04-13 20:47:06 +00:00
2014-07-06 00:12:25 +00:00
# define editlinewidth (osd->draw.cols-1-3)
static hashtable_t h_osd = { OSDMAXSYMBOLS < < 1 , NULL } ;
2008-08-25 02:12:02 +00:00
2013-11-04 22:56:12 +00:00
// Application callbacks: these are the currently effective ones.
2009-01-09 09:29:17 +00:00
static void ( * drawosdchar ) ( int32_t , int32_t , char , int32_t , int32_t ) = _internal_drawosdchar ;
2012-12-25 16:13:50 +00:00
static void ( * drawosdstr ) ( int32_t , int32_t , const char * , int32_t , int32_t , int32_t ) = _internal_drawosdstr ;
2009-01-09 09:29:17 +00:00
static void ( * drawosdcursor ) ( int32_t , int32_t , int32_t , int32_t ) = _internal_drawosdcursor ;
static int32_t ( * getcolumnwidth ) ( int32_t ) = _internal_getcolumnwidth ;
static int32_t ( * getrowheight ) ( int32_t ) = _internal_getrowheight ;
2013-11-04 22:56:12 +00:00
2009-01-09 09:29:17 +00:00
static void ( * clearbackground ) ( int32_t , int32_t ) = _internal_clearbackground ;
static int32_t ( * gettime ) ( void ) = _internal_gettime ;
static void ( * onshowosd ) ( int32_t ) = _internal_onshowosd ;
2013-11-04 22:56:12 +00:00
// Application callbacks: these are the backed-up ones.
2009-01-09 09:29:17 +00:00
static void ( * _drawosdchar ) ( int32_t , int32_t , char , int32_t , int32_t ) = _internal_drawosdchar ;
2012-12-25 16:13:50 +00:00
static void ( * _drawosdstr ) ( int32_t , int32_t , const char * , int32_t , int32_t , int32_t ) = _internal_drawosdstr ;
2009-01-09 09:29:17 +00:00
static void ( * _drawosdcursor ) ( int32_t , int32_t , int32_t , int32_t ) = _internal_drawosdcursor ;
static int32_t ( * _getcolumnwidth ) ( int32_t ) = _internal_getcolumnwidth ;
static int32_t ( * _getrowheight ) ( int32_t ) = _internal_getrowheight ;
2008-07-20 05:31:23 +00:00
2014-07-06 00:12:25 +00:00
static hashtable_t h_cvars = { OSDMAXSYMBOLS < < 1 , NULL } ;
2010-05-22 23:41:18 +00:00
int32_t m32_osd_tryscript = 0 ; // whether to try executing m32script on unkown command in the osd
2009-04-29 06:20:07 +00:00
int32_t OSD_RegisterCvar ( const cvar_t * cvar )
{
2014-07-06 00:12:25 +00:00
if ( ! osd )
2010-05-02 23:27:30 +00:00
OSD_Init ( ) ;
2009-04-29 06:20:07 +00:00
2012-12-31 01:51:03 +00:00
if ( ! cvar - > name | | ! cvar - > name [ 0 ] | | ! cvar - > vptr )
2009-04-29 06:20:07 +00:00
{
2010-05-02 23:27:30 +00:00
OSD_Printf ( " OSD_RegisterCvar(): can't register null cvar \n " ) ;
2009-04-29 06:20:07 +00:00
return - 1 ;
}
// check for illegal characters in name
2015-07-08 03:34:37 +00:00
for ( const char * cp = cvar - > name ; * cp ; cp + + )
2009-04-29 06:20:07 +00:00
{
if ( ( cp = = cvar - > name ) & & ( * cp > = ' 0 ' ) & & ( * cp < = ' 9 ' ) )
{
OSD_Printf ( " OSD_RegisterCvar(): first character of cvar name \" %s \" must not be a numeral \n " , cvar - > name ) ;
return - 1 ;
}
if ( ( * cp < ' 0 ' ) | |
2009-04-30 01:07:08 +00:00
( * cp > ' 9 ' & & * cp < ' A ' ) | |
( * cp > ' Z ' & & * cp < ' a ' & & * cp ! = ' _ ' ) | |
( * cp > ' z ' ) )
2009-04-29 06:20:07 +00:00
{
OSD_Printf ( " OSD_RegisterCvar(): illegal character in cvar name \" %s \" \n " , cvar - > name ) ;
return - 1 ;
}
}
2014-07-06 00:12:25 +00:00
osd - > cvars = ( osdcvar_t * ) Xrealloc ( osd - > cvars , ( osd - > numcvars + 1 ) * sizeof ( osdcvar_t ) ) ;
2010-06-07 09:03:16 +00:00
2014-07-06 00:12:25 +00:00
hash_add ( & h_cvars , cvar - > name , osd - > numcvars , 1 ) ;
2010-06-07 09:03:16 +00:00
switch ( cvar - > type & ( CVAR_BOOL | CVAR_INT | CVAR_UINT | CVAR_FLOAT | CVAR_DOUBLE ) )
{
case CVAR_BOOL :
case CVAR_INT :
2014-07-06 00:12:25 +00:00
osd - > cvars [ osd - > numcvars ] . dval . i = * ( int32_t * ) cvar - > vptr ;
2010-06-07 09:03:16 +00:00
break ;
case CVAR_UINT :
2014-07-06 00:12:25 +00:00
osd - > cvars [ osd - > numcvars ] . dval . uint = * ( uint32_t * ) cvar - > vptr ;
2010-06-07 09:03:16 +00:00
break ;
case CVAR_FLOAT :
2014-07-06 00:12:25 +00:00
osd - > cvars [ osd - > numcvars ] . dval . f = * ( float * ) cvar - > vptr ;
2010-06-07 09:03:16 +00:00
break ;
case CVAR_DOUBLE :
2014-07-06 00:12:25 +00:00
osd - > cvars [ osd - > numcvars ] . dval . d = * ( double * ) cvar - > vptr ;
2010-06-07 09:03:16 +00:00
break ;
}
2011-01-16 02:50:27 +00:00
2014-07-06 00:12:25 +00:00
Bmemcpy ( & osd - > cvars [ osd - > numcvars + + ] , cvar , sizeof ( cvar_t ) ) ;
2009-04-29 06:20:07 +00:00
return 0 ;
}
2010-06-07 09:03:16 +00:00
static int32_t OSD_CvarModified ( const osdcvar_t * cvar )
{
2014-07-06 00:12:25 +00:00
if ( ! osd )
2010-06-07 09:03:16 +00:00
return 0 ;
2012-12-31 01:51:03 +00:00
if ( ! cvar - > c . vptr )
2010-06-07 09:03:16 +00:00
{
OSD_Printf ( " OSD_CvarModified(): null cvar?! \n " ) ;
return 0 ;
}
2015-03-24 00:39:52 +00:00
int rv = 0 ;
switch ( cvar - > c . type & ( CVAR_BOOL | CVAR_INT | CVAR_UINT | CVAR_FLOAT | CVAR_DOUBLE | CVAR_STRING ) )
2010-06-07 09:03:16 +00:00
{
case CVAR_BOOL :
case CVAR_INT :
2015-03-24 00:39:52 +00:00
rv = ( cvar - > dval . i ! = * ( int32_t * ) cvar - > c . vptr ) ; break ;
2010-06-07 09:03:16 +00:00
case CVAR_UINT :
2015-03-24 00:39:52 +00:00
rv = ( cvar - > dval . uint ! = * ( uint32_t * ) cvar - > c . vptr ) ; break ;
2010-06-07 09:03:16 +00:00
case CVAR_FLOAT :
2015-03-24 00:39:52 +00:00
rv = ( cvar - > dval . f ! = * ( float * ) cvar - > c . vptr ) ; break ;
2010-06-07 09:03:16 +00:00
case CVAR_DOUBLE :
2015-03-24 00:39:52 +00:00
rv = ( cvar - > dval . d ! = * ( double * ) cvar - > c . vptr ) ; break ;
case CVAR_STRING :
rv = 1 ; break ;
2010-06-07 09:03:16 +00:00
default :
2015-03-24 00:39:52 +00:00
EDUKE32_UNREACHABLE_SECTION ( break ) ;
2010-06-07 09:03:16 +00:00
}
2015-03-24 00:39:52 +00:00
return rv ;
2010-06-07 09:03:16 +00:00
}
2010-05-02 23:27:30 +00:00
// color code format is as follows:
// ^## sets a color, where ## is the palette number
// ^S# sets a shade, range is 0-7 equiv to shades 0-14
// ^O resets formatting to defaults
2011-01-16 02:50:27 +00:00
const char * OSD_StripColors ( char * out , const char * in )
2008-06-30 07:30:48 +00:00
{
2010-05-02 23:27:30 +00:00
const char * ptr = out ;
2008-06-30 07:30:48 +00:00
2013-05-04 16:36:13 +00:00
while ( * in )
2008-06-30 07:30:48 +00:00
{
2008-08-03 11:45:15 +00:00
if ( * in = = ' ^ ' & & isdigit ( * ( in + 1 ) ) )
2008-06-30 07:30:48 +00:00
{
2008-08-03 11:45:15 +00:00
in + = 2 ;
if ( isdigit ( * in ) )
in + + ;
2008-06-30 07:30:48 +00:00
continue ;
}
2008-08-03 11:45:15 +00:00
if ( * in = = ' ^ ' & & ( Btoupper ( * ( in + 1 ) ) = = ' S ' ) & & isdigit ( * ( in + 2 ) ) )
2008-07-19 07:39:51 +00:00
{
2008-08-03 11:45:15 +00:00
in + = 3 ;
2008-07-19 07:39:51 +00:00
continue ;
}
2008-08-03 11:45:15 +00:00
if ( * in = = ' ^ ' & & ( Btoupper ( * ( in + 1 ) ) = = ' O ' ) )
2008-07-19 00:50:20 +00:00
{
2008-08-03 11:45:15 +00:00
in + = 2 ;
2008-07-19 00:50:20 +00:00
continue ;
}
2010-06-07 09:03:16 +00:00
* ( out + + ) = * ( in + + ) ;
2008-08-24 06:17:09 +00:00
}
2008-08-24 05:39:28 +00:00
2008-08-03 11:45:15 +00:00
* out = ' \0 ' ;
2013-05-04 16:36:13 +00:00
return ptr ;
2008-06-30 07:30:48 +00:00
}
2009-01-09 09:29:17 +00:00
int32_t OSD_Exec ( const char * szScript )
2008-06-30 07:30:48 +00:00
{
2014-10-25 03:29:53 +00:00
int32_t i , len , err = 0 ;
2015-07-08 03:34:37 +00:00
char * buf = NULL ;
2014-10-25 03:29:53 +00:00
2016-01-12 10:31:19 +00:00
if ( ( i = kopen4load ( szScript , 0 ) ) = = - 1 )
err = 1 ;
else if ( ( len = kfilelength ( i ) ) < = 0 )
err = 2 ; // blank file
else if ( ( buf = ( char * ) Xmalloc ( len + 1 ) ) = = NULL )
err = 3 ;
2008-06-30 07:30:48 +00:00
2014-10-25 03:35:05 +00:00
if ( ! err | | err = = 3 )
OSD_Printf ( " Executing \" %s \" \n " , szScript ) ;
2014-10-25 03:29:53 +00:00
if ( err | | kread ( i , buf , len ) ! = len )
2008-06-30 07:30:48 +00:00
{
2014-10-25 03:35:05 +00:00
if ( ! err | | err = = 3 ) // no error message for blank file
2014-10-25 03:29:53 +00:00
OSD_Printf ( " Error executing \" %s \" ! \n " , szScript ) ;
if ( i ! = - 1 ) kclose ( i ) ;
2015-09-23 17:55:31 +00:00
Bfree ( buf ) ;
2014-10-25 03:29:53 +00:00
return 1 ;
}
2008-06-30 07:30:48 +00:00
2014-10-25 03:29:53 +00:00
osd - > execdepth + + ;
buf [ len ] = 0 ;
2015-07-08 03:34:37 +00:00
char * cp = strtok ( buf , " \r \n " ) ;
2014-10-25 03:29:53 +00:00
while ( cp ! = NULL )
{
OSD_Dispatch ( cp ) ;
cp = strtok ( NULL , " \r \n " ) ;
2008-06-30 07:30:48 +00:00
}
2014-10-25 03:29:53 +00:00
osd - > execdepth - - ;
kclose ( i ) ;
Bfree ( buf ) ;
return 0 ;
2008-06-30 07:30:48 +00:00
}
2009-01-09 09:29:17 +00:00
int32_t OSD_ParsingScript ( void )
2008-07-23 03:56:50 +00:00
{
2014-07-06 00:12:25 +00:00
return osd - > execdepth ;
2008-07-23 03:56:50 +00:00
}
2009-01-09 09:29:17 +00:00
int32_t OSD_OSDKey ( void )
2008-07-23 03:56:50 +00:00
{
2014-07-06 00:12:25 +00:00
return osd - > keycode ;
2008-07-23 03:56:50 +00:00
}
2009-01-09 09:29:17 +00:00
int32_t OSD_GetCols ( void )
2008-08-17 11:07:28 +00:00
{
2014-07-06 00:12:25 +00:00
return osd - > draw . cols ;
2008-08-17 11:07:28 +00:00
}
2010-05-18 05:14:17 +00:00
int32_t OSD_IsMoving ( void )
{
2014-07-06 00:12:25 +00:00
return ( osdrowscur ! = - 1 & & osdrowscur ! = osd - > draw . rows ) ;
2010-05-18 05:14:17 +00:00
}
2011-06-04 00:06:08 +00:00
int32_t OSD_GetRowsCur ( void )
{
return osdrowscur ;
}
2009-01-09 09:29:17 +00:00
int32_t OSD_GetTextMode ( void )
2008-07-23 03:56:50 +00:00
{
2014-07-06 00:12:25 +00:00
return osd - > draw . mode ;
2008-07-23 03:56:50 +00:00
}
2013-11-04 22:56:08 +00:00
void OSD_GetShadePal ( const char * ch , int32_t * shadeptr , int32_t * palptr )
{
2014-07-06 00:12:25 +00:00
// Use format buffer when 'ch' falls inside osd->text.buf[] bounds (well,
2013-11-04 22:56:08 +00:00
// almost).
// TODO: when is this false?
2014-07-06 00:12:25 +00:00
if ( ch > osd - > text . buf & & ch < osd - > text . buf + OSDBUFFERSIZE )
2013-11-04 22:56:08 +00:00
{
2014-07-06 00:12:25 +00:00
* shadeptr = ( osd - > text . fmt [ ch - osd - > text . buf ] & ~ 0x1F ) > > 4 ;
* palptr = osd - > text . fmt [ ch - osd - > text . buf ] & ~ 0xE0 ;
2013-11-04 22:56:08 +00:00
}
}
2013-11-04 22:56:12 +00:00
// XXX: well, converting function pointers to "data pointers" (void *) is
// undefined behavior. See
// http://blog.frama-c.com/index.php?post/2013/08/24/Function-pointers-in-C
// Then again, my GCC just crashed (any kept on crashing until after a reboot!)
// when I tried to rewrite this into something different.
2012-12-25 16:13:50 +00:00
2014-07-06 00:12:25 +00:00
static inline void swaposdptrs ( void )
{
swapptr ( & _drawosdchar , & drawosdchar ) ;
swapptr ( & _drawosdstr , & drawosdstr ) ;
swapptr ( & _drawosdcursor , & drawosdcursor ) ;
swapptr ( & _getcolumnwidth , & getcolumnwidth ) ;
swapptr ( & _getrowheight , & getrowheight ) ;
}
2009-01-09 09:29:17 +00:00
void OSD_SetTextMode ( int32_t mode )
2008-07-23 03:56:50 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > draw . mode = ( mode ! = 0 ) ;
2013-05-30 09:13:32 +00:00
2015-07-08 03:34:37 +00:00
if ( ( osd - > draw . mode & & drawosdchar ! = _internal_drawosdchar ) | |
( ! osd - > draw . mode & & drawosdchar = = _internal_drawosdchar ) )
2014-07-06 00:12:25 +00:00
swaposdptrs ( ) ;
2013-05-30 09:13:32 +00:00
if ( in3dmode ( ) )
2008-07-23 03:56:50 +00:00
OSD_ResizeDisplay ( xdim , ydim ) ;
}
2009-01-09 09:29:17 +00:00
static int32_t _internal_osdfunc_exec ( const osdfuncparm_t * parm )
2008-06-30 07:30:48 +00:00
{
2015-07-08 03:34:37 +00:00
if ( parm - > numparms ! = 1 )
return OSDCMD_SHOWHELP ;
2008-06-30 07:30:48 +00:00
char fn [ BMAX_PATH ] ;
Bstrcpy ( fn , parm - > parms [ 0 ] ) ;
if ( OSD_Exec ( fn ) )
2008-07-27 01:22:17 +00:00
OSD_Printf ( OSD_ERROR " exec: file \" %s \" not found. \n " , fn ) ;
2015-07-08 03:34:37 +00:00
2008-06-30 07:30:48 +00:00
return OSDCMD_OK ;
}
2010-05-09 22:12:29 +00:00
static int32_t _internal_osdfunc_echo ( const osdfuncparm_t * parm )
{
2014-10-25 03:29:53 +00:00
OSD_Printf ( " %s \n " , parm - > raw + 5 ) ;
2010-05-09 22:12:29 +00:00
return OSDCMD_OK ;
}
static int32_t _internal_osdfunc_fileinfo ( const osdfuncparm_t * parm )
{
int32_t i , j ;
if ( parm - > numparms ! = 1 ) return OSDCMD_SHOWHELP ;
2016-01-11 05:05:38 +00:00
if ( ( i = kopen4load ( parm - > parms [ 0 ] , 0 ) ) < 0 )
2010-05-09 22:12:29 +00:00
{
OSD_Printf ( " fileinfo: File \" %s \" not found. \n " , parm - > parms [ 0 ] ) ;
return OSDCMD_OK ;
}
2015-07-08 03:34:37 +00:00
char buf [ 256 ] ;
uint32_t length = kfilelength ( i ) ;
int32_t crctime = getticks ( ) ;
uint32_t crc = 0 ;
2010-05-09 22:12:29 +00:00
do
{
j = kread ( i , buf , 256 ) ;
2014-10-01 17:09:54 +00:00
crc = Bcrc32 ( ( uint8_t * ) buf , j , crc ) ;
2010-05-09 22:12:29 +00:00
}
while ( j = = 256 ) ;
2014-03-22 09:26:39 +00:00
crctime = getticks ( ) - crctime ;
klseek ( i , 0 , BSEEK_SET ) ;
2015-07-08 03:34:37 +00:00
int32_t xxhtime = getticks ( ) ;
2016-01-11 05:05:47 +00:00
XXH32_CREATESTATE_STATIC ( xxh ) ;
XXH32_reset ( xxh , 0x1337 ) ;
2014-03-22 09:26:39 +00:00
do
{
j = kread ( i , buf , 256 ) ;
XXH32_update ( xxh , ( uint8_t * ) buf , j ) ;
}
while ( j = = 256 ) ;
2015-07-08 03:34:37 +00:00
uint32_t xxhash = XXH32_digest ( xxh ) ;
2014-03-22 09:26:39 +00:00
xxhtime = getticks ( ) - xxhtime ;
2010-05-09 22:12:29 +00:00
kclose ( i ) ;
OSD_Printf ( " fileinfo: %s \n "
2011-01-16 02:50:27 +00:00
" File size: %d \n "
2014-03-22 09:26:39 +00:00
" CRC-32: %08X (%g sec) \n "
" xxHash: %08X (%g sec) \n " ,
parm - > parms [ 0 ] , length ,
crc , ( double ) crctime / gettimerfreq ( ) ,
xxhash , ( double ) xxhtime / gettimerfreq ( ) ) ;
2010-05-09 22:12:29 +00:00
return OSDCMD_OK ;
}
2009-01-09 09:29:17 +00:00
static void _internal_drawosdchar ( int32_t x , int32_t y , char ch , int32_t shade , int32_t pal )
2006-04-13 20:47:06 +00:00
{
2008-03-23 00:06:42 +00:00
UNREFERENCED_PARAMETER ( shade ) ;
UNREFERENCED_PARAMETER ( pal ) ;
2015-07-08 03:34:37 +00:00
char st [ 2 ] = { ch , 0 } ;
2006-04-24 19:04:22 +00:00
printext256 ( 4 + ( x < < 3 ) , 4 + ( y < < 3 ) , white , - 1 , st , 0 ) ;
2006-04-13 20:47:06 +00:00
}
2012-12-25 16:13:50 +00:00
static void _internal_drawosdstr ( int32_t x , int32_t y , const char * ch , int32_t len , int32_t shade , int32_t pal )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
char st [ 1024 ] ;
2008-03-23 00:06:42 +00:00
UNREFERENCED_PARAMETER ( shade ) ;
2006-04-24 19:04:22 +00:00
if ( len > 1023 ) len = 1023 ;
2009-06-09 06:19:58 +00:00
Bmemcpy ( st , ch , len ) ;
2006-04-24 19:04:22 +00:00
st [ len ] = 0 ;
2013-11-04 22:56:09 +00:00
OSD_GetShadePal ( ch , & shade , & pal ) ;
{
int32_t colidx = white > = 0 ? palookup [ ( uint8_t ) pal ] [ white ] : white ;
printext256 ( 4 + ( x < < 3 ) , 4 + ( y < < 3 ) , colidx , - 1 , st , 0 ) ;
}
2006-04-13 20:47:06 +00:00
}
2009-01-09 09:29:17 +00:00
static void _internal_drawosdcursor ( int32_t x , int32_t y , int32_t type , int32_t lastkeypress )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
char st [ 2 ] = { ' _ ' , 0 } ;
2008-03-23 00:06:42 +00:00
UNREFERENCED_PARAMETER ( lastkeypress ) ;
2006-04-24 19:04:22 +00:00
if ( type ) st [ 0 ] = ' # ' ;
2010-05-02 23:27:30 +00:00
if ( white > - 1 )
{
printext256 ( 4 + ( x < < 3 ) , 4 + ( y < < 3 ) + 2 , white , - 1 , st , 0 ) ;
return ;
}
2007-12-12 17:42:14 +00:00
{
2013-11-04 22:56:09 +00:00
int32_t i , k ;
// Find the palette index closest to Duke3D's brightest blue
// "foreground" color. (Index 79, or the last column of the 5th row,
// if the palette is laid out in a 16x16 pattern.)
k = INT32_MAX ;
2009-02-19 16:47:54 +00:00
for ( i = 0 ; i < 256 ; i + + )
2006-04-24 19:04:22 +00:00
{
2013-11-04 22:56:09 +00:00
int32_t j =
klabs ( curpalette [ i ] . r - 4 * 47 ) +
klabs ( curpalette [ i ] . g - 4 * 55 ) +
klabs ( curpalette [ i ] . b - 4 * 63 ) ;
if ( j < k ) { k = j ; white = i ; }
2006-04-24 19:04:22 +00:00
}
}
2006-04-13 20:47:06 +00:00
}
2009-01-09 09:29:17 +00:00
static int32_t _internal_getcolumnwidth ( int32_t w )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
return w / 8 - 1 ;
2006-04-13 20:47:06 +00:00
}
2009-01-09 09:29:17 +00:00
static int32_t _internal_getrowheight ( int32_t w )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
return w / 8 ;
2006-04-13 20:47:06 +00:00
}
2009-01-09 09:29:17 +00:00
static void _internal_clearbackground ( int32_t cols , int32_t rows )
2006-04-13 20:47:06 +00:00
{
2008-03-23 00:06:42 +00:00
UNREFERENCED_PARAMETER ( cols ) ;
UNREFERENCED_PARAMETER ( rows ) ;
2006-04-13 20:47:06 +00:00
}
2009-01-09 09:29:17 +00:00
static int32_t _internal_gettime ( void )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
return 0 ;
2006-04-13 20:47:06 +00:00
}
2009-01-09 09:29:17 +00:00
static void _internal_onshowosd ( int32_t a )
2006-04-13 20:47:06 +00:00
{
2008-03-23 00:06:42 +00:00
UNREFERENCED_PARAMETER ( a ) ;
2006-04-13 20:47:06 +00:00
}
////////////////////////////
2009-01-09 09:29:17 +00:00
static int32_t _internal_osdfunc_alias ( const osdfuncparm_t * parm )
2008-06-29 22:37:30 +00:00
{
symbol_t * i ;
if ( parm - > numparms < 1 )
{
2009-01-09 09:29:17 +00:00
int32_t j = 0 ;
2008-06-29 22:37:30 +00:00
OSD_Printf ( " Alias listing: \n " ) ;
for ( i = symbols ; i ! = NULL ; i = i - > next )
2010-05-02 23:27:30 +00:00
if ( i - > func = = OSD_ALIAS )
2008-07-02 22:45:04 +00:00
{
j + + ;
2008-06-30 07:30:48 +00:00
OSD_Printf ( " %s \" %s \" \n " , i - > name , i - > help ) ;
2008-07-02 22:45:04 +00:00
}
if ( j = = 0 )
OSD_Printf ( " No aliases found. \n " ) ;
2008-06-29 22:37:30 +00:00
return OSDCMD_OK ;
}
2008-06-30 00:18:59 +00:00
for ( i = symbols ; i ! = NULL ; i = i - > next )
2008-06-29 22:37:30 +00:00
{
2008-06-30 00:32:05 +00:00
if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , i - > name ) )
2008-06-30 00:18:59 +00:00
{
2008-06-30 00:32:05 +00:00
if ( parm - > numparms < 2 )
2008-06-30 00:18:59 +00:00
{
2010-05-02 23:27:30 +00:00
if ( i - > func = = OSD_ALIAS )
2008-06-30 00:18:59 +00:00
OSD_Printf ( " alias %s \" %s \" \n " , i - > name , i - > help ) ;
else OSD_Printf ( " %s is a function, not an alias \n " , i - > name ) ;
2008-06-30 00:32:05 +00:00
return OSDCMD_OK ;
}
2011-04-07 01:16:29 +00:00
2010-05-02 23:27:30 +00:00
if ( i - > func ! = OSD_ALIAS & & i - > func ! = OSD_UNALIASED )
2008-06-30 00:32:05 +00:00
{
OSD_Printf ( " Cannot override function \" %s \" with alias \n " , i - > name ) ;
return OSDCMD_OK ;
2008-06-30 00:18:59 +00:00
}
}
2008-06-29 22:37:30 +00:00
}
2014-05-30 00:02:19 +00:00
OSD_RegisterFunction ( Xstrdup ( parm - > parms [ 0 ] ) , Xstrdup ( parm - > parms [ 1 ] ) , OSD_ALIAS ) ;
2014-07-06 00:12:25 +00:00
if ( ! osd - > execdepth )
2008-06-30 07:30:48 +00:00
OSD_Printf ( " %s \n " , parm - > raw ) ;
2014-07-06 00:12:25 +00:00
2008-06-29 22:37:30 +00:00
return OSDCMD_OK ;
}
2009-01-09 09:29:17 +00:00
static int32_t _internal_osdfunc_unalias ( const osdfuncparm_t * parm )
2008-06-30 01:03:51 +00:00
{
symbol_t * i ;
if ( parm - > numparms < 1 )
return OSDCMD_SHOWHELP ;
for ( i = symbols ; i ! = NULL ; i = i - > next )
{
if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , i - > name ) )
{
if ( parm - > numparms < 2 )
{
2010-05-02 23:27:30 +00:00
if ( i - > func = = OSD_ALIAS )
2008-06-30 01:03:51 +00:00
{
2008-06-30 07:30:48 +00:00
OSD_Printf ( " Removed alias %s ( \" %s \" ) \n " , i - > name , i - > help ) ;
2010-05-02 23:27:30 +00:00
i - > func = OSD_UNALIASED ;
2008-06-30 01:03:51 +00:00
}
else OSD_Printf ( " Invalid alias %s \n " , i - > name ) ;
return OSDCMD_OK ;
}
}
}
OSD_Printf ( " Invalid alias %s \n " , parm - > parms [ 0 ] ) ;
return OSDCMD_OK ;
}
2009-01-09 09:29:17 +00:00
static int32_t _internal_osdfunc_listsymbols ( const osdfuncparm_t * parm )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
symbol_t * i ;
2009-01-09 09:29:17 +00:00
int32_t maxwidth = 0 ;
2006-04-13 20:47:06 +00:00
2013-08-06 23:53:12 +00:00
if ( parm - > numparms > 1 )
return OSDCMD_SHOWHELP ;
2008-03-23 00:06:42 +00:00
2006-04-24 19:04:22 +00:00
for ( i = symbols ; i ! = NULL ; i = i - > next )
2010-05-02 23:27:30 +00:00
if ( i - > func ! = OSD_UNALIASED )
2008-06-30 07:30:48 +00:00
maxwidth = max ( ( unsigned ) maxwidth , Bstrlen ( i - > name ) ) ;
if ( maxwidth > 0 )
{
2009-01-09 09:29:17 +00:00
int32_t x = 0 , count = 0 ;
2008-06-30 07:30:48 +00:00
maxwidth + = 3 ;
2013-08-06 23:53:12 +00:00
if ( parm - > numparms > 0 )
OSD_Printf ( OSDTEXT_RED " Symbol listing for %s: \n " , parm - > parms [ 0 ] ) ;
else
OSD_Printf ( OSDTEXT_RED " Symbol listing: \n " ) ;
2008-06-30 07:30:48 +00:00
for ( i = symbols ; i ! = NULL ; i = i - > next )
{
2013-08-06 23:53:12 +00:00
if ( i - > func = = OSD_UNALIASED | | ( parm - > numparms = = 1 & & Bstrncmp ( parm - > parms [ 0 ] , i - > name , Bstrlen ( parm - > parms [ 0 ] ) ) ) )
2011-04-07 01:16:29 +00:00
continue ;
2008-06-30 07:30:48 +00:00
{
2010-06-07 09:03:16 +00:00
int32_t j = hash_find ( & h_cvars , i - > name ) ;
2014-07-06 00:12:25 +00:00
if ( j ! = - 1 & & OSD_CvarModified ( & osd - > cvars [ j ] ) )
2010-06-07 09:03:16 +00:00
{
OSD_Printf ( OSDTEXT_RED " * " ) ;
OSD_Printf ( " %-*s " , maxwidth - 1 , i - > name ) ;
}
else OSD_Printf ( " %-*s " , maxwidth , i - > name ) ;
2008-06-30 07:30:48 +00:00
x + = maxwidth ;
2008-07-30 05:41:03 +00:00
count + + ;
2008-06-30 07:30:48 +00:00
}
2011-04-07 01:16:29 +00:00
2014-07-06 00:12:25 +00:00
if ( x > osd - > draw . cols - maxwidth )
2008-06-30 07:30:48 +00:00
{
x = 0 ;
OSD_Printf ( " \n " ) ;
}
}
2008-07-30 05:41:03 +00:00
if ( x ) OSD_Printf ( " \n " ) ;
OSD_Printf ( OSDTEXT_RED " Found %d symbols \n " , count ) ;
2008-06-30 07:30:48 +00:00
}
2006-04-24 19:04:22 +00:00
return OSDCMD_OK ;
2006-04-13 20:47:06 +00:00
}
2009-01-09 09:29:17 +00:00
static int32_t _internal_osdfunc_help ( const osdfuncparm_t * parm )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
symbol_t * symb ;
2014-07-06 00:12:25 +00:00
if ( parm - > numparms ! = 1 )
return OSDCMD_SHOWHELP ;
2006-04-24 19:04:22 +00:00
symb = findexactsymbol ( parm - > parms [ 0 ] ) ;
2014-07-06 00:12:25 +00:00
2007-12-12 17:42:14 +00:00
if ( ! symb )
2011-01-16 02:50:27 +00:00
OSD_Printf ( " Error: no help for undefined symbol \" %s \" \n " , parm - > parms [ 0 ] ) ;
2007-12-12 17:42:14 +00:00
else
2006-04-24 19:04:22 +00:00
OSD_Printf ( " %s \n " , symb - > help ) ;
return OSDCMD_OK ;
2006-04-13 20:47:06 +00:00
}
2009-01-09 09:29:17 +00:00
static int32_t _internal_osdfunc_clear ( const osdfuncparm_t * parm )
2007-01-04 07:15:17 +00:00
{
2014-07-06 00:12:25 +00:00
osdtext_t * t = & osd - > text ;
2008-03-23 00:06:42 +00:00
UNREFERENCED_PARAMETER ( parm ) ;
2014-07-06 00:12:25 +00:00
Bmemset ( t - > buf , 0 , OSDBUFFERSIZE ) ;
Bmemset ( t - > fmt , osd - > draw . textpal + ( osd - > draw . textshade < < 5 ) , OSDBUFFERSIZE ) ;
t - > lines = 1 ;
2007-01-04 07:15:17 +00:00
return OSDCMD_OK ;
}
2006-04-13 20:47:06 +00:00
2009-01-09 09:29:17 +00:00
static int32_t _internal_osdfunc_history ( const osdfuncparm_t * parm )
2008-07-07 12:17:27 +00:00
{
2015-07-08 03:34:37 +00:00
int32_t j = 0 ;
2014-07-06 00:12:25 +00:00
osdhist_t * h = & osd - > history ;
2008-07-07 12:17:27 +00:00
UNREFERENCED_PARAMETER ( parm ) ;
2014-07-06 00:12:25 +00:00
2008-08-18 07:20:36 +00:00
OSD_Printf ( OSDTEXT_RED " Command history: \n " ) ;
2014-07-06 00:12:25 +00:00
2016-08-27 01:41:21 +00:00
for ( bssize_t i = osd - > history . maxlines - 1 ; i > = 0 ; i - - )
2014-07-06 00:12:25 +00:00
if ( h - > buf [ i ] )
OSD_Printf ( " %4d \" %s \" \n " , h - > total - h - > lines + ( + + j ) , h - > buf [ i ] ) ;
2008-07-07 12:17:27 +00:00
return OSDCMD_OK ;
}
2006-04-13 20:47:06 +00:00
////////////////////////////
//
// OSD_Cleanup() -- Cleans up the on-screen display
//
void OSD_Cleanup ( void )
{
2010-05-02 23:27:30 +00:00
hash_free ( & h_osd ) ;
hash_free ( & h_cvars ) ;
2008-08-25 02:12:02 +00:00
2015-07-08 03:34:37 +00:00
for ( symbol_t * s ; symbols ; symbols = s )
2007-12-12 17:42:14 +00:00
{
2006-04-24 19:04:22 +00:00
s = symbols - > next ;
Bfree ( symbols ) ;
}
2006-04-13 20:47:06 +00:00
2014-07-06 00:12:25 +00:00
MAYBE_FCLOSE_AND_NULL ( osdlog ) ;
DO_FREE_AND_NULL ( osd - > cvars ) ;
DO_FREE_AND_NULL ( osd - > editor . buf ) ;
2015-05-25 12:57:49 +00:00
DO_FREE_AND_NULL ( osd - > editor . tmp ) ;
2016-08-27 01:41:21 +00:00
for ( bssize_t i = 0 ; i < OSDMAXHISTORYDEPTH ; i + + )
2014-07-06 00:12:25 +00:00
DO_FREE_AND_NULL ( osd - > history . buf [ i ] ) ;
DO_FREE_AND_NULL ( osd - > text . buf ) ;
DO_FREE_AND_NULL ( osd - > text . fmt ) ;
DO_FREE_AND_NULL ( osd ) ;
2006-04-13 20:47:06 +00:00
}
2009-04-30 01:07:08 +00:00
static int32_t osdcmd_cvar_set_osd ( const osdfuncparm_t * parm )
{
int32_t r = osdcmd_cvar_set ( parm ) ;
2015-07-08 03:34:37 +00:00
if ( r ! = OSDCMD_OK )
return r ;
2014-07-06 00:12:25 +00:00
2015-07-08 03:34:37 +00:00
if ( ! Bstrcasecmp ( parm - > name , " osdrows " ) )
{
if ( osd - > draw . rows > osdmaxrows )
osd - > draw . rows = osdmaxrows ;
if ( osdrowscur ! = - 1 )
osdrowscur = osd - > draw . rows ;
}
else if ( ! Bstrcasecmp ( parm - > name , " osdtextmode " ) )
OSD_SetTextMode ( osd - > draw . mode ) ;
else if ( ! Bstrcasecmp ( parm - > name , " osdhistorydepth " ) )
{
2016-08-27 01:41:21 +00:00
for ( bssize_t i = OSDMAXHISTORYDEPTH - 1 ; i > = osd - > history . maxlines ; i - - )
2015-07-08 03:34:37 +00:00
DO_FREE_AND_NULL ( osd - > history . buf [ i ] ) ;
2009-04-30 01:07:08 +00:00
}
2015-07-08 03:34:37 +00:00
return OSDCMD_OK ;
2009-04-30 01:07:08 +00:00
}
2010-06-07 09:03:16 +00:00
static int32_t _internal_osdfunc_toggle ( const osdfuncparm_t * parm )
{
if ( parm - > numparms ! = 1 ) return OSDCMD_SHOWHELP ;
2015-07-08 03:34:37 +00:00
intptr_t i = hash_find ( & h_cvars , parm - > parms [ 0 ] ) ;
2010-06-07 09:03:16 +00:00
if ( i = = - 1 )
2014-07-06 00:12:25 +00:00
for ( i = osd - > numcvars - 1 ; i > = 0 ; i - - )
if ( ! Bstrcasecmp ( parm - > parms [ 0 ] , osd - > cvars [ i ] . c . name ) ) break ;
2010-06-07 09:03:16 +00:00
2014-07-06 00:12:25 +00:00
if ( i = = - 1 | | ( osd - > cvars [ i ] . c . type & CVAR_BOOL ) ! = CVAR_BOOL )
2010-06-07 09:03:16 +00:00
{
OSD_Printf ( " Bad cvar name or cvar not boolean \n " ) ;
return OSDCMD_OK ;
}
2014-07-06 00:12:25 +00:00
* ( int32_t * ) osd - > cvars [ i ] . c . vptr = 1 - * ( int32_t * ) osd - > cvars [ i ] . c . vptr ;
2010-06-07 09:03:16 +00:00
return OSDCMD_OK ;
}
2006-04-13 20:47:06 +00:00
//
2008-02-24 00:46:57 +00:00
// OSD_Init() -- Initializes the on-screen display
2006-04-13 20:47:06 +00:00
//
void OSD_Init ( void )
{
2014-07-06 00:12:25 +00:00
osd = ( osdmain_t * ) Bcalloc ( 1 , sizeof ( osdmain_t ) ) ;
mutex_init ( & osd - > mutex ) ;
if ( ! osd - > keycode ) osd - > keycode = sc_Tilde ;
osd - > text . buf = ( char * ) Bmalloc ( OSDBUFFERSIZE ) ;
osd - > text . fmt = ( char * ) Bmalloc ( OSDBUFFERSIZE ) ;
osd - > editor . buf = ( char * ) Bmalloc ( OSDEDITLENGTH ) ;
osd - > editor . tmp = ( char * ) Bmalloc ( OSDEDITLENGTH ) ;
Bmemset ( osd - > text . buf , asc_Space , OSDBUFFERSIZE ) ;
Bmemset ( osd - > text . fmt , osd - > draw . textpal + ( osd - > draw . textshade < < 5 ) , OSDBUFFERSIZE ) ;
Bmemset ( osd - > symbptrs , 0 , sizeof ( osd - > symbptrs ) ) ;
osd - > numsymbols = osd - > numcvars = 0 ;
osd - > text . lines = 1 ;
osd - > text . maxlines = OSDDEFAULTMAXLINES ; // overwritten later
osd - > draw . rows = OSDDEFAULTROWS ;
osd - > draw . cols = OSDDEFAULTCOLS ;
osd - > log . cutoff = OSDLOGCUTOFF ;
osd - > history . maxlines = OSDMINHISTORYDEPTH ;
2008-08-25 02:12:02 +00:00
2010-05-02 23:27:30 +00:00
hash_init ( & h_osd ) ;
hash_init ( & h_cvars ) ;
2008-08-25 02:12:02 +00:00
2015-07-08 03:34:37 +00:00
cvar_t cvars_osd [ ] =
2009-04-30 01:07:08 +00:00
{
2015-07-08 03:34:37 +00:00
{ " osdeditpal " , " sets the palette of the OSD input text " , ( void * ) & osd - > draw . editpal , CVAR_INT , 0 , MAXPALOOKUPS - 1 } ,
{ " osdpromptpal " , " sets the palette of the OSD prompt " , ( void * ) & osd - > draw . promptpal , CVAR_INT , 0 , MAXPALOOKUPS - 1 } ,
{ " osdtextpal " , " sets the palette of the OSD text " , ( void * ) & osd - > draw . textpal , CVAR_INT , 0 , MAXPALOOKUPS - 1 } ,
{ " osdeditshade " , " sets the shade of the OSD input text " , ( void * ) & osd - > draw . editshade , CVAR_INT , 0 , 7 } ,
{ " osdtextshade " , " sets the shade of the OSD text " , ( void * ) & osd - > draw . textshade , CVAR_INT , 0 , 7 } ,
{ " osdpromptshade " , " sets the shade of the OSD prompt " , ( void * ) & osd - > draw . promptshade , CVAR_INT , INT8_MIN , INT8_MAX } ,
2016-01-27 07:30:18 +00:00
{ " osdrows " , " sets the number of visible lines of the OSD " , ( void * ) & osd - > draw . rows , CVAR_INT | CVAR_FUNCPTR , 1 , 400 } ,
2015-07-08 03:34:37 +00:00
{ " osdtextmode " , " set OSD text mode (0:graphical, 1:fast) " , ( void * ) & osd - > draw . mode , CVAR_BOOL | CVAR_FUNCPTR , 0 , 1 } ,
{ " osdlogcutoff " , " sets the maximal line count of the log file " , ( void * ) & osd - > log . cutoff , CVAR_INT , 0 , 262144 } ,
{ " osdhistorydepth " , " sets the history depth, in lines " , ( void * ) & osd - > history . maxlines , CVAR_INT | CVAR_FUNCPTR , OSDMINHISTORYDEPTH , OSDMAXHISTORYDEPTH } ,
} ;
for ( unsigned i = 0 ; i < ARRAY_SIZE ( cvars_osd ) ; i + + )
{
if ( OSD_RegisterCvar ( & cvars_osd [ i ] ) )
continue ;
2010-05-02 23:27:30 +00:00
2015-07-08 03:34:37 +00:00
OSD_RegisterFunction ( cvars_osd [ i ] . name , cvars_osd [ i ] . desc ,
cvars_osd [ i ] . type & CVAR_FUNCPTR ? osdcmd_cvar_set_osd : osdcmd_cvar_set ) ;
2009-04-30 01:07:08 +00:00
}
2006-04-13 20:47:06 +00:00
2008-07-09 09:34:12 +00:00
OSD_RegisterFunction ( " alias " , " alias: creates an alias for calling multiple commands " , _internal_osdfunc_alias ) ;
OSD_RegisterFunction ( " clear " , " clear: clears the console text buffer " , _internal_osdfunc_clear ) ;
2010-05-09 22:12:29 +00:00
OSD_RegisterFunction ( " echo " , " echo [text]: echoes text to the console " , _internal_osdfunc_echo ) ;
2008-07-09 09:34:12 +00:00
OSD_RegisterFunction ( " exec " , " exec <scriptfile>: executes a script " , _internal_osdfunc_exec ) ;
2010-05-09 22:12:29 +00:00
OSD_RegisterFunction ( " fileinfo " , " fileinfo <file>: gets a file's information " , _internal_osdfunc_fileinfo ) ;
2008-07-09 09:34:12 +00:00
OSD_RegisterFunction ( " help " , " help: displays help for the specified cvar or command; \" listsymbols \" to show all commands " , _internal_osdfunc_help ) ;
OSD_RegisterFunction ( " history " , " history: displays the console command history " , _internal_osdfunc_history ) ;
2010-05-09 22:12:29 +00:00
OSD_RegisterFunction ( " listsymbols " , " listsymbols: lists all registered functions, cvars and aliases " , _internal_osdfunc_listsymbols ) ;
2010-06-07 09:03:16 +00:00
OSD_RegisterFunction ( " toggle " , " toggle: toggles the value of a boolean cvar " , _internal_osdfunc_toggle ) ;
2010-05-02 23:27:30 +00:00
OSD_RegisterFunction ( " unalias " , " unalias: removes a command alias " , _internal_osdfunc_unalias ) ;
2006-04-13 20:47:06 +00:00
2014-07-06 00:12:25 +00:00
// atexit(OSD_Cleanup);
2006-04-13 20:47:06 +00:00
}
//
// OSD_SetLogFile() -- Sets the text file where printed text should be echoed
//
2012-07-01 22:11:33 +00:00
void OSD_SetLogFile ( const char * fn )
2006-04-13 20:47:06 +00:00
{
2014-11-02 05:36:05 +00:00
MAYBE_FCLOSE_AND_NULL ( osdlog ) ;
2014-12-17 13:02:21 +00:00
osdlogfn = NULL ;
2014-11-02 05:36:05 +00:00
if ( ! fn )
return ;
2011-01-16 02:50:27 +00:00
2014-11-02 05:36:05 +00:00
osdlog = Bfopen ( fn , " w " ) ;
2014-10-25 03:29:53 +00:00
if ( osdlog )
2014-12-17 13:02:21 +00:00
{
2015-07-08 03:34:37 +00:00
# ifdef DEBUGGINGAIDS
const int bufmode = _IONBF ;
# else
const int bufmode = _IOLBF ;
# endif
2014-11-02 05:36:05 +00:00
setvbuf ( osdlog , ( char * ) NULL , bufmode , BUFSIZ ) ;
2014-12-17 13:02:21 +00:00
osdlogfn = fn ;
}
2006-04-13 20:47:06 +00:00
}
//
// OSD_SetFunctions() -- Sets some callbacks which the OSD uses to understand its world
//
void OSD_SetFunctions (
2009-01-09 09:29:17 +00:00
void ( * drawchar ) ( int32_t , int32_t , char , int32_t , int32_t ) ,
2012-12-25 16:13:50 +00:00
void ( * drawstr ) ( int32_t , int32_t , const char * , int32_t , int32_t , int32_t ) ,
2009-01-09 09:29:17 +00:00
void ( * drawcursor ) ( int32_t , int32_t , int32_t , int32_t ) ,
int32_t ( * colwidth ) ( int32_t ) ,
int32_t ( * rowheight ) ( int32_t ) ,
void ( * clearbg ) ( int32_t , int32_t ) ,
int32_t ( * gtime ) ( void ) ,
void ( * showosd ) ( int32_t )
2006-04-24 19:04:22 +00:00
)
2006-04-13 20:47:06 +00:00
{
2014-07-06 00:12:25 +00:00
drawosdchar = drawchar ? drawchar : _internal_drawosdchar ;
drawosdstr = drawstr ? drawstr : _internal_drawosdstr ;
drawosdcursor = drawcursor ? drawcursor : _internal_drawosdcursor ;
getcolumnwidth = colwidth ? colwidth : _internal_getcolumnwidth ;
getrowheight = rowheight ? rowheight : _internal_getrowheight ;
clearbackground = clearbg ? clearbg : _internal_clearbackground ;
gettime = gtime ? gtime : _internal_gettime ;
onshowosd = showosd ? showosd : _internal_onshowosd ;
2006-04-13 20:47:06 +00:00
}
//
// OSD_SetParameters() -- Sets the parameters for presenting the text
//
void OSD_SetParameters (
2009-01-09 09:29:17 +00:00
int32_t promptshade , int32_t promptpal ,
int32_t editshade , int32_t editpal ,
int32_t textshade , int32_t textpal
2006-04-24 19:04:22 +00:00
)
2006-04-13 20:47:06 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > draw . promptshade = promptshade ;
osd - > draw . promptpal = promptpal ;
osd - > draw . editshade = editshade ;
osd - > draw . editpal = editpal ;
osd - > draw . textshade = textshade ;
osd - > draw . textpal = textpal ;
2006-04-13 20:47:06 +00:00
}
//
// OSD_CaptureKey() -- Sets the scancode for the key which activates the onscreen display
//
2009-01-09 09:29:17 +00:00
void OSD_CaptureKey ( int32_t sc )
2006-04-13 20:47:06 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > keycode = sc ;
2006-04-13 20:47:06 +00:00
}
2008-07-01 10:31:03 +00:00
//
// OSD_FindDiffPoint() -- Finds the length of the longest common prefix of 2 strings, stolen from ZDoom
//
2009-01-09 09:29:17 +00:00
static int32_t OSD_FindDiffPoint ( const char * str1 , const char * str2 )
2008-07-01 11:14:18 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t i ;
2008-07-01 11:14:18 +00:00
for ( i = 0 ; Btolower ( str1 [ i ] ) = = Btolower ( str2 [ i ] ) ; i + + )
if ( str1 [ i ] = = 0 | | str2 [ i ] = = 0 )
break ;
return i ;
}
2008-07-08 04:52:39 +00:00
static void OSD_HistoryPrev ( void )
{
2014-07-06 00:12:25 +00:00
if ( osd - > history . pos > = osd - > history . lines - 1 ) return ;
2008-07-09 09:34:12 +00:00
2014-07-06 00:12:25 +00:00
Bmemcpy ( osd - > editor . buf , osd - > history . buf [ + + osd - > history . pos ] , OSDEDITLENGTH ) ;
2010-05-02 23:27:30 +00:00
2014-07-06 00:12:25 +00:00
osd - > editor . pos = 0 ;
while ( osd - > editor . buf [ osd - > editor . pos ] ) osd - > editor . pos + + ;
osd - > editor . len = osd - > editor . pos ;
2010-05-02 23:27:30 +00:00
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos < osd - > editor . start )
2008-07-08 04:52:39 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . end = osd - > editor . pos ;
osd - > editor . start = osd - > editor . end - editlinewidth ;
2008-07-08 04:52:39 +00:00
2014-07-06 00:12:25 +00:00
if ( osd - > editor . start < 0 )
2010-05-02 23:27:30 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . end - = osd - > editor . start ;
osd - > editor . start = 0 ;
2010-05-02 23:27:30 +00:00
}
2008-07-08 04:52:39 +00:00
}
2014-07-06 00:12:25 +00:00
else if ( osd - > editor . pos > = osd - > editor . end )
2010-05-02 23:27:30 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . start + = ( osd - > editor . pos - osd - > editor . end ) ;
osd - > editor . end + = ( osd - > editor . pos - osd - > editor . end ) ;
2010-05-02 23:27:30 +00:00
}
2008-07-08 04:52:39 +00:00
}
static void OSD_HistoryNext ( void )
{
2014-07-06 00:12:25 +00:00
if ( osd - > history . pos < 0 ) return ;
2008-07-09 09:34:12 +00:00
2014-07-06 00:12:25 +00:00
if ( osd - > history . pos = = 0 )
2008-07-08 04:52:39 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . len = 0 ;
osd - > editor . pos = 0 ;
osd - > editor . start = 0 ;
osd - > editor . end = editlinewidth ;
osd - > history . pos = - 1 ;
2008-07-09 09:34:12 +00:00
return ;
}
2008-07-08 04:52:39 +00:00
2014-07-06 00:12:25 +00:00
Bmemcpy ( osd - > editor . buf , osd - > history . buf [ - - osd - > history . pos ] , OSDEDITLENGTH ) ;
2010-05-02 23:27:30 +00:00
2014-07-06 00:12:25 +00:00
osd - > editor . pos = 0 ;
while ( osd - > editor . buf [ osd - > editor . pos ] ) osd - > editor . pos + + ;
osd - > editor . len = osd - > editor . pos ;
2010-05-02 23:27:30 +00:00
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos < osd - > editor . start )
2008-07-09 09:34:12 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . end = osd - > editor . pos ;
osd - > editor . start = osd - > editor . end - editlinewidth ;
2008-07-09 09:34:12 +00:00
2014-07-06 00:12:25 +00:00
if ( osd - > editor . start < 0 )
2010-05-02 23:27:30 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . end - = osd - > editor . start ;
osd - > editor . start = 0 ;
2010-05-02 23:27:30 +00:00
}
2008-07-08 04:52:39 +00:00
}
2014-07-06 00:12:25 +00:00
else if ( osd - > editor . pos > = osd - > editor . end )
2010-05-02 23:27:30 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . start + = ( osd - > editor . pos - osd - > editor . end ) ;
osd - > editor . end + = ( osd - > editor . pos - osd - > editor . end ) ;
2010-05-02 23:27:30 +00:00
}
2008-07-08 04:52:39 +00:00
}
2010-05-02 23:27:30 +00:00
//
// OSD_HandleKey() -- Handles keyboard input when capturing input.
// Returns 0 if the key was handled internally, or the scancode if it should
// be passed on to the game.
//
2009-01-09 09:29:17 +00:00
int32_t OSD_HandleChar ( char ch )
2006-04-13 20:47:06 +00:00
{
2009-01-09 09:29:17 +00:00
int32_t i , j ;
2006-04-24 19:04:22 +00:00
symbol_t * tabc = NULL ;
static symbol_t * lastmatch = NULL ;
2014-07-06 00:12:25 +00:00
if ( ! osd | | ( osd - > flags & OSD_CAPTURE ) ! = OSD_CAPTURE )
2010-05-02 23:27:30 +00:00
return ch ;
2006-04-24 19:04:22 +00:00
2010-05-02 23:27:30 +00:00
if ( ch ! = 9 ) // tab
lastmatch = NULL ;
switch ( ch )
2007-12-12 17:42:14 +00:00
{
2010-05-02 23:27:30 +00:00
case 1 : // control a. jump to beginning of line
2014-07-06 00:12:25 +00:00
osd - > editor . pos = 0 ;
osd - > editor . start = 0 ;
osd - > editor . end = editlinewidth ;
2010-05-02 23:27:30 +00:00
return 0 ;
case 2 : // control b, move one character left
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos > 0 ) osd - > editor . pos - - ;
2010-05-02 23:27:30 +00:00
return 0 ;
case 3 : // control c
2014-07-06 00:12:25 +00:00
osd - > editor . buf [ osd - > editor . len ] = 0 ;
OSD_Printf ( " %s \n " , osd - > editor . buf ) ;
osd - > editor . len = 0 ;
osd - > editor . pos = 0 ;
osd - > editor . start = 0 ;
osd - > editor . end = editlinewidth ;
osd - > editor . buf [ 0 ] = 0 ;
2010-05-02 23:27:30 +00:00
return 0 ;
case 5 : // control e, jump to end of line
2014-07-06 00:12:25 +00:00
osd - > editor . pos = osd - > editor . len ;
osd - > editor . end = osd - > editor . pos ;
osd - > editor . start = osd - > editor . end - editlinewidth ;
if ( osd - > editor . start < 0 )
2008-07-08 04:52:39 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . start = 0 ;
osd - > editor . end = editlinewidth ;
2008-07-08 04:52:39 +00:00
}
2010-05-02 23:27:30 +00:00
return 0 ;
case 6 : // control f, move one character right
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos < osd - > editor . len ) osd - > editor . pos + + ;
2010-05-02 23:27:30 +00:00
return 0 ;
case 8 :
2011-06-17 11:53:41 +00:00
# ifdef __APPLE__
case 127 : // control h, backspace
# endif
2014-07-06 00:12:25 +00:00
if ( ! osd - > editor . pos | | ! osd - > editor . len ) return 0 ;
if ( ( osd - > flags & OSD_OVERTYPE ) = = 0 )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos < osd - > editor . len )
Bmemmove ( osd - > editor . buf + osd - > editor . pos - 1 , osd - > editor . buf + osd - > editor . pos , osd - > editor . len - osd - > editor . pos ) ;
osd - > editor . len - - ;
2007-12-12 17:42:14 +00:00
}
2014-07-06 00:12:25 +00:00
osd - > editor . pos - - ;
if ( osd - > editor . pos < osd - > editor . start ) osd - > editor . start - - , osd - > editor . end - - ;
2011-06-17 11:53:41 +00:00
# ifndef __APPLE__
2010-05-18 05:14:17 +00:00
case 127 : // handled in OSD_HandleScanCode (delete)
2011-06-17 11:53:41 +00:00
# endif
2010-05-02 23:27:30 +00:00
return 0 ;
case 9 : // tab
2011-01-16 02:50:27 +00:00
{
int32_t commonsize = 512 ;
if ( ! lastmatch )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
for ( i = osd - > editor . pos ; i > 0 ; i - - ) if ( osd - > editor . buf [ i - 1 ] = = ' ' ) break ;
2015-02-07 17:29:13 +00:00
for ( j = 0 ; i < osd - > editor . len & & osd - > editor . buf [ i ] ! = ' ' ; j + + , i + + )
2014-07-06 00:12:25 +00:00
osd - > editor . tmp [ j ] = osd - > editor . buf [ i ] ;
osd - > editor . tmp [ j ] = 0 ;
2008-07-01 10:31:03 +00:00
2011-01-16 02:50:27 +00:00
if ( j > 0 )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
tabc = findsymbol ( osd - > editor . tmp , NULL ) ;
2006-04-24 19:04:22 +00:00
2014-07-06 00:12:25 +00:00
if ( tabc & & tabc - > next & & findsymbol ( osd - > editor . tmp , tabc - > next ) )
2006-12-11 03:06:49 +00:00
{
2011-01-16 02:50:27 +00:00
symbol_t * symb = tabc ;
int32_t maxwidth = 0 , x = 0 , num = 0 , diffpt ;
2008-07-09 09:34:12 +00:00
2011-01-16 02:50:27 +00:00
while ( symb & & symb ! = lastmatch )
2006-12-11 03:06:49 +00:00
{
2011-01-16 02:50:27 +00:00
num + + ;
2008-07-09 09:34:12 +00:00
2011-01-16 02:50:27 +00:00
if ( lastmatch )
2008-07-09 09:34:12 +00:00
{
2011-01-16 02:50:27 +00:00
diffpt = OSD_FindDiffPoint ( symb - > name , lastmatch - > name ) ;
if ( diffpt < commonsize )
commonsize = diffpt ;
2008-07-09 09:34:12 +00:00
}
2011-01-16 02:50:27 +00:00
maxwidth = max ( ( unsigned ) maxwidth , Bstrlen ( symb - > name ) ) ;
lastmatch = symb ;
if ( ! lastmatch - > next ) break ;
2014-07-06 00:12:25 +00:00
symb = findsymbol ( osd - > editor . tmp , lastmatch - > next ) ;
2011-01-16 02:50:27 +00:00
}
2014-07-06 00:12:25 +00:00
OSD_Printf ( OSDTEXT_RED " Found %d possible completions for \" %s \" : \n " , num , osd - > editor . tmp ) ;
2011-01-16 02:50:27 +00:00
maxwidth + = 3 ;
symb = tabc ;
OSD_Printf ( " " ) ;
while ( symb & & ( symb ! = lastmatch ) )
{
tabc = lastmatch = symb ;
OSD_Printf ( " %-*s " , maxwidth , symb - > name ) ;
if ( ! lastmatch - > next ) break ;
2014-07-06 00:12:25 +00:00
symb = findsymbol ( osd - > editor . tmp , lastmatch - > next ) ;
2011-01-16 02:50:27 +00:00
x + = maxwidth ;
2014-07-06 00:12:25 +00:00
if ( x > ( osd - > draw . cols - maxwidth ) )
2008-07-09 09:34:12 +00:00
{
2011-01-16 02:50:27 +00:00
x = 0 ;
OSD_Printf ( " \n " ) ;
if ( symb & & ( symb ! = lastmatch ) )
OSD_Printf ( " " ) ;
2006-12-11 03:06:49 +00:00
}
}
2011-01-16 02:50:27 +00:00
if ( x ) OSD_Printf ( " \n " ) ;
OSD_Printf ( OSDTEXT_RED " Press TAB again to cycle through matches \n " ) ;
2006-12-11 03:06:49 +00:00
}
2007-12-12 17:42:14 +00:00
}
2011-01-16 02:50:27 +00:00
}
else
{
2014-07-06 00:12:25 +00:00
tabc = findsymbol ( osd - > editor . tmp , lastmatch - > next ) ;
2011-01-16 02:50:27 +00:00
if ( ! tabc & & lastmatch )
2014-07-06 00:12:25 +00:00
tabc = findsymbol ( osd - > editor . tmp , NULL ) ; // wrap */
2011-01-16 02:50:27 +00:00
}
2006-04-24 19:04:22 +00:00
2011-01-16 02:50:27 +00:00
if ( tabc )
{
2014-07-06 00:12:25 +00:00
for ( i = osd - > editor . pos ; i > 0 ; i - - ) if ( osd - > editor . buf [ i - 1 ] = = ' ' ) break ;
osd - > editor . len = i ;
for ( j = 0 ; tabc - > name [ j ] & & osd - > editor . len < = OSDEDITLENGTH - 1
& & ( osd - > editor . len < commonsize ) ; i + + , j + + , osd - > editor . len + + )
osd - > editor . buf [ i ] = tabc - > name [ j ] ;
osd - > editor . pos = osd - > editor . len ;
osd - > editor . end = osd - > editor . pos ;
osd - > editor . start = osd - > editor . end - editlinewidth ;
if ( osd - > editor . start < 0 )
2011-01-16 02:50:27 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . start = 0 ;
osd - > editor . end = editlinewidth ;
2010-05-02 23:27:30 +00:00
}
2011-01-16 02:50:27 +00:00
lastmatch = tabc ;
2007-12-12 17:42:14 +00:00
}
2011-01-16 02:50:27 +00:00
}
return 0 ;
2010-05-02 23:27:30 +00:00
case 11 : // control k, delete all to end of line
2015-08-09 09:58:44 +00:00
Bmemset ( osd - > editor . buf + osd - > editor . pos , 0 , OSDEDITLENGTH - osd - > editor . pos ) ;
osd - > editor . len = osd - > editor . pos ;
2010-05-02 23:27:30 +00:00
return 0 ;
case 12 : // control l, clear screen
2014-07-06 00:12:25 +00:00
Bmemset ( osd - > text . buf , 0 , OSDBUFFERSIZE ) ;
Bmemset ( osd - > text . fmt , osd - > draw . textpal + ( osd - > draw . textshade < < 5 ) , OSDBUFFERSIZE ) ;
osd - > text . lines = 1 ;
2010-05-02 23:27:30 +00:00
return 0 ;
case 13 : // control m, enter
2014-07-06 00:12:25 +00:00
if ( osd - > editor . len > 0 )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . buf [ osd - > editor . len ] = 0 ;
if ( ! osd - > history . buf [ 0 ] | | Bstrcmp ( osd - > history . buf [ 0 ] , osd - > editor . buf ) )
2008-07-07 12:17:27 +00:00
{
2014-07-06 00:12:25 +00:00
DO_FREE_AND_NULL ( osd - > history . buf [ osd - > history . maxlines - 1 ] ) ;
Bmemmove ( & osd - > history . buf [ 1 ] , & osd - > history . buf [ 0 ] , sizeof ( intptr_t ) * osd - > history . maxlines - 1 ) ;
2014-11-06 23:43:49 +00:00
OSD_SetHistory ( 0 , osd - > editor . buf ) ;
2014-07-06 00:12:25 +00:00
if ( osd - > history . lines < osd - > history . maxlines )
osd - > history . lines + + ;
osd - > history . total + + ;
if ( osd - > history . exec = = osd - > history . maxlines )
2008-07-07 12:17:27 +00:00
OSD_Printf ( " Command Buffer Warning: Failed queueing command "
2014-07-06 00:12:25 +00:00
" for execution. Buffer full. Consider increasing \" osdhistorydepth \" . \n " ) ;
2008-07-07 12:17:27 +00:00
else
2014-07-06 00:12:25 +00:00
osd - > history . exec + + ;
2008-07-07 12:17:27 +00:00
}
2008-07-04 02:13:48 +00:00
else
2008-07-07 12:17:27 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > history . exec = = osd - > history . maxlines )
2008-07-07 12:17:27 +00:00
OSD_Printf ( " Command Buffer Warning: Failed queueing command "
2014-07-06 00:12:25 +00:00
" for execution. Buffer full. Consider increasing \" osdhistorydepth \" . \n " ) ;
2008-07-07 12:17:27 +00:00
else
2014-07-06 00:12:25 +00:00
osd - > history . exec + + ;
2008-07-07 12:17:27 +00:00
}
2014-07-06 00:12:25 +00:00
osd - > history . pos = - 1 ;
2007-12-12 17:42:14 +00:00
}
2008-07-04 02:13:48 +00:00
2014-07-06 00:12:25 +00:00
osd - > editor . len = 0 ;
osd - > editor . pos = 0 ;
osd - > editor . start = 0 ;
osd - > editor . end = editlinewidth ;
2010-05-02 23:27:30 +00:00
return 0 ;
case 14 : // control n, next (ie. down arrow)
2008-07-08 04:52:39 +00:00
OSD_HistoryNext ( ) ;
2010-05-02 23:27:30 +00:00
return 0 ;
case 16 : // control p, previous (ie. up arrow)
2008-07-08 04:52:39 +00:00
OSD_HistoryPrev ( ) ;
2010-05-02 23:27:30 +00:00
return 0 ;
case 21 : // control u, delete all to beginning
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos > 0 & & osd - > editor . len )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos < osd - > editor . len )
Bmemmove ( osd - > editor . buf , osd - > editor . buf + osd - > editor . pos , osd - > editor . len - osd - > editor . pos ) ;
osd - > editor . len - = osd - > editor . pos ;
osd - > editor . pos = 0 ;
osd - > editor . start = 0 ;
osd - > editor . end = editlinewidth ;
2007-12-12 17:42:14 +00:00
}
2010-05-02 23:27:30 +00:00
return 0 ;
case 23 : // control w, delete one word back
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos > 0 & & osd - > editor . len > 0 )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
i = osd - > editor . pos ;
while ( i > 0 & & osd - > editor . buf [ i - 1 ] = = asc_Space ) i - - ;
while ( i > 0 & & osd - > editor . buf [ i - 1 ] ! = asc_Space ) i - - ;
if ( osd - > editor . pos < osd - > editor . len )
Bmemmove ( osd - > editor . buf + i , osd - > editor . buf + osd - > editor . pos , osd - > editor . len - osd - > editor . pos ) ;
osd - > editor . len - = ( osd - > editor . pos - i ) ;
osd - > editor . pos = i ;
if ( osd - > editor . pos < osd - > editor . start )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . start = osd - > editor . pos ;
osd - > editor . end = osd - > editor . start + editlinewidth ;
2006-04-24 19:04:22 +00:00
}
2007-12-12 17:42:14 +00:00
}
2010-05-02 23:27:30 +00:00
return 0 ;
default :
if ( ch > = asc_Space ) // text char
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
if ( ( osd - > flags & OSD_OVERTYPE ) = = 0 )
2010-05-02 23:27:30 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > editor . len = = OSDEDITLENGTH ) // buffer full, can't insert another char
2010-05-02 23:27:30 +00:00
return 0 ;
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos < osd - > editor . len )
Bmemmove ( osd - > editor . buf + osd - > editor . pos + 1 , osd - > editor . buf + osd - > editor . pos , osd - > editor . len - osd - > editor . pos ) ;
osd - > editor . len + + ;
2010-05-02 23:27:30 +00:00
}
2014-07-06 00:12:25 +00:00
else if ( osd - > editor . pos = = osd - > editor . len )
osd - > editor . len + + ;
2010-05-02 23:27:30 +00:00
2014-07-06 00:12:25 +00:00
osd - > editor . buf [ osd - > editor . pos + + ] = ch ;
2010-05-02 23:27:30 +00:00
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos > osd - > editor . end )
osd - > editor . start + + , osd - > editor . end + + ;
2006-04-24 19:04:22 +00:00
}
2010-05-02 23:27:30 +00:00
return 0 ;
2006-04-24 19:04:22 +00:00
}
2008-07-02 01:32:53 +00:00
return 0 ;
}
2009-01-09 09:29:17 +00:00
int32_t OSD_HandleScanCode ( int32_t sc , int32_t press )
2008-07-02 01:32:53 +00:00
{
2014-07-06 00:12:25 +00:00
if ( ! osd )
2014-01-27 10:30:25 +00:00
return 1 ;
2008-07-02 01:32:53 +00:00
2014-07-06 00:12:25 +00:00
if ( sc = = osd - > keycode )
2008-07-02 01:32:53 +00:00
{
if ( press )
{
osdscroll = - osdscroll ;
if ( osdrowscur = = - 1 )
osdscroll = 1 ;
2014-07-06 00:12:25 +00:00
else if ( osdrowscur = = osd - > draw . rows )
2008-07-02 01:32:53 +00:00
osdscroll = - 1 ;
osdrowscur + = osdscroll ;
OSD_CaptureInput ( osdscroll = = 1 ) ;
osdscrtime = getticks ( ) ;
}
2014-01-27 10:30:25 +00:00
return - 1 ;
2008-07-02 01:32:53 +00:00
}
2014-07-06 00:12:25 +00:00
else if ( ( osd - > flags & OSD_CAPTURE ) = = 0 )
2014-01-27 10:30:25 +00:00
return 2 ;
2008-07-02 01:32:53 +00:00
if ( ! press )
{
2010-05-02 23:27:30 +00:00
if ( sc = = sc_LeftShift | | sc = = sc_RightShift )
2014-07-06 00:12:25 +00:00
osd - > flags & = ~ OSD_SHIFT ;
2010-05-02 23:27:30 +00:00
if ( sc = = sc_LeftControl | | sc = = sc_RightControl )
2014-07-06 00:12:25 +00:00
osd - > flags & = ~ OSD_CTRL ;
2010-05-02 23:27:30 +00:00
return 0 ;
2008-07-02 01:32:53 +00:00
}
keytime = gettime ( ) ;
2006-04-24 19:04:22 +00:00
2010-05-02 23:27:30 +00:00
switch ( sc )
2007-12-20 19:14:38 +00:00
{
2010-05-02 23:27:30 +00:00
case sc_Escape :
2007-12-12 17:42:14 +00:00
// OSD_ShowDisplay(0);
osdscroll = - 1 ;
2010-05-02 23:27:30 +00:00
osdrowscur - - ;
2007-12-12 17:42:14 +00:00
OSD_CaptureInput ( 0 ) ;
osdscrtime = getticks ( ) ;
2010-05-02 23:27:30 +00:00
break ;
case sc_PgUp :
2014-07-06 00:12:25 +00:00
if ( osd - > draw . head < osd - > text . lines - 1 )
osd - > draw . head + + ;
2010-05-02 23:27:30 +00:00
break ;
case sc_PgDn :
2014-07-06 00:12:25 +00:00
if ( osd - > draw . head > 0 )
osd - > draw . head - - ;
2010-05-02 23:27:30 +00:00
break ;
case sc_Home :
2014-07-06 00:12:25 +00:00
if ( osd - > flags & OSD_CTRL )
osd - > draw . head = osd - > text . lines - 1 ;
2007-12-12 17:42:14 +00:00
else
{
2014-07-06 00:12:25 +00:00
osd - > editor . pos = 0 ;
osd - > editor . start = osd - > editor . pos ;
osd - > editor . end = osd - > editor . start + editlinewidth ;
2006-04-24 19:04:22 +00:00
}
2010-05-02 23:27:30 +00:00
break ;
case sc_End :
2014-07-06 00:12:25 +00:00
if ( osd - > flags & OSD_CTRL )
osd - > draw . head = 0 ;
2007-12-12 17:42:14 +00:00
else
{
2014-07-06 00:12:25 +00:00
osd - > editor . pos = osd - > editor . len ;
osd - > editor . end = osd - > editor . pos ;
osd - > editor . start = osd - > editor . end - editlinewidth ;
if ( osd - > editor . start < 0 )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . start = 0 ;
osd - > editor . end = editlinewidth ;
2006-04-24 19:04:22 +00:00
}
}
2010-05-02 23:27:30 +00:00
break ;
case sc_Insert :
2014-07-06 00:12:25 +00:00
osd - > flags = ( osd - > flags & ~ OSD_OVERTYPE ) | ( - ( ( osd - > flags & OSD_OVERTYPE ) = = 0 ) & OSD_OVERTYPE ) ;
2010-05-18 05:14:17 +00:00
break ;
2010-05-02 23:27:30 +00:00
case sc_LeftArrow :
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos > 0 )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > flags & OSD_CTRL )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
while ( osd - > editor . pos > 0 )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > editor . buf [ osd - > editor . pos - 1 ] ! = asc_Space )
2010-05-02 23:27:30 +00:00
break ;
2014-07-06 00:12:25 +00:00
osd - > editor . pos - - ;
2006-04-24 19:04:22 +00:00
}
2014-07-06 00:12:25 +00:00
while ( osd - > editor . pos > 0 )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > editor . buf [ osd - > editor . pos - 1 ] = = asc_Space )
2010-05-02 23:27:30 +00:00
break ;
2014-07-06 00:12:25 +00:00
osd - > editor . pos - - ;
2006-04-24 19:04:22 +00:00
}
2007-12-12 17:42:14 +00:00
}
2014-07-06 00:12:25 +00:00
else osd - > editor . pos - - ;
2006-04-24 19:04:22 +00:00
}
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos < osd - > editor . start )
2010-05-02 23:27:30 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . end - = ( osd - > editor . start - osd - > editor . pos ) ;
osd - > editor . start - = ( osd - > editor . start - osd - > editor . pos ) ;
2010-05-02 23:27:30 +00:00
}
break ;
case sc_RightArrow :
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos < osd - > editor . len )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > flags & OSD_CTRL )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
while ( osd - > editor . pos < osd - > editor . len )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > editor . buf [ osd - > editor . pos ] = = asc_Space )
2010-05-02 23:27:30 +00:00
break ;
2014-07-06 00:12:25 +00:00
osd - > editor . pos + + ;
2006-04-24 19:04:22 +00:00
}
2014-07-06 00:12:25 +00:00
while ( osd - > editor . pos < osd - > editor . len )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > editor . buf [ osd - > editor . pos ] ! = asc_Space )
2010-05-02 23:27:30 +00:00
break ;
2014-07-06 00:12:25 +00:00
osd - > editor . pos + + ;
2006-04-24 19:04:22 +00:00
}
2007-12-12 17:42:14 +00:00
}
2014-07-06 00:12:25 +00:00
else osd - > editor . pos + + ;
2006-04-24 19:04:22 +00:00
}
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos > = osd - > editor . end )
2010-05-02 23:27:30 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > editor . start + = ( osd - > editor . pos - osd - > editor . end ) ;
osd - > editor . end + = ( osd - > editor . pos - osd - > editor . end ) ;
2010-05-02 23:27:30 +00:00
}
break ;
case sc_UpArrow :
2008-07-08 04:52:39 +00:00
OSD_HistoryPrev ( ) ;
2010-05-02 23:27:30 +00:00
break ;
case sc_DownArrow :
2008-07-08 04:52:39 +00:00
OSD_HistoryNext ( ) ;
2010-05-02 23:27:30 +00:00
break ;
case sc_LeftShift :
case sc_RightShift :
2014-07-06 00:12:25 +00:00
osd - > flags | = OSD_SHIFT ;
2010-05-02 23:27:30 +00:00
break ;
case sc_LeftControl :
case sc_RightControl :
2014-07-06 00:12:25 +00:00
osd - > flags | = OSD_CTRL ;
2010-05-02 23:27:30 +00:00
break ;
case sc_CapsLock :
2014-07-06 00:12:25 +00:00
osd - > flags = ( osd - > flags & ~ OSD_CAPS ) | ( - ( ( osd - > flags & OSD_CAPS ) = = 0 ) & OSD_CAPS ) ;
2010-05-02 23:27:30 +00:00
break ;
case sc_Delete :
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos = = osd - > editor . len | | ! osd - > editor . len )
2010-05-02 23:27:30 +00:00
return 0 ;
2014-07-06 00:12:25 +00:00
if ( osd - > editor . pos < = osd - > editor . len - 1 )
Bmemmove ( osd - > editor . buf + osd - > editor . pos , osd - > editor . buf + osd - > editor . pos + 1 , osd - > editor . len - osd - > editor . pos - 1 ) ;
osd - > editor . len - - ;
2010-05-02 23:27:30 +00:00
break ;
2006-04-24 19:04:22 +00:00
}
return 0 ;
2006-04-13 20:47:06 +00:00
}
//
// OSD_ResizeDisplay() -- Handles readjustment of the display when the screen resolution
2008-08-23 15:37:30 +00:00
// changes on us.
2006-04-13 20:47:06 +00:00
//
2009-01-09 09:29:17 +00:00
void OSD_ResizeDisplay ( int32_t w , int32_t h )
2006-04-13 20:47:06 +00:00
{
2014-07-06 00:12:25 +00:00
int32_t newcols , newmaxlines ;
char * newtext , * newfmt ;
2009-01-09 09:29:17 +00:00
int32_t i , j , k ;
2006-04-24 19:04:22 +00:00
newcols = getcolumnwidth ( w ) ;
2014-07-06 00:12:25 +00:00
newmaxlines = OSDBUFFERSIZE / newcols ;
j = min ( newmaxlines , osd - > text . maxlines ) ;
k = min ( newcols , osd - > draw . cols ) ;
newtext = ( char * ) Bmalloc ( OSDBUFFERSIZE ) ;
newfmt = ( char * ) Bmalloc ( OSDBUFFERSIZE ) ;
2006-04-24 19:04:22 +00:00
2014-07-06 00:12:25 +00:00
Bmemset ( newtext , asc_Space , OSDBUFFERSIZE ) ;
2006-04-24 19:04:22 +00:00
2009-02-19 16:47:54 +00:00
for ( i = j - 1 ; i > = 0 ; i - - )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
Bmemcpy ( newtext + newcols * i , osd - > text . buf + osd - > draw . cols * i , k ) ;
Bmemcpy ( newfmt + newcols * i , osd - > text . fmt + osd - > draw . cols * i , k ) ;
2006-04-24 19:04:22 +00:00
}
2014-07-06 00:12:25 +00:00
Bfree ( osd - > text . buf ) ;
osd - > text . buf = newtext ;
Bfree ( osd - > text . fmt ) ;
osd - > text . fmt = newfmt ;
osd - > text . maxlines = newmaxlines ;
osd - > draw . cols = newcols ;
2006-04-24 19:04:22 +00:00
osdmaxrows = getrowheight ( h ) - 2 ;
2014-07-06 00:12:25 +00:00
if ( osd - > draw . rows > osdmaxrows ) osd - > draw . rows = osdmaxrows ;
2006-04-24 19:04:22 +00:00
2014-07-06 00:12:25 +00:00
osd - > text . pos = 0 ;
osd - > draw . head = 0 ;
osd - > editor . start = 0 ;
osd - > editor . end = editlinewidth ;
2006-04-24 19:04:22 +00:00
white = - 1 ;
2006-04-13 20:47:06 +00:00
}
//
2006-12-11 03:32:43 +00:00
// OSD_CaptureInput()
2006-04-13 20:47:06 +00:00
//
2009-01-09 09:29:17 +00:00
void OSD_CaptureInput ( int32_t cap )
2006-04-13 20:47:06 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > flags = ( osd - > flags & ~ ( OSD_CAPTURE | OSD_CTRL | OSD_SHIFT ) ) | ( - cap & OSD_CAPTURE ) ;
2010-05-02 23:27:30 +00:00
2014-11-17 07:39:12 +00:00
grabmouse ( cap = = 0 ? AppMouseGrab : 0 ) ;
2010-05-02 23:27:30 +00:00
onshowosd ( cap ) ;
if ( cap )
releaseallbuttons ( ) ;
2006-04-13 20:47:06 +00:00
2006-12-11 21:18:21 +00:00
bflushchars ( ) ;
2006-12-11 03:32:43 +00:00
}
2010-05-02 23:27:30 +00:00
2006-12-11 03:32:43 +00:00
//
// OSD_ShowDisplay() -- Shows or hides the onscreen display
//
2009-01-09 09:29:17 +00:00
void OSD_ShowDisplay ( int32_t onf )
2006-12-11 03:32:43 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > flags = ( osd - > flags & ~ OSD_DRAW ) | ( - onf & OSD_DRAW ) ;
2010-05-02 23:27:30 +00:00
OSD_CaptureInput ( onf ) ;
2006-04-13 20:47:06 +00:00
}
//
// OSD_Draw() -- Draw the onscreen display
//
2007-01-02 02:27:31 +00:00
2006-04-13 20:47:06 +00:00
void OSD_Draw ( void )
{
2009-06-05 20:09:13 +00:00
uint32_t topoffs ;
2009-01-09 09:29:17 +00:00
int32_t row , lines , x , len ;
2006-04-24 19:04:22 +00:00
2014-07-06 00:12:25 +00:00
if ( ! osd )
2010-05-02 23:27:30 +00:00
return ;
2006-12-11 03:06:49 +00:00
2006-12-11 21:18:21 +00:00
if ( osdrowscur = = 0 )
2014-07-06 00:12:25 +00:00
OSD_ShowDisplay ( osd - > flags & OSD_DRAW ? 0 : 1 ) ;
2006-12-11 03:06:49 +00:00
2014-07-06 00:12:25 +00:00
if ( osdrowscur = = osd - > draw . rows )
2006-12-11 03:06:49 +00:00
osdscroll = 0 ;
else
{
2009-01-09 09:29:17 +00:00
int32_t j ;
2007-12-12 17:42:14 +00:00
2014-07-06 00:12:25 +00:00
if ( ( osdrowscur < osd - > draw . rows & & osdscroll = = 1 ) | | osdrowscur < - 1 )
2007-01-06 09:50:02 +00:00
{
2007-01-12 05:05:19 +00:00
j = ( getticks ( ) - osdscrtime ) ;
2007-01-06 09:50:02 +00:00
while ( j > - 1 )
{
osdrowscur + + ;
2014-10-25 03:29:21 +00:00
j - = tabledivide32_noinline ( 200 , osd - > draw . rows ) ;
2014-07-06 00:12:25 +00:00
if ( osdrowscur > osd - > draw . rows - 1 )
2007-01-06 09:50:02 +00:00
break ;
}
}
2014-07-06 00:12:25 +00:00
if ( ( osdrowscur > - 1 & & osdscroll = = - 1 ) | | osdrowscur > osd - > draw . rows )
2007-01-06 09:50:02 +00:00
{
2007-01-12 05:05:19 +00:00
j = ( getticks ( ) - osdscrtime ) ;
2007-01-06 09:50:02 +00:00
while ( j > - 1 )
{
osdrowscur - - ;
2014-10-25 03:29:21 +00:00
j - = tabledivide32_noinline ( 200 , osd - > draw . rows ) ;
2007-01-06 09:50:02 +00:00
if ( osdrowscur < 1 )
break ;
}
}
osdscrtime = getticks ( ) ;
2007-01-02 02:27:31 +00:00
}
2007-12-12 17:42:14 +00:00
2014-07-06 00:12:25 +00:00
if ( ( osd - > flags & OSD_DRAW ) = = 0 | | ! osdrowscur ) return ;
2006-04-24 19:04:22 +00:00
2014-07-06 00:12:25 +00:00
topoffs = osd - > draw . head * osd - > draw . cols ;
2006-12-11 03:06:49 +00:00
row = osdrowscur - 1 ;
2014-07-06 00:12:25 +00:00
lines = min ( osd - > text . lines - osd - > draw . head , osdrowscur ) ;
2006-04-24 19:04:22 +00:00
begindrawing ( ) ;
2014-07-06 00:12:25 +00:00
clearbackground ( osd - > draw . cols , osdrowscur + 1 ) ;
2007-12-12 17:42:14 +00:00
for ( ; lines > 0 ; lines - - , row - - )
{
2013-12-24 09:44:20 +00:00
// XXX: May happen, which would ensue an oob if not checked.
2014-07-06 00:12:25 +00:00
// Last char accessed is osd->text.buf[topoffs + osd->draw.cols-1].
2013-12-24 09:44:20 +00:00
// Reproducible by running test.lua with -Lopts=diag
// and scrolling to the top.
2014-07-06 00:12:25 +00:00
if ( topoffs + osd - > draw . cols - 1 > = OSDBUFFERSIZE )
2013-12-24 09:44:20 +00:00
break ;
2014-07-06 00:12:25 +00:00
drawosdstr ( 0 , row , osd - > text . buf + topoffs , osd - > draw . cols , osd - > draw . textshade , osd - > draw . textpal ) ;
topoffs + = osd - > draw . cols ;
2006-04-24 19:04:22 +00:00
}
2008-10-11 09:20:04 +00:00
{
2014-07-06 00:12:25 +00:00
int32_t offset = ( ( osd - > flags & ( OSD_CAPS | OSD_SHIFT ) ) = = ( OSD_CAPS | OSD_SHIFT ) & & osd - > draw . head > 0 ) ;
int32_t shade = osd - > draw . promptshade ? osd - > draw . promptshade : ( sintable [ ( totalclock < < 4 ) & 2047 ] > > 11 ) ;
2008-10-11 09:20:04 +00:00
2014-07-06 00:12:25 +00:00
if ( osd - > draw . head = = osd - > text . lines - 1 ) drawosdchar ( 0 , osdrowscur , ' ~ ' , shade , osd - > draw . promptpal ) ;
else if ( osd - > draw . head > 0 ) drawosdchar ( 0 , osdrowscur , ' ^ ' , shade , osd - > draw . promptpal ) ;
if ( osd - > flags & OSD_CAPS ) drawosdchar ( 0 + ( osd - > draw . head > 0 ) , osdrowscur , ' C ' , shade , osd - > draw . promptpal ) ;
if ( osd - > flags & OSD_SHIFT ) drawosdchar ( 1 + ( osd - > flags & OSD_CAPS & & osd - > draw . head > 0 ) , osdrowscur , ' H ' , shade , osd - > draw . promptpal ) ;
2006-04-24 19:04:22 +00:00
2014-07-06 00:12:25 +00:00
drawosdchar ( 2 + offset , osdrowscur , ' > ' , shade , osd - > draw . promptpal ) ;
2006-04-24 19:04:22 +00:00
2014-07-06 00:12:25 +00:00
len = min ( osd - > draw . cols - 1 - 3 - offset , osd - > editor . len - osd - > editor . start ) ;
2008-10-11 09:20:04 +00:00
for ( x = len - 1 ; x > = 0 ; x - - )
2014-07-06 00:12:25 +00:00
drawosdchar ( 3 + x + offset , osdrowscur , osd - > editor . buf [ osd - > editor . start + x ] , osd - > draw . editshade < < 1 , osd - > draw . editpal ) ;
2008-10-11 09:20:04 +00:00
2014-07-06 00:12:25 +00:00
offset + = 3 + osd - > editor . pos - osd - > editor . start ;
2010-05-25 10:56:00 +00:00
2014-07-06 00:12:25 +00:00
drawosdcursor ( offset , osdrowscur , osd - > flags & OSD_OVERTYPE , keytime ) ;
2010-05-25 10:56:00 +00:00
2014-07-06 00:12:25 +00:00
if ( osd - > verstr . buf )
drawosdstr ( osd - > draw . cols - osd - > verstr . len , osdrowscur - ( offset > = osd - > draw . cols - osd - > verstr . len ) ,
osd - > verstr . buf , osd - > verstr . len , ( sintable [ ( totalclock < < 4 ) & 2047 ] > > 11 ) , osd - > verstr . pal ) ;
2008-10-11 09:20:04 +00:00
}
2007-12-12 17:42:14 +00:00
2006-04-24 19:04:22 +00:00
enddrawing ( ) ;
2006-04-13 20:47:06 +00:00
}
//
2014-07-24 14:01:44 +00:00
// OSD_Printf() -- Print a formatted string to the onscreen display
// and write it to the log file
//
void OSD_Printf ( const char * fmt , . . . )
{
static char tmpstr [ 8192 ] ;
va_list va ;
va_start ( va , fmt ) ;
Bvsnprintf ( tmpstr , sizeof ( tmpstr ) , fmt , va ) ;
va_end ( va ) ;
OSD_Puts ( tmpstr ) ;
}
//
// OSD_Puts() -- Print a string to the onscreen display
2006-04-13 20:47:06 +00:00
// and write it to the log file
//
2010-05-02 23:27:30 +00:00
static inline void OSD_LineFeed ( void )
2006-04-13 20:47:06 +00:00
{
2014-07-06 00:12:25 +00:00
Bmemmove ( osd - > text . buf + osd - > draw . cols , osd - > text . buf , OSDBUFFERSIZE - osd - > draw . cols ) ;
Bmemset ( osd - > text . buf , asc_Space , osd - > draw . cols ) ;
Bmemmove ( osd - > text . fmt + osd - > draw . cols , osd - > text . fmt , OSDBUFFERSIZE - osd - > draw . cols ) ;
Bmemset ( osd - > text . fmt , osd - > draw . textpal , osd - > draw . cols ) ;
if ( osd - > text . lines < osd - > text . maxlines ) osd - > text . lines + + ;
2006-04-13 20:47:06 +00:00
}
2014-07-24 14:01:44 +00:00
2008-08-23 15:37:30 +00:00
# define MAX_ERRORS 4096
2014-07-24 14:01:44 +00:00
void OSD_Puts ( const char * tmpstr )
2006-04-13 20:47:06 +00:00
{
2014-07-24 14:01:44 +00:00
const char * chp ;
char p = osd - > draw . textpal , s = osd - > draw . textshade ;
2006-04-24 19:04:22 +00:00
2014-07-06 00:12:25 +00:00
mutex_lock ( & osd - > mutex ) ;
2006-04-24 19:04:22 +00:00
2012-12-25 16:13:36 +00:00
if ( tmpstr [ 0 ] = = 0 )
{
2014-07-06 00:12:25 +00:00
mutex_unlock ( & osd - > mutex ) ;
2012-12-25 16:13:36 +00:00
return ;
}
2014-07-06 00:12:25 +00:00
if ( tmpstr [ 0 ] = = ' ^ ' & & tmpstr [ 1 ] = = ' 1 ' & & tmpstr [ 2 ] = = ' 0 ' & & + + osd - > log . errors > MAX_ERRORS )
2008-08-23 15:37:30 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osd - > log . errors = = MAX_ERRORS + 1 )
2014-07-24 14:01:44 +00:00
tmpstr = " \n Too many errors. Logging errors stopped. \n " ;
2008-08-24 06:17:09 +00:00
else
{
2014-07-06 00:12:25 +00:00
osd - > log . errors = MAX_ERRORS + 2 ;
mutex_unlock ( & osd - > mutex ) ;
2008-08-24 06:17:09 +00:00
return ;
}
2008-08-23 15:37:30 +00:00
}
2014-07-06 00:12:25 +00:00
if ( osd - > log . lines < osd - > log . cutoff )
2008-01-04 01:04:35 +00:00
{
2014-07-06 00:12:25 +00:00
if ( osdlog & & ( ! osd - > log . cutoff | | osd - > log . lines < osd - > log . cutoff ) )
2008-08-03 11:45:15 +00:00
{
2014-07-24 14:01:44 +00:00
char * chp2 = Xstrdup ( tmpstr ) ;
Bfputs ( OSD_StripColors ( chp2 , tmpstr ) , osdlog ) ;
Bprintf ( " %s " , chp2 ) ;
Bfree ( chp2 ) ;
2008-08-03 11:45:15 +00:00
}
2008-01-04 01:04:35 +00:00
}
2014-07-06 00:12:25 +00:00
else if ( osd - > log . lines = = osd - > log . cutoff )
2008-01-04 01:04:35 +00:00
{
2014-07-24 14:01:44 +00:00
Bfputs ( " \n Maximal log size reached. Logging stopped. \n Set the \" osdlogcutoff \" console variable to a higher value if you need a longer log. \n " , osdlog ) ;
2014-07-06 00:12:25 +00:00
osd - > log . lines = osd - > log . cutoff + 1 ;
2008-01-04 01:04:35 +00:00
}
2008-08-24 05:39:28 +00:00
chp = tmpstr ;
do
2007-12-12 17:42:14 +00:00
{
2008-08-24 05:39:28 +00:00
if ( * chp = = ' \n ' )
{
2014-07-06 00:12:25 +00:00
osd - > text . pos = 0 ;
osd - > log . lines + + ;
2010-05-02 23:27:30 +00:00
OSD_LineFeed ( ) ;
2008-08-24 05:39:28 +00:00
continue ;
}
2011-01-16 02:50:27 +00:00
2008-08-24 05:39:28 +00:00
if ( * chp = = ' \r ' )
{
2014-07-06 00:12:25 +00:00
osd - > text . pos = 0 ;
2008-08-24 05:39:28 +00:00
continue ;
}
2011-01-16 02:50:27 +00:00
2008-08-24 05:39:28 +00:00
if ( * chp = = ' ^ ' )
2008-07-18 09:50:44 +00:00
{
if ( isdigit ( * ( chp + 1 ) ) )
{
2008-08-24 05:39:28 +00:00
char smallbuf [ 4 ] ;
2008-08-24 09:29:03 +00:00
if ( ! isdigit ( * ( + + chp + 1 ) ) )
2008-08-24 05:39:28 +00:00
{
smallbuf [ 0 ] = * ( chp ) ;
smallbuf [ 1 ] = ' \0 ' ;
2012-02-20 21:17:39 +00:00
p = Batol ( smallbuf ) ;
2008-08-24 09:29:03 +00:00
continue ;
2008-08-24 05:39:28 +00:00
}
2011-01-16 02:50:27 +00:00
2008-08-24 09:29:03 +00:00
smallbuf [ 0 ] = * ( chp + + ) ;
smallbuf [ 1 ] = * ( chp ) ;
smallbuf [ 2 ] = ' \0 ' ;
2012-02-20 21:17:39 +00:00
p = Batol ( smallbuf ) ;
2008-08-24 05:39:28 +00:00
continue ;
}
2011-01-16 02:50:27 +00:00
2008-08-24 05:39:28 +00:00
if ( Btoupper ( * ( chp + 1 ) ) = = ' S ' )
{
chp + + ;
if ( isdigit ( * ( + + chp ) ) )
s = * chp ;
continue ;
2008-07-18 09:50:44 +00:00
}
2011-01-16 02:50:27 +00:00
2008-08-24 05:39:28 +00:00
if ( Btoupper ( * ( chp + 1 ) ) = = ' O ' )
2008-07-18 09:50:44 +00:00
{
2008-08-24 05:39:28 +00:00
chp + + ;
2014-07-06 00:12:25 +00:00
p = osd - > draw . textpal ;
s = osd - > draw . textshade ;
2008-08-24 05:39:28 +00:00
continue ;
2008-07-18 09:50:44 +00:00
}
}
2011-01-16 02:50:27 +00:00
2014-07-06 00:12:25 +00:00
osd - > text . buf [ osd - > text . pos ] = * chp ;
osd - > text . fmt [ osd - > text . pos + + ] = p + ( s < < 5 ) ;
2011-01-16 02:50:27 +00:00
2014-07-06 00:12:25 +00:00
if ( osd - > text . pos = = osd - > draw . cols )
2007-12-12 17:42:14 +00:00
{
2014-07-06 00:12:25 +00:00
osd - > text . pos = 0 ;
2010-05-02 23:27:30 +00:00
OSD_LineFeed ( ) ;
2007-12-12 17:42:14 +00:00
}
2008-08-24 06:17:09 +00:00
}
while ( * ( + + chp ) ) ;
2010-06-22 21:50:01 +00:00
2014-07-06 00:12:25 +00:00
mutex_unlock ( & osd - > mutex ) ;
2006-04-13 20:47:06 +00:00
}
//
// OSD_DispatchQueued() -- Executes any commands queued in the buffer
//
void OSD_DispatchQueued ( void )
{
2009-01-09 09:29:17 +00:00
int32_t cmd ;
2006-04-13 20:47:06 +00:00
2014-07-06 00:12:25 +00:00
if ( ! osd - > history . exec ) return ;
2006-04-13 20:47:06 +00:00
2014-07-06 00:12:25 +00:00
cmd = osd - > history . exec - 1 ;
osd - > history . exec = 0 ;
2006-04-24 19:04:22 +00:00
2007-12-12 17:42:14 +00:00
for ( ; cmd > = 0 ; cmd - - )
2014-07-06 00:12:25 +00:00
OSD_Dispatch ( ( const char * ) osd - > history . buf [ cmd ] ) ;
2006-04-13 20:47:06 +00:00
}
//
// OSD_Dispatch() -- Executes a command string
//
2009-01-09 09:29:17 +00:00
static char * strtoken ( char * s , char * * ptrptr , int32_t * restart )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
char * p , * p2 , * start ;
* restart = 0 ;
if ( ! ptrptr ) return NULL ;
// if s != NULL, we process from the start of s, otherwise
// we just continue with where ptrptr points to
if ( s ) p = s ;
else p = * ptrptr ;
if ( ! p ) return NULL ;
// eat up any leading whitespace
while ( * p ! = 0 & & * p ! = ' ; ' & & * p = = ' ' ) p + + ;
// a semicolon is an end of statement delimiter like a \0 is, so we signal
// the caller to 'restart' for the rest of the string pointed at by *ptrptr
2007-12-12 17:42:14 +00:00
if ( * p = = ' ; ' )
{
2006-04-24 19:04:22 +00:00
* restart = 1 ;
* ptrptr = p + 1 ;
return NULL ;
}
// or if we hit the end of the input, signal all done by nulling *ptrptr
2007-12-12 17:42:14 +00:00
else if ( * p = = 0 )
{
2006-04-24 19:04:22 +00:00
* ptrptr = NULL ;
return NULL ;
}
2007-12-12 17:42:14 +00:00
if ( * p = = ' \" ' )
{
2006-04-24 19:04:22 +00:00
// quoted string
start = + + p ;
p2 = p ;
2007-12-12 17:42:14 +00:00
while ( * p ! = 0 )
{
if ( * p = = ' \" ' )
{
2006-04-24 19:04:22 +00:00
p + + ;
break ;
2007-12-12 17:42:14 +00:00
}
else if ( * p = = ' \\ ' )
{
switch ( * ( + + p ) )
{
2006-11-13 23:12:47 +00:00
case ' n ' :
* p2 = ' \n ' ; break ;
case ' r ' :
* p2 = ' \r ' ; break ;
default :
* p2 = * p ; break ;
2006-04-24 19:04:22 +00:00
}
2007-12-12 17:42:14 +00:00
}
else
{
2006-04-24 19:04:22 +00:00
* p2 = * p ;
}
p2 + + , p + + ;
}
* p2 = 0 ;
2007-12-12 17:42:14 +00:00
}
else
{
2006-04-24 19:04:22 +00:00
start = p ;
while ( * p ! = 0 & & * p ! = ' ; ' & & * p ! = ' ' ) p + + ;
}
// if we hit the end of input, signal all done by nulling *ptrptr
2007-12-12 17:42:14 +00:00
if ( * p = = 0 )
{
2006-04-24 19:04:22 +00:00
* ptrptr = NULL ;
}
// or if we came upon a semicolon, signal caller to restart with the
// string at *ptrptr
2007-12-12 17:42:14 +00:00
else if ( * p = = ' ; ' )
{
2006-04-24 19:04:22 +00:00
* p = 0 ;
* ptrptr = p + 1 ;
* restart = 1 ;
}
// otherwise, clip off the token and carry on
2007-12-12 17:42:14 +00:00
else
{
2006-04-24 19:04:22 +00:00
* ( p + + ) = 0 ;
* ptrptr = p ;
}
return start ;
2006-04-13 20:47:06 +00:00
}
# define MAXPARMS 512
2009-01-09 09:29:17 +00:00
int32_t OSD_Dispatch ( const char * cmd )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
char * workbuf , * wp , * wtp , * state ;
2010-05-09 08:51:25 +00:00
int32_t restart = 0 ;
2006-04-24 19:04:22 +00:00
2014-05-30 00:02:19 +00:00
workbuf = state = Xstrdup ( cmd ) ;
2006-04-24 19:04:22 +00:00
2007-12-12 17:42:14 +00:00
do
{
2010-05-09 08:51:25 +00:00
int32_t numparms = 0 ;
symbol_t * symb ;
osdfuncparm_t ofp ;
2016-01-11 05:05:38 +00:00
char const * parms [ MAXPARMS ] ;
2010-05-09 08:51:25 +00:00
2006-04-24 19:04:22 +00:00
Bmemset ( parms , 0 , sizeof ( parms ) ) ;
2010-05-09 08:51:25 +00:00
if ( ( wp = strtoken ( state , & wtp , & restart ) ) = = NULL )
2007-12-12 17:42:14 +00:00
{
2006-04-24 19:04:22 +00:00
state = wtp ;
continue ;
}
2010-05-09 08:51:25 +00:00
if ( ( symb = findexactsymbol ( wp ) ) = = NULL )
2008-06-29 12:53:18 +00:00
{
2010-05-22 23:41:18 +00:00
if ( ( wp [ 0 ] ! = ' / ' | | wp [ 1 ] ! = ' / ' ) & & ! m32_osd_tryscript ) // cheap hack for comments in cfgs
{
2010-05-09 08:51:25 +00:00
OSD_Printf ( OSDTEXT_RED " \" %s \" is not a valid command or cvar \n " , wp ) ;
2010-05-22 23:41:18 +00:00
}
else if ( m32_osd_tryscript )
{
M32RunScript ( cmd ) ;
}
2009-10-07 06:47:35 +00:00
Bfree ( workbuf ) ;
2006-04-24 19:04:22 +00:00
return - 1 ;
}
ofp . name = wp ;
2007-12-12 17:42:14 +00:00
while ( wtp & & ! restart )
{
2006-04-24 19:04:22 +00:00
wp = strtoken ( NULL , & wtp , & restart ) ;
if ( wp & & numparms < MAXPARMS ) parms [ numparms + + ] = wp ;
}
ofp . numparms = numparms ;
ofp . parms = ( const char * * ) parms ;
ofp . raw = cmd ;
2010-05-09 08:51:25 +00:00
2012-11-05 02:49:08 +00:00
if ( ( intptr_t ) symb - > func = = ( intptr_t ) OSD_ALIAS )
2010-05-09 08:51:25 +00:00
OSD_Dispatch ( symb - > help ) ;
2012-11-05 02:49:08 +00:00
else if ( ( intptr_t ) symb - > func ! = ( intptr_t ) OSD_UNALIASED )
2008-06-30 00:18:59 +00:00
switch ( symb - > func ( & ofp ) )
{
case OSDCMD_OK :
break ;
case OSDCMD_SHOWHELP :
OSD_Printf ( " %s \n " , symb - > help ) ;
break ;
}
2006-04-24 19:04:22 +00:00
state = wtp ;
2007-12-12 17:42:14 +00:00
}
while ( wtp & & restart ) ;
2006-04-24 19:04:22 +00:00
2009-10-07 06:47:35 +00:00
Bfree ( workbuf ) ;
2006-04-24 19:04:22 +00:00
return 0 ;
2006-04-13 20:47:06 +00:00
}
//
// OSD_RegisterFunction() -- Registers a new function
//
2011-01-16 02:50:27 +00:00
int32_t OSD_RegisterFunction ( const char * name , const char * help , int32_t ( * func ) ( const osdfuncparm_t * ) )
2006-04-13 20:47:06 +00:00
{
2006-04-24 19:04:22 +00:00
symbol_t * symb ;
const char * cp ;
2014-07-06 00:12:25 +00:00
if ( ! osd )
2010-05-02 23:27:30 +00:00
OSD_Init ( ) ;
2006-04-24 19:04:22 +00:00
2010-05-07 20:45:40 +00:00
if ( ! name | | ! name [ 0 ] )
2007-12-12 17:42:14 +00:00
{
2010-05-07 20:45:40 +00:00
OSD_Printf ( " OSD_RegisterFunction(): can't register function with null name \n " ) ;
2006-04-24 19:04:22 +00:00
return - 1 ;
}
2010-05-07 20:45:40 +00:00
if ( ! func )
2007-12-12 17:42:14 +00:00
{
2010-05-07 20:45:40 +00:00
OSD_Printf ( " OSD_RegisterFunction(): can't register null function \n " ) ;
2006-04-24 19:04:22 +00:00
return - 1 ;
}
// check for illegal characters in name
2007-12-12 17:42:14 +00:00
for ( cp = name ; * cp ; cp + + )
{
if ( ( cp = = name ) & & ( * cp > = ' 0 ' ) & & ( * cp < = ' 9 ' ) )
{
2008-06-29 22:37:30 +00:00
OSD_Printf ( " OSD_RegisterFunction(): first character of function name \" %s \" must not be a numeral \n " , name ) ;
2006-04-24 19:04:22 +00:00
return - 1 ;
}
if ( ( * cp < ' 0 ' ) | |
( * cp > ' 9 ' & & * cp < ' A ' ) | |
( * cp > ' Z ' & & * cp < ' a ' & & * cp ! = ' _ ' ) | |
2007-12-12 17:42:14 +00:00
( * cp > ' z ' ) )
{
2008-06-29 22:37:30 +00:00
OSD_Printf ( " OSD_RegisterFunction(): illegal character in function name \" %s \" \n " , name ) ;
2006-04-24 19:04:22 +00:00
return - 1 ;
}
}
if ( ! help ) help = " (no description for this function) " ;
symb = findexactsymbol ( name ) ;
2010-05-07 20:45:40 +00:00
2008-06-29 22:37:30 +00:00
if ( symb ) // allow this now for reusing an alias name
2007-12-12 17:42:14 +00:00
{
2011-01-16 02:50:27 +00:00
/*
if ( symb - > func ! = OSD_ALIAS & & symb - > func ! = OSD_UNALIASED )
{
OSD_Printf ( " OSD_RegisterFunction(): \" %s \" is already defined \n " , name ) ;
return - 1 ;
}
*/
2010-07-05 01:45:29 +00:00
// Bfree((char *)symb->help);
2008-06-29 22:37:30 +00:00
symb - > help = help ;
2008-06-30 01:03:51 +00:00
symb - > func = func ;
2008-06-30 00:32:05 +00:00
return 0 ;
2006-04-24 19:04:22 +00:00
}
symb = addnewsymbol ( name ) ;
2010-05-07 20:45:40 +00:00
2007-12-12 17:42:14 +00:00
if ( ! symb )
{
2008-06-29 22:37:30 +00:00
OSD_Printf ( " OSD_RegisterFunction(): Failed registering function \" %s \" \n " , name ) ;
2006-04-24 19:04:22 +00:00
return - 1 ;
}
symb - > name = name ;
symb - > help = help ;
symb - > func = func ;
return 0 ;
2006-04-13 20:47:06 +00:00
}
2006-12-11 04:38:10 +00:00
//
// OSD_SetVersionString()
//
2010-05-02 23:27:30 +00:00
void OSD_SetVersion ( const char * version , int32_t shade , int32_t pal )
2006-12-11 04:38:10 +00:00
{
2014-07-06 00:12:25 +00:00
osdstr_t * v = & osd - > verstr ;
DO_FREE_AND_NULL ( v - > buf ) ;
v - > buf = Bstrdup ( version ) ;
v - > len = Bstrlen ( version ) ;
v - > shade = shade ;
v - > pal = pal ;
2006-12-11 04:38:10 +00:00
}
2006-04-13 20:47:06 +00:00
//
// addnewsymbol() -- Allocates space for a new symbol and attaches it
// appropriately to the lists, sorted.
//
2008-08-25 02:12:02 +00:00
2006-04-13 20:47:06 +00:00
static symbol_t * addnewsymbol ( const char * name )
{
2006-04-24 19:04:22 +00:00
symbol_t * newsymb , * s , * t ;
2014-07-06 00:12:25 +00:00
if ( osd - > numsymbols > = OSDMAXSYMBOLS ) return NULL ;
2014-05-30 00:02:19 +00:00
newsymb = ( symbol_t * ) Xmalloc ( sizeof ( symbol_t ) ) ;
2006-04-24 19:04:22 +00:00
Bmemset ( newsymb , 0 , sizeof ( symbol_t ) ) ;
// link it to the main chain
2007-12-12 17:42:14 +00:00
if ( ! symbols )
{
2006-04-24 19:04:22 +00:00
symbols = newsymb ;
2007-12-12 17:42:14 +00:00
}
else
{
if ( Bstrcasecmp ( name , symbols - > name ) < = 0 )
{
2006-04-24 19:04:22 +00:00
t = symbols ;
symbols = newsymb ;
symbols - > next = t ;
2007-12-12 17:42:14 +00:00
}
else
{
2006-04-24 19:04:22 +00:00
s = symbols ;
2007-12-12 17:42:14 +00:00
while ( s - > next )
{
2006-04-24 19:04:22 +00:00
if ( Bstrcasecmp ( s - > next - > name , name ) > 0 ) break ;
s = s - > next ;
}
t = s - > next ;
s - > next = newsymb ;
newsymb - > next = t ;
}
}
2014-07-06 00:12:25 +00:00
hash_add ( & h_osd , name , osd - > numsymbols , 1 ) ;
2015-09-23 17:55:31 +00:00
char * const newname = Bstrtolower ( Xstrdup ( name ) ) ;
hash_add ( & h_osd , newname , osd - > numsymbols , 1 ) ;
Bfree ( newname ) ;
2014-07-06 00:12:25 +00:00
osd - > symbptrs [ osd - > numsymbols + + ] = newsymb ;
2006-04-24 19:04:22 +00:00
return newsymb ;
2006-04-13 20:47:06 +00:00
}
//
// findsymbol() -- Finds a symbol, possibly partially named
2006-04-24 19:04:22 +00:00
//
2006-04-13 20:47:06 +00:00
static symbol_t * findsymbol ( const char * name , symbol_t * startingat )
{
2006-04-24 19:04:22 +00:00
if ( ! startingat ) startingat = symbols ;
if ( ! startingat ) return NULL ;
2006-04-13 20:47:06 +00:00
2006-04-24 19:04:22 +00:00
for ( ; startingat ; startingat = startingat - > next )
2010-05-02 23:27:30 +00:00
if ( startingat - > func ! = OSD_UNALIASED & & ! Bstrncasecmp ( name , startingat - > name , Bstrlen ( name ) ) ) return startingat ;
2006-04-13 20:47:06 +00:00
2006-04-24 19:04:22 +00:00
return NULL ;
2006-04-13 20:47:06 +00:00
}
//
// findexactsymbol() -- Finds a symbol, complete named
2006-04-24 19:04:22 +00:00
//
2006-04-13 20:47:06 +00:00
static symbol_t * findexactsymbol ( const char * name )
{
2006-04-24 19:04:22 +00:00
if ( ! symbols ) return NULL ;
2006-04-13 20:47:06 +00:00
2015-07-08 03:34:37 +00:00
char * lname = Xstrdup ( name ) ;
intptr_t i = hash_find ( & h_osd , lname ) ;
2008-08-25 02:33:25 +00:00
if ( i > - 1 )
{
2010-05-02 23:27:30 +00:00
// if ((symbol_t *)osdsymbptrs[i]->func == OSD_UNALIASED)
2008-08-25 23:48:00 +00:00
// return NULL;
2008-10-18 12:37:26 +00:00
Bfree ( lname ) ;
2014-07-06 00:12:25 +00:00
return osd - > symbptrs [ i ] ;
2008-08-25 02:33:25 +00:00
}
2008-12-31 09:07:49 +00:00
// try it again
2010-05-16 22:53:08 +00:00
Bstrtolower ( lname ) ;
2010-05-02 23:27:30 +00:00
i = hash_find ( & h_osd , lname ) ;
2008-10-18 12:37:26 +00:00
Bfree ( lname ) ;
2008-12-31 09:07:49 +00:00
2015-07-08 03:34:37 +00:00
return ( i > - 1 ) ? osd - > symbptrs [ i ] : NULL ;
2006-04-13 20:47:06 +00:00
}
2009-04-29 06:20:07 +00:00
int32_t osdcmd_cvar_set ( const osdfuncparm_t * parm )
{
int32_t showval = ( parm - > numparms = = 0 ) ;
2015-07-08 03:34:37 +00:00
intptr_t i = hash_find ( & h_cvars , parm - > name ) ;
2009-04-29 06:20:07 +00:00
if ( i < 0 )
2014-07-06 00:12:25 +00:00
for ( i = osd - > numcvars - 1 ; i > = 0 ; i - - )
if ( ! Bstrcasecmp ( parm - > name , osd - > cvars [ i ] . c . name ) ) break ;
2009-04-29 06:20:07 +00:00
if ( i > - 1 )
{
2014-07-06 00:12:25 +00:00
if ( osd - > cvars [ i ] . c . type & CVAR_LOCKED )
2009-04-29 06:20:07 +00:00
{
// sound the alarm
2014-07-06 00:12:25 +00:00
OSD_Printf ( " Cvar \" %s \" is read only. \n " , osd - > cvars [ i ] . c . name ) ;
2009-04-29 06:20:07 +00:00
return OSDCMD_OK ;
}
2009-04-30 21:09:44 +00:00
2014-07-06 00:12:25 +00:00
switch ( osd - > cvars [ i ] . c . type & ( CVAR_FLOAT | CVAR_DOUBLE | CVAR_INT | CVAR_UINT | CVAR_BOOL | CVAR_STRING ) )
2009-04-30 21:09:44 +00:00
{
case CVAR_FLOAT :
2009-06-24 08:20:10 +00:00
{
if ( showval )
2009-04-30 01:07:08 +00:00
{
2016-01-11 05:05:38 +00:00
OSD_Printf ( " \" %s \" is \" %f \" \n %s: %s \n " , osd - > cvars [ i ] . c . name , * ( float * ) osd - > cvars [ i ] . c . vptr , osd - > cvars [ i ] . c . name , osd - > cvars [ i ] . c . desc ) ;
2009-06-24 08:20:10 +00:00
return OSDCMD_OK ;
}
2009-04-29 06:20:07 +00:00
2015-07-08 03:34:37 +00:00
float val ;
Bsscanf ( parm - > parms [ 0 ] , " %f " , & val ) ;
2009-04-29 06:20:07 +00:00
2014-07-06 00:12:25 +00:00
if ( val < osd - > cvars [ i ] . c . min | | val > osd - > cvars [ i ] . c . max )
2009-06-24 08:20:10 +00:00
{
2014-07-06 00:12:25 +00:00
OSD_Printf ( " %s value out of range \n " , osd - > cvars [ i ] . c . name ) ;
2009-06-24 08:20:10 +00:00
return OSDCMD_OK ;
2009-04-30 01:07:08 +00:00
}
2014-07-06 00:12:25 +00:00
* ( float * ) osd - > cvars [ i ] . c . vptr = val ;
2009-06-24 08:20:10 +00:00
if ( ! OSD_ParsingScript ( ) )
2014-07-06 00:12:25 +00:00
OSD_Printf ( " %s %f " , osd - > cvars [ i ] . c . name , val ) ;
2009-06-24 08:20:10 +00:00
}
break ;
2009-04-30 21:09:44 +00:00
case CVAR_DOUBLE :
2009-06-24 08:20:10 +00:00
{
if ( showval )
2009-04-30 21:09:44 +00:00
{
2016-01-11 05:05:38 +00:00
OSD_Printf ( " \" %s \" is \" %f \" \n %s: %s \n " , osd - > cvars [ i ] . c . name , * ( double * ) osd - > cvars [ i ] . c . vptr , osd - > cvars [ i ] . c . name , osd - > cvars [ i ] . c . desc ) ;
2009-06-24 08:20:10 +00:00
return OSDCMD_OK ;
}
2009-04-30 21:09:44 +00:00
2015-07-08 03:34:37 +00:00
double val ;
Bsscanf ( parm - > parms [ 0 ] , " %lf " , & val ) ;
2009-04-30 21:09:44 +00:00
2014-07-06 00:12:25 +00:00
if ( val < osd - > cvars [ i ] . c . min | | val > osd - > cvars [ i ] . c . max )
2009-06-24 08:20:10 +00:00
{
2014-07-06 00:12:25 +00:00
OSD_Printf ( " %s value out of range \n " , osd - > cvars [ i ] . c . name ) ;
2009-06-24 08:20:10 +00:00
return OSDCMD_OK ;
2009-04-30 21:09:44 +00:00
}
2014-07-06 00:12:25 +00:00
* ( double * ) osd - > cvars [ i ] . c . vptr = val ;
2009-06-24 08:20:10 +00:00
if ( ! OSD_ParsingScript ( ) )
2014-07-06 00:12:25 +00:00
OSD_Printf ( " %s %f " , osd - > cvars [ i ] . c . name , val ) ;
2009-06-24 08:20:10 +00:00
}
break ;
2009-04-30 21:09:44 +00:00
case CVAR_INT :
case CVAR_BOOL :
2009-06-24 08:20:10 +00:00
{
if ( showval )
2009-04-30 01:07:08 +00:00
{
2016-03-14 00:07:52 +00:00
OSD_Printf ( " \" %s \" is \" %d \" \n %s: %s \n " , osd - > cvars [ i ] . c . name , * ( int32_t * ) osd - > cvars [ i ] . c . vptr , osd - > cvars [ i ] . c . name , osd - > cvars [ i ] . c . desc ) ;
2009-06-24 08:20:10 +00:00
return OSDCMD_OK ;
}
2009-04-29 06:20:07 +00:00
2015-07-08 03:34:37 +00:00
int32_t val = Batoi ( parm - > parms [ 0 ] ) ;
2014-07-06 00:12:25 +00:00
if ( osd - > cvars [ i ] . c . type & CVAR_BOOL ) val = val ! = 0 ;
2009-04-29 06:20:07 +00:00
2016-03-14 00:07:52 +00:00
if ( val < osd - > cvars [ i ] . c . min | | ( ( val > osd - > cvars [ i ] . c . max ) ) )
2009-06-24 08:20:10 +00:00
{
2014-07-06 00:12:25 +00:00
OSD_Printf ( " %s value out of range \n " , osd - > cvars [ i ] . c . name ) ;
2009-06-24 08:20:10 +00:00
return OSDCMD_OK ;
2009-04-30 01:07:08 +00:00
}
2014-07-06 00:12:25 +00:00
* ( int32_t * ) osd - > cvars [ i ] . c . vptr = val ;
2009-06-24 08:20:10 +00:00
if ( ! OSD_ParsingScript ( ) )
2014-07-06 00:12:25 +00:00
OSD_Printf ( " %s %d " , osd - > cvars [ i ] . c . name , val ) ;
2009-06-24 08:20:10 +00:00
}
break ;
2016-03-14 00:07:52 +00:00
case CVAR_UINT :
{
if ( showval )
{
OSD_Printf ( " \" %s \" is \" %u \" \n %s: %s \n " , osd - > cvars [ i ] . c . name , * ( int32_t * ) osd - > cvars [ i ] . c . vptr , osd - > cvars [ i ] . c . name , osd - > cvars [ i ] . c . desc ) ;
return OSDCMD_OK ;
}
uint32_t val = Bstrtoul ( parm - > parms [ 0 ] , NULL , 0 ) ;
if ( val < ( unsigned ) osd - > cvars [ i ] . c . min | | val > ( unsigned ) osd - > cvars [ i ] . c . max )
{
OSD_Printf ( " %s value out of range \n " , osd - > cvars [ i ] . c . name ) ;
return OSDCMD_OK ;
}
* ( uint32_t * ) osd - > cvars [ i ] . c . vptr = val ;
if ( ! OSD_ParsingScript ( ) )
OSD_Printf ( " %s %d " , osd - > cvars [ i ] . c . name , val ) ;
}
break ;
2009-04-30 21:09:44 +00:00
case CVAR_STRING :
2009-06-24 08:20:10 +00:00
{
if ( showval )
2009-04-30 01:07:08 +00:00
{
2016-01-11 05:05:38 +00:00
OSD_Printf ( " \" %s \" is \" %s \" \n %s: %s \n " , osd - > cvars [ i ] . c . name , ( char * ) osd - > cvars [ i ] . c . vptr , osd - > cvars [ i ] . c . name , osd - > cvars [ i ] . c . desc ) ;
2009-06-24 08:20:10 +00:00
return OSDCMD_OK ;
2009-04-30 01:07:08 +00:00
}
2009-06-24 08:20:10 +00:00
2014-07-06 00:12:25 +00:00
Bstrncpy ( ( char * ) osd - > cvars [ i ] . c . vptr , parm - > parms [ 0 ] , osd - > cvars [ i ] . c . max - 1 ) ;
( ( char * ) osd - > cvars [ i ] . c . vptr ) [ osd - > cvars [ i ] . c . max - 1 ] = 0 ;
2009-06-24 08:20:10 +00:00
if ( ! OSD_ParsingScript ( ) )
2014-07-06 00:12:25 +00:00
OSD_Printf ( " %s %s " , osd - > cvars [ i ] . c . name , ( char * ) osd - > cvars [ i ] . c . vptr ) ;
2009-06-24 08:20:10 +00:00
}
break ;
2009-04-30 21:09:44 +00:00
default :
2014-10-29 17:06:43 +00:00
EDUKE32_UNREACHABLE_SECTION ( break ) ;
2009-04-30 21:09:44 +00:00
}
2013-05-15 02:16:19 +00:00
# ifdef USE_OPENGL
if ( ! OSD_ParsingScript ( ) )
{
2014-07-06 00:12:25 +00:00
switch ( osd - > cvars [ i ] . c . type & ( CVAR_RESTARTVID | CVAR_INVALIDATEALL | CVAR_INVALIDATEART ) )
2013-05-15 02:16:19 +00:00
{
case CVAR_RESTARTVID :
osdcmd_restartvid ( NULL ) ;
break ;
2013-05-15 02:17:17 +00:00
case CVAR_INVALIDATEALL :
2013-05-15 02:20:08 +00:00
gltexinvalidatetype ( INVALIDATE_ALL ) ;
2013-05-15 02:17:17 +00:00
case CVAR_INVALIDATEART :
2013-05-15 02:20:08 +00:00
gltexinvalidatetype ( INVALIDATE_ART ) ;
2013-05-15 02:16:19 +00:00
# ifdef POLYMER
if ( getrendermode ( ) = = REND_POLYMER )
polymer_texinvalidate ( ) ;
# endif
break ;
}
}
# endif
2009-04-29 06:20:07 +00:00
}
2009-04-30 21:09:44 +00:00
2009-04-29 19:43:51 +00:00
if ( ! OSD_ParsingScript ( ) )
OSD_Printf ( " \n " ) ;
2009-04-30 21:09:44 +00:00
2009-04-29 06:20:07 +00:00
return OSDCMD_OK ;
}
2013-12-24 09:44:24 +00:00
void OSD_WriteAliases ( FILE * fp )
{
2015-07-08 03:34:37 +00:00
for ( symbol_t * symb = symbols ; symb ! = NULL ; symb = symb - > next )
2013-12-24 09:44:24 +00:00
if ( symb - > func = = ( void * ) OSD_ALIAS )
Bfprintf ( fp , " alias \" %s \" \" %s \" \n " , symb - > name , symb - > help ) ;
}
2009-04-30 21:09:44 +00:00
void OSD_WriteCvars ( FILE * fp )
2009-04-29 19:43:51 +00:00
{
2010-05-02 23:27:30 +00:00
if ( ! fp )
return ;
2015-07-08 03:34:37 +00:00
for ( unsigned i = 0 ; i < osd - > numcvars ; i + + )
2009-04-29 19:43:51 +00:00
{
2014-07-06 00:12:25 +00:00
if ( ! ( osd - > cvars [ i ] . c . type & CVAR_NOSAVE ) & & OSD_CvarModified ( & osd - > cvars [ i ] ) )
switch ( osd - > cvars [ i ] . c . type & ( CVAR_FLOAT | CVAR_DOUBLE | CVAR_INT | CVAR_UINT | CVAR_BOOL | CVAR_STRING ) )
2011-01-16 02:50:27 +00:00
{
2010-05-02 23:27:30 +00:00
case CVAR_FLOAT :
2014-07-06 00:12:25 +00:00
fprintf ( fp , " %s \" %f \" \n " , osd - > cvars [ i ] . c . name , * ( float * ) osd - > cvars [ i ] . c . vptr ) ;
2010-05-02 23:27:30 +00:00
break ;
case CVAR_DOUBLE :
2014-07-06 00:12:25 +00:00
fprintf ( fp , " %s \" %f \" \n " , osd - > cvars [ i ] . c . name , * ( double * ) osd - > cvars [ i ] . c . vptr ) ;
2010-05-02 23:27:30 +00:00
break ;
case CVAR_INT :
case CVAR_BOOL :
2014-07-06 00:12:25 +00:00
fprintf ( fp , " %s \" %d \" \n " , osd - > cvars [ i ] . c . name , * ( int32_t * ) osd - > cvars [ i ] . c . vptr ) ;
2010-05-02 23:27:30 +00:00
break ;
2015-03-24 10:49:03 +00:00
case CVAR_UINT :
fprintf ( fp , " %s \" %u \" \n " , osd - > cvars [ i ] . c . name , * ( uint32_t * ) osd - > cvars [ i ] . c . vptr ) ;
break ;
2010-05-02 23:27:30 +00:00
case CVAR_STRING :
2014-07-06 00:12:25 +00:00
fprintf ( fp , " %s \" %s \" \n " , osd - > cvars [ i ] . c . name , ( char * ) osd - > cvars [ i ] . c . vptr ) ;
2010-05-02 23:27:30 +00:00
break ;
default :
2014-10-29 17:06:43 +00:00
EDUKE32_UNREACHABLE_SECTION ( break ) ;
2011-01-16 02:50:27 +00:00
}
2009-04-29 19:43:51 +00:00
}
}