Skip to content

Commit

Permalink
Further work on ID24 SKYDEFS support
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Dec 15, 2024
1 parent 16eee81 commit 0ded791
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 18 deletions.
21 changes: 21 additions & 0 deletions src/r_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,27 @@ void R_DrawPlayerSpriteColumn(void)
*dest = dc_source[frac >> FRACBITS];
}

void R_DrawSkyColumn(void)
{
int count = dc_yh - dc_yl + 1;
byte *dest = ylookup0[dc_yl] + dc_x;
fixed_t frac = dc_texturemid + (dc_yl - centery) * dc_iscale;
const lighttable_t *colormap = dc_colormap[0];
byte dot;

while (--count)
{
if ((dot = dc_source[frac >> FRACBITS]))
*dest = colormap[dot];

dest += SCREENWIDTH;
frac += dc_iscale;
}

if ((dot = dc_source[frac >> FRACBITS]))
*dest = colormap[dot];
}

void R_DrawFlippedSkyColumn(void)
{
int count = dc_yh - dc_yl + 1;
Expand Down
1 change: 1 addition & 0 deletions src/r_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void R_DrawBrightmapDitherLowWallColumn(void);
void R_DrawBrightmapDitherWallColumn(void);
void R_DrawColorDitherLowColumn(void);
void R_DrawColorDitherColumn(void);
void R_DrawSkyColumn(void);
void R_DrawFlippedSkyColumn(void);
void R_DrawTranslucentColumn(void);
void R_DrawTranslucent50Column(void);
Expand Down
4 changes: 0 additions & 4 deletions src/r_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ static void CreatePatch(int patchnum)
// sanity check that we've got all the memory allocated we need
SDL_assert((((byte *)patch->posts + numpoststotal * sizeof(rpost_t)) - (byte *)patch->data) == datasize);

memset(patch->pixels, 0xFF, (size_t)patch->width * patch->height);

// fill in the pixels, posts, and columns
for (int x = 0, numpostsusedsofar = 0; x < patch->width; x++)
{
Expand Down Expand Up @@ -369,8 +367,6 @@ static void CreateTextureCompositePatch(const int id)
// sanity check that we've got all the memory allocated we need
SDL_assert((((byte *)compositepatch->posts + numpoststotal * sizeof(rpost_t)) - (byte *)compositepatch->data) == datasize);

memset(compositepatch->pixels, 0xFF, (size_t)compositepatch->width * compositepatch->height);

for (int x = 0, numpostsusedsofar = 0; x < texture->width; x++)
{
// setup the column's data
Expand Down
54 changes: 42 additions & 12 deletions src/r_plane.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,26 @@ static byte *R_DistortedFlat(const int flatnum)
return distortedflat;
}

static void DrawSkyTex(visplane_t *pl, skytex_t *skytex, void func(void))
{
const int texture = R_TextureNumForName(skytex->name);
const angle_t angle = viewangle + FixedToAngle(skytex->currx);

dc_colormap[0] = fullcolormap;
dc_texturemid = (fixed_t)(skytex->mid * FRACUNIT) + skytex->curry;
dc_texheight = textureheight[texture] >> FRACBITS;
dc_iscale = FixedMul(skyiscale, skytex->scaley);

for (dc_x = pl->left; dc_x <= pl->right; dc_x++)
if ((dc_yl = pl->top[dc_x]) != USHRT_MAX
&& dc_yl <= (dc_yh = pl->bottom[dc_x]))
{
dc_source = R_GetTextureColumn(R_CacheTextureCompositePatchNum(texture),
(angle + xtoskyangle[dc_x]) >> ANGLETOSKYSHIFT);
func();
}
}

//
// R_DrawPlanes
// At the end of each frame.
Expand All @@ -451,21 +471,31 @@ void R_DrawPlanes(void)

if (picnum == skyflatnum)
{
dc_iscale = skyiscale;

if (sky && sky->type == SkyType_Fire)
if (sky)
{
id24compatible = true;
dc_texheight = FIREHEIGHT;
dc_texturemid = -28 * FRACUNIT;
dc_iscale = skyiscale;

for (dc_x = pl->left; dc_x <= pl->right; dc_x++)
if ((dc_yl = pl->top[dc_x]) != USHRT_MAX
&& dc_yl <= (dc_yh = pl->bottom[dc_x]))
{
dc_source = R_GetFireColumn((viewangle + xtoskyangle[dc_x]) >> ANGLETOSKYSHIFT);
skycolfunc();
}
if (sky->type == SkyType_Fire)
{
dc_texheight = FIREHEIGHT;
dc_texturemid = -28 * FRACUNIT;

for (dc_x = pl->left; dc_x <= pl->right; dc_x++)
if ((dc_yl = pl->top[dc_x]) != USHRT_MAX
&& dc_yl <= (dc_yh = pl->bottom[dc_x]))
{
dc_source = R_GetFireColumn((viewangle + xtoskyangle[dc_x]) >> ANGLETOSKYSHIFT);
skycolfunc();
}
}
else
{
DrawSkyTex(pl, &sky->skytex, skycolfunc);

if (sky->type == SkyType_WithForeground)
DrawSkyTex(pl, &sky->foreground, R_DrawSkyColumn);
}
}
else
{
Expand Down
2 changes: 0 additions & 2 deletions src/r_sky.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@ static void InitSkyDefs(void)

return;
}

sky = NULL;
}

void R_UpdateSky(void)
Expand Down

0 comments on commit 0ded791

Please sign in to comment.