-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathr_sky.c
95 lines (73 loc) · 2.33 KB
/
r_sky.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
/*-----------------------------------------------------------------------------
*
*
* Copyright (C) 2023-2025 Frenkel Smeijers
*
* 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., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* DESCRIPTION:
* Render sky
*
*-----------------------------------------------------------------------------*/
#include "r_defs.h"
#include "r_main.h"
#include "w_wad.h"
#define FLAT_SKY_COLOR 99
#define ANGLETOSKYSHIFT 22
#define COLEXTRABITS (8 - 1)
const int16_t skyflatnum = -2;
static int16_t skypatchnum;
static uint16_t skywidthmask;
static const patch_t __far* skypatch;
void R_LoadSkyPatch(void)
{
skypatch = W_TryGetLumpByNum(skypatchnum);
}
void R_FreeSkyPatch(void)
{
if (skypatch)
{
Z_ChangeTagToCache(skypatch);
skypatch = NULL;
}
}
void R_DrawSky(draw_column_vars_t *dcvars)
{
if (skypatch == NULL)
R_DrawColumnFlat(FLAT_SKY_COLOR, dcvars);
else
{
dcvars->texturemid = (SCREENHEIGHT_VGA / 2) * FRACUNIT;
if (!(dcvars->colormap = fixedcolormap))
dcvars->colormap = fullcolormap;
dcvars->fracstep = ((FRACUNIT * SCREENHEIGHT_VGA) / (VIEWWINDOWHEIGHT + 16)) >> COLEXTRABITS;
int16_t xc = viewangle >> FRACBITS;
xc += xtoviewangleTable[dcvars->x];
xc >>= ANGLETOSKYSHIFT - FRACBITS;
xc &= skywidthmask;
const column_t __far* column = (const column_t __far*) ((const byte __far*)skypatch + (uint16_t)skypatch->columnofs[xc]);
dcvars->source = (const byte __far*)column + 3;
R_DrawColumn(dcvars);
}
}
// Set the sky map.
void R_InitSky(void)
{
int16_t skytexture = R_CheckTextureNumForName("SKY1");
const texture_t __far* tex = R_GetTexture(skytexture);
skypatchnum = tex->patches[0].patch_num;
skywidthmask = tex->widthmask;
}