/
d_refresh.c
478 lines (401 loc) · 13.8 KB
/
d_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
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2007 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2007 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1993-1996 by id Software, Inc.
*
* 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
*/
/**
* d_refresh.c
*/
// HEADER FILES ------------------------------------------------------------
#include "wolftc.h"
#include "hu_stuff.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"
// MACROS ------------------------------------------------------------------
#define viewheight Get(DD_VIEWWINDOW_HEIGHT)
#define SIZEFACT 4
#define SIZEFACT2 16
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
void R_SetAllDoomsdayFlags(void);
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern int actual_leveltime;
extern float lookOffset;
// PUBLIC DATA DEFINITIONS -------------------------------------------------
gamestate_t wipegamestate = GS_DEMOSCREEN;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static int setdetail;
// CODE --------------------------------------------------------------------
/**
* Creates the translation tables to map the green color ramp to gray,
* brown, red.
* NOTE: Assumes a given structure of the PLAYPAL.
* Could be read from a lump instead.
*/
static void initTranslation(void)
{
byte *translationtables = (byte *)
DD_GetVariable(DD_TRANSLATIONTABLES_ADDRESS);
int i;
// translate just the 16 green colors
for(i = 0; i < 256; ++i)
{
if(i >= 0x70 && i <= 0x7f)
{
// map green ramp to gray, brown, red
translationtables[i] = 0x60 + (i & 0xf);
translationtables[i + 256] = 0x40 + (i & 0xf);
translationtables[i + 512] = 0x20 + (i & 0xf);
}
else
{
// Keep all other colors as is.
translationtables[i] = translationtables[i + 256] =
translationtables[i + 512] = i;
}
}
}
void R_InitRefresh(void)
{
initTranslation();
}
/**
* Draws a special filter over the screen (eg the inversing filter used when
* in god mode).
*/
void R_DrawSpecialFilter(void)
{
player_t *player = &players[displayplayer];
if(player->powers[PT_INVULNERABILITY])
{
float x, y, w, h;
float max = 30;
float str, r, g, b;
int t = player->powers[PT_INVULNERABILITY];
if(t < max)
str = t / max;
else if(t < 4 * 32 && !(t & 8))
str = .7f;
else if(t > INVULNTICS - max)
str = (INVULNTICS - t) / max;
else
str = 1; // Full inversion.
// Draw an inversing filter.
gl.Disable(DGL_TEXTURING);
gl.Func(DGL_BLENDING, DGL_ONE_MINUS_DST_COLOR,
DGL_ONE_MINUS_SRC_COLOR);
r = str * 2;
g = str * 2 - .4;
b = str * 2 - .8;
CLAMP(r, 0, 1);
CLAMP(g, 0, 1);
CLAMP(b, 0, 1);
R_GetViewWindow(&x, &y, &w, &h);
GL_DrawRect(x, y, w, h, r, g, b, 1);
// Restore the normal rendering state.
gl.Func(DGL_BLENDING, DGL_SRC_ALPHA, DGL_ONE_MINUS_SRC_ALPHA);
gl.Enable(DGL_TEXTURING);
}
}
/**
* Show map name and author.
*/
void R_DrawLevelTitle(void)
{
float alpha = 1;
int y = 12;
int mapnum;
char *lname, *lauthor;
if(!cfg.levelTitle || actual_leveltime > 6 * 35)
return;
// Make the text a bit smaller.
gl.MatrixMode(DGL_MODELVIEW);
gl.PushMatrix();
gl.Translatef(160, y, 0);
gl.Scalef(.7f, .7f, 1);
gl.Translatef(-160, -y, 0);
if(actual_leveltime < 35)
alpha = actual_leveltime / 35.0f;
if(actual_leveltime > 5 * 35)
alpha = 1 - (actual_leveltime - 5 * 35) / 35.0f;
// Get the strings from Doomsday
lname = P_GetMapNiceName();
lauthor = (char *) DD_GetVariable(DD_MAP_AUTHOR);
// Compose the mapnumber used to check the map name patches array.
if(gamemode == commercial)
mapnum = gamemap -1;
else
mapnum = ((gameepisode -1) * 9) + gamemap -1;
if(lname)
{
WI_DrawPatch(SCREENWIDTH / 2, y, 1, 1, 1, alpha, lnames[mapnum].lump,
lname, false, ALIGN_CENTER);
y += 14; //9;
}
//gl.Color4f(.5f, .5f, .5f, alpha);
if(lauthor && W_IsFromIWAD(lnames[mapnum].lump) &&
(!cfg.hideAuthorIdSoft || stricmp(lauthor, "id software")))
{
M_WriteText3(160 - M_StringWidth(lauthor, hu_font_a) / 2, y, lauthor,
hu_font_a, .5f, .5f, .5f, alpha, false, 0);
}
gl.MatrixMode(DGL_MODELVIEW);
gl.PopMatrix();
}
/**
* 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, int detail)
{
cfg.setsizeneeded = true;
if(cfg.setblocks != blocks && blocks > 10 && blocks < 13)
{ // When going fullscreen, force a hud show event (to reset the timer).
ST_HUDUnHide(HUE_FORCE);
}
cfg.setblocks = blocks;
setdetail = detail;
}
void D_Display(void)
{
static boolean viewactivestate = false;
static boolean menuactivestate = false;
static gamestate_t oldgamestate = -1;
player_t *player = &players[displayplayer];
boolean iscam = (player->plr->flags & DDPF_CAMERA) != 0; // $democam
float x, y, w, h;
boolean mapHidesView;
// $democam: can be set on every frame
if(cfg.setblocks > 10 || iscam)
{
// Full screen.
R_SetViewWindowTarget(0, 0, 320, 200);
}
else
{
int w = cfg.setblocks * 32;
int h = cfg.setblocks * (200 - ST_HEIGHT * cfg.sbarscale / 20) / 10;
R_SetViewWindowTarget(160 - (w >> 1),
(200 - ST_HEIGHT * cfg.sbarscale / 20 - h) >> 1,
w, h);
}
R_GetViewWindow(&x, &y, &w, &h);
R_ViewWindow((int) x, (int) y, (int) w, (int) h);
// Do buffered drawing.
switch(G_GetGameState())
{
case GS_LEVEL:
if(IS_CLIENT && (!Get(DD_GAME_READY) || !Get(DD_GOTFRAME)))
break;
if(!IS_CLIENT && leveltime < 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...
break;
}
mapHidesView =
R_MapObscures(displayplayer, (int) x, (int) y, (int) w, (int) h);
if(!(MN_CurrentMenuHasBackground() && Hu_MenuAlpha() >= 1) &&
!mapHidesView)
{
int viewAngleOffset = ANGLE_MAX * -G_GetLookOffset(displayplayer);
// Draw the player view.
if(IS_CLIENT)
{
// Server updates mobj flags in NetSv_Ticker.
R_SetAllDoomsdayFlags();
}
// The view angle offset.
DD_SetVariable(DD_VIEWANGLE_OFFSET, &viewAngleOffset);
GL_SetFilter(players[displayplayer].plr->filter); // $democam
// How about fullbright?
Set(DD_FULLBRIGHT, (player->powers[PT_INFRARED] > 4 * 32) ||
(player->powers[PT_INFRARED] & 8) ||
player->powers[PT_INVULNERABILITY] > 30);
// Render the view with possible custom filters.
R_RenderPlayerView(players[displayplayer].plr);
R_DrawSpecialFilter();
// Crosshair.
if(!iscam)
X_Drawer(); // $democam
}
// Draw the automap?
AM_Drawer(displayplayer);
break;
default:
break;
}
menuactivestate = Hu_MenuIsActive();
viewactivestate = viewactive;
oldgamestate = wipegamestate = G_GetGameState();
}
void D_Display2(void)
{
// Do buffered drawing.
switch(G_GetGameState())
{
case GS_LEVEL:
if(IS_CLIENT && (!Get(DD_GAME_READY) || !Get(DD_GOTFRAME)))
break;
if(!IS_CLIENT && leveltime < 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...
break;
}
// These various HUD's will be drawn unless Doomsday advises not to
if(DD_GetInteger(DD_GAME_DRAW_HUD_HINT))
{
boolean redrawsbar = false;
// Draw HUD displays only visible when the automap is open.
if(AM_IsMapActive(displayplayer))
HU_DrawMapCounters();
// Level information is shown for a few seconds in the
// beginning of a level.
R_DrawLevelTitle();
if((viewheight != 200))
redrawsbar = true;
// Do we need to render a full status bar at this point?
if(!(AM_IsMapActive(displayplayer) && cfg.automapHudDisplay == 0 ))
{
player_t *player = &players[displayplayer];
boolean iscam = (player->plr->flags & DDPF_CAMERA) != 0; // $democam
if(!iscam)
{
if(true == (viewheight == 200))
{
// Fullscreen. Which mode?
ST_Drawer(cfg.setblocks - 10 , redrawsbar);
}
else
{
ST_Drawer(0 , redrawsbar);
}
}
}
HU_Drawer();
}
break;
case GS_INTERMISSION:
WI_Drawer();
break;
case GS_WAITING:
gl.Clear(DGL_COLOR_BUFFER_BIT);
M_WriteText2(5, 188, "WAITING... PRESS ESC FOR MENU", hu_font_a, 1, 0, 0, 1);
break;
default:
break;
}
// draw pause pic (but not if InFine active)
if(paused && !fi_active)
{
WI_DrawPatch(SCREENWIDTH /2, 4, 1, 1, 1, 1, W_GetNumForName("M_PAUSE"),
NULL, false, ALIGN_CENTER);
}
// InFine is drawn whenever active.
FI_Drawer();
// The menu is drawn whenever active.
Hu_MenuDrawer();
}
/**
* Updates the mobj flags used by Doomsday with the state of our local flags
* for the given mobj.
*/
void P_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)
{
mo->ddflags |= DDMF_MISSILE;
}
if(mo->type == MT_LIGHTSOURCE)
mo->ddflags |= DDMF_ALWAYSLIT | DDMF_DONTDRAW;
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_IsCamera(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;
// The torches often go into the ceiling. This'll prevent
// them from 'jumping'.
if(mo->type == MT_MISC41 || mo->type == MT_MISC42 || mo->type == MT_MISC43 // tall torches
|| mo->type == MT_MISC44 || mo->type == MT_MISC45 || mo->type == MT_MISC46) // short torches
mo->ddflags |= DDMF_NOFITBOTTOM;
if(mo->flags & MF_BRIGHTSHADOW)
mo->ddflags |= DDMF_BRIGHTSHADOW;
else if(mo->flags & MF_SHADOW)
mo->ddflags |= DDMF_SHADOW;
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;
mo->ddflags |= mo->flags & MF_TRANSLATION;
}
/**
* 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)
{
for(iter = P_GetPtr(DMU_SECTOR, i, DMT_MOBJS); iter; iter = iter->snext)
P_SetDoomsdayFlags(iter);
}
}