UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_screen.cpp
Go to the documentation of this file.
1
12
13/*
14All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
15
16Original file from Quake 2 v3.21: quake2-2.31/client/
17Copyright (C) 1997-2001 Id Software, Inc.
18
19This program is free software; you can redistribute it and/or
20modify it under the terms of the GNU General Public License
21as published by the Free Software Foundation; either version 2
22of the License, or (at your option) any later version.
23
24This program is distributed in the hope that it will be useful,
25but WITHOUT ANY WARRANTY; without even the implied warranty of
26MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27
28See the GNU General Public License for more details.
29
30You should have received a copy of the GNU General Public License
31along with this program; if not, write to the Free Software
32Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33
34*/
35
36#include "client.h"
37#include "cl_screen.h"
38#include "cl_console.h"
41#include "battlescape/cl_view.h"
42#include "battlescape/cl_hud.h"
43#include "renderer/r_main.h"
44#include "renderer/r_draw.h"
45#include "renderer/r_local.h"
46#include "ui/ui_main.h"
47#include "ui/ui_draw.h"
48#include "ui/ui_nodes.h"
49#include "ui/ui_windows.h"
50#include "ui/ui_dragndrop.h"
51#include "ui/ui_render.h"
52#include "../ports/system.h"
53
54static float scr_con_current; /* approaches scr_conlines at scr_conspeed */
55static float scr_conlines; /* 0.0 to 1.0 lines of console to display */
56
57static bool screenInitialized = false;/* ready to draw */
58
64
66
70static void SCR_DrawString (int x, int y, const char* string)
71{
72 if (Q_strnull(string))
73 return;
74
75 Con_DrawString(string, x, y, strlen(string));
76}
77
81static void SCR_DrawLoadingBar (int x, int y, int w, int h, int percent)
82{
83 const vec4_t color = {0.3f, 0.3f, 0.3f, 0.7f};
84
85 R_DrawFill(x, y, w, h, color);
86
87 if (percent != 0) {
88 const vec4_t colorBar = {0.8f, 0.8f, 0.8f, 0.7f};
89 R_DrawFill((int)(x + (h * 0.2)), (int)(y + (h * 0.2)), (int)((w - (h * 0.4)) * percent * 0.01), (int)(h * 0.6), colorBar);
90 }
91}
92
100void SCR_DrawLoadingScreen (bool string, int percent)
101{
102 R_BeginFrame();
103
104 const image_t* image = R_FindImage("pics/background/loading", it_pic);
105 if (image)
106 R_DrawImage(viddef.virtualWidth / 2 - image->width / 2, viddef.virtualHeight / 2 - image->height / 2, image);
107 if (string) {
108 /* Not used with gettext because it would make removing it too easy. */
109 UI_DrawString("f_menubig", ALIGN_UC,
110 (int)(viddef.virtualWidth / 2), 30,
111 0, viddef.virtualWidth, 50, "Download this free game at http://ufoai.sf.net");
112 }
113 SCR_DrawLoadingBar((int)(viddef.virtualWidth / 2) - 300, viddef.virtualHeight - 30, 600, 20, percent);
114
115 R_EndFrame();
116}
117
124static void SCR_DrawDownloading (void)
125{
126 const char* dlmsg = va(_("Downloading [%s]"), cls.downloadName);
127 UI_DrawString("f_menubig", ALIGN_UC,
128 (int)(viddef.virtualWidth / 2),
129 (int)(viddef.virtualHeight / 2 - 60),
130 (int)(viddef.virtualWidth / 2),
131 viddef.virtualWidth, 50, dlmsg, 1);
132
133 SCR_DrawLoadingBar((int)(viddef.virtualWidth / 2) - 300, viddef.virtualHeight - 30, 600, 20, (int)cls.downloadPercent);
134}
135
140void SCR_DrawLoading (int percent)
141{
142 if (cls.downloadName[0]) {
144 return;
145 }
146
147 R_BeginFrame();
148
149 UI_Draw();
150
151 SCR_DrawLoadingBar((int)(viddef.virtualWidth / 2) - 300, viddef.virtualHeight - 30, 600, 20, percent);
152
153 R_EndFrame();
154}
155
159static void SCR_TouchPics (void)
160{
161 if (scr_cursor->integer) {
162 if (scr_cursor->integer > 9 || scr_cursor->integer < 0)
164
165 R_FindImage("pics/cursors/wait", it_pic);
166 R_FindImage("pics/cursors/ducked", it_pic);
167 R_FindImage("pics/cursors/reactionfire", it_pic);
168 R_FindImage("pics/cursors/reactionfiremany", it_pic);
169 Com_sprintf(cursorImage, sizeof(cursorImage), "pics/cursors/cursor%i", scr_cursor->integer);
171 Com_Printf("SCR_TouchPics: Could not register cursor: %s\n", cursorImage);
172 cursorImage[0] = '\0';
174 }
175 } else
176 cursorImage[0] = '\0';
177}
178
182static void SCR_DrawCursor (void)
183{
184 if (scr_showcursor->integer == 0)
185 return;
186
187 if (!scr_cursor->integer)
188 return;
189
190 if (scr_cursor->modified) {
191 scr_cursor->modified = false;
193 }
194
195 if (!cursorImage[0])
196 return;
197
198 if (!UI_DNDIsDragging()) {
199 const char* pic;
200
201 if (!cls.isOurRound() && CL_BattlescapeRunning())
202 pic = "pics/cursors/wait";
203 else
204 pic = cursorImage;
205
206 const image_t* image = R_FindImage(pic, it_pic);
207 if (image)
208 R_DrawImage(mousePosX - image->width / 2, mousePosY - image->height / 2, image);
209
212 }
213 } else {
215 }
216}
217
218
222void SCR_RunConsole (void)
223{
224 /* decide on the height of the console */
225 if (cls.keyDest == key_console)
226 scr_conlines = scr_consize->value; /* half screen */
227 else
228 scr_conlines = 0; /* none visible */
229
231 scr_con_current -= scr_conspeed->value * cls.frametime;
234
235 } else if (scr_conlines > scr_con_current) {
236 scr_con_current += scr_conspeed->value * cls.frametime;
239 }
240}
241
247static void SCR_DrawConsole (void)
248{
250
251 if (!viddef.viewWidth || !viddef.viewHeight) {
252 /* active full screen menu */
253 /* draw the console like in game */
254 if (scr_con_current > 0.0)
256 return;
257 }
258
259 if (scr_con_current > 0.0) {
261 }
262}
263
270{
271 cls.disableScreen = CL_Milliseconds();
272}
273
278{
279 cls.disableScreen = 0;
280}
281
282static void SCR_TimeRefresh_f (void)
283{
284 if (cls.state != ca_active)
285 return;
286
287 const int start = Sys_Milliseconds();
288
289 if (Cmd_Argc() == 2) { /* run without page flipping */
290 R_BeginFrame();
291 for (int i = 0; i < 128; i++) {
292 refdef.viewAngles[1] = i / 128.0 * 360.0;
295 }
296 R_EndFrame();
297 } else {
298 for (int i = 0; i < 128; i++) {
299 refdef.viewAngles[1] = i / 128.0 * 360.0;
300
301 R_BeginFrame();
304 R_EndFrame();
305 }
306 }
307
308 const int stop = Sys_Milliseconds();
309 const float time = (stop - start) / 1000.0f;
310 Com_Printf("%f seconds (%f fps)\n", time, 128 / time);
311}
312
321{
322 if (cls.waitingForStart)
323 return;
324
325 /* if the screen is disabled (loading plaque is up, or vid mode changing)
326 * do nothing at all */
327 if (cls.disableScreen) {
328 if (CL_Milliseconds() - cls.disableScreen > 120000 && refdef.ready) {
329 cls.disableScreen = 0;
330 Com_Printf("Loading plaque timed out.\n");
331 return;
332 }
333 }
334
335 /* not initialized yet */
337 return;
338
339 R_BeginFrame();
340
341 /* draw scene, if it is need */
343
344 /* draw the ui on top of the render view */
345 UI_Draw();
346
348
349 if (cl_fps->integer)
350 SCR_DrawString(viddef.context.width - 20 - con_fontWidth * 10, 0, va("fps: %3.1f", cls.framerate));
351 if (scr_rspeed->integer) {
352 if (CL_OnBattlescape())
353 SCR_DrawString(viddef.context.width - 20 - con_fontWidth * 30, 80, va("brushes: %6i alias: %6i\n", refdef.brushCount, refdef.aliasCount));
354 else
355 SCR_DrawString(viddef.context.width - 20 - con_fontWidth * 30, 80, va("alias: %6i\n", refdef.aliasCount));
356
357 SCR_DrawString(viddef.context.width - 20 - con_fontWidth * 30, 80 + con_fontHeight, va("batches: %6i\n", refdef.batchCount));
358 if (r_programs->integer) {
359 SCR_DrawString(viddef.context.width - 20 - con_fontWidth * 30, 80 + con_fontHeight * 2, va("FFP->shader switches: %6i\n", refdef.FFPToShaderCount));
360 SCR_DrawString(viddef.context.width - 20 - con_fontWidth * 30, 80 + con_fontHeight * 3, va("shader->shader switches: %6i\n", refdef.shaderToShaderCount));
361 SCR_DrawString(viddef.context.width - 20 - con_fontWidth * 30, 80 + con_fontHeight * 4, va("shader->FFP switches: %6i\n", refdef.shaderToFFPCount));
362 }
363 }
364
366
367 R_EndFrame();
368}
369
370void SCR_ChangeCursor (int cursor)
371{
372 if (cursor > 0)
373 Cvar_SetValue("cursor", cursor);
374}
375
379void SCR_Init (void)
380{
381 scr_conspeed = Cvar_Get("scr_conspeed", "3", 0, "Console open/close speed");
382 scr_consize = Cvar_Get("scr_consize", "1.0", 0, "Console size");
383 scr_rspeed = Cvar_Get("r_speeds", "0", CVAR_ARCHIVE, "Show some rendering stats");
384 scr_cursor = Cvar_Get("cursor", "1", 0, "Which cursor should be shown - 0-9");
386 scr_cursor->flags = 0;
387 scr_showcursor = Cvar_Get("scr_showcursor", "1", 0, "Show/hide mouse cursor- 0-1");
388
389 /* register our commands */
390 Cmd_AddCommand("timerefresh", SCR_TimeRefresh_f, "Run a benchmark");
391
393
394 screenInitialized = true;
395}
396
397void SCR_Shutdown (void)
398{
399 screenInitialized = false;
400}
bool CL_OnBattlescape(void)
Check whether we are in a tactical mission as server or as client. But this only means that we are ab...
bool CL_BattlescapeRunning(void)
Check whether we already have actors spawned on the battlefield.
const int con_fontWidth
const int con_fontHeight
void Con_DrawConsole(float frac)
Draws the console with the solid background.
void Con_CheckResize(void)
If the line width has changed, reformat the buffer.
void Con_DrawString(const char *txt, int x, int y, unsigned int width)
Console header file.
void HUD_UpdateCursor(void)
Updates the cursor texts when in battlescape.
Definition cl_hud.cpp:976
HUD related routines.
int mousePosY
Definition cl_input.cpp:76
int mousePosX
Definition cl_input.cpp:76
#define IN_GetMouseSpace()
Definition cl_input.h:48
@ MS_WORLD
Definition cl_input.h:34
@ key_console
Definition cl_keys.h:183
cvar_t * cl_fps
Definition cl_main.cpp:71
client_static_t cls
Definition cl_main.cpp:83
int CL_Milliseconds(void)
Definition cl_main.cpp:1207
@ THREAD_BSP
renderer_threadstate_t r_threadstate
Definition r_thread.cpp:34
rendererData_t refdef
Definition r_main.cpp:45
void SCR_Init(void)
void SCR_DrawLoading(int percent)
Draws the current loading pic of the map from base/pics/maps/loading.
void SCR_DrawLoadingScreen(bool string, int percent)
Precache and loading screen at startup.
static void SCR_TimeRefresh_f(void)
static bool screenInitialized
Definition cl_screen.cpp:57
static void SCR_DrawLoadingBar(int x, int y, int w, int h, int percent)
Definition cl_screen.cpp:81
void SCR_EndLoadingPlaque(void)
static void SCR_DrawDownloading(void)
Draws the current downloading status.
void SCR_UpdateScreen(void)
This is called every frame, and can also be called explicitly to flush text to the screen.
void SCR_ChangeCursor(int cursor)
static char cursorImage[MAX_QPATH]
Definition cl_screen.cpp:65
static cvar_t * scr_conspeed
Definition cl_screen.cpp:59
static cvar_t * scr_showcursor
Definition cl_screen.cpp:63
static cvar_t * scr_rspeed
Definition cl_screen.cpp:61
void SCR_RunConsole(void)
Scroll it up or down.
static cvar_t * scr_consize
Definition cl_screen.cpp:60
void SCR_BeginLoadingPlaque(void)
static float scr_con_current
Definition cl_screen.cpp:54
static void SCR_TouchPics(void)
Allows rendering code to cache all needed sbar graphics.
static void SCR_DrawString(int x, int y, const char *string)
Definition cl_screen.cpp:70
void SCR_Shutdown(void)
static void SCR_DrawCursor(void)
Draws the 3D-cursor in battlemode and the icons/info next to it.
static float scr_conlines
Definition cl_screen.cpp:55
static cvar_t * scr_cursor
Definition cl_screen.cpp:62
static void SCR_DrawConsole(void)
Header for certain screen operations.
#define _(String)
Definition cl_shared.h:44
@ ca_active
Definition cl_shared.h:80
viddef_t viddef
Definition cl_video.cpp:34
void CL_ViewRender(void)
Definition cl_view.cpp:225
Primary header for client.
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
Definition cmd.cpp:505
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition cmd.cpp:744
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
Definition cvar.cpp:671
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition cvar.cpp:342
#define CVAR_ARCHIVE
Definition cvar.h:40
#define MAX_QPATH
Definition filesys.h:40
void R_DrawFill(int x, int y, int w, int h, const vec4_t color)
Fills a box of pixels with a single color.
Definition r_draw.cpp:188
void R_DrawImage(float x, float y, const image_t *image)
Draws an image or parts of it.
Definition r_draw.cpp:341
QGL_EXTERN GLint i
Definition r_gl.h:113
image_t * R_FindImage(const char *pname, imagetype_t type)
Finds or loads the given image.
Definition r_image.cpp:603
@ it_pic
Definition r_image.h:45
local graphics definitions
cvar_t * r_programs
Definition r_main.cpp:97
void R_RenderFrame(void)
Definition r_main.cpp:298
void R_BeginFrame(void)
Definition r_main.cpp:220
void R_EndFrame(void)
Definition r_main.cpp:443
@ ALIGN_UC
Definition scripts.h:91
bool Q_strnull(const char *string)
Definition shared.h:138
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
Definition shared.cpp:494
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
Definition shared.cpp:410
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition cvar.h:71
int height
Definition r_image.h:64
int width
Definition r_image.h:64
System specific stuff.
int Sys_Milliseconds(void)
vec_t vec4_t[4]
Definition ufotypes.h:40
bool UI_DNDIsDragging(void)
Return true if we are dragging something.
void UI_DrawCursor(void)
Definition ui_draw.cpp:399
void UI_Draw(void)
Draws the window stack.
Definition ui_draw.cpp:341
int UI_DrawString(const char *fontID, align_t align, int x, int y, int absX, int maxWidth, int lineHeight, const char *c, int boxHeight, int scrollPos, int *curLine, bool increaseLine, longlines_t method)