diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index ccf77c39..4f0481ed 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -400,19 +400,20 @@ void dokill(playerent *pl, playerent *act, bool gib) s_strcpy(pname, pl==player1 ? "you" : colorname(pl)); s_strcpy(aname, act==player1 ? "you" : colorname(act)); s_strcpy(death, gib ? "gibbed" : "fragged"); + void (*outf)(const char *s, ...) = (pl == player1 || act == player1) ? hudoutf : conoutf; if(pl==act) - conoutf("\f2%s suicided%s", pname, pl==player1 ? "!" : ""); + outf("\f2%s suicided%s", pname, pl==player1 ? "!" : ""); else if(isteam(pl->team, act->team)) { - if(pl==player1) conoutf("\f2you got %s by a teammate (%s)", death, aname); - else conoutf("\f2%s %s %s teammate (%s)", aname, death, act==player1 ? "a" : "his", pname); + if(pl==player1) outf("\f2you got %s by a teammate (%s)", death, aname); + else outf("\f2%s %s %s teammate (%s)", aname, death, act==player1 ? "a" : "his", pname); if(act==player1) showteamkill(); } else { - if(pl==player1) conoutf("\f2you got %s by %s", death, aname); - else conoutf("\f2%s %s %s", aname, death, pname); + if(pl==player1) outf("\f2you got %s by %s", death, aname); + else outf("\f2%s %s %s", aname, death, pname); } pl->state = CS_DEAD; diff --git a/source/src/console.cpp b/source/src/console.cpp index c8e59891..17cd6354 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -2,45 +2,65 @@ #include "cube.h" -struct cline { char *cref; int outtime; }; -vector conlines; +#define CONSPAD (FONTH/3) -const int ndraw = 6; -const int WORDWRAP = 80; -int conskip = 0; +struct console : consolebuffer +{ + static const int ndraw = 6; + + int conskip; + void setconskip(int n) + { + conskip += n; + if(conskip<0) conskip = 0; + } + + static const int WORDWRAP = 80; + + bool fullconsole; + void toggleconsole() { fullconsole = !fullconsole; } + + void addline(const char *sf, bool highlight) { consolebuffer::addline(sf, highlight, lastmillis); } + void render() + { + if(fullconsole) + { + int w = VIRTW*2, h = VIRTH*2; + int numl = (h*2/5)/(FONTH*5/4); + int offset = min(conskip, max(conlines.length() - numl, 0)); + blendbox(CONSPAD, CONSPAD, w-CONSPAD, 2*CONSPAD+numl*FONTH*5/4+2*FONTH/3, true); + loopi(numl) draw_text(offset+i>=conlines.length() ? "" : conlines[offset+i].cref, CONSPAD+FONTH/3, CONSPAD+(FONTH*5/4)*(numl-i-1)+FONTH/3); + } + else + { + int nd = 0; + char *refs[ndraw]; + loopv(conlines) if(conskip ? i>=conskip-1 || i>=conlines.length()-ndraw : lastmillis-conlines[i].millis<20000) + { + refs[nd++] = conlines[i].cref; + if(nd==ndraw) break; + } + loopj(nd) draw_text(refs[j], CONSPAD+FONTH/3, CONSPAD+(FONTH*5/4)*(nd-j-1)+FONTH/3); + } + } + + console() : fullconsole(false) {} +}; + +console con; bool saycommandon = false; string commandbuf; int commandpos = -1; -void setconskip(int n) -{ - conskip += n; - if(conskip<0) conskip = 0; -} +void setconskip(int n) { con.setconskip(n); } COMMANDN(conskip, setconskip, ARG_1INT); -void conline(const char *sf, bool highlight) // add a line to the console buffer -{ - cline cl; - cl.cref = conlines.length()>100 ? conlines.pop().cref : newstringbuf(""); // constrain the buffer size - cl.outtime = lastmillis; // for how long to keep line on screen - conlines.insert(0,cl); - if(highlight) // show line in a different colour, for chat etc. - { - cl.cref[0] = '\f'; - cl.cref[1] = '0'; - cl.cref[2] = 0; - s_strcat(cl.cref, sf); - } - else - { - s_strcpy(cl.cref, sf); - } -} +void toggleconsole() { con.toggleconsole(); } +COMMANDN(toggleconsole, toggleconsole, ARG_NONE); -#define CONSPAD (FONTH/3) +void renderconsole() { con.render(); } void conoutf(const char *s, ...) { @@ -51,14 +71,10 @@ void conoutf(const char *s, ...) s = sf; vector lines; text_block(s, curfont ? VIRTW*2-2*CONSPAD-2*FONTH/3 : 0, lines); - loopv(lines) conline(lines[i], i!=0); + loopv(lines) con.addline(lines[i], i!=0); lines.deletecontentsa(); } -bool fullconsole = false; -void toggleconsole() { fullconsole = !fullconsole; } -COMMAND(toggleconsole, ARG_NONE); - void rendercommand(int x, int y) { s_sprintfd(s)("> %s", commandbuf); @@ -67,29 +83,6 @@ void rendercommand(int x, int y) draw_text(s, x, y); } -void renderconsole() // render buffer taking into account time & scrolling -{ - if(fullconsole) - { - int w = VIRTW*2, h = VIRTH*2; - int numl = (h*2/5)/(FONTH*5/4); - int offset = min(conskip, max(conlines.length() - numl, 0)); - blendbox(CONSPAD, CONSPAD, w-CONSPAD, 2*CONSPAD+numl*FONTH*5/4+2*FONTH/3, true); - loopi(numl) draw_text(offset+i>=conlines.length() ? "" : conlines[offset+i].cref, CONSPAD+FONTH/3, CONSPAD+(FONTH*5/4)*(numl-i-1)+FONTH/3); - } - else - { - int nd = 0; - char *refs[ndraw]; - loopv(conlines) if(conskip ? i>=conskip-1 || i>=conlines.length()-ndraw : lastmillis-conlines[i].outtime<20000) - { - refs[nd++] = conlines[i].cref; - if(nd==ndraw) break; - } - loopj(nd) draw_text(refs[j], CONSPAD+FONTH/3, CONSPAD+(FONTH*5/4)*(nd-j-1)+FONTH/3); - } -} - // keymap is defined externally in keymap.cfg struct keym diff --git a/source/src/console.h b/source/src/console.h new file mode 100644 index 00000000..538b2ed1 --- /dev/null +++ b/source/src/console.h @@ -0,0 +1,27 @@ +struct cline { char *cref; int millis; }; + +struct consolebuffer +{ + vector conlines; + + void addline(const char *sf, bool highlight, int millis) // add a line to the console buffer + { + cline cl; + cl.cref = conlines.length()>100 ? conlines.pop().cref : newstringbuf(""); // constrain the buffer size + cl.millis = millis; // for how long to keep line on screen + conlines.insert(0,cl); + if(highlight) // show line in a different colour, for chat etc. + { + cl.cref[0] = '\f'; + cl.cref[1] = '0'; + cl.cref[2] = 0; + s_strcat(cl.cref, sf); + } + else + { + s_strcpy(cl.cref, sf); + } + } + + virtual void render() = 0; +}; \ No newline at end of file diff --git a/source/src/cube.h b/source/src/cube.h index 681dc71b..bef3bdde 100644 --- a/source/src/cube.h +++ b/source/src/cube.h @@ -59,6 +59,7 @@ #include "entity.h" #include "command.h" #include "vote.h" +#include "console.h" typedef vector cvector; typedef vector ivector; diff --git a/source/src/protos.h b/source/src/protos.h index f9ee1f5f..e3932fa8 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -306,6 +306,7 @@ extern void pruneundos(int maxremain = 0); extern void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater); extern void damageblend(int n); extern void loadingscreen(const char *fmt = NULL, ...); +extern void hudoutf(const char *s, ...); extern void show_out_of_renderloop_progress(float bar1, const char *text1, float bar2 = 0, const char *text2 = NULL); // renderparticles diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 41b34ae4..a4c52f9e 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -162,6 +162,37 @@ void drawradarent(float x, float y, float yaw, int col, int row, float iconsize, } } +struct hudmessages : consolebuffer +{ + void addline(const char *sf) { consolebuffer::addline(sf, false, lastmillis); } + void render() + { + if(!conlines.length()) return; + glLoadIdentity(); + glOrtho(0, VIRTW*0.8f, VIRTH*0.8f, 0, -1, 1); + int dispmillis = 3000; + loopi(min(conlines.length, 3)) if(lastmillis-conlines[i].millis VIRTW*0.8f ? 0 : (VIRTW*0.8f-tw)/2, ((VIRTH*0.8f)/4*3)+FONTH*i+pow((lastmillis-c.millis)/(float)dispmillis, 4)*VIRTH*0.8f/4.0f); + } + } +}; + +hudmessages hudmsgs; + +void hudoutf(const char *s, ...) +{ + s_sprintfdv(sf, s); + string sp; + filtertext(sp, sf); + puts(sp); + s = sf; + hudmsgs.addline(s); + conoutf(s); +} + bool insideradar(const vec ¢erpos, float radius, const vec &o) { if(showmap) return !o.reject(centerpos, radius); @@ -363,6 +394,9 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat } } } + + hudmsgs.render(); + if(player1->state==CS_ALIVE) { glLoadIdentity(); @@ -377,13 +411,6 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat draw_text(gunstats, 690, 827); } - if(didteamkill) - { - glLoadIdentity(); - glOrtho(0, VIRTW/3, VIRTH/3, 0, -1, 1); - draw_text("\f3you killed a teammate", VIRTW/3/40, VIRTH/3/2); - } - if(m_ctf && !hidectfhud) { glLoadIdentity();