From 664467e41cf210b3996f7c3131adc28dce06a90c Mon Sep 17 00:00:00 2001 From: TimeServ Date: Wed, 11 Jan 2006 07:23:31 +0000 Subject: [PATCH] fix to sw colormaps (MSVC is stupid) fixed clear command from crashing added ^h for toggleable half-alpha (still not rendered yet) added ^&?? for extended fg/bg colors: (poosibly temporary?) - first ? corresponds to foreground - second ? corresponds to background - valid characters for ? are 0-9, A-F and - - hexadecimal number represents a color from CGA RGBI colors - -(dash) represents default color for FG, clear for BG git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1838 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_screen.c | 28 ++++++++++++ engine/client/console.c | 88 ++++++++++++++++++++++++++++++++++++- engine/client/sbar.c | 56 +++++++++++++++++++++++ engine/common/console.h | 2 + engine/common/log.c | 13 ++++-- engine/server/sv_sys_unix.c | 28 ++++++++++++ engine/server/sv_sys_win.c | 28 ++++++++++++ engine/sw/d_trans.c | 4 +- 8 files changed, 241 insertions(+), 6 deletions(-) diff --git a/engine/client/cl_screen.c b/engine/client/cl_screen.c index 4c3135a36..f5a8f45f7 100644 --- a/engine/client/cl_screen.c +++ b/engine/client/cl_screen.c @@ -194,6 +194,28 @@ void CopyAndMarkup(conchar_t *dest, qbyte *src, int maxlength) ext = q3codemasks[*src - '0'] | (ext&~CON_Q3MASK); continue; } + else if (*src == '&') // extended code + { + if (isextendedcode(*src+1) && isextendedcode(*src+2)) + { + src++; // foreground char + if (*src == '-') // default for FG + ext = (COLOR_WHITE << CON_FGSHIFT) | (ext&~CON_FGMASK); + else if (*src >= 'A') + ext = ((*src - ('A' - 10)) << CON_FGSHIFT) | (ext&~CON_FGMASK); + else + ext = ((*src - '0') << CON_FGSHIFT) | (ext&~CON_FGMASK); + src++; // background char + if (*src == '-') // default (clear) for BG + ext &= ~CON_BGMASK & ~CON_NONCLEARBG; + else if (*src >= 'A') + ext = ((*src - ('A' - 10)) << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + else + ext = ((*src - '0') << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + continue; + } + src--; // else invalid code + } else if (*src == 'b') // toggle blink bit { src++; @@ -206,6 +228,12 @@ void CopyAndMarkup(conchar_t *dest, qbyte *src, int maxlength) ext ^= CON_2NDCHARSETTEXT; continue; } + else if (*src == 'h') + { + src++; + ext ^= CON_HALFALPHA; + continue; + } else if (*src == 's') { src++; diff --git a/engine/client/console.c b/engine/client/console.c index 5445c8150..d092e7439 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -403,7 +403,7 @@ void Con_Clear_f (void) { int i; //wide chars, not standard ascii - for (i = 0; i < sizeof(con_main.text)/sizeof(unsigned short); i++) + for (i = 0; i < sizeof(con_main.text)/sizeof(conchar_t); i++) { con_main.text[i] = ' '; // Q_memset (con_main.text, ' ', sizeof(con_main.text)); @@ -635,6 +635,26 @@ void Con_PrintCon (console_t *con, char *txt) txt+=2; continue; } + if (txt[1] == '&') // extended code + { + if (isextendedcode(txt[2]) && isextendedcode(txt[3])) + { + if (txt[2] == '-') // default for FG + mask = (COLOR_WHITE << CON_FGSHIFT) | (mask&~CON_FGMASK); + else if (txt[2] >= 'A') + mask = ((txt[2] - ('A' - 10)) << CON_FGSHIFT) | (mask&~CON_FGMASK); + else + mask = ((txt[2] - '0') << CON_FGSHIFT) | (mask&~CON_FGMASK); + if (txt[3] == '-') // default (clear) for BG + mask &= ~CON_BGMASK & ~CON_NONCLEARBG; + else if (txt[3] >= 'A') + mask = ((txt[3]- ('A' - 10)) << CON_BGSHIFT) | (mask&~CON_BGMASK) | CON_NONCLEARBG; + else + mask = ((txt[3] - '0') << CON_BGSHIFT) | (mask&~CON_BGMASK) | CON_NONCLEARBG; + txt+=4; + continue; + } + } if (txt[1] == 'b') { mask ^= CON_BLINKTEXT; @@ -647,6 +667,12 @@ void Con_PrintCon (console_t *con, char *txt) txt+=2; continue; } + if (txt[1] == 'h') + { + mask ^= CON_HALFALPHA; + txt+=2; + continue; + } if (txt[1] == 's') { if (maskstackdepth < sizeof(maskstack)/sizeof(maskstack[0])) @@ -920,10 +946,30 @@ void Con_DrawInput (void) { if (text[i+1]>='0' && text[i+1]<='9') mask = q3codemasks[text[i+1]-'0'] | (mask&~CON_Q3MASK); //change colour only. + else if (text[i+1] == '&') // extended code + { + if (isextendedcode(text[i+2]) && isextendedcode(text[i+3])) + { + if (text[i+2] == '-') // default for FG + mask = (COLOR_WHITE << CON_FGSHIFT) | (mask&~CON_FGMASK); + else if (text[i+2] >= 'A') + mask = ((text[i+2] - ('A' - 10)) << CON_FGSHIFT) | (mask&~CON_FGMASK); + else + mask = ((text[i+2] - '0') << CON_FGSHIFT) | (mask&~CON_FGMASK); + if (text[i+3] == '-') // default (clear) for BG + mask &= ~CON_BGMASK & ~CON_NONCLEARBG; + else if (text[i+3] >= 'A') + mask = ((text[i+3] - ('A' - 10)) << CON_BGSHIFT) | (mask&~CON_BGMASK) | CON_NONCLEARBG; + else + mask = ((text[i+3] - '0') << CON_BGSHIFT) | (mask&~CON_BGMASK) | CON_NONCLEARBG; + } + } else if (text[i+1] == 'b') mask ^= CON_BLINKTEXT; else if (text[i+1] == 'a') //alternate mask ^= CON_2NDCHARSETTEXT; + else if (text[i+1] == 'h') // half-alpha + mask ^= CON_HALFALPHA; else if (text[i+1] == 's') //store on stack (it's great for names) { if (maskstackdepth < sizeof(maskstack)/sizeof(maskstack[0])) @@ -1117,10 +1163,30 @@ void Con_DrawNotify (void) { if (s[x+1]>='0' && s[x+1]<='9') mask = q3codemasks[s[x+1]-'0'] | (mask&~CON_Q3MASK); //change colour only. + else if (s[x+1] == '&') // extended code + { + if (isextendedcode(s[x+2]) && isextendedcode(s[x+3])) + { + if (s[x+2] == '-') // default for FG + mask = (COLOR_WHITE << CON_FGSHIFT) | (mask&~CON_FGMASK); + else if (s[x+2] >= 'A') + mask = ((s[x+2] - ('A' - 10)) << CON_FGSHIFT) | (mask&~CON_FGMASK); + else + mask = ((s[x+2] - '0') << CON_FGSHIFT) | (mask&~CON_FGMASK); + if (s[x+3] == '-') // default (clear) for BG + mask &= ~CON_BGMASK & ~CON_NONCLEARBG; + else if (s[x+3] >= 'A') + mask = ((s[x+3] - ('A' - 10)) << CON_BGSHIFT) | (mask&~CON_BGMASK) | CON_NONCLEARBG; + else + mask = ((s[x+3] - '0') << CON_BGSHIFT) | (mask&~CON_BGMASK) | CON_NONCLEARBG; + } + } else if (s[x+1] == 'b') mask ^= CON_BLINKTEXT; else if (s[x+1] == 'a') //alternate mask ^= CON_2NDCHARSETTEXT; + else if (s[x+1] == 'h') //half-alpha + mask ^= CON_HALFALPHA; else if (s[x+1] == 's') //store on stack (it's great for names) { if (maskstackdepth < sizeof(maskstack)/sizeof(maskstack[0])) @@ -1147,10 +1213,30 @@ void Con_DrawNotify (void) { if (s[x+1]>='0' && s[x+1]<='9') mask = q3codemasks[s[x+1]-'0'] | (mask&~CON_Q3MASK); //change colour only. + else if (s[x+1] == '&') // extended code + { + if (isextendedcode(s[x+2]) && isextendedcode(s[x+3])) + { + if (s[x+2] == '-') // default for FG + mask = (COLOR_WHITE << CON_FGSHIFT) | (mask&~CON_FGMASK); + else if (s[x+2] >= 'A') + mask = ((s[x+2] - ('A' - 10)) << CON_FGSHIFT) | (mask&~CON_FGMASK); + else + mask = ((s[x+2] - '0') << CON_FGSHIFT) | (mask&~CON_FGMASK); + if (s[x+3] == '-') // default (clear) for BG + mask &= ~CON_BGMASK & ~CON_NONCLEARBG; + else if (s[x+3] >= 'A') + mask = ((s[x+3] - ('A' - 10)) << CON_BGSHIFT) | (mask&~CON_BGMASK) | CON_NONCLEARBG; + else + mask = ((s[x+3] - '0') << CON_BGSHIFT) | (mask&~CON_BGMASK) | CON_NONCLEARBG; + } + } else if (s[x+1] == 'b') mask ^= CON_BLINKTEXT; else if (s[x+1] == 'a') //alternate mask ^= CON_2NDCHARSETTEXT; + else if (s[x+1] == 'h') //halfalpha + mask ^= CON_HALFALPHA; else if (s[x+1] == 's') //store on stack (it's great for names) { if (maskstackdepth < sizeof(maskstack)/sizeof(maskstack[0])) diff --git a/engine/client/sbar.c b/engine/client/sbar.c index 3a05dfde3..ec70eeab7 100644 --- a/engine/client/sbar.c +++ b/engine/client/sbar.c @@ -125,6 +125,28 @@ void Draw_FunString(int x, int y, unsigned char *str) ext = q3codemasks[*str++-'0'] | (ext&~CON_Q3MASK); //change colour only. continue; } + else if (*str == '&') // extended code + { + if (isextendedcode(*str+1) && isextendedcode(*str+2)) + { + str++; // foreground char + if (*str == '-') // default for FG + ext = (COLOR_WHITE << CON_FGSHIFT) | (ext&~CON_FGMASK); + else if (*str >= 'A') + ext = ((*str - ('A' - 10)) << CON_FGSHIFT) | (ext&~CON_FGMASK); + else + ext = ((*str - '0') << CON_FGSHIFT) | (ext&~CON_FGMASK); + str++; // background char + if (*str == '-') // default (clear) for BG + ext &= ~CON_BGMASK & ~CON_NONCLEARBG; + else if (*str >= 'A') + ext = ((*str - ('A' - 10)) << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + else + ext = ((*str - '0') << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + continue; + } + str--; // else invalid code + } else if (*str == 'a') { str++; @@ -137,6 +159,12 @@ void Draw_FunString(int x, int y, unsigned char *str) ext ^= CON_BLINKTEXT; continue; } + else if (*str == 'h') + { + str++; + ext ^= CON_HALFALPHA; + continue; + } else if (*str == 's') //store on stack (it's great for names) { str++; @@ -196,6 +224,28 @@ void Draw_FunStringLen(int x, int y, unsigned char *str, int len) ext = q3codemasks[*str++-'0'] | (ext&~CON_Q3MASK); //change colour only. continue; } + else if (*str == '&') // extended code + { + if (isextendedcode(*str+1) && isextendedcode(*str+2)) + { + str++; // foreground char + if (*str == '-') // default for FG + ext = (COLOR_WHITE << CON_FGSHIFT) | (ext&~CON_FGMASK); + else if (*str >= 'A') + ext = ((*str - ('A' - 10)) << CON_FGSHIFT) | (ext&~CON_FGMASK); + else + ext = ((*str - '0') << CON_FGSHIFT) | (ext&~CON_FGMASK); + str++; // background char + if (*str == '-') // default (clear) for BG + ext &= ~CON_BGMASK & ~CON_NONCLEARBG; + else if (*str >= 'A') + ext = ((*str - ('A' - 10)) << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + else + ext = ((*str - '0') << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + continue; + } + str--; // else invalid code + } else if (*str == 'a') { str++; @@ -208,6 +258,12 @@ void Draw_FunStringLen(int x, int y, unsigned char *str, int len) ext ^= CON_BLINKTEXT; continue; } + else if (*str == 'h') + { + str++; + ext ^= CON_HALFALPHA; + continue; + } else if (*str == 's') //store on stack (it's great for names) { str++; diff --git a/engine/common/console.h b/engine/common/console.h index 5fb1adeca..a162bece7 100644 --- a/engine/common/console.h +++ b/engine/common/console.h @@ -80,6 +80,8 @@ extern conchar_t q3codemasks[MAXQ3COLOURS]; #define CON_TEXTSIZE 16384 +#define isextendedcode(x) ((x >= '0' && x <= '9') || (x >= 'A' && x <= 'F') || x == '-') + typedef struct console_s { char name[64]; diff --git a/engine/common/log.c b/engine/common/log.c index 523d84349..b2348310a 100644 --- a/engine/common/log.c +++ b/engine/common/log.c @@ -110,14 +110,21 @@ void Con_Log (char *s) else if (((int)(log_readable.value) & 2) && *s == '^') { // log_readable 2 removes Q3 codes as well - char c; - c = *(s+1); + char c = s[1]; - if ((c >= '0' && c <= '9') || c == 'a' || c == 'b' || c == 's' || c == 'r') + if ((c >= '0' && c <= '9') || c == 'a' || c == 'b' || c == 'h' || c == 's' || c == 'r') { i--; s++; } + else if (c == '&') + { + if (isextendedcode(s[2]) && isextendedcode(s[3])) + { + i--; + s += 3; + } + } else { *t = '^'; diff --git a/engine/server/sv_sys_unix.c b/engine/server/sv_sys_unix.c index 02b33db41..bc0ab769e 100644 --- a/engine/server/sv_sys_unix.c +++ b/engine/server/sv_sys_unix.c @@ -344,6 +344,28 @@ void Sys_Printf (char *fmt, ...) ext = q3codemasks[*str++-'0'] | (ext&~CON_Q3MASK); //change colour only. continue; } + else if (*str == '&') // extended code + { + if (isextendedcode(*str+1) && isextendedcode(*str+2)) + { + str++; // foreground char + if (*str == '-') // default for FG + ext = (COLOR_WHITE << CON_FGSHIFT) | (ext&~CON_FGMASK); + else if (*str >= 'A') + ext = ((*str - ('A' - 10)) << CON_FGSHIFT) | (ext&~CON_FGMASK); + else + ext = ((*str - '0') << CON_FGSHIFT) | (ext&~CON_FGMASK); + str++; // background char + if (*str == '-') // default (clear) for BG + ext &= ~CON_BGMASK & ~CON_NONCLEARBG; + else if (*str >= 'A') + ext = ((*str - ('A' - 10)) << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + else + ext = ((*str - '0') << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + continue; + } + str--; // else invalid code + } else if (*str == 'a') { str++; @@ -356,6 +378,12 @@ void Sys_Printf (char *fmt, ...) ext ^= CON_BLINKTEXT; continue; } + else if (*str == 'h') + { + str++; + ext ^= CON_HALFALPHA; + continue; + } else if (*str == 's') //store on stack (it's great for names) { str++; diff --git a/engine/server/sv_sys_win.c b/engine/server/sv_sys_win.c index d8cf7be2a..2da548f39 100644 --- a/engine/server/sv_sys_win.c +++ b/engine/server/sv_sys_win.c @@ -561,6 +561,28 @@ void Sys_Printf (char *fmt, ...) ext = q3codemasks[*str++-'0'] | (ext&~CON_Q3MASK); //change colour only. continue; } + else if (*str == '&') // extended code + { + if (isextendedcode(*str+1) && isextendedcode(*str+2)) + { + str++; // foreground char + if (*str == '-') // default for FG + ext = (COLOR_WHITE << CON_FGSHIFT) | (ext&~CON_FGMASK); + else if (*str >= 'A') + ext = ((*str - ('A' - 10)) << CON_FGSHIFT) | (ext&~CON_FGMASK); + else + ext = ((*str - '0') << CON_FGSHIFT) | (ext&~CON_FGMASK); + str++; // background char + if (*str == '-') // default (clear) for BG + ext &= ~CON_BGMASK & ~CON_NONCLEARBG; + else if (*str >= 'A') + ext = ((*str - ('A' - 10)) << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + else + ext = ((*str - '0') << CON_BGSHIFT) | (ext&~CON_BGMASK) | CON_NONCLEARBG; + continue; + } + str--; // else invalid code + } else if (*str == 'a') { str++; @@ -573,6 +595,12 @@ void Sys_Printf (char *fmt, ...) ext ^= CON_BLINKTEXT; continue; } + else if (*str == 'h') + { + str++; + ext ^= CON_HALFALPHA; + continue; + } else if (*str == 's') //store on stack (it's great for names) { str++; diff --git a/engine/sw/d_trans.c b/engine/sw/d_trans.c index a1981cec3..5193e2dc1 100644 --- a/engine/sw/d_trans.c +++ b/engine/sw/d_trans.c @@ -256,7 +256,7 @@ void MakePaletteRemaps(void) for (i = 2; i < palremapsize; i++) { palremaps[i].key = 0; - palremaps[i].references = -2147483648; + palremaps[i].references = -2147483647; } } @@ -433,7 +433,7 @@ void D_DereferenceRemap(palremap_t *palremap) if (palremap->references < 2) { if (dereftime >= 0) - dereftime = -2147483648; // lowest negative 32-bit number + dereftime = -2147483647; // lowest negative 32-bit number (without MSVC being stupid) palremap->references = dereftime; dereftime++; }