Debian Codegraph @

prboom2/src/r_sky.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * Sky rendering. The DOOM sky is a texture map like any
31 * wall, wrapping around. A 1024 columns equal 360 degrees.
32 * The default sky map is 256 columns and repeats 4 times
33 * on a 320 screen?
34 *
35 *-----------------------------------------------------------------------------*/
36
37 #include "r_sky.h"
38 #include "r_main.h"
39 #include "e6y.h"
40
41 #include "dsda/configuration.h"
42 #include "dsda/excmd.h"
43 #include "dsda/mapinfo.h"
44 #include "dsda/settings.h"
45
46 //
47 // sky mapping
48 //
49 int skyflatnum;
50 int skytexture;
51 int skytexturemid;
52
53 int skystretch;
54 fixed_t freelookviewheight;
55
56 //
57 // R_InitSkyMap
58 // Called whenever the view size changes.
59 //
60 void R_InitSkyMap(void)
61 {
62 int r_stretchsky;
63
64 r_stretchsky = dsda_IntConfig(dsda_config_render_stretchsky);
65
66 if (raven || !dsda_FreeAim())
67 {
68 skystretch = false;
69 skytexturemid = (raven ? 200 : 100) * FRACUNIT;
70 skyiscale = (200 << FRACBITS) / SCREENHEIGHT;
71 }
72 else
73 {
74 int skyheight;
75
76 if (!textureheight)
77 return;
78
79 // There are various combinations for sky rendering depending on how tall the sky is:
80 // h < 128: Unstretched and tiled, centered on horizon
81 // 128 <= h < 200: Can possibly be stretched. When unstretched, the baseline is
82 // 28 rows below the horizon so that the top of the texture
83 // aligns with the top of the screen when looking straight ahead.
84 // When stretched, it is scaled to 228 pixels with the baseline
85 // in the same location as an unstretched 128-tall sky, so the top
86 // of the texture aligns with the top of the screen when looking
87 // fully up.
88 // h == 200: Unstretched, baseline is on horizon, and top is at the top of
89 // the screen when looking fully up.
90 // h > 200: Unstretched, but the baseline is shifted down so that the top
91 // of the texture is at the top of the screen when looking fully up.
92
93 skyheight = textureheight[skytexture]>>FRACBITS;
94 skystretch = false;
95 skytexturemid = 0;
96 if (skyheight >= 128 && skyheight < 200)
97 {
98 skystretch = (r_stretchsky && skyheight >= 128);
99 skytexturemid = -28*FRACUNIT;
100 }
101 else if (skyheight > 200)
102 {
103 skytexturemid = (200 - skyheight) << FRACBITS;
104 }
105
106 skyiscale = (200 << FRACBITS) / SCREENHEIGHT;
107
108 if (skystretch)
109 {
110 skyiscale = (fixed_t)((int64_t)skyiscale * skyheight / SKYSTRETCH_HEIGHT);
111 skytexturemid = (int)((int64_t)skytexturemid * skyheight / SKYSTRETCH_HEIGHT);
112 }
113 else
114 {
115 skytexturemid = 100*FRACUNIT;
116 }
117 }
118 }