Skip to content

Commit 53123db

Browse files
committed
Update cgame_classic for recent removal of SetAlpha(), SetColor()
Keep track of the color internally.
1 parent f0c409a commit 53123db

File tree

3 files changed

+30
-58
lines changed

3 files changed

+30
-58
lines changed

src/client/cgame.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,9 @@ static color_t apply_scr_alpha(color_t color)
4040
return color;
4141
}
4242

43-
static void CGX_ClearColor(void)
43+
static void CGX_DrawCharEx(int x, int y, int flags, int ch, color_t color)
4444
{
45-
color_t clear_color;
46-
clear_color.r = clear_color.g = clear_color.b = 255;
47-
clear_color.a = 255 * Cvar_ClampValue(scr_alpha, 0, 1);
48-
//R_SetColor(clear_color.u32);
49-
}
50-
51-
static void CGX_SetAlpha(float alpha)
52-
{
53-
//R_SetAlpha(alpha * Cvar_ClampValue(scr_alpha, 0, 1));
54-
}
55-
56-
static void CGX_SetColor(color_t color)
57-
{
58-
color_t new_color;
59-
new_color = color;
60-
new_color.a *= Cvar_ClampValue(scr_alpha, 0, 1);
61-
//R_SetColor(new_color.u32);
45+
R_DrawChar(x, y, flags, ch, apply_scr_alpha(color), scr.font_pic);
6246
}
6347

6448
static const pmoveParams_t* CGX_GetPmoveParams(void)
@@ -67,12 +51,10 @@ static const pmoveParams_t* CGX_GetPmoveParams(void)
6751
}
6852

6953
static cgame_q2pro_extended_support_ext_t cgame_q2pro_extended_support = {
70-
.api_version = 1,
54+
.api_version = 2,
7155

7256
.IsExtendedServer = CGX_IsExtendedServer,
73-
.ClearColor = CGX_ClearColor,
74-
.SetAlpha = CGX_SetAlpha,
75-
.SetColor = CGX_SetColor,
57+
.DrawCharEx = CGX_DrawCharEx,
7658
.GetPmoveParams = CGX_GetPmoveParams,
7759
};
7860

src/client/cgame_classic.c

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ static char scr_centerstring[MAX_STRING_CHARS];
6060
static unsigned scr_centertime_start; // for slow victory printing
6161
static int scr_center_lines;
6262

