-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
h_refresh.c
485 lines (399 loc) · 13.5 KB
/
h_refresh.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2009 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2009 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* h_refresh.c: - jHeretic specific.
*/
// HEADER FILES ------------------------------------------------------------
#include <string.h>
#include "jheretic.h"
#include "hu_stuff.h"
#include "hu_menu.h"
#include "hu_msg.h"
#include "hu_pspr.h"
#include "am_map.h"
#include "g_common.h"
#include "r_common.h"
#include "d_net.h"
#include "f_infine.h"
#include "x_hair.h"
#include "g_controls.h"
#include "p_mapsetup.h"
#include "p_tick.h"
#include "rend_automap.h"
// MACROS ------------------------------------------------------------------
#define WINDOWHEIGHT Get(DD_VIEWWINDOW_HEIGHT)
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void R_SetAllDoomsdayFlags(void);
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern const float defFontRGB[];
extern const float defFontRGB2[];
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
/**
* Draws a special filter over the screen.
*/
void R_DrawSpecialFilter(int pnum)
{
float x, y, w, h;
player_t* player = &players[pnum];
if(player->powers[PT_INVULNERABILITY] <= BLINKTHRESHOLD &&
!(player->powers[PT_INVULNERABILITY] & 8))
return;
R_GetViewWindow(&x, &y, &w, &h);
DGL_Disable(DGL_TEXTURING);
if(cfg.ringFilter == 1)
{
DGL_BlendFunc(DGL_SRC_COLOR, DGL_SRC_COLOR);
DGL_DrawRect(x, y, w, h, .5f, .35f, .1f, cfg.filterStrength);
}
else
{
DGL_BlendFunc(DGL_DST_COLOR, DGL_SRC_COLOR);
DGL_DrawRect(x, y, w, h, 0, 0, .6f, cfg.filterStrength);
}
// Restore the normal rendering state.
DGL_BlendMode(BM_NORMAL);
DGL_Enable(DGL_TEXTURING);
}
boolean R_GetFilterColor(float rgba[4], int filter)
{
if(!rgba)
return false;
// We have to choose the right color and alpha.
if(filter >= STARTREDPALS && filter < STARTREDPALS + NUMREDPALS)
{ // Red.
rgba[CR] = 1;
rgba[CG] = 0;
rgba[CB] = 0;
rgba[CA] = (deathmatch? 1.0f : cfg.filterStrength) * filter / 8.f; // Full red with filter 8.
return true;
}
else if(filter >= STARTBONUSPALS && filter < STARTBONUSPALS + NUMBONUSPALS)
{ // Light Yellow.
rgba[CR] = 1;
rgba[CG] = 1;
rgba[CB] = .5f;
rgba[CA] = cfg.filterStrength * (filter - STARTBONUSPALS + 1) / 16.f;
return true;
}
if(filter)
Con_Message("R_GetFilterColor: Real strange filter number: %d.\n", filter);
return false;
}
void R_DrawMapTitle(int x, int y, float alpha, gamefontid_t font,
boolean center)
{
const char* lname, *lauthor;
lname = P_GetMapNiceName();
if(lname)
{
M_WriteText3(x - M_StringWidth(lname, font) / 2, y, lname, font,
defFontRGB[0], defFontRGB[1], defFontRGB[2], alpha,
false, true, 0);
y += 20;
}
lauthor = P_GetMapAuthor(cfg.hideIWADAuthor);
if(lauthor)
{
M_WriteText3(x - M_StringWidth(lauthor, GF_FONTA) / 2, y,
lauthor, GF_FONTA, .5f, .5f, .5f, alpha,
false, true, 0);
}
}
/**
* Do not really change anything here, because Doomsday might be in the
* middle of a refresh. The change will take effect next refresh.
*/
void R_SetViewSize(int blocks)
{
cfg.setSizeNeeded = true;
if(cfg.setBlocks != blocks && blocks > 10 && blocks < 13)
{ // Going to/from fullscreen.
int i;
// Force a hud show event (to reset the timer).
for(i = 0; i < MAXPLAYERS; ++i)
ST_HUDUnHide(i, HUE_FORCE);
}
cfg.setBlocks = blocks;
}
static void rendPlayerView(int player)
{
player_t* plr = &players[player];
int viewAngleOffset =
ANGLE_MAX * -G_GetLookOffset(player);
boolean isFullBright =
(plr->powers[PT_INVULNERABILITY] > BLINKTHRESHOLD) ||
(plr->powers[PT_INVULNERABILITY] & 8);
if(IS_CLIENT)
{
// Server updates mobj flags in NetSv_Ticker.
R_SetAllDoomsdayFlags();
}
DD_SetVariable(DD_VIEWX_OFFSET, &plr->viewOffset[VX]);
DD_SetVariable(DD_VIEWY_OFFSET, &plr->viewOffset[VY]);
DD_SetVariable(DD_VIEWZ_OFFSET, &plr->viewOffset[VZ]);
// The view angle offset.
DD_SetVariable(DD_VIEWANGLE_OFFSET, &viewAngleOffset);
// $democam
GL_SetFilter((plr->plr->flags & DDPF_VIEW_FILTER)? true : false);
if(plr->plr->flags & DDPF_VIEW_FILTER)
{
const float* color = plr->plr->filterColor;
GL_SetFilterColor(color[CR], color[CG], color[CB], color[CA]);
}
// How about fullbright?
DD_SetInteger(DD_FULLBRIGHT, isFullBright);
// Render the view with possible custom filters.
R_RenderPlayerView(player);
}
static void rendHUD(int player)
{
player_t* plr;
if(player < 0 || player >= MAXPLAYERS)
return;
if(G_GetGameState() != GS_MAP)
return;
if(IS_CLIENT && (!Get(DD_GAME_READY) || !Get(DD_GOTFRAME)))
return;
plr = &players[player];
// These various HUD's will be drawn unless Doomsday advises not to
if(DD_GetInteger(DD_GAME_DRAW_HUD_HINT))
{
automapid_t map = AM_MapForPlayer(player);
boolean redrawsbar = false;
if((WINDOWHEIGHT != 200))
redrawsbar = true;
// Draw HUD displays only visible when the automap is open.
if(AM_IsActive(map))
HU_DrawMapCounters();
// Do we need to render a full status bar at this point?
if(!(AM_IsActive(map) && cfg.automapHudDisplay == 0) &&
!(P_MobjIsCamera(plr->plr->mo) && Get(DD_PLAYBACK)))
{
int viewmode =
((WINDOWHEIGHT == 200)? (cfg.setBlocks - 10) : 0);
ST_Drawer(player, viewmode, redrawsbar); // $democam
}
HU_Drawer(player);
}
}
/**
* Draws the in-viewport display.
*
* @param layer @c 0 = bottom layer (before the viewport border).
* @c 1 = top layer (after the viewport border).
*/
void H_Display(int layer)
{
int player = DISPLAYPLAYER;
player_t* plr = &players[player];
float x, y, w, h;
if(layer == 0)
{
if(G_GetGameState() == GS_MAP)
{
// $democam: can be set on every frame.
if(cfg.setBlocks > 10 || (P_MobjIsCamera(plr->plr->mo) && Get(DD_PLAYBACK)))
{
// Full screen.
R_SetViewWindowTarget(0, 0, 320, 200);
}
else
{
int w = cfg.setBlocks * 32;
int h = cfg.setBlocks *
(200 - SBARHEIGHT * cfg.statusbarScale / 20) / 10;
R_SetViewWindowTarget(160 - (w / 2),
(200 - SBARHEIGHT * cfg.statusbarScale / 20 - h) / 2,
w, h);
}
R_GetViewWindow(&x, &y, &w, &h);
}
else
{
x = 0;
y = 0;
w = SCREENWIDTH;
h = SCREENHEIGHT;
}
R_SetViewWindow((int) x, (int) y, (int) w, (int) h);
if(!(MN_CurrentMenuHasBackground() && Hu_MenuAlpha() >= 1) &&
!R_MapObscures(player, (int) x, (int) y, (int) w, (int) h))
{
if(G_GetGameState() != GS_MAP)
return;
if(IS_CLIENT && (!Get(DD_GAME_READY) || !Get(DD_GOTFRAME)))
return;
if(!IS_CLIENT && mapTime < 2)
{
// Don't render too early; the first couple of frames
// might be a bit unstable -- this should be considered
// a bug, but since there's an easy fix...
return;
}
rendPlayerView(player);
R_DrawSpecialFilter(player);
// Crosshair.
if(!(P_MobjIsCamera(plr->plr->mo) && Get(DD_PLAYBACK))) // $democam
X_Drawer(player);
}
// Draw the automap?
AM_Drawer(player);
}
else if(layer == 1)
{
rendHUD(player);
}
}
void H_Display2(void)
{
switch(G_GetGameState())
{
case GS_MAP:
if(IS_CLIENT && (!Get(DD_GAME_READY) || !Get(DD_GOTFRAME)))
break;
if(DD_GetInteger(DD_GAME_DRAW_HUD_HINT))
{
// Level information is shown for a few seconds in the
// beginning of a level.
if(cfg.mapTitle || actualMapTime <= 6 * TICSPERSEC)
{
int x, y;
float alpha = 1;
if(actualMapTime < 35)
alpha = actualMapTime / 35.0f;
if(actualMapTime > 5 * 35)
alpha = 1 - (actualMapTime - 5 * 35) / 35.0f;
x = SCREENWIDTH / 2;
y = 13;
Draw_BeginZoom((1 + cfg.hudScale)/2, x, y);
R_DrawMapTitle(x, y, alpha, GF_FONTB, true);
Draw_EndZoom();
}
}
break;
case GS_INTERMISSION:
IN_Drawer();
break;
case GS_WAITING:
// Clear the screen while waiting, doesn't mess up the menu.
//gl.Clear(DGL_COLOR_BUFFER_BIT);
break;
case GS_INFINE:
if(!fiCmdExecuted)
{ // A (de)briefing is in process but the script hasn't started yet.
// Just clear the screen, then.
DGL_Disable(DGL_TEXTURING);
DGL_DrawRect(0, 0, 320, 200, 0, 0, 0, 1);
DGL_Enable(DGL_TEXTURING);
}
break;
default:
break;
}
// Draw pause pic (but not if InFine active).
if(paused && !fiActive)
{
GL_DrawPatch(SCREENWIDTH/2, 4, W_GetNumForName("PAUSED"));
}
// InFine is drawn whenever active.
FI_Drawer();
// Draw HUD displays; menu, messages.
Hu_Drawer();
}
/**
* Updates the mobj flags used by Doomsday with the state of our local flags
* for the given mobj.
*/
void R_SetDoomsdayFlags(mobj_t* mo)
{
// Client mobjs can't be set here.
if(IS_CLIENT && mo->ddFlags & DDMF_REMOTE)
return;
// Reset the flags for a new frame.
mo->ddFlags &= DDMF_CLEAR_MASK;
// Local objects aren't sent to clients.
if(mo->flags & MF_LOCAL)
mo->ddFlags |= DDMF_LOCAL;
if(mo->flags & MF_SOLID)
mo->ddFlags |= DDMF_SOLID;
if(mo->flags & MF_NOGRAVITY)
mo->ddFlags |= DDMF_NOGRAVITY;
if(mo->flags2 & MF2_FLOATBOB)
mo->ddFlags |= DDMF_NOGRAVITY | DDMF_BOB;
if(mo->flags & MF_MISSILE)
{ // Mace death balls are controlled by the server.
//if(mo->type != MT_MACEFX4)
mo->ddFlags |= DDMF_MISSILE;
}
if(mo->info && (mo->info->flags2 & MF2_ALWAYSLIT))
mo->ddFlags |= DDMF_ALWAYSLIT;
if(mo->flags2 & MF2_FLY)
mo->ddFlags |= DDMF_FLY | DDMF_NOGRAVITY;
// $democam: cameramen are invisible.
if(P_MobjIsCamera(mo))
mo->ddFlags |= DDMF_DONTDRAW;
if((mo->flags & MF_CORPSE) && cfg.corpseTime && mo->corpseTics == -1)
mo->ddFlags |= DDMF_DONTDRAW;
// Choose which ddflags to set.
if(mo->flags2 & MF2_DONTDRAW)
{
mo->ddFlags |= DDMF_DONTDRAW;
return; // No point in checking the other flags.
}
if(mo->flags2 & MF2_LOGRAV)
mo->ddFlags |= DDMF_LOWGRAVITY;
if(mo->flags & MF_BRIGHTSHADOW)
mo->ddFlags |= DDMF_BRIGHTSHADOW;
else if(mo->flags & MF_SHADOW)
mo->ddFlags |= DDMF_ALTSHADOW;
if(((mo->flags & MF_VIEWALIGN) && !(mo->flags & MF_MISSILE)) ||
(mo->flags & MF_FLOAT) ||
((mo->flags & MF_MISSILE) && !(mo->flags & MF_VIEWALIGN)))
mo->ddFlags |= DDMF_VIEWALIGN;
if(mo->flags & MF_TRANSLATION)
mo->tmap = (mo->flags & MF_TRANSLATION) >> MF_TRANSSHIFT;
}
/**
* Updates the status flags for all visible things.
*/
void R_SetAllDoomsdayFlags(void)
{
uint i;
mobj_t* iter;
// Only visible things are in the sector thinglists, so this is good.
for(i = 0; i < numsectors; ++i)
{
iter = P_GetPtr(DMU_SECTOR, i, DMT_MOBJS);
while(iter)
{
R_SetDoomsdayFlags(iter);
iter = iter->sNext;
}
}
}