⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.c

📁 The source code of Doom legacy for windows
💻 C
📖 第 1 页 / 共 2 页
字号:
//  Setup the console text buffer//void CON_Init(void){    int i;    for(i=0;i<NUMINPUTS;i++)        bindtable[i]=NULL;    // clear all lines    memset(con_buffer,0,CON_BUFFERSIZE);    // make sure it is ready for the loading screen    con_width = 0;    CON_RecalcSize ();    CON_SetupBackColormap ();    //note: CON_Ticker should always execute at least once before D_Display()    con_clipviewtop = -1;     // -1 does not clip    con_hudlines = CON_MAXHUDLINES;    // setup console input filtering    CON_InputInit ();    // load console background pic    con_backpic = (pic_t*) W_CacheLumpName ("CONSBACK",PU_STATIC);    // borders MUST be there    con_bordleft  = (pic_t*) W_CacheLumpName ("CBLEFT",PU_STATIC);    con_bordright = (pic_t*) W_CacheLumpName ("CBRIGHT",PU_STATIC);    // register our commands    //    CV_RegisterVar (&cons_msgtimeout);    CV_RegisterVar (&cons_speed);    CV_RegisterVar (&cons_height);    CV_RegisterVar (&cons_backpic);    COM_AddCommand ("cls", CONS_Clear_f);    COM_AddCommand ("english", CONS_English_f);    COM_AddCommand ("french", CONS_French_f);    COM_AddCommand ("bind", CONS_Bind_f);    // set console full screen for game startup MAKE SURE VID_Init() done !!!    con_destlines = vid.height;    con_curlines = vid.height;    consoletoggle = false;    con_started = true;    con_startup = true; // need explicit screen refresh                        // until we are in Doomloop}//  Console input initialization//static void CON_InputInit (void){    int    i;    // prepare the first prompt line    memset (inputlines,0,sizeof(inputlines));    for (i=0; i<32; i++)        inputlines[i][0] = CON_PROMPTCHAR;    inputline = 0;    input_cx = 1;}//======================================================================//                        CONSOLE EXECUTION//======================================================================//  Called at screen size change to set the rows and line size of the//  console text buffer.//static void CON_RecalcSize (void){    int   conw, oldcon_width, oldnumlines, i, oldcon_cy;    char  tmp_buffer[CON_BUFFERSIZE];    char  string[CON_BUFFERSIZE]; // BP: it is a line but who know    con_recalc = false;    conw = (vid.width>>3)-2;    if( con_curlines==200 )  // first init    {        con_curlines=vid.height;        con_destlines=vid.height;    }    // check for change of video width    if (conw == con_width)        return;                 // didnt change    oldcon_width = con_width;    oldnumlines = con_totallines;    oldcon_cy = con_cy;    memcpy(tmp_buffer, con_buffer, CON_BUFFERSIZE);    if (conw<1)        con_width = (BASEVIDWIDTH>>3)-2;    else        con_width = conw;    con_totallines = CON_BUFFERSIZE / con_width;    memset (con_buffer,' ',CON_BUFFERSIZE);    con_cx = 0;    con_cy = con_totallines-1;    con_line = &con_buffer[con_cy*con_width];    con_scrollup = 0;    // re-arrange console text buffer to keep text    if(oldcon_width) // not the first time    {        for(i=oldcon_cy+1;i<oldcon_cy+oldnumlines;i++)        {            if( tmp_buffer[(i% oldnumlines)*oldcon_width])            {                memcpy(string, &tmp_buffer[(i% oldnumlines)*oldcon_width], oldcon_width);                conw=oldcon_width-1;                while(string[conw]==' ' && conw) conw--;                string[conw+1]='\n';                string[conw+2]='\0';                CON_Print(string);            }        }    }}// Handles Console moves in/out of screen (per frame)//static void CON_MoveConsole (void){    // up/down move to dest    if (con_curlines < con_destlines)    {        con_curlines+=cons_speed.value;        if (con_curlines > con_destlines)           con_curlines = con_destlines;    }    else if (con_curlines > con_destlines)    {        con_curlines-=cons_speed.value;        if (con_curlines < con_destlines)            con_curlines = con_destlines;    }}//  Clear time of console heads up messages//void CON_ClearHUD (void){    int    i;    for(i=0; i<con_hudlines; i++)        con_hudtime[i]=0;}// Force console to move out immediately// note: con_ticker will set consoleready falsevoid CON_ToggleOff (void){    if (!con_destlines)        return;    con_destlines = 0;    con_curlines = 0;    CON_ClearHUD ();    con_forcepic = 0;    con_clipviewtop = -1;       //remove console clipping of view}//  Console ticker : handles console move in/out, cursor blinking//void CON_Ticker (void){    int    i;    // cursor blinking    con_tick++;    con_tick &= 7;    // console key was pushed    if (consoletoggle)    {        consoletoggle = false;        // toggle off console        if (con_destlines > 0)        {            con_destlines = 0;            CON_ClearHUD ();        }        else        {            // toggle console in            con_destlines = (cons_height.value*vid.height)/100;            if (con_destlines < 20)                con_destlines = 20;            else            if (con_destlines > vid.height-stbarheight)                con_destlines = vid.height-stbarheight;            con_destlines &= ~0x3;      // multiple of text row height        }    }    // console movement    if (con_destlines!=con_curlines)        CON_MoveConsole ();    // clip the view, so that the part under the console is not drawn    con_clipviewtop = -1;    if (cons_backpic.value)   // clip only when using an opaque background    {        if (con_curlines > 0)            con_clipviewtop = con_curlines - viewwindowy - 1 - 10;//NOTE: BIG HACK::SUBTRACT 10, SO THAT WATER DON'T COPY LINES OF THE CONSOLE//      WINDOW!!! (draw some more lines behind the bottom of the console)        if (con_clipviewtop<0)            con_clipviewtop = -1;   //maybe not necessary, provided it's <0    }    // check if console ready for prompt    if (/*(con_curlines==con_destlines) &&*/ (con_destlines>=20))        consoleready = true;    else        consoleready = false;    // make overlay messages disappear after a while    for (i=0 ; i<con_hudlines; i++)    {        con_hudtime[i]--;        if (con_hudtime[i]<0)            con_hudtime[i]=0;    }}//  Handles console key input//boolean CON_Responder (event_t *ev){//static boolean altdown;static boolean shiftdown;// sequential completions a la 4dosstatic char    completion[80];static int     comskips,varskips;    char   *cmd;    int     key;    if(chat_on)        return false;     // special keys state    if (ev->data1 == KEY_SHIFT && ev->type == ev_keyup)    {        shiftdown = false;        return false;    }    //else if (ev->data1 == KEY_ALT)    //{    //    altdown = (ev->type == ev_keydown);    //    return false;    //}    // let go keyup events, don't eat them    if (ev->type != ev_keydown)        return false;    key = ev->data1;////  check for console toggle key//    if (key == gamecontrol[gc_console][0] ||        key == gamecontrol[gc_console][1] )    {        consoletoggle = true;        return true;    }////  check other keys only if console prompt is active//    if (!consoleready && key < NUMINPUTS) // metzgermeister: boundary check !!    {        if(bindtable[key])        {            COM_BufAddText (bindtable[key]);            COM_BufAddText ("\n");            return true;        }        return false;    }    // eat shift only if console active    if (key == KEY_SHIFT)    {        shiftdown = true;        return true;    }    // escape key toggle off console    if (key == KEY_ESCAPE)    {        consoletoggle = true;        return true;    }    // command completion forward (tab) and backward (shift-tab)    if (key == KEY_TAB)    {        // TOTALLY UTTERLY UGLY NIGHT CODING BY FAB!!! :-)        //        // sequential command completion forward and backward        // remember typing for several completions (

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -