-
Notifications
You must be signed in to change notification settings - Fork 29
/
wl_parallax.cpp
64 lines (52 loc) · 1.68 KB
/
wl_parallax.cpp
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
#include "version.h"
#ifdef USE_PARALLAX
#include "wl_def.h"
#ifdef USE_FEATUREFLAGS
// The lower left tile of every map determines the start texture of the parallax sky.
static int GetParallaxStartTexture()
{
int startTex = ffDataBottomLeft;
assert(startTex >= 0 && startTex < PMSpriteStart);
return startTex;
}
#else
static int GetParallaxStartTexture()
{
int startTex;
switch(gamestate.episode * 10 + mapon)
{
case 0: startTex = 20; break;
default: startTex = 0; break;
}
assert(startTex >= 0 && startTex < PMSpriteStart);
return startTex;
}
#endif
void DrawParallax(byte *vbuf, unsigned vbufPitch)
{
int startpage = GetParallaxStartTexture();
int midangle = player->angle * (FINEANGLES / ANGLES);
int skyheight = viewheight >> 1;
int curtex = -1;
byte *skytex;
startpage += USE_PARALLAX - 1;
for(int x = 0; x < viewwidth; x++)
{
int curang = pixelangle[x] + midangle;
if(curang < 0) curang += FINEANGLES;
else if(curang >= FINEANGLES) curang -= FINEANGLES;
int xtex = curang * USE_PARALLAX * TEXTURESIZE / FINEANGLES;
int newtex = xtex >> TEXTURESHIFT;
if(newtex != curtex)
{
curtex = newtex;
skytex = PM_GetTexture(startpage - curtex);
}
int texoffs = TEXTUREMASK - ((xtex & (TEXTURESIZE - 1)) << TEXTURESHIFT);
int yend = skyheight - (wallheight[x] >> 3);
if(yend <= 0) continue;
for(int y = 0, offs = x; y < yend; y++, offs += vbufPitch)
vbuf[offs] = skytex[texoffs + (y * TEXTURESIZE) / skyheight];
}
}
#endif