Skip to content

Commit

Permalink
Add r_swirl
Browse files Browse the repository at this point in the history
  • Loading branch information
kraflab committed Sep 26, 2024
1 parent 28bfde5 commit c5c9269
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
2 changes: 2 additions & 0 deletions prboom2/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ set(COMMON_SRC
r_sky.c
r_sky.h
r_state.h
r_swirl.c
r_swirl.h
r_things.c
r_things.h
scanner.cpp
Expand Down
128 changes: 128 additions & 0 deletions prboom2/src/r_swirl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2000, 2005-2014 Simon Howard
// Copyright(C) 2019 Fabian Greffrath
//
// 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.
//
// DESCRIPTION:
// [crispy] add support for SMMU swirling flats
//

// [crispy] adapted from smmu/r_ripple.c, by Simon Howard

#include "doomstat.h"
#include "tables.h"
#include "w_wad.h"
#include "z_zone.h"

#include "dsda.h"

// swirl factors determine the number of waves per flat width

// 1 cycle per 64 units
#define swirlfactor (FINEANGLES / 64)

// 1 cycle per 32 units (2 in 64)
#define swirlfactor2 (FINEANGLES / 32)

#define SEQUENCE 256
#define FLATSIZE (64 * 64)

static int *offsets;
static int *offset;

#define AMP 2
#define AMP2 2
#define SPEED 32

static void R_InitDistortedFlats()
{
int i;

offsets = Z_Malloc(SEQUENCE * FLATSIZE * sizeof(*offsets));
offset = offsets;

for (i = 0; i < SEQUENCE; i++)
{
int x, y;

for (x = 0; x < 64; x++)
{
for (y = 0; y < 64; y++)
{
int x1, y1;
int sinvalue, sinvalue2;

sinvalue = (y * swirlfactor + i * SPEED * 5 + 900) & FINEMASK;
sinvalue2 = (x * swirlfactor2 + i * SPEED * 4 + 300) & FINEMASK;
x1 = x + 128 + ((finesine[sinvalue] * AMP) >> FRACBITS)
+ ((finesine[sinvalue2] * AMP2) >> FRACBITS);

sinvalue = (x * swirlfactor + i * SPEED * 3 + 700) & FINEMASK;
sinvalue2 = (y * swirlfactor2 + i * SPEED * 4 + 1200) & FINEMASK;
y1 = y + 128 + ((finesine[sinvalue] * AMP) >> FRACBITS)
+ ((finesine[sinvalue2] * AMP2) >> FRACBITS);

x1 &= 63;
y1 &= 63;

offset[(y << 6) + x] = (y1 << 6) + x1;
}
}

offset += FLATSIZE;
}
}

byte *R_DistortedFlat(int flatnum)
{
static int swirltic = -1;
static int swirlflat = -1;
static byte distortedflat[FLATSIZE];

if (!offsets)
{
R_InitDistortedFlats();
}

if (swirltic != leveltime)
{
if (!dsda_FrozenMode())
{
offset = offsets + ((leveltime & (SEQUENCE - 1)) * FLATSIZE);
}
else
{
offset = offsets;
}

swirltic = leveltime;
swirlflat = -1;
}

if (swirlflat != flatnum)
{
const char *normalflat;
int i;

normalflat = W_LumpByNum(flatnum);

for (i = 0; i < FLATSIZE; i++)
{
distortedflat[i] = normalflat[offset[i]];
}

swirlflat = flatnum;
}

return distortedflat;
}
27 changes: 27 additions & 0 deletions prboom2/src/r_swirl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2000, 2005-2014 Simon Howard
// Copyright(C) 2019 Fabian Greffrath
//
// 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.
//
// DESCRIPTION:
// [crispy] add support for SMMU swirling flats
//

#ifndef __R_SWIRL__
#define __R_SWIRL__

#include "doomtype.h"

byte *R_DistortedFlat(int flatnum);

#endif

0 comments on commit c5c9269

Please sign in to comment.