00001
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "client.h"
00037 #include "cl_screen.h"
00038 #include "cl_console.h"
00039 #include "cl_sequence.h"
00040 #include "battlescape/cl_localentity.h"
00041 #include "battlescape/cl_actor.h"
00042 #include "battlescape/cl_view.h"
00043 #include "battlescape/cl_hud.h"
00044 #include "renderer/r_main.h"
00045 #include "renderer/r_draw.h"
00046 #include "ui/ui_main.h"
00047 #include "ui/ui_draw.h"
00048 #include "ui/ui_nodes.h"
00049 #include "ui/ui_windows.h"
00050 #include "ui/ui_dragndrop.h"
00051 #include "ui/ui_render.h"
00052 #include "../ports/system.h"
00053
00054 static float scr_con_current;
00055 static float scr_conlines;
00056
00057 static qboolean screenInitialized = qfalse;
00058
00059 static int screenDrawLoading = 0;
00060
00061 static cvar_t *scr_conspeed;
00062 static cvar_t *scr_consize;
00063 static cvar_t *scr_rspeed;
00064 static cvar_t *scr_cursor;
00065 static cvar_t *scr_showcursor;
00066
00067 static char cursorImage[MAX_QPATH];
00071 static void SCR_DrawString (int x, int y, const char *string, qboolean bitmapFont)
00072 {
00073 if (!string || !*string)
00074 return;
00075
00076 if (bitmapFont) {
00077 while (string[0] != '\0') {
00078 R_DrawChar(x, y, *string);
00079 x += con_fontWidth;
00080 string++;
00081 }
00082 } else
00083 UI_DrawString("f_verysmall", ALIGN_UL, x, y, 0, viddef.virtualWidth, 12, string, 0, 0, NULL, qfalse, 0);
00084 }
00085
00089 static void SCR_DrawLoadingBar (int x, int y, int w, int h, int percent)
00090 {
00091 const vec4_t color = {0.3f, 0.3f, 0.3f, 0.7f};
00092 const vec4_t colorBar = {0.8f, 0.8f, 0.8f, 0.7f};
00093
00094 R_DrawFill(x, y, w, h, color);
00095
00096 if (percent != 0)
00097 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);
00098 }
00099
00106 void SCR_DrawPrecacheScreen (qboolean string)
00107 {
00108 const image_t *image;
00109
00110 R_BeginFrame();
00111
00112 image = R_FindImage("pics/background/loading", it_pic);
00113 if (image)
00114 R_DrawImage(viddef.virtualWidth / 2 - image->width / 2, viddef.virtualHeight / 2 - image->height / 2, image);
00115 if (string) {
00116
00117 UI_DrawString("f_menubig", ALIGN_UC,
00118 (int)(viddef.virtualWidth / 2), 30,
00119 0, viddef.virtualWidth, 50, "Download this game for free at http://ufoai.sf.net", 0, 0, NULL, qfalse, 0);
00120 }
00121 SCR_DrawLoadingBar((int)(viddef.virtualWidth / 2) - 300, viddef.virtualHeight - 30, 600, 20, (int)cls.loadingPercent);
00122
00123 R_EndFrame();
00124 }
00125
00132 static const image_t* SCR_SetLoadingBackground (const char *mapString)
00133 {
00134 const char *mapname;
00135 image_t* image;
00136
00137 if (!mapString || Com_ServerState())
00138 mapname = Cvar_GetString("sv_mapname");
00139 else {
00140 mapname = mapString;
00141 Cvar_Set("sv_mapname", mapString);
00142 }
00143
00144
00145 if (mapname[0] == '+')
00146 mapname++;
00147
00148 image = R_FindImage(va("pics/maps/loading/%s", mapname), it_pic);
00149 if (image == r_noTexture)
00150 image = R_FindImage("pics/maps/loading/default", it_pic);
00151
00152
00153 Cvar_Set("mn_mappicbig", image->name + 5);
00154
00155 return image;
00156 }
00157
00164 static void SCR_DrawDownloading (void)
00165 {
00166 const char *dlmsg = va(_("Downloading [%s]"), cls.downloadName);
00167 UI_DrawString("f_menubig", ALIGN_UC,
00168 (int)(viddef.virtualWidth / 2),
00169 (int)(viddef.virtualHeight / 2 - 60),
00170 (int)(viddef.virtualWidth / 2),
00171 viddef.virtualWidth, 50, dlmsg, 1, 0, NULL, qfalse, 0);
00172
00173 SCR_DrawLoadingBar((int)(viddef.virtualWidth / 2) - 300, viddef.virtualHeight - 30, 600, 20, (int)cls.downloadPercent);
00174 }
00175
00180 static void SCR_DrawLoading (void)
00181 {
00182 static const image_t* loadingPic;
00183 const vec4_t color = {0.0, 0.7, 0.0, 0.8};
00184 char *mapmsg;
00185
00186 if (cls.downloadName[0]) {
00187 SCR_DrawDownloading();
00188 return;
00189 }
00190
00191 if (!screenDrawLoading) {
00192 loadingPic = NULL;
00193 return;
00194 }
00195
00196 if (!loadingPic)
00197 loadingPic = SCR_SetLoadingBackground(CL_GetConfigString(CS_MAPTITLE));
00198
00199
00200 R_DrawImage(viddef.virtualWidth / 2 - loadingPic->width / 2, viddef.virtualHeight / 2 - loadingPic->height / 2, loadingPic);
00201 R_Color(color);
00202
00203 if (CL_GetConfigString(CS_TILES)[0] != '\0') {
00204 mapmsg = va(_("Loading Map [%s]"), _(CL_GetConfigString(CS_MAPTITLE)));
00205 UI_DrawString("f_menubig", ALIGN_UC,
00206 (int)(viddef.virtualWidth / 2),
00207 (int)(viddef.virtualHeight / 2 - 60),
00208 (int)(viddef.virtualWidth / 2),
00209 viddef.virtualWidth, 50, mapmsg, 1, 0, NULL, qfalse, 0);
00210 }
00211
00212 UI_DrawString("f_menu", ALIGN_UC,
00213 (int)(viddef.virtualWidth / 2),
00214 (int)(viddef.virtualHeight / 2),
00215 (int)(viddef.virtualWidth / 2),
00216 viddef.virtualWidth, 50, cls.loadingMessages, 1, 0, NULL, qfalse, 0);
00217
00218 SCR_DrawLoadingBar((int)(viddef.virtualWidth / 2) - 300, viddef.virtualHeight - 30, 600, 20, (int)cls.loadingPercent);
00219 }
00220
00224 static void SCR_TouchPics (void)
00225 {
00226 if (scr_cursor->integer) {
00227 if (scr_cursor->integer > 9 || scr_cursor->integer < 0)
00228 Cvar_SetValue("cursor", 1);
00229
00230 R_FindImage("pics/cursors/wait", it_pic);
00231 R_FindImage("pics/cursors/ducked", it_pic);
00232 R_FindImage("pics/cursors/reactionfire", it_pic);
00233 R_FindImage("pics/cursors/reactionfiremany", it_pic);
00234 Com_sprintf(cursorImage, sizeof(cursorImage), "pics/cursors/cursor%i", scr_cursor->integer);
00235 if (!R_FindImage(cursorImage, it_pic)) {
00236 Com_Printf("SCR_TouchPics: Could not register cursor: %s\n", cursorImage);
00237 cursorImage[0] = '\0';
00238 }
00239 } else
00240 cursorImage[0] = '\0';
00241 }
00242
00243 static const vec4_t cursorBG = { 0.0f, 0.0f, 0.0f, 0.7f };
00247 static void SCR_DrawCursor (void)
00248 {
00249 if (scr_showcursor->integer == 0)
00250 return;
00251
00252 if (!scr_cursor->integer)
00253 return;
00254
00255 if (scr_cursor->modified) {
00256 scr_cursor->modified = qfalse;
00257 SCR_TouchPics();
00258 }
00259
00260 if (!cursorImage[0])
00261 return;
00262
00263 if (!UI_DNDIsDragging()) {
00264 const char *pic;
00265 image_t *image;
00266
00267 if (cls.team != cl.actTeam && CL_BattlescapeRunning())
00268 pic = "pics/cursors/wait";
00269 else
00270 pic = cursorImage;
00271
00272 image = R_FindImage(pic, it_pic);
00273 if (image)
00274 R_DrawImage(mousePosX - image->width / 2, mousePosY - image->height / 2, image);
00275
00276 if (mouseSpace == MS_WORLD && CL_BattlescapeRunning()) {
00277 HUD_UpdateCursor();
00278 }
00279 } else {
00280 UI_DrawCursor();
00281 }
00282 }
00283
00284
00288 void SCR_RunConsole (void)
00289 {
00290
00291 if (cls.keyDest == key_console)
00292 scr_conlines = scr_consize->value;
00293 else
00294 scr_conlines = 0;
00295
00296 if (scr_conlines < scr_con_current) {
00297 scr_con_current -= scr_conspeed->value * cls.frametime;
00298 if (scr_conlines > scr_con_current)
00299 scr_con_current = scr_conlines;
00300
00301 } else if (scr_conlines > scr_con_current) {
00302 scr_con_current += scr_conspeed->value * cls.frametime;
00303 if (scr_conlines < scr_con_current)
00304 scr_con_current = scr_conlines;
00305 }
00306 }
00307
00313 static void SCR_DrawConsole (void)
00314 {
00315 Con_CheckResize();
00316
00317 if (!viddef.viewWidth || !viddef.viewHeight) {
00318
00319
00320 if (scr_con_current)
00321 Con_DrawConsole(scr_con_current);
00322
00323 if (cls.keyDest == key_message)
00324 Con_DrawNotify();
00325 return;
00326 }
00327
00328 #if 0
00329 if (cls.state == ca_connecting || cls.state == ca_connected) {
00330 Con_DrawConsole(1.0);
00331 return;
00332 }
00333 #endif
00334
00335 if (scr_con_current) {
00336 Con_DrawConsole(scr_con_current);
00337 } else {
00338 if ((cls.keyDest == key_game || cls.keyDest == key_message) && cls.state != ca_sequence)
00339 Con_DrawNotify();
00340 }
00341 }
00342
00348 void SCR_BeginLoadingPlaque (void)
00349 {
00350 screenDrawLoading = 1;
00351
00352 SCR_UpdateScreen();
00353 cls.disableScreen = CL_Milliseconds();
00354 }
00355
00359 void SCR_EndLoadingPlaque (void)
00360 {
00361 cls.disableScreen = 0;
00362 screenDrawLoading = 0;
00363 SCR_DrawLoading();
00364
00365 Con_ClearNotify();
00366 }
00367
00368 static void SCR_TimeRefresh_f (void)
00369 {
00370 int i;
00371 int start, stop;
00372 float time;
00373
00374 if (cls.state != ca_active)
00375 return;
00376
00377 start = Sys_Milliseconds();
00378
00379 if (Cmd_Argc() == 2) {
00380 R_BeginFrame();
00381 for (i = 0; i < 128; i++) {
00382 refdef.viewAngles[1] = i / 128.0 * 360.0;
00383 r_threadstate.state = THREAD_BSP;
00384 R_RenderFrame();
00385 }
00386 R_EndFrame();
00387 } else {
00388 for (i = 0; i < 128; i++) {
00389 refdef.viewAngles[1] = i / 128.0 * 360.0;
00390
00391 R_BeginFrame();
00392 r_threadstate.state = THREAD_BSP;
00393 R_RenderFrame();
00394 R_EndFrame();
00395 }
00396 }
00397
00398 stop = Sys_Milliseconds();
00399 time = (stop - start) / 1000.0;
00400 Com_Printf("%f seconds (%f fps)\n", time, 128 / time);
00401 }
00402
00410 void SCR_UpdateScreen (void)
00411 {
00412
00413
00414 if (cls.disableScreen) {
00415 if (CL_Milliseconds() - cls.disableScreen > 120000 && refdef.ready) {
00416 cls.disableScreen = 0;
00417 Com_Printf("Loading plaque timed out.\n");
00418 return;
00419 }
00420 }
00421
00422
00423 if (!screenInitialized)
00424 return;
00425
00426 R_BeginFrame();
00427
00428 if (cls.state == ca_disconnected && !screenDrawLoading)
00429 SCR_EndLoadingPlaque();
00430
00431 if (screenDrawLoading)
00432 SCR_DrawLoading();
00433 else {
00434 UI_GetActiveRenderRect(&viddef.x, &viddef.y, &viddef.viewWidth, &viddef.viewHeight);
00435
00436
00437 if (cls.state == ca_sequence) {
00438 CL_SequenceRender();
00439 } else {
00440 CL_ViewRender();
00441 }
00442
00443
00444 UI_Draw();
00445
00446 SCR_DrawConsole();
00447
00448 if (cl_fps->integer)
00449 SCR_DrawString(viddef.width - 20 - con_fontWidth * 10, 0, va("fps: %3.1f", cls.framerate), qtrue);
00450 if (scr_rspeed->integer) {
00451 if (CL_OnBattlescape())
00452 SCR_DrawString(viddef.width - 20 - con_fontWidth * 30, 80, va("brushes: %6i alias: %6i\n", refdef.brushCount, refdef.aliasCount), qtrue);
00453 else
00454 SCR_DrawString(viddef.width - 20 - con_fontWidth * 14, 80, va("alias: %6i\n", refdef.aliasCount), qtrue);
00455 }
00456
00458 if (cls.state != ca_sequence)
00459 SCR_DrawCursor();
00460 }
00461
00462 R_DrawChars();
00463
00464 R_EndFrame();
00465 }
00466
00470 void SCR_Init (void)
00471 {
00472 scr_conspeed = Cvar_Get("scr_conspeed", "3", 0, "Console open/close speed");
00473 scr_consize = Cvar_Get("scr_consize", "1.0", 0, "Console size");
00474 scr_rspeed = Cvar_Get("r_speeds", "0", CVAR_ARCHIVE, "Show some rendering stats");
00475 scr_cursor = Cvar_Get("cursor", "1", CVAR_ARCHIVE, "Which cursor should be shown - 0-9");
00476 scr_showcursor = Cvar_Get("scr_showcursor", "1", 0, "Show/hide mouse cursor- 0-1");
00477
00478
00479 Cmd_AddCommand("timerefresh", SCR_TimeRefresh_f, "Run a benchmark");
00480
00481 SCR_TouchPics();
00482
00483 screenInitialized = qtrue;
00484 }