initial integration of Andrew Apted voxel code (#1249)

* remove -Wdeclaration-after-statement

* use index instead of address

* load voxels from autoload, *.zip and *.pk3 files

* fix widescreen clipping

Calculate `vx_clipangle` according to widescreen fov.

* calculate FOV using precise formula

* fix hires flickering (integer overflow)

* enable interpolation for voxel models
This commit is contained in:
Roman Fomin 2023-11-11 16:57:53 +07:00 committed by GitHub
parent 8c1fea93a6
commit afd707b181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 1108 additions and 8 deletions

View File

@ -35,7 +35,6 @@ endfunction()
# that pretend to be MSVC can take both GCC and MSVC-style parameters at the
# same time, like clang-cl.exe.
_checked_add_compile_option(-Wdeclaration-after-statement)
_checked_add_compile_option(-Werror=array-bounds)
_checked_add_compile_option(-Werror=clobbered)
_checked_add_compile_option(-Werror=format-security)

View File

@ -111,6 +111,7 @@ set(WOOF_SOURCES
r_state.h
r_swirl.c r_swirl.h
r_things.c r_things.h
r_voxel.c r_voxel.h
s_musinfo.c s_musinfo.h
s_sound.c s_sound.h
sounds.c sounds.h

View File

@ -57,6 +57,7 @@
#include "p_setup.h"
#include "r_draw.h"
#include "r_main.h"
#include "r_voxel.h"
#include "d_main.h"
#include "d_iwad.h" // [FG] D_FindWADByName()
#include "d_deh.h" // Ty 04/08/98 - Externalizations
@ -592,7 +593,7 @@ static boolean D_AddZipFile(const char *file)
char *str, *tempdir, counter[8];
static int idx = 0;
if (!M_StringCaseEndsWith(file, ".zip"))
if (!M_StringCaseEndsWith(file, ".zip") && !M_StringEndsWith(file, ".pk3"))
{
return false;
}
@ -628,7 +629,7 @@ static boolean D_AddZipFile(const char *file)
if (M_StringCaseEndsWith(name, ".wad") || M_StringCaseEndsWith(name, ".lmp") ||
M_StringCaseEndsWith(name, ".ogg") || M_StringCaseEndsWith(name, ".flac") ||
M_StringCaseEndsWith(name, ".mp3"))
M_StringCaseEndsWith(name, ".mp3") || M_StringCaseEndsWith(name, ".kvx"))
{
char *dest = M_StringJoin(tempdir, DIR_SEPARATOR_S, name, NULL);
@ -1604,7 +1605,8 @@ static void AutoLoadWADs(const char *path)
const char *filename;
glob = I_StartMultiGlob(path, GLOB_FLAG_NOCASE|GLOB_FLAG_SORTED,
"*.wad", "*.lmp", "*.zip", "*.ogg", "*.flac", "*.mp3", NULL);
"*.wad", "*.lmp", "*.kvx", "*.zip", "*.pk3",
"*.ogg", "*.flac", "*.mp3", NULL);
for (;;)
{
filename = I_NextGlob(glob);
@ -1612,6 +1614,13 @@ static void AutoLoadWADs(const char *path)
{
break;
}
if (M_StringCaseEndsWith(filename, ".kvx"))
{
VX_AddFile(filename);
continue;
}
D_AddFile(filename);
}
@ -2645,6 +2654,10 @@ void D_DoomMain(void)
ST_Init();
ST_Warnings();
// andrewj: voxel support
I_Printf(VB_INFO, "VX_Init: loading voxels....");
VX_Init();
I_PutChar(VB_INFO, '\n');
idmusnum = -1; //jff 3/17/98 insure idmus number is blank

View File

@ -18,6 +18,8 @@
//
//-----------------------------------------------------------------------------
#include <math.h>
#include "SDL.h" // haleyjd
#include "../miniz/miniz.h"
@ -45,6 +47,7 @@
int SCREENWIDTH, SCREENHEIGHT;
int NONWIDEWIDTH; // [crispy] non-widescreen SCREENWIDTH
int WIDESCREENDELTA; // [crispy] horizontal widescreen offset
angle_t FOV;
boolean use_vsync; // killough 2/8/98: controls whether vsync is called
int hires, default_hires; // killough 11/98
@ -958,6 +961,8 @@ void I_GetScreenDimensions(void)
}
WIDESCREENDELTA = (SCREENWIDTH - NONWIDEWIDTH) / 2;
FOV = 2 * atan(SCREENWIDTH / (1.2 * SCREENHEIGHT) * 3 / 4) / M_PI * ANG180;
}
static void CreateUpscaledTexture(boolean force)

View File

@ -23,11 +23,15 @@
#include "doomtype.h"
#include "tables.h"
extern int SCREENWIDTH;
extern int SCREENHEIGHT;
extern int NONWIDEWIDTH; // [crispy] non-widescreen SCREENWIDTH
extern int WIDESCREENDELTA; // [crispy] horizontal widescreen offset
extern angle_t FOV;
void I_GetScreenDimensions (void); // [crispy] re-calculate WIDESCREENDELTA
enum