63+
static color_t ui_color;
64+
6365
static void CGC_Init(void)
6466
{
6567
/* We don't consider rerelease servers here and assume the appropriate
@@ -72,6 +74,8 @@ static void CGC_Init(void)
7274
ch_scale = cgi.cvar("ch_scale", "1", 0);
7375
ch_x = cgi.cvar("ch_x", "0", 0);
7476
ch_y = cgi.cvar("ch_y", "0", 0);
77+
78+
ui_color = COLOR_WHITE;
7579
}
7680

7781
static void CGC_Shutdown(void)
@@ -91,22 +95,11 @@ static void DrawPic(int x, int y, const char* pic)
9195
cgi.SCR_DrawPic(x, y, w, h, pic);
9296
}
9397

94-
static void CG_DrawString(int x, int y, int flags, size_t maxlen, const char *s)
98+
static void CG_DrawString(int x, int y, int flags, size_t maxlen, const char *s, color_t color)
9599
{
96-
const char *write_str = s;
97-
if (flags & UI_XORCOLOR) {
98-
size_t new_str_len = min(strlen(s), maxlen);
99-
char *new_str = alloca(new_str_len + 1);
100-
for (size_t i = 0; i < new_str_len; i++) {
101-
new_str[i] = s[i] ^ 0x80;
102-
}
103-
new_str[new_str_len] = 0;
104-
write_str = new_str;
105-
}
106-
107-
while (maxlen-- && *write_str) {
108-
byte c = *write_str++;
109-
cgi.SCR_DrawChar(x, y, 1, c, flags & UI_DROPSHADOW);
100+
while (maxlen-- && *s) {
101+
byte c = *s++;
102+
cgix.DrawCharEx(x, y, flags, c, color);
110103
x += CHAR_WIDTH;
111104
}
112105
}
@@ -116,7 +109,7 @@ static void CG_DrawString(int x, int y, int flags, size_t maxlen, const char *s)
116109
DrawStringEx
117110
==============
118111
*/
119-
static void CG_DrawStringEx(int x, int y, int flags, size_t maxlen, const char *s)
112+
static void CG_DrawStringEx(int x, int y, int flags, size_t maxlen, const char *s, color_t color)
120113
{
121114
size_t len = strlen(s);
122115

@@ -130,54 +123,54 @@ static void CG_DrawStringEx(int x, int y, int flags, size_t maxlen, const char *
130123
x -= len * CHAR_WIDTH;
131124
}
132125

133-
CG_DrawString(x, y, flags, maxlen, s);
126+
CG_DrawString(x, y, flags, maxlen, s, color);
134127
}
135128

136129
/*
137130
==============
138131
DrawStringMulti
139132
==============
140133
*/
141-
static void CG_DrawStringMulti(int x, int y, int flags, size_t maxlen, const char *s)
134+
static void CG_DrawStringMulti(int x, int y, int flags, size_t maxlen, const char *s, color_t color)
142135
{
143136
char *p;
144137
size_t len;
145138

146139
while (*s) {
147140
p = strchr(s, '\n');
148141
if (!p) {
149-
CG_DrawStringEx(x, y, flags, maxlen, s);
142+
CG_DrawStringEx(x, y, flags, maxlen, s, color);
150143
break;
151144
}
152145

153146
len = p - s;
154147
if (len > maxlen) {
155148
len = maxlen;
156149
}
157-
CG_DrawStringEx(x, y, flags, len, s);
150+
CG_DrawStringEx(x, y, flags, len, s, color);
158151

159152
y += CHAR_HEIGHT;
160153
s = p + 1;
161154
}
162155
}
163156

164157
#define HUD_DrawString(x, y, string) \
165-
CG_DrawString(x, y, 0, MAX_STRING_CHARS, string)
158+
CG_DrawString(x, y, 0, MAX_STRING_CHARS, string, ui_color)
166159

167160
#define HUD_DrawAltString(x, y, string) \
168-
CG_DrawString(x, y, UI_XORCOLOR, MAX_STRING_CHARS, string)
161+
CG_DrawString(x, y, UI_XORCOLOR, MAX_STRING_CHARS, string, ui_color)
169162

170163
#define HUD_DrawCenterString(x, y, string) \
171-
CG_DrawStringMulti(x, y, UI_CENTER, MAX_STRING_CHARS, string)
164+
CG_DrawStringMulti(x, y, UI_CENTER, MAX_STRING_CHARS, string, ui_color)
172165

173166
#define HUD_DrawAltCenterString(x, y, string) \
174-
CG_DrawStringMulti(x, y, UI_CENTER | UI_XORCOLOR, MAX_STRING_CHARS, string)
167+
CG_DrawStringMulti(x, y, UI_CENTER | UI_XORCOLOR, MAX_STRING_CHARS, string, ui_color)
175168

176169
#define HUD_DrawRightString(x, y, string) \
177-
CG_DrawStringEx(x, y, UI_RIGHT, MAX_STRING_CHARS, string)
170+
CG_DrawStringEx(x, y, UI_RIGHT, MAX_STRING_CHARS, string, ui_color)
178171

179172
#define HUD_DrawAltRightString(x, y, string) \
180-
CG_DrawStringEx(x, y, UI_RIGHT | UI_XORCOLOR, MAX_STRING_CHARS, string)
173+
CG_DrawStringEx(x, y, UI_RIGHT | UI_XORCOLOR, MAX_STRING_CHARS, string, ui_color)
181174

182175
static const char field_pic[] = "field_3";
183176
static const char inven_pic[] = "inventory";
@@ -708,7 +701,7 @@ static void SCR_ExecuteLayoutString(vrect_t hud_vrect, const char *s, int32_t pl
708701

709702
token = COM_Parse(&s);
710703
if (SCR_ParseColor(token, &color)) {
711-
cgix.SetColor(color);
704+
ui_color = color;
712705
}
713706
continue;
714707
}
@@ -734,7 +727,7 @@ static void SCR_ExecuteLayoutString(vrect_t hud_vrect, const char *s, int32_t pl
734727
}
735728
}
736729

737-
cgix.ClearColor();
730+
ui_color = COLOR_WHITE;
738731
}
739732

740733
// The status bar is a small layout program that is based on the stats array
@@ -849,14 +842,13 @@ static void SCR_DrawCenterString(vrect_t hud_vrect)
849842
return;
850843
}
851844

852-
cgix.SetAlpha(alpha);
845+
color_t color = ui_color;
846+
color.a *= alpha;
853847

854848
y = hud_vrect.height / 4 - scr_center_lines * 8 / 2;
855849

856850
CG_DrawStringMulti(hud_vrect.width / 2, y, UI_CENTER,
857-
MAX_STRING_CHARS, scr_centerstring);
858-
859-
cgix.ClearColor();
851+
MAX_STRING_CHARS, scr_centerstring, color);
860852
}
861853

862854
static void CGC_DrawHUD (int32_t isplit, const cg_server_data_t *data, vrect_t hud_vrect, vrect_t hud_safe, int32_t scale, int32_t playernum, const player_state_t *ps)

src/client/cgame_classic.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ typedef struct {
2626
// Whether server is using "extended" protocol
2727
bool (*IsExtendedServer)(void);
2828

29-
// Drawing color support
30-
void (*ClearColor)(void);
31-
void (*SetAlpha)(float alpha);
32-
void (*SetColor)(color_t color);
29+
// Draw single character, colorized & w/ flags
30+
void (*DrawCharEx)(int x, int y, int flags, int ch, color_t color);
3331

3432
// Return pmove parameters for server
3533
const pmoveParams_t *(*GetPmoveParams)(void);

0 commit comments

Comments
 (0)