rockbox/apps/plugins/sdl/progs/wolf3d/wl_parallax.c
Franklin Wei 3f59fc8b77 Wolfenstein 3-D!
This is a port of Wolf4SDL, which is derived from the original id
software source release. The port runs on top of the SDL plugin
runtime and is loaded as an overlay.

Licensing of the game code is not an issue, as discussed below
(essentially, the Debian project treats Wolf4SDL as GPLv2, with an
email from John Carmack backing it up):

  http://forums.rockbox.org/index.php?topic=52872

Included is a copy of MAME's Yamaha OPL sound chip emulator
(fmopl_gpl.c).  This file was not part of the original Wolf4SDL source
(which includes a non-GPL'd version), but was rather rebased from from
a later MAME source which had been relicensed to GPLv2.

Change-Id: I64c2ba035e0be7e2f49252f40640641416613439
2019-07-09 11:20:55 -04:00

64 lines
1.6 KiB
C

#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