View File

@ -390,6 +390,9 @@ typedef struct vissprite_s
// [FG] colored blood and gibs
int color;
const byte *brightmap;
// andrewj: voxel support
int voxel_index;
} vissprite_t;
//

View File

@ -25,8 +25,9 @@
#include "r_plane.h"
#include "r_bsp.h"
#include "r_draw.h"
#include "m_bbox.h"
#include "r_sky.h"
#include "r_voxel.h"
#include "m_bbox.h"
#include "v_video.h"
#include "st_stuff.h"
#include "hu_stuff.h"
@ -56,6 +57,7 @@ fixed_t viewheightfrac; // [FG] sprite clipping optimizations
//
angle_t clipangle;
angle_t vx_clipangle;
// The viewangletox[viewangle + FINEANGLES/4] lookup
// maps the visible view angles to screen X coordinates,
@ -304,6 +306,8 @@ static void R_InitTextureMapping (void)
viewangletox[i] = viewwidth;
clipangle = xtoviewangle[0];
vx_clipangle = clipangle - (FOV - ANG90);
}
//
@ -741,6 +745,7 @@ void R_RenderPlayerView (player_t* player)
R_ClearDrawSegs ();
R_ClearPlanes ();
R_ClearSprites ();
VX_ClearVoxels ();
if (autodetect_hom)
{ // killough 2/10/98: add flashing red HOM indicators
@ -818,7 +823,9 @@ void R_RenderPlayerView (player_t* player)
// The head node is the last node output.
R_RenderBSPNode (numnodes-1);
VX_NearbySprites ();
// [FG] update automap while playing
if (automap_on)
return;

View File

@ -96,6 +96,7 @@ extern fixed_t viewz;
extern angle_t viewangle;
extern player_t *viewplayer;
extern angle_t clipangle;
extern angle_t vx_clipangle;
extern int viewangletox[FINEANGLES/2];
extern angle_t xtoviewangle[MAX_SCREENWIDTH+1]; // killough 2/8/98
extern fixed_t rw_distance;

View File

@ -29,6 +29,7 @@
#include "r_draw.h"
#include "r_things.h"
#include "r_bmaps.h" // [crispy] R_BrightmapForTexName()
#include "r_voxel.h"
#include "m_swap.h"
#include "hu_stuff.h" // [Alaux] Lock crosshair on target
@ -54,7 +55,7 @@ typedef struct {
fixed_t pspritescale;
fixed_t pspriteiscale;
static lighttable_t **spritelights; // killough 1/25/98 made static
lighttable_t **spritelights; // killough 1/25/98 made static
// [Woof!] optimization for drawing huge amount of drawsegs.
// adapted from prboom-plus/src/r_things.c
@ -465,6 +466,10 @@ void R_ProjectSprite (mobj_t* thing)
fixed_t tr_x, tr_y, gxt, gyt, tz;
fixed_t interpx, interpy, interpz, interpangle;
// andrewj: voxel support
if (VX_ProjectVoxel (thing))
return;
// [AM] Interpolate between current and last position,
// if prudent.
if (uncapped &&
@ -597,6 +602,8 @@ void R_ProjectSprite (mobj_t* thing)
// killough 3/27/98: save sector for special clipping later
vis->heightsec = heightsec;
vis->voxel_index = -1;
vis->mobjflags = thing->flags;
vis->mobjflags2 = thing->flags2;
vis->scale = xscale;
@ -1100,7 +1107,12 @@ void R_DrawSprite (vissprite_t* spr)
mfloorclip = clipbot;
mceilingclip = cliptop;
R_DrawVisSprite (spr, spr->x1, spr->x2);
// andrewj: voxel support
if (spr->voxel_index >= 0)
VX_DrawVoxel (spr);
else
R_DrawVisSprite (spr, spr->x1, spr->x2);
}
//

View File

@ -41,6 +41,8 @@ extern fixed_t pspriteiscale;
extern boolean pspr_interp; // weapon bobbing interpolation
extern lighttable_t **spritelights;
void R_DrawMaskedColumn(column_t *column);
void R_SortVisSprites(void);
void R_AddSprites(sector_t *sec,int); // killough 9/18/98

1023
src/r_voxel.c Normal file

File diff suppressed because it is too large Load Diff

30
src/r_voxel.h Normal file
View File

@ -0,0 +1,30 @@
//
// Copyright(C) 2023 Andrew Apted
//
// 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.
//
#ifndef __R_VOXEL__
#define __R_VOXEL__
void VX_Init (void);
void VX_AddFile (const char *filename);
void VX_ClearVoxels (void);
void VX_NearbySprites (void);
boolean VX_ProjectVoxel (mobj_t * thing);
void VX_DrawVoxel (vissprite_t * vis);
#endif /* __R_VOXEL__ */