UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cl_screen.cpp
Go to the documentation of this file.
1 
13 /*
14 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
15 
16 Original file from Quake 2 v3.21: quake2-2.31/client/
17 Copyright (C) 1997-2001 Id Software, Inc.
18 
19 This program is free software; you can redistribute it and/or
20 modify it under the terms of the GNU General Public License
21 as published by the Free Software Foundation; either version 2
22 of the License, or (at your option) any later version.
23 
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 
28 See the GNU General Public License for more details.
29 
30 You should have received a copy of the GNU General Public License
31 along with this program; if not, write to the Free Software
32 Foundation, 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"
40 #include "battlescape/cl_actor.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 
54 static float scr_con_current; /* approaches scr_conlines at scr_conspeed */
55 static float scr_conlines; /* 0.0 to 1.0 lines of console to display */
56 
57 static bool screenInitialized = false;/* ready to draw */
58 
64 
65 static char cursorImage[MAX_QPATH];
66 
70 static 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 
81 static 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 
100 void 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 
124 static 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 
140 void 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 
159 static void SCR_TouchPics (void)
160 {
161  if (scr_cursor->integer) {
162  if (scr_cursor->integer > 9 || scr_cursor->integer < 0)
163  SCR_ChangeCursor(1);
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);
170  if (!R_FindImage(cursorImage, it_pic)) {
171  Com_Printf("SCR_TouchPics: Could not register cursor: %s\n", cursorImage);
172  cursorImage[0] = '\0';
173  SCR_ChangeCursor(1);
174  }
175  } else
176  cursorImage[0] = '\0';
177 }
178 
182 static 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;
192  SCR_TouchPics();
193  }
194 
195  if (!cursorImage[0])
196  return;
197 
198  if (!UI_DNDIsDragging()) {
199  const char* pic;
200 
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 {
214  UI_DrawCursor();
215  }
216 }
217 
218 
222 void 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 
247 static void SCR_DrawConsole (void)
248 {
249  Con_CheckResize();
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 {
272 }
273 
278 {
279  cls.disableScreen = 0;
280 }
281 
282 static 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;
294  R_RenderFrame();
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();
303  R_RenderFrame();
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 
320 void SCR_UpdateScreen (void)
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 */
336  if (!screenInitialized)
337  return;
338 
339  R_BeginFrame();
340 
341  /* draw scene, if it is need */
342  CL_ViewRender();
343 
344  /* draw the ui on top of the render view */
345  UI_Draw();
346 
347  SCR_DrawConsole();
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 
365  SCR_DrawCursor();
366 
367  R_EndFrame();
368 }
369 
370 void SCR_ChangeCursor (int cursor)
371 {
372  if (cursor > 0)
373  Cvar_SetValue("cursor", cursor);
374 }
375 
379 void 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 
392  SCR_TouchPics();
393 
394  screenInitialized = true;
395 }
396 
397 void SCR_Shutdown (void)
398 {
399  screenInitialized = false;
400 }
bool Q_strnull(const char *string)
Definition: shared.h:138
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition: cmd.cpp:744
static char cursorImage[MAX_QPATH]
Definition: cl_screen.cpp:65
void Con_DrawString(const char *txt, int x, int y, unsigned int width)
Definition: cl_console.cpp:105
int viewHeight
Definition: cl_video.h:76
void SCR_DrawLoading(int percent)
Draws the current loading pic of the map from base/pics/maps/loading.
Definition: cl_screen.cpp:140
renderer_threadstate_t r_threadstate
Definition: r_thread.cpp:34
static cvar_t * scr_showcursor
Definition: cl_screen.cpp:63
void R_DrawImage(float x, float y, const image_t *image)
Draws an image or parts of it.
Definition: r_draw.cpp:341
static cvar_t * scr_rspeed
Definition: cl_screen.cpp:61
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...
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
static void SCR_DrawLoadingBar(int x, int y, int w, int h, int percent)
Definition: cl_screen.cpp:81
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition: cvar.h:71
bool isOurRound() const
Definition: client.h:106
#define _(String)
Definition: cl_shared.h:43
void SCR_DrawLoadingScreen(bool string, int percent)
Precache and loading screen at startup.
Definition: cl_screen.cpp:100
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
Definition: shared.cpp:494
void SCR_Shutdown(void)
Definition: cl_screen.cpp:397
cvar_t * r_programs
Definition: r_main.cpp:97
float value
Definition: cvar.h:80
viddef_t viddef
Definition: cl_video.cpp:34
vec3_t viewAngles
Definition: cl_renderer.h:173
local graphics definitions
void SCR_UpdateScreen(void)
This is called every frame, and can also be called explicitly to flush text to the screen...
Definition: cl_screen.cpp:320
void SCR_Init(void)
Definition: cl_screen.cpp:379
unsigned width
Definition: cl_video.h:44
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
int virtualHeight
Definition: cl_video.h:74
Definition: r_image.h:45
int width
Definition: r_image.h:64
static void SCR_DrawCursor(void)
Draws the 3D-cursor in battlemode and the icons/info next to it.
Definition: cl_screen.cpp:182
int integer
Definition: cvar.h:81
#define CVAR_ARCHIVE
Definition: cvar.h:40
const int con_fontWidth
Definition: cl_console.cpp:76
static void SCR_DrawDownloading(void)
Draws the current downloading status.
Definition: cl_screen.cpp:124
int flags
Definition: cvar.h:78
image_t * R_FindImage(const char *pname, imagetype_t type)
Finds or loads the given image.
Definition: r_image.cpp:603
client_static_t cls
Definition: cl_main.cpp:83
float frametime
Definition: client.h:59
void UI_Draw(void)
Draws the window stack.
Definition: ui_draw.cpp:341
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
rendererData_t refdef
Definition: r_main.cpp:45
int mousePosY
Definition: cl_input.cpp:80
void SCR_EndLoadingPlaque(void)
Definition: cl_screen.cpp:277
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
cvar_t * cl_fps
Definition: cl_main.cpp:71
static void SCR_TimeRefresh_f(void)
Definition: cl_screen.cpp:282
void HUD_UpdateCursor(void)
Updates the cursor texts when in battlescape.
Definition: cl_hud.cpp:976
void R_BeginFrame(void)
Definition: r_main.cpp:220
void CL_ViewRender(void)
Definition: cl_view.cpp:225
static bool screenInitialized
Definition: cl_screen.cpp:57
int waitingForStart
Definition: client.h:72
int disableScreen
Definition: client.h:63
viddefContext_t context
Definition: cl_video.h:67
threadstate_t state
Definition: cl_renderer.h:227
Header for certain screen operations.
static float scr_con_current
Definition: cl_screen.cpp:54
static void SCR_DrawString(int x, int y, const char *string)
Definition: cl_screen.cpp:70
bool CL_BattlescapeRunning(void)
Check whether we already have actors spawned on the battlefield.
void SCR_ChangeCursor(int cursor)
Definition: cl_screen.cpp:370
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
static cvar_t * scr_conspeed
Definition: cl_screen.cpp:59
void SCR_BeginLoadingPlaque(void)
Definition: cl_screen.cpp:269
void Con_DrawConsole(float frac)
Draws the console with the solid background.
Definition: cl_console.cpp:443
#define MAX_QPATH
Definition: filesys.h:40
QGL_EXTERN GLint i
Definition: r_gl.h:113
int viewWidth
Definition: cl_video.h:76
void UI_DrawCursor(void)
Definition: ui_draw.cpp:399
int shaderToShaderCount
Definition: cl_renderer.h:178
float framerate
Definition: client.h:60
int height
Definition: r_image.h:64
HUD related routines.
static void SCR_DrawConsole(void)
Definition: cl_screen.cpp:247
void R_EndFrame(void)
Definition: r_main.cpp:443
int downloadPercent
Definition: client.h:84
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)
Definition: ui_render.cpp:371
int virtualWidth
Definition: cl_video.h:74
static void SCR_TouchPics(void)
Allows rendering code to cache all needed sbar graphics.
Definition: cl_screen.cpp:159
connstate_t state
Definition: client.h:55
Primary header for client.
void SCR_RunConsole(void)
Scroll it up or down.
Definition: cl_screen.cpp:222
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
bool UI_DNDIsDragging(void)
Return true if we are dragging something.
void R_RenderFrame(void)
Definition: r_main.cpp:298
bool modified
Definition: cvar.h:79
int mousePosX
Definition: cl_input.cpp:80
#define IN_GetMouseSpace()
Definition: cl_input.h:48
char downloadName[MAX_OSPATH]
Definition: client.h:82
static float scr_conlines
Definition: cl_screen.cpp:55
Console header file.
static cvar_t * scr_consize
Definition: cl_screen.cpp:60
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
Definition: cvar.cpp:671
void Con_CheckResize(void)
If the line width has changed, reformat the buffer.
Definition: cl_console.cpp:184
const int con_fontHeight
Definition: cl_console.cpp:75
keydest_t keyDest
Definition: client.h:56
static cvar_t * scr_cursor
Definition: cl_screen.cpp:62
int CL_Milliseconds(void)
Definition: cl_main.cpp:1208
int Sys_Milliseconds(void)
Definition: unix_shared.cpp:41
vec_t vec4_t[4]
Definition: ufotypes.h:40