Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 21-installer-nodd
  • 2210-pre1
  • 2210-pre2
  • 2210-rc1
  • 2210-rc2
  • 2210-rc3
  • 2211-pre1
  • 2211-pre2
  • 2211-rc1
  • 2212-pre1
  • 2212-pre2
  • 2212-pre3
  • 2212-rc1
  • 2213
  • 2_2_12
  • 64-gl-log
  • COM_ImmedExecute-lua
  • DJGPP
  • SRB2-Stuff
  • SRB2_Discord
  • Sugoi-2
  • accel-momentum
  • any-resolution
  • appveyor
  • blend-locking
  • blentran
  • blua-unary-not-fix
  • boost-tickrate
  • bustablemobjzfix
  • bustablesoundz
  • cleanup-opengl
  • cleanupmusic
  • cmake-valgrind
  • crawlacommander-sprites
  • cutscene-cleanup
  • dd-music-bypass
  • dd-music-fix
  • delfile2
  • deprecate-lua-dedicated-server
  • dpl-2
  • dropshadows-spawning
  • dynabsp
  • emblem-drawing
  • exchndl-xp-fix
  • few-kart-lua-changes
  • ffloorclip
  • fix-cvar-conflicts
  • fix-opengl-shear-roll
  • flipfuncpointers
  • fof-lightlist-fixes
  • font-FUCK
  • font_drawer
  • frictionrefactor
  • fruits-clipper
  • fuck-macros-1
  • gamepad-luakeydown
  • gamepad-morefixes
  • gamepad_experiments
  • gametype-refactor
  • ghost-networking
  • gif-splitting
  • gitlab-ci
  • grr-lj
  • hitboxviewer
  • hwr-texture-cache-refactor
  • hwrender2
  • improve-439
  • improve-download-refuse-message
  • increase-packet-tics
  • input-display
  • input-display-translucency
  • io
  • joystick-juggling-maz
  • keycodes-only
  • kill-hud-feetoffset
  • ksf-wadfiles
  • ld413-mp-fix
  • levelstruct
  • libpng-version-support
  • linedef-actions
  • lj-test
  • lol-states
  • loopedsounds
  • lower-unpegged-fix
  • lua-change-gametype
  • lua-colorlib
  • lua-command-netids
  • lua-extracolormap
  • lua-local
  • lua-minmax-plus-bruh-moments
  • makefile-auto-mingw-gcc
  • makefile-tinkering
  • map-components-signedness-fixes
  • maretimers
  • master
  • menu-edits
  • mobj-dispoffset
  • more-cleanup
  • multithread
  • musicdef-lua
  • SRB2_release_2.1
  • SRB2_release_2.1.1
  • SRB2_release_2.1.10
  • SRB2_release_2.1.11
  • SRB2_release_2.1.12
  • SRB2_release_2.1.14
  • SRB2_release_2.1.15
  • SRB2_release_2.1.16
  • SRB2_release_2.1.16a
  • SRB2_release_2.1.17
  • SRB2_release_2.1.18
  • SRB2_release_2.1.19
  • SRB2_release_2.1.2
  • SRB2_release_2.1.20
  • SRB2_release_2.1.21
  • SRB2_release_2.1.22
  • SRB2_release_2.1.23
  • SRB2_release_2.1.24
  • SRB2_release_2.1.25
  • SRB2_release_2.1.3
  • SRB2_release_2.1.4
  • SRB2_release_2.1.5
  • SRB2_release_2.1.6
  • SRB2_release_2.1.7
  • SRB2_release_2.1.8
  • SRB2_release_2.1.9
  • SRB2_release_2.2.0
  • SRB2_release_2.2.1
  • SRB2_release_2.2.10
  • SRB2_release_2.2.11
  • SRB2_release_2.2.12
  • SRB2_release_2.2.13
  • SRB2_release_2.2.2
  • SRB2_release_2.2.3
  • SRB2_release_2.2.4
  • SRB2_release_2.2.5
  • SRB2_release_2.2.6
  • SRB2_release_2.2.7
  • SRB2_release_2.2.8
  • SRB2_release_2.2.9
  • td-release-v1.0.0
141 results

Target

Select target project
  • STJr/SRB2
  • Sryder/SRB2
  • wolfy852/SRB2
  • Alpha2244/SRB2
  • Inuyasha/SRB2
  • yoshibot/SRB2
  • TehRealSalt/SRB2
  • PrisimaTF/SRB2
  • Hatninja/SRB2
  • SteelT/SRB2
  • james/SRB2
  • ShaderWraith/SRB2
  • SinnamonLat/SRB2
  • mazmazz_/SRB2
  • filpAM/SRB2
  • chaoloveicemdboy/SRB2
  • Whooa21/SRB2
  • Machturne/SRB2
  • Golden/SRB2
  • Tatsuru/SRB2
  • Snu/SRB2
  • Zwip-Zwap_Zapony/SRB2
  • fickleheart/SRB2
  • alphaRexJames/SRB2
  • JJK/SRB2
  • diskpoppy/SRB2
  • Hannu_Hanhi/SRB2
  • ZipperQR/SRB2
  • kays/SRB2
  • spherallic/SRB2
  • Zippy_Zolton/SRB2
  • namiishere/SRB2
  • Ors/SRB2
  • SMS_Alfredo/SRB2
  • sonic_edge/SRB2
  • lavla/SRB2
  • ashi/SRB2
  • X.organic/SRB2
  • Fafabis/SRB2
  • Meziu/SRB2
  • v-rob/SRB2
  • tertu/SRB2
  • bitten2up/SRB2
  • flarn2006/SRB2
  • Krabs/SRB2
  • clairebun/SRB2
  • Lactozilla/SRB2
  • thehackstack/SRB2
  • Spice/SRB2
  • win8linux/SRB2
  • JohnFrostFox/SRB2
  • talktoneon726/SRB2
  • Wane/SRB2
  • Lamibe/SRB2
  • spectrumuk2/srb-2
  • nerdyminer18/srb-2
  • 256nil/SRB2
  • ARJr/SRB2
  • Alam/SRB2
  • Zenya/srb-2-marathon-demos
  • Acelite/srb-2-archivedmodifications
  • MIDIMan/SRB2
  • Lach/SRB2
  • Frostiikin/bounce-tweaks
  • Jaden/SRB2
  • Tyron/SRB2
  • Astronight/SRB2
  • Mari0shi06/SRB2
  • aiire/SRB2
  • Galactice/SRB2
  • srb2-ports/srb2-dreamcast
  • sdasdas/SRB2
  • chreas/srb-2-vr
  • StarManiaKG/the-story-of-sinically-rocketing-and-botching-the-2nd
  • LoganAir/SRB2
  • NepDisk/srb-2
  • alufolie91/SRB2
  • Felicia.iso/SRB2
  • twi/SRB2
  • BarrelsOFun/SRB2
  • Speed2411/SRB2
  • Leather_Realms/SRB2
  • Ayemar/SRB2
  • Acelite/SRB2
  • VladDoc/SRB2
  • kaldrum/model-features
  • strawberryfox417/SRB2
  • Lugent/SRB2
  • Rem/SRB2
  • Refrag/SRB2
  • Henry_3230/srb-3230
  • TehPuertoRicanSpartan2/tprs-srb2
  • Leminn/srb-2-marathon-stuff
  • chromaticpipe2/SRB2
  • MiguelGustavo15/SRB2
  • Maru/srb-2-tests
  • SilicDev/SRB2
  • UnmatchedBracket/SRB2
  • HybridDog/SRB2
  • xordspar0/SRB2
  • jsjhbewfhh/SRB2
  • Fancy2209/SRB2
  • Lorsoen/SRB2
  • shindoukin/SRB2
  • GamerOfDays/SRB2
  • Craftyawesome/SRB2
  • tenshi-tensai-tennoji/SRB2
  • Scarfdudebalder/SRB2
  • luigi-budd/srb-2-fix-interplag-lockon
  • mskluesner/SRB2
  • johnpetersa19/SRB2
  • Pheazant/SRB2
  • chromaticpipe2/srb2classic
  • romoney5/SRB2
  • PAS/SRB2Classic
  • BlueStaggo/SRB2
  • Jisk/srb-2-beef-jerky
117 results
Select Git revision
  • 1392-2-2-15-attempting-to-draw-a-hud-graphic-with-the-same-lump-name-as-a-lua-script-crashes-the
  • 21-installer-nodd
  • 2210-pre1
  • 2210-pre2
  • 2210-rc1
  • 2210-rc2
  • 2210-rc3
  • 2211-pre1
  • 2211-pre2
  • 2211-rc1
  • 2212-pre1
  • 2212-pre2
  • 2212-pre3
  • 2212-rc1
  • 2213
  • 2214-pre1
  • 2214-pre2
  • 2214-pre3
  • 2214-pre4
  • 2_2_12
  • 64-gl-log
  • COM_ImmedExecute-lua
  • DJGPP
  • accel-momentum
  • acs
  • action-args
  • alpha-fixes
  • any-resolution
  • appveyor
  • blend-locking
  • blentran
  • blua-unary-not-fix
  • boost-tickrate
  • bustablesoundz
  • cleanup-opengl
  • cleanupmusic
  • clipmidtex
  • cmake-valgrind
  • crawlacommander-sprites
  • custom-map-names
  • custom-teams
  • cutscene-cleanup
  • dd-music-bypass
  • dd-music-fix
  • delfile2
  • deprecate-lua-dedicated-server
  • dpl-2
  • dropshadows-spawning
  • dynabsp
  • emblem-drawing
  • exchndl-xp-fix
  • extra-textures
  • few-kart-lua-changes
  • ffloorclip
  • fix-167
  • fix-cvar-conflicts
  • fix-opengl-parameter-crash
  • fix-opengl-shear-roll
  • flipfuncpointers
  • fof-lightlist-fixes
  • font-FUCK
  • frictionrefactor
  • fuck-macros-1
  • gamepad-luakeydown
  • gamepad-morefixes
  • gamepad_experiments
  • gametype-refactor
  • gametype-refactor-1
  • gametype-refactor-player-spawns
  • ghost-networking
  • gif-splitting
  • grr-lj
  • hitboxviewer
  • hwr-texture-cache-refactor
  • hwrender2
  • improve-439
  • increase-maxconditionsets
  • increase-packet-tics
  • input-display
  • input-display-translucency
  • io
  • joystick-juggling-maz
  • just-in-case
  • keycodes-only
  • ksf-wadfiles
  • ld413-mp-fix
  • levelstruct
  • libpng-version-support
  • linedef-actions
  • lj-test
  • lol-states
  • loopedsounds
  • lower-unpegged-fix
  • lua-change-gametype
  • lua-command-netids
  • lua-gfx-2
  • lua-gfx-sprites
  • lua-local
  • makefile-auto-mingw-gcc
  • makefile-tinkering
  • SRB2_release_2.1
  • SRB2_release_2.1.1
  • SRB2_release_2.1.10
  • SRB2_release_2.1.11
  • SRB2_release_2.1.12
  • SRB2_release_2.1.14
  • SRB2_release_2.1.15
  • SRB2_release_2.1.16
  • SRB2_release_2.1.16a
  • SRB2_release_2.1.17
  • SRB2_release_2.1.18
  • SRB2_release_2.1.19
  • SRB2_release_2.1.2
  • SRB2_release_2.1.20
  • SRB2_release_2.1.21
  • SRB2_release_2.1.22
  • SRB2_release_2.1.23
  • SRB2_release_2.1.24
  • SRB2_release_2.1.25
  • SRB2_release_2.1.3
  • SRB2_release_2.1.4
  • SRB2_release_2.1.5
  • SRB2_release_2.1.6
  • SRB2_release_2.1.7
  • SRB2_release_2.1.8
  • SRB2_release_2.1.9
  • SRB2_release_2.2.0
  • SRB2_release_2.2.1
  • SRB2_release_2.2.10
  • SRB2_release_2.2.11
  • SRB2_release_2.2.12
  • SRB2_release_2.2.13
  • SRB2_release_2.2.15
  • SRB2_release_2.2.2
  • SRB2_release_2.2.3
  • SRB2_release_2.2.4
  • SRB2_release_2.2.5
  • SRB2_release_2.2.6
  • SRB2_release_2.2.7
  • SRB2_release_2.2.8
  • SRB2_release_2.2.9
  • td-release-v1.0.0
142 results
Show changes
Commits on Source (1)
...@@ -8,8 +8,6 @@ target_sources(SRB2SDL2 PRIVATE comptime.c md5.c config.h.in) ...@@ -8,8 +8,6 @@ target_sources(SRB2SDL2 PRIVATE comptime.c md5.c config.h.in)
set(SRB2_ASM_SOURCES vid_copy.s) set(SRB2_ASM_SOURCES vid_copy.s)
set(SRB2_NASM_SOURCES tmap_mmx.nas tmap.nas)
### Configuration ### Configuration
set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL
"Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.") "Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.")
...@@ -213,8 +211,7 @@ if(${SRB2_CONFIG_USEASM}) ...@@ -213,8 +211,7 @@ if(${SRB2_CONFIG_USEASM})
target_compile_definitions(SRB2SDL2 PRIVATE -DUSEASM) target_compile_definitions(SRB2SDL2 PRIVATE -DUSEASM)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3 -mfpmath=sse") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3 -mfpmath=sse")
target_sources(SRB2SDL2 PRIVATE ${SRB2_ASM_SOURCES} target_sources(SRB2SDL2 PRIVATE ${SRB2_ASM_SOURCES})
${SRB2_NASM_SOURCES})
else() else()
set(SRB2_USEASM OFF) set(SRB2_USEASM OFF)
target_compile_definitions(SRB2SDL2 PRIVATE -DNONX86 -DNORUSEASM) target_compile_definitions(SRB2SDL2 PRIVATE -DNONX86 -DNORUSEASM)
......
...@@ -210,7 +210,7 @@ sources+=\ ...@@ -210,7 +210,7 @@ sources+=\
$(call List,blua/Sourcefile)\ $(call List,blua/Sourcefile)\
depends:=$(basename $(filter %.c %.s,$(sources))) depends:=$(basename $(filter %.c %.s,$(sources)))
objects:=$(basename $(filter %.c %.s %.nas,$(sources))) objects:=$(basename $(filter %.c %.s,$(sources)))
depends:=$(depends:%=$(depdir)/%.d) depends:=$(depends:%=$(depdir)/%.d)
......
...@@ -20,7 +20,6 @@ endif ...@@ -20,7 +20,6 @@ endif
ifndef NOASM ifndef NOASM
ifndef NONX86 ifndef NONX86
sources+=tmap.nas tmap_mmx.nas
opts+=-DUSEASM opts+=-DUSEASM
endif endif
endif endif
......
...@@ -511,8 +511,10 @@ static void D_Display(void) ...@@ -511,8 +511,10 @@ static void D_Display(void)
M_Memcpy(ylookup, ylookup1, viewheight*sizeof (ylookup[0])); M_Memcpy(ylookup, ylookup1, viewheight*sizeof (ylookup[0]));
} }
} }
ps_rendercalltime = I_GetPreciseTime() - ps_rendercalltime;
// Image postprocessing effect // Image postprocessing effect
ps_postprocesstime = I_GetPreciseTime();
if (rendermode == render_soft) if (rendermode == render_soft)
{ {
if (!splitscreen) if (!splitscreen)
...@@ -523,7 +525,7 @@ static void D_Display(void) ...@@ -523,7 +525,7 @@ static void D_Display(void)
if (postimgtype2) if (postimgtype2)
V_DoPostProcessor(1, postimgtype2, postimgparam2); V_DoPostProcessor(1, postimgtype2, postimgparam2);
} }
ps_rendercalltime = I_GetPreciseTime() - ps_rendercalltime; ps_postprocesstime = I_GetPreciseTime() - ps_postprocesstime;
} }
if (lastdraw) if (lastdraw)
......
...@@ -537,6 +537,9 @@ INT32 I_GetKey(void); ...@@ -537,6 +537,9 @@ INT32 I_GetKey(void);
// Max gamepad/joysticks that can be detected/used. // Max gamepad/joysticks that can be detected/used.
#define MAX_JOYSTICKS 4 #define MAX_JOYSTICKS 4
// Software multithreading
#define MAX_RENDER_THREADS 8
#ifndef M_PIl #ifndef M_PIl
#define M_PIl 3.1415926535897932384626433832795029L #define M_PIl 3.1415926535897932384626433832795029L
#endif #endif
...@@ -608,13 +611,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; ...@@ -608,13 +611,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch;
/// Experimental attempts at preventing MF_PAPERCOLLISION objects from getting stuck in walls. /// Experimental attempts at preventing MF_PAPERCOLLISION objects from getting stuck in walls.
//#define PAPER_COLLISIONCORRECTION //#define PAPER_COLLISIONCORRECTION
/// FINALLY some real clipping that doesn't make walls dissappear AND speeds the game up
/// (that was the original comment from SRB2CB, sadly it is a lie and actually slows game down)
/// on the bright side it fixes some weird issues with translucent walls
/// \note SRB2CB port.
/// SRB2CB itself ported this from PrBoom+
#define NEWCLIP
/// OpenGL shaders /// OpenGL shaders
#define GL_SHADERS #define GL_SHADERS
......
...@@ -40,10 +40,7 @@ ...@@ -40,10 +40,7 @@
#include "../r_things.h" // R_GetShadowZ #include "../r_things.h" // R_GetShadowZ
#include "../p_slopes.h" #include "../p_slopes.h"
#include "hw_md2.h" #include "hw_md2.h"
#ifdef NEWCLIP
#include "hw_clip.h" #include "hw_clip.h"
#endif
#define R_FAKEFLOORS #define R_FAKEFLOORS
#define HWPRECIP #define HWPRECIP
...@@ -71,26 +68,6 @@ void HWR_AddTransparentPolyobjectFloor(levelflat_t *levelflat, polyobj_t *polyse ...@@ -71,26 +68,6 @@ void HWR_AddTransparentPolyobjectFloor(levelflat_t *levelflat, polyobj_t *polyse
boolean drawsky = true; boolean drawsky = true;
// ==========================================================================
// VIEW GLOBALS
// ==========================================================================
// Fineangles in the SCREENWIDTH wide window.
#define FIELDOFVIEW ANGLE_90
#define ABS(x) ((x) < 0 ? -(x) : (x))
static angle_t gl_clipangle;
// The viewangletox[viewangle + FINEANGLES/4] lookup
// maps the visible view angles to screen X coordinates,
// flattening the arc to a flat projection plane.
// There will be many angles mapped to the same X.
static INT32 gl_viewangletox[FINEANGLES/2];
// The xtoviewangleangle[] table maps a screen pixel
// to the lowest viewangle that maps back to x ranges
// from clipangle to -clipangle.
static angle_t gl_xtoviewangle[MAXVIDWIDTH+1];
// ========================================================================== // ==========================================================================
// GLOBALS // GLOBALS
// ========================================================================== // ==========================================================================
...@@ -131,10 +108,8 @@ static sector_t *gl_backsector; ...@@ -131,10 +108,8 @@ static sector_t *gl_backsector;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
FTransform atransform; FTransform atransform;
// duplicates of the main code, set after R_SetupFrame() passed them into sharedstruct,
// copied here for local use static viewcontext_t gl_viewcontext;
static fixed_t dup_viewx, dup_viewy, dup_viewz;
static angle_t dup_viewangle;
static float gl_viewx, gl_viewy, gl_viewz; static float gl_viewx, gl_viewy, gl_viewz;
static float gl_viewsin, gl_viewcos; static float gl_viewsin, gl_viewcos;
...@@ -594,7 +569,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool ...@@ -594,7 +569,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool
for (i = 0; i < subsector->numlines; i++, line++) for (i = 0; i < subsector->numlines; i++, line++)
{ {
if (!line->glseg && line->linedef->special == HORIZONSPECIAL && R_PointOnSegSide(dup_viewx, dup_viewy, line) == 0) if (!line->glseg && line->linedef->special == HORIZONSPECIAL && R_PointOnSegSide(gl_viewcontext.x, gl_viewcontext.y, line) == 0)
{ {
P_ClosestPointOnLine(viewx, viewy, line->linedef, &v); P_ClosestPointOnLine(viewx, viewy, line->linedef, &v);
dist = FIXED_TO_FLOAT(R_PointToDist(v.x, v.y)); dist = FIXED_TO_FLOAT(R_PointToDist(v.x, v.y));
...@@ -803,41 +778,6 @@ static void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIEL ...@@ -803,41 +778,6 @@ static void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIEL
// BSP, CULL, ETC.. // BSP, CULL, ETC..
// ========================================================================== // ==========================================================================
// return the frac from the interception of the clipping line
// (in fact a clipping plane that has a constant, so can clip with simple 2d)
// with the wall segment
//
#ifndef NEWCLIP
static float HWR_ClipViewSegment(INT32 x, polyvertex_t *v1, polyvertex_t *v2)
{
float num, den;
float v1x, v1y, v1dx, v1dy, v2dx, v2dy;
angle_t pclipangle = gl_xtoviewangle[x];
// a segment of a polygon
v1x = v1->x;
v1y = v1->y;
v1dx = (v2->x - v1->x);
v1dy = (v2->y - v1->y);
// the clipping line
pclipangle = pclipangle + dup_viewangle; //back to normal angle (non-relative)
v2dx = FIXED_TO_FLOAT(FINECOSINE(pclipangle>>ANGLETOFINESHIFT));
v2dy = FIXED_TO_FLOAT(FINESINE(pclipangle>>ANGLETOFINESHIFT));
den = v2dy*v1dx - v2dx*v1dy;
if (den == 0)
return -1; // parallel
// calc the frac along the polygon segment,
//num = (v2x - v1x)*v2dy + (v1y - v2y)*v2dx;
//num = -v1x * v2dy + v1y * v2dx;
num = (gl_viewx - v1x)*v2dy + (v1y - gl_viewy)*v2dx;
return num / den;
}
#endif
// //
// HWR_SplitWall // HWR_SplitWall
// //
...@@ -1903,7 +1843,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom ...@@ -1903,7 +1843,7 @@ static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
// //
// e6y: Check whether the player can look beyond this line // e6y: Check whether the player can look beyond this line
// //
#ifdef NEWCLIP
boolean checkforemptylines = true; boolean checkforemptylines = true;
// Don't modify anything here, just check // Don't modify anything here, just check
// Kalaron: Modified for sloped linedefs // Kalaron: Modified for sloped linedefs
...@@ -1986,295 +1926,6 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks ...@@ -1986,295 +1926,6 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks
return false; return false;
} }
#else
//Hurdler: just like in r_bsp.c
#if 1
#define MAXSEGS MAXVIDWIDTH/2+1
#else
//Alam_GBC: Or not (may cause overflow)
#define MAXSEGS 128
#endif
// hw_newend is one past the last valid seg
static cliprange_t * hw_newend;
static cliprange_t gl_solidsegs[MAXSEGS];
// needs fix: walls are incorrectly clipped one column less
static consvar_t cv_glclipwalls = CVAR_INIT ("gr_clipwalls", "Off", 0, CV_OnOff, NULL);
static void printsolidsegs(void)
{
cliprange_t * start;
if (!hw_newend)
return;
for (start = gl_solidsegs;start != hw_newend;start++)
{
CONS_Debug(DBG_RENDER, "%d-%d|",start->first,start->last);
}
CONS_Debug(DBG_RENDER, "\n\n");
}
//
//
//
static void HWR_ClipSolidWallSegment(INT32 first, INT32 last)
{
cliprange_t *next, *start;
float lowfrac, highfrac;
boolean poorhack = false;
// Find the first range that touches the range
// (adjacent pixels are touching).
start = gl_solidsegs;
while (start->last < first-1)
start++;
if (first < start->first)
{
if (last < start->first-1)
{
// Post is entirely visible (above start),
// so insert a new clippost.
HWR_StoreWallRange(first, last);
next = hw_newend;
hw_newend++;
while (next != start)
{
*next = *(next-1);
next--;
}
next->first = first;
next->last = last;
printsolidsegs();
return;
}
// There is a fragment above *start.
if (!cv_glclipwalls.value)
{
if (!poorhack) HWR_StoreWallRange(first, last);
poorhack = true;
}
else
{
highfrac = HWR_ClipViewSegment(start->first+1, (polyvertex_t *)gl_curline->pv1, (polyvertex_t *)gl_curline->pv2);
HWR_StoreWallRange(0, highfrac);
}
// Now adjust the clip size.
start->first = first;
}
// Bottom contained in start?
if (last <= start->last)
{
printsolidsegs();
return;
}
next = start;
while (last >= (next+1)->first-1)
{
// There is a fragment between two posts.
if (!cv_glclipwalls.value)
{
if (!poorhack) HWR_StoreWallRange(first,last);
poorhack = true;
}
else
{
lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gl_curline->pv1, (polyvertex_t *)gl_curline->pv2);
highfrac = HWR_ClipViewSegment((next+1)->first+1, (polyvertex_t *)gl_curline->pv1, (polyvertex_t *)gl_curline->pv2);
HWR_StoreWallRange(lowfrac, highfrac);
}
next++;
if (last <= next->last)
{
// Bottom is contained in next.
// Adjust the clip size.
start->last = next->last;
goto crunch;
}
}
if (first == next->first+1) // 1 line texture
{
if (!cv_glclipwalls.value)
{
if (!poorhack) HWR_StoreWallRange(first,last);
poorhack = true;
}
else
HWR_StoreWallRange(0, 1);
}
else
{
// There is a fragment after *next.
if (!cv_glclipwalls.value)
{
if (!poorhack) HWR_StoreWallRange(first,last);
poorhack = true;
}
else
{
lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gl_curline->pv1, (polyvertex_t *)gl_curline->pv2);
HWR_StoreWallRange(lowfrac, 1);
}
}
// Adjust the clip size.
start->last = last;
// Remove start+1 to next from the clip list,
// because start now covers their area.
crunch:
if (next == start)
{
printsolidsegs();
// Post just extended past the bottom of one post.
return;
}
while (next++ != hw_newend)
{
// Remove a post.
*++start = *next;
}
hw_newend = start;
printsolidsegs();
}
//
// handle LineDefs with upper and lower texture (windows)
//
static void HWR_ClipPassWallSegment(INT32 first, INT32 last)
{
cliprange_t *start;
float lowfrac, highfrac;
//to allow noclipwalls but still solidseg reject of non-visible walls
boolean poorhack = false;
// Find the first range that touches the range
// (adjacent pixels are touching).
start = gl_solidsegs;
while (start->last < first - 1)
start++;
if (first < start->first)
{
if (last < start->first-1)
{
// Post is entirely visible (above start).
HWR_StoreWallRange(0, 1);
return;
}
// There is a fragment above *start.
if (!cv_glclipwalls.value)
{ //20/08/99: Changed by Hurdler (taken from faB's code)
if (!poorhack) HWR_StoreWallRange(0, 1);
poorhack = true;
}
else
{
highfrac = HWR_ClipViewSegment(min(start->first + 1,
start->last), (polyvertex_t *)gl_curline->pv1,
(polyvertex_t *)gl_curline->pv2);
HWR_StoreWallRange(0, highfrac);
}
}
// Bottom contained in start?
if (last <= start->last)
return;
while (last >= (start+1)->first-1)
{
// There is a fragment between two posts.
if (!cv_glclipwalls.value)
{
if (!poorhack) HWR_StoreWallRange(0, 1);
poorhack = true;
}
else
{
lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (polyvertex_t *)gl_curline->pv1, (polyvertex_t *)gl_curline->pv2);
highfrac = HWR_ClipViewSegment(min((start+1)->first+1,(start+1)->last), (polyvertex_t *)gl_curline->pv1, (polyvertex_t *)gl_curline->pv2);
HWR_StoreWallRange(lowfrac, highfrac);
}
start++;
if (last <= start->last)
return;
}
if (first == start->first+1) // 1 line texture
{
if (!cv_glclipwalls.value)
{
if (!poorhack) HWR_StoreWallRange(0, 1);
poorhack = true;
}
else
HWR_StoreWallRange(0, 1);
}
else
{
// There is a fragment after *next.
if (!cv_glclipwalls.value)
{
if (!poorhack) HWR_StoreWallRange(0,1);
poorhack = true;
}
else
{
lowfrac = HWR_ClipViewSegment(max(start->last - 1,
start->first), (polyvertex_t *)gl_curline->pv1,
(polyvertex_t *)gl_curline->pv2);
HWR_StoreWallRange(lowfrac, 1);
}
}
}
// --------------------------------------------------------------------------
// HWR_ClipToSolidSegs check if it is hide by wall (solidsegs)
// --------------------------------------------------------------------------
static boolean HWR_ClipToSolidSegs(INT32 first, INT32 last)
{
cliprange_t * start;
// Find the first range that touches the range
// (adjacent pixels are touching).
start = gl_solidsegs;
while (start->last < first-1)
start++;
if (first < start->first)
return true;
// Bottom contained in start?
if (last <= start->last)
return false;
return true;
}
//
// HWR_ClearClipSegs
//
static void HWR_ClearClipSegs(void)
{
gl_solidsegs[0].first = -0x7fffffff;
gl_solidsegs[0].last = -1;
gl_solidsegs[1].first = vid.width; //viewwidth;
gl_solidsegs[1].last = 0x7fffffff;
hw_newend = gl_solidsegs+2;
}
#endif // NEWCLIP
// -----------------+ // -----------------+
// HWR_AddLine : Clips the given segment and adds any visible pieces to the line list. // HWR_AddLine : Clips the given segment and adds any visible pieces to the line list.
...@@ -2284,11 +1935,6 @@ static void HWR_ClearClipSegs(void) ...@@ -2284,11 +1935,6 @@ static void HWR_ClearClipSegs(void)
static void HWR_AddLine(seg_t * line) static void HWR_AddLine(seg_t * line)
{ {
angle_t angle1, angle2; angle_t angle1, angle2;
#ifndef NEWCLIP
INT32 x1, x2;
angle_t span, tspan;
boolean bothceilingssky = false, bothfloorssky = false;
#endif
// SoM: Backsector needs to be run through R_FakeFlat // SoM: Backsector needs to be run through R_FakeFlat
static sector_t tempsec; static sector_t tempsec;
...@@ -2308,7 +1954,6 @@ static void HWR_AddLine(seg_t * line) ...@@ -2308,7 +1954,6 @@ static void HWR_AddLine(seg_t * line)
angle1 = R_PointToAngle64(v1x, v1y); angle1 = R_PointToAngle64(v1x, v1y);
angle2 = R_PointToAngle64(v2x, v2y); angle2 = R_PointToAngle64(v2x, v2y);
#ifdef NEWCLIP
// PrBoom: Back side, i.e. backface culling - read: endAngle >= startAngle! // PrBoom: Back side, i.e. backface culling - read: endAngle >= startAngle!
if (angle2 - angle1 < ANGLE_180) if (angle2 - angle1 < ANGLE_180)
return; return;
...@@ -2321,90 +1966,9 @@ static void HWR_AddLine(seg_t * line) ...@@ -2321,90 +1966,9 @@ static void HWR_AddLine(seg_t * line)
} }
checkforemptylines = true; checkforemptylines = true;
#else
// Clip to view edges.
span = angle1 - angle2;
// backface culling : span is < ANGLE_180 if ang1 > ang2 : the seg is facing
if (span >= ANGLE_180)
return;
// Global angle needed by segcalc.
//rw_angle1 = angle1;
angle1 -= dup_viewangle;
angle2 -= dup_viewangle;
tspan = angle1 + gl_clipangle;
if (tspan > 2*gl_clipangle)
{
tspan -= 2*gl_clipangle;
// Totally off the left edge?
if (tspan >= span)
return;
angle1 = gl_clipangle;
}
tspan = gl_clipangle - angle2;
if (tspan > 2*gl_clipangle)
{
tspan -= 2*gl_clipangle;
// Totally off the left edge?
if (tspan >= span)
return;
angle2 = (angle_t)-(signed)gl_clipangle;
}
#if 0
{
float fx1,fx2,fy1,fy2;
//BP: test with a better projection than viewangletox[R_PointToAngle(angle)]
// do not enable this at release 4 mul and 2 div
fx1 = ((polyvertex_t *)(line->pv1))->x-gl_viewx;
fy1 = ((polyvertex_t *)(line->pv1))->y-gl_viewy;
fy2 = (fx1 * gl_viewcos + fy1 * gl_viewsin);
if (fy2 < 0)
// the point is back
fx1 = 0;
else
fx1 = gl_windowcenterx + (fx1 * gl_viewsin - fy1 * gl_viewcos) * gl_centerx / fy2;
fx2 = ((polyvertex_t *)(line->pv2))->x-gl_viewx;
fy2 = ((polyvertex_t *)(line->pv2))->y-gl_viewy;
fy1 = (fx2 * gl_viewcos + fy2 * gl_viewsin);
if (fy1 < 0)
// the point is back
fx2 = vid.width;
else
fx2 = gl_windowcenterx + (fx2 * gl_viewsin - fy2 * gl_viewcos) * gl_centerx / fy1;
x1 = fx1+0.5f;
x2 = fx2+0.5f;
}
#else
// The seg is in the view range,
// but not necessarily visible.
angle1 = (angle1+ANGLE_90)>>ANGLETOFINESHIFT;
angle2 = (angle2+ANGLE_90)>>ANGLETOFINESHIFT;
x1 = gl_viewangletox[angle1];
x2 = gl_viewangletox[angle2];
#endif
// Does not cross a pixel?
// if (x1 == x2)
/* {
// BP: HERE IS THE MAIN PROBLEM !
//CONS_Debug(DBG_RENDER, "tineline\n");
return;
}
*/
#endif
gl_backsector = line->backsector; gl_backsector = line->backsector;
#ifdef NEWCLIP
if (!line->backsector) if (!line->backsector)
{ {
gld_clipper_SafeAddClipRange(angle2, angle1); gld_clipper_SafeAddClipRange(angle2, angle1);
...@@ -2413,7 +1977,7 @@ static void HWR_AddLine(seg_t * line) ...@@ -2413,7 +1977,7 @@ static void HWR_AddLine(seg_t * line)
{ {
boolean bothceilingssky = false, bothfloorssky = false; boolean bothceilingssky = false, bothfloorssky = false;
gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true); gl_backsector = R_FakeFlat(&gl_viewcontext, gl_backsector, &tempsec, NULL, NULL, true);
if (gl_backsector->ceilingpic == skyflatnum && gl_frontsector->ceilingpic == skyflatnum) if (gl_backsector->ceilingpic == skyflatnum && gl_frontsector->ceilingpic == skyflatnum)
bothceilingssky = true; bothceilingssky = true;
...@@ -2446,115 +2010,6 @@ static void HWR_AddLine(seg_t * line) ...@@ -2446,115 +2010,6 @@ static void HWR_AddLine(seg_t * line)
} }
HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D
return;
#else
// Single sided line?
if (!gl_backsector)
goto clipsolid;
gl_backsector = R_FakeFlat(gl_backsector, &tempsec, NULL, NULL, true);
if (gl_backsector->ceilingpic == skyflatnum && gl_frontsector->ceilingpic == skyflatnum)
bothceilingssky = true;
if (gl_backsector->floorpic == skyflatnum && gl_frontsector->floorpic == skyflatnum)
bothfloorssky = true;
if (bothceilingssky && bothfloorssky) // everything's sky? let's save us a bit of time then
{
if (!line->polyseg &&
!line->sidedef->midtexture
&& ((!gl_frontsector->ffloors && !gl_backsector->ffloors)
|| Tag_Compare(&gl_frontsector->tags, &gl_backsector->tags)))
return; // line is empty, don't even bother
goto clippass; // treat like wide open window instead
}
if (gl_frontsector->f_slope || gl_frontsector->c_slope || gl_backsector->f_slope || gl_backsector->c_slope)
{
fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends
fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends
#define SLOPEPARAMS(slope, end1, end2, normalheight) \
end1 = P_GetZAt(slope, v1x, v1y, normalheight); \
end2 = P_GetZAt(slope, v2x, v2y, normalheight);
SLOPEPARAMS(gl_frontsector->f_slope, frontf1, frontf2, gl_frontsector-> floorheight)
SLOPEPARAMS(gl_frontsector->c_slope, frontc1, frontc2, gl_frontsector->ceilingheight)
SLOPEPARAMS( gl_backsector->f_slope, backf1, backf2, gl_backsector-> floorheight)
SLOPEPARAMS( gl_backsector->c_slope, backc1, backc2, gl_backsector->ceilingheight)
#undef SLOPEPARAMS
// if both ceilings are skies, consider it always "open"
// same for floors
if (!bothceilingssky && !bothfloorssky)
{
// Closed door.
if ((backc1 <= frontf1 && backc2 <= frontf2)
|| (backf1 >= frontc1 && backf2 >= frontc2))
{
goto clipsolid;
}
// Check for automap fix.
if (backc1 <= backf1 && backc2 <= backf2
&& ((backc1 >= frontc1 && backc2 >= frontc2) || gl_curline->sidedef->toptexture)
&& ((backf1 <= frontf1 && backf2 >= frontf2) || gl_curline->sidedef->bottomtexture))
goto clipsolid;
}
// Window.
if (!bothceilingssky) // ceilings are always the "same" when sky
if (backc1 != frontc1 || backc2 != frontc2)
goto clippass;
if (!bothfloorssky) // floors are always the "same" when sky
if (backf1 != frontf1 || backf2 != frontf2)
goto clippass;
}
else
{
// if both ceilings are skies, consider it always "open"
// same for floors
if (!bothceilingssky && !bothfloorssky)
{
// Closed door.
if (gl_backsector->ceilingheight <= gl_frontsector->floorheight ||
gl_backsector->floorheight >= gl_frontsector->ceilingheight)
goto clipsolid;
// Check for automap fix.
if (gl_backsector->ceilingheight <= gl_backsector->floorheight
&& ((gl_backsector->ceilingheight >= gl_frontsector->ceilingheight) || gl_curline->sidedef->toptexture)
&& ((gl_backsector->floorheight <= gl_backsector->floorheight) || gl_curline->sidedef->bottomtexture))
goto clipsolid;
}
// Window.
if (!bothceilingssky) // ceilings are always the "same" when sky
if (gl_backsector->ceilingheight != gl_frontsector->ceilingheight)
goto clippass;
if (!bothfloorssky) // floors are always the "same" when sky
if (gl_backsector->floorheight != gl_frontsector->floorheight)
goto clippass;
}
// Reject empty lines used for triggers and special events.
// Identical floor and ceiling on both sides,
// identical light levels on both sides,
// and no middle texture.
if (R_IsEmptyLine(gl_curline, gl_frontsector, gl_backsector))
return;
clippass:
if (x1 == x2)
{ x2++;x1 -= 2; }
HWR_ClipPassWallSegment(x1, x2-1);
return;
clipsolid:
if (x1 == x2)
goto clippass;
HWR_ClipSolidWallSegment(x1, x2-1);
#endif
} }
// HWR_CheckBBox // HWR_CheckBBox
...@@ -2569,23 +2024,19 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) ...@@ -2569,23 +2024,19 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord)
INT32 boxpos; INT32 boxpos;
fixed_t px1, py1, px2, py2; fixed_t px1, py1, px2, py2;
angle_t angle1, angle2; angle_t angle1, angle2;
#ifndef NEWCLIP
INT32 sx1, sx2;
angle_t span, tspan;
#endif
// Find the corners of the box // Find the corners of the box
// that define the edges from current viewpoint. // that define the edges from current viewpoint.
if (dup_viewx <= bspcoord[BOXLEFT]) if (gl_viewcontext.x <= bspcoord[BOXLEFT])
boxpos = 0; boxpos = 0;
else if (dup_viewx < bspcoord[BOXRIGHT]) else if (gl_viewcontext.x < bspcoord[BOXRIGHT])
boxpos = 1; boxpos = 1;
else else
boxpos = 2; boxpos = 2;
if (dup_viewy >= bspcoord[BOXTOP]) if (gl_viewcontext.y >= bspcoord[BOXTOP])
boxpos |= 0; boxpos |= 0;
else if (dup_viewy > bspcoord[BOXBOTTOM]) else if (gl_viewcontext.y > bspcoord[BOXBOTTOM])
boxpos |= 1<<2; boxpos |= 1<<2;
else else
boxpos |= 2<<2; boxpos |= 2<<2;
...@@ -2598,59 +2049,9 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) ...@@ -2598,59 +2049,9 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord)
px2 = bspcoord[checkcoord[boxpos][2]]; px2 = bspcoord[checkcoord[boxpos][2]];
py2 = bspcoord[checkcoord[boxpos][3]]; py2 = bspcoord[checkcoord[boxpos][3]];
#ifdef NEWCLIP
angle1 = R_PointToAngle64(px1, py1); angle1 = R_PointToAngle64(px1, py1);
angle2 = R_PointToAngle64(px2, py2); angle2 = R_PointToAngle64(px2, py2);
return gld_clipper_SafeCheckRange(angle2, angle1); return gld_clipper_SafeCheckRange(angle2, angle1);
#else
// check clip list for an open space
angle1 = R_PointToAngle2(dup_viewx>>1, dup_viewy>>1, px1>>1, py1>>1) - dup_viewangle;
angle2 = R_PointToAngle2(dup_viewx>>1, dup_viewy>>1, px2>>1, py2>>1) - dup_viewangle;
span = angle1 - angle2;
// Sitting on a line?
if (span >= ANGLE_180)
return true;
tspan = angle1 + gl_clipangle;
if (tspan > 2*gl_clipangle)
{
tspan -= 2*gl_clipangle;
// Totally off the left edge?
if (tspan >= span)
return false;
angle1 = gl_clipangle;
}
tspan = gl_clipangle - angle2;
if (tspan > 2*gl_clipangle)
{
tspan -= 2*gl_clipangle;
// Totally off the left edge?
if (tspan >= span)
return false;
angle2 = (angle_t)-(signed)gl_clipangle;
}
// Find the first clippost
// that touches the source post
// (adjacent pixels are touching).
angle1 = (angle1+ANGLE_90)>>ANGLETOFINESHIFT;
angle2 = (angle2+ANGLE_90)>>ANGLETOFINESHIFT;
sx1 = gl_viewangletox[angle1];
sx2 = gl_viewangletox[angle2];
// Does not cross a pixel.
if (sx1 == sx2)
return false;
return HWR_ClipToSolidSegs(sx1, sx2 - 1);
#endif
} }
// //
...@@ -3012,23 +2413,10 @@ static void HWR_Subsector(size_t num) ...@@ -3012,23 +2413,10 @@ static void HWR_Subsector(size_t num)
} }
//SoM: 4/7/2000: Test to make Boom water work in Hardware mode. //SoM: 4/7/2000: Test to make Boom water work in Hardware mode.
gl_frontsector = R_FakeFlat(gl_frontsector, &tempsec, &floorlightlevel, gl_frontsector = R_FakeFlat(&gl_viewcontext, gl_frontsector, &tempsec, &floorlightlevel, &ceilinglightlevel, false);
&ceilinglightlevel, false);
//FIXME: Use floorlightlevel and ceilinglightlevel insted of lightlevel.
floorcolormap = ceilingcolormap = gl_frontsector->extra_colormap; floorcolormap = ceilingcolormap = gl_frontsector->extra_colormap;
// ------------------------------------------------------------------------
// sector lighting, DISABLED because it's done in HWR_StoreWallRange
// ------------------------------------------------------------------------
/// \todo store a RGBA instead of just intensity, allow coloured sector lighting
//light = (FUBYTE)(sub->sector->lightlevel & 0xFF) / 255.0f;
//gl_cursectorlight.red = light;
//gl_cursectorlight.green = light;
//gl_cursectorlight.blue = light;
//gl_cursectorlight.alpha = light;
// ----- end special tricks -----
cullFloorHeight = P_GetSectorFloorZAt (gl_frontsector, viewx, viewy); cullFloorHeight = P_GetSectorFloorZAt (gl_frontsector, viewx, viewy);
cullCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, viewx, viewy); cullCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, viewx, viewy);
locFloorHeight = P_GetSectorFloorZAt (gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y); locFloorHeight = P_GetSectorFloorZAt (gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y);
...@@ -3061,7 +2449,7 @@ static void HWR_Subsector(size_t num) ...@@ -3061,7 +2449,7 @@ static void HWR_Subsector(size_t num)
// render floor ? // render floor ?
#ifdef DOPLANES #ifdef DOPLANES
// yeah, easy backface cull! :) // yeah, easy backface cull! :)
if (cullFloorHeight < dup_viewz) if (cullFloorHeight < gl_viewcontext.z)
{ {
if (gl_frontsector->floorpic != skyflatnum) if (gl_frontsector->floorpic != skyflatnum)
{ {
...@@ -3083,7 +2471,7 @@ static void HWR_Subsector(size_t num) ...@@ -3083,7 +2471,7 @@ static void HWR_Subsector(size_t num)
} }
} }
if (cullCeilingHeight > dup_viewz) if (cullCeilingHeight > gl_viewcontext.z)
{ {
if (gl_frontsector->ceilingpic != skyflatnum) if (gl_frontsector->ceilingpic != skyflatnum)
{ {
...@@ -3132,14 +2520,14 @@ static void HWR_Subsector(size_t num) ...@@ -3132,14 +2520,14 @@ static void HWR_Subsector(size_t num)
if (centerHeight <= locCeilingHeight && if (centerHeight <= locCeilingHeight &&
centerHeight >= locFloorHeight && centerHeight >= locFloorHeight &&
((dup_viewz < cullHeight && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES))) || ((gl_viewcontext.z < cullHeight && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES))) ||
(dup_viewz > cullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) (gl_viewcontext.z > cullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES))))
{ {
if (rover->flags & FF_FOG) if (rover->flags & FF_FOG)
{ {
UINT8 alpha; UINT8 alpha;
light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); light = R_GetPlaneLight(gl_frontsector, centerHeight, gl_viewcontext.z < cullHeight ? true : false);
alpha = HWR_FogBlockAlpha(*gl_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap); alpha = HWR_FogBlockAlpha(*gl_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap);
HWR_AddTransparentFloor(0, HWR_AddTransparentFloor(0,
...@@ -3152,7 +2540,7 @@ static void HWR_Subsector(size_t num) ...@@ -3152,7 +2540,7 @@ static void HWR_Subsector(size_t num)
} }
else if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256) // SoM: Flags are more efficient else if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256) // SoM: Flags are more efficient
{ {
light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); light = R_GetPlaneLight(gl_frontsector, centerHeight, gl_viewcontext.z < cullHeight ? true : false);
HWR_AddTransparentFloor(&levelflats[*rover->bottompic], HWR_AddTransparentFloor(&levelflats[*rover->bottompic],
&extrasubsectors[num], &extrasubsectors[num],
...@@ -3165,7 +2553,7 @@ static void HWR_Subsector(size_t num) ...@@ -3165,7 +2553,7 @@ static void HWR_Subsector(size_t num)
else else
{ {
HWR_GetLevelFlat(&levelflats[*rover->bottompic]); HWR_GetLevelFlat(&levelflats[*rover->bottompic]);
light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); light = R_GetPlaneLight(gl_frontsector, centerHeight, gl_viewcontext.z < cullHeight ? true : false);
HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, &levelflats[*rover->bottompic], HWR_RenderPlane(sub, &extrasubsectors[num], false, *rover->bottomheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, &levelflats[*rover->bottompic],
rover->master->frontsector, 255, *gl_frontsector->lightlist[light].extra_colormap); rover->master->frontsector, 255, *gl_frontsector->lightlist[light].extra_colormap);
} }
...@@ -3177,14 +2565,14 @@ static void HWR_Subsector(size_t num) ...@@ -3177,14 +2565,14 @@ static void HWR_Subsector(size_t num)
if (centerHeight >= locFloorHeight && if (centerHeight >= locFloorHeight &&
centerHeight <= locCeilingHeight && centerHeight <= locCeilingHeight &&
((dup_viewz > cullHeight && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES))) || ((gl_viewcontext.z > cullHeight && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES))) ||
(dup_viewz < cullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) (gl_viewcontext.z < cullHeight && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES))))
{ {
if (rover->flags & FF_FOG) if (rover->flags & FF_FOG)
{ {
UINT8 alpha; UINT8 alpha;
light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); light = R_GetPlaneLight(gl_frontsector, centerHeight, gl_viewcontext.z < cullHeight ? true : false);
alpha = HWR_FogBlockAlpha(*gl_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap); alpha = HWR_FogBlockAlpha(*gl_frontsector->lightlist[light].lightlevel, rover->master->frontsector->extra_colormap);
HWR_AddTransparentFloor(0, HWR_AddTransparentFloor(0,
...@@ -3197,7 +2585,7 @@ static void HWR_Subsector(size_t num) ...@@ -3197,7 +2585,7 @@ static void HWR_Subsector(size_t num)
} }
else if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256) else if (rover->flags & FF_TRANSLUCENT && rover->alpha < 256)
{ {
light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); light = R_GetPlaneLight(gl_frontsector, centerHeight, gl_viewcontext.z < cullHeight ? true : false);
HWR_AddTransparentFloor(&levelflats[*rover->toppic], HWR_AddTransparentFloor(&levelflats[*rover->toppic],
&extrasubsectors[num], &extrasubsectors[num],
...@@ -3210,7 +2598,7 @@ static void HWR_Subsector(size_t num) ...@@ -3210,7 +2598,7 @@ static void HWR_Subsector(size_t num)
else else
{ {
HWR_GetLevelFlat(&levelflats[*rover->toppic]); HWR_GetLevelFlat(&levelflats[*rover->toppic]);
light = R_GetPlaneLight(gl_frontsector, centerHeight, dup_viewz < cullHeight ? true : false); light = R_GetPlaneLight(gl_frontsector, centerHeight, gl_viewcontext.z < cullHeight ? true : false);
HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, &levelflats[*rover->toppic], HWR_RenderPlane(sub, &extrasubsectors[num], true, *rover->topheight, (rover->flags & FF_RIPPLE ? PF_Ripple : 0)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, &levelflats[*rover->toppic],
rover->master->frontsector, 255, *gl_frontsector->lightlist[light].extra_colormap); rover->master->frontsector, 255, *gl_frontsector->lightlist[light].extra_colormap);
} }
...@@ -3235,7 +2623,7 @@ static void HWR_Subsector(size_t num) ...@@ -3235,7 +2623,7 @@ static void HWR_Subsector(size_t num)
} }
// for render stats // for render stats
ps_numpolyobjects += numpolys; ps_numpolyobjects[0] += numpolys;
// Sort polyobjects // Sort polyobjects
R_SortPolyObjects(sub); R_SortPolyObjects(sub);
...@@ -3311,39 +2699,12 @@ fixed_t *hwbbox; ...@@ -3311,39 +2699,12 @@ fixed_t *hwbbox;
static void HWR_RenderBSPNode(INT32 bspnum) static void HWR_RenderBSPNode(INT32 bspnum)
{ {
/*//GZDoom code
if(bspnum == -1)
{
HWR_Subsector(subsectors);
return;
}
while(!((size_t)bspnum&(~NF_SUBSECTOR))) // Keep going until found a subsector
{
node_t *bsp = &nodes[bspnum];
// Decide which side the view point is on
INT32 side = R_PointOnSide(dup_viewx, dup_viewy, bsp);
// Recursively divide front space (toward the viewer)
HWR_RenderBSPNode(bsp->children[side]);
// Possibly divide back space (away from viewer)
side ^= 1;
if (!HWR_CheckBBox(bsp->bbox[side]))
return;
bspnum = bsp->children[side];
}
HWR_Subsector(bspnum-1);
*/
node_t *bsp = &nodes[bspnum]; node_t *bsp = &nodes[bspnum];
// Decide which side the view point is on // Decide which side the view point is on
INT32 side; INT32 side;
ps_numbspcalls++; ps_numbspcalls[0]++;
// Found a subsector? // Found a subsector?
if (bspnum & NF_SUBSECTOR) if (bspnum & NF_SUBSECTOR)
...@@ -3362,7 +2723,7 @@ static void HWR_RenderBSPNode(INT32 bspnum) ...@@ -3362,7 +2723,7 @@ static void HWR_RenderBSPNode(INT32 bspnum)
} }
// Decide which side the view point is on. // Decide which side the view point is on.
side = R_PointOnSide(dup_viewx, dup_viewy, bsp); side = R_PointOnSide(gl_viewcontext.x, gl_viewcontext.y, bsp);
// BP: big hack for a test in lighning ref : 1249753487AB // BP: big hack for a test in lighning ref : 1249753487AB
hwbbox = bsp->bbox[side]; hwbbox = bsp->bbox[side];
...@@ -3379,100 +2740,6 @@ static void HWR_RenderBSPNode(INT32 bspnum) ...@@ -3379,100 +2740,6 @@ static void HWR_RenderBSPNode(INT32 bspnum)
} }
} }
/*
//
// Clear 'stack' of subsectors to draw
//
static void HWR_ClearDrawSubsectors(void)
{
gl_drawsubsector_p = gl_drawsubsectors;
}
//
// Draw subsectors pushed on the drawsubsectors 'stack', back to front
//
static void HWR_RenderSubsectors(void)
{
while (gl_drawsubsector_p > gl_drawsubsectors)
{
HWR_RenderBSPNode(
lastsubsec->nextsubsec = bspnum & (~NF_SUBSECTOR);
}
}
*/
// ==========================================================================
// FROM R_MAIN.C
// ==========================================================================
//BP : exactely the same as R_InitTextureMapping
void HWR_InitTextureMapping(void)
{
angle_t i;
INT32 x;
INT32 t;
fixed_t focallength;
fixed_t grcenterx;
fixed_t grcenterxfrac;
INT32 grviewwidth;
#define clipanglefov (FIELDOFVIEW>>ANGLETOFINESHIFT)
grviewwidth = vid.width;
grcenterx = grviewwidth/2;
grcenterxfrac = grcenterx<<FRACBITS;
// Use tangent table to generate viewangletox:
// viewangletox will give the next greatest x
// after the view angle.
//
// Calc focallength
// so FIELDOFVIEW angles covers SCREENWIDTH.
focallength = FixedDiv(grcenterxfrac,
FINETANGENT(FINEANGLES/4+clipanglefov/2));
for (i = 0; i < FINEANGLES/2; i++)
{
if (FINETANGENT(i) > FRACUNIT*2)
t = -1;
else if (FINETANGENT(i) < -FRACUNIT*2)
t = grviewwidth+1;
else
{
t = FixedMul(FINETANGENT(i), focallength);
t = (grcenterxfrac - t+FRACUNIT-1)>>FRACBITS;
if (t < -1)
t = -1;
else if (t > grviewwidth+1)
t = grviewwidth+1;
}
gl_viewangletox[i] = t;
}
// Scan viewangletox[] to generate xtoviewangle[]:
// xtoviewangle will give the smallest view angle
// that maps to x.
for (x = 0; x <= grviewwidth; x++)
{
i = 0;
while (gl_viewangletox[i]>x)
i++;
gl_xtoviewangle[x] = (i<<ANGLETOFINESHIFT) - ANGLE_90;
}
// Take out the fencepost cases from viewangletox.
for (i = 0; i < FINEANGLES/2; i++)
{
if (gl_viewangletox[i] == -1)
gl_viewangletox[i] = 0;
else if (gl_viewangletox[i] == grviewwidth+1)
gl_viewangletox[i] = grviewwidth;
}
gl_clipangle = gl_xtoviewangle[0];
}
// ========================================================================== // ==========================================================================
// gl_things.c // gl_things.c
// ========================================================================== // ==========================================================================
...@@ -4695,7 +3962,7 @@ static int CompareDrawNodePlanes(const void *p1, const void *p2) ...@@ -4695,7 +3962,7 @@ static int CompareDrawNodePlanes(const void *p1, const void *p2)
size_t n2 = *(const size_t*)p2; size_t n2 = *(const size_t*)p2;
if (!sortnode[n1].plane) I_Error("CompareDrawNodePlanes: Uh.. This isn't a plane! (n1)"); if (!sortnode[n1].plane) I_Error("CompareDrawNodePlanes: Uh.. This isn't a plane! (n1)");
if (!sortnode[n2].plane) I_Error("CompareDrawNodePlanes: Uh.. This isn't a plane! (n2)"); if (!sortnode[n2].plane) I_Error("CompareDrawNodePlanes: Uh.. This isn't a plane! (n2)");
return ABS(sortnode[n2].plane->fixedheight - viewz) - ABS(sortnode[n1].plane->fixedheight - viewz); return abs(sortnode[n2].plane->fixedheight - viewz) - abs(sortnode[n1].plane->fixedheight - viewz);
} }
// //
...@@ -4738,7 +4005,7 @@ static void HWR_CreateDrawNodes(void) ...@@ -4738,7 +4005,7 @@ static void HWR_CreateDrawNodes(void)
sortindex[p] = p; sortindex[p] = p;
} }
ps_numdrawnodes = p; ps_numdrawnodes[0] = p;
// p is the number of stuff to sort // p is the number of stuff to sort
...@@ -4935,7 +4202,7 @@ static void HWR_AddSprites(sector_t *sec) ...@@ -4935,7 +4202,7 @@ static void HWR_AddSprites(sector_t *sec)
hoop_limit_dist = (fixed_t)(cv_drawdist_nights.value) << FRACBITS; hoop_limit_dist = (fixed_t)(cv_drawdist_nights.value) << FRACBITS;
for (thing = sec->thinglist; thing; thing = thing->snext) for (thing = sec->thinglist; thing; thing = thing->snext)
{ {
if (R_ThingVisibleWithinDist(thing, limit_dist, hoop_limit_dist)) if (R_ThingVisibleWithinDist(viewx, viewy, thing, r_viewmobj, limit_dist, hoop_limit_dist))
HWR_ProjectSprite(thing); HWR_ProjectSprite(thing);
} }
...@@ -4945,7 +4212,7 @@ static void HWR_AddSprites(sector_t *sec) ...@@ -4945,7 +4212,7 @@ static void HWR_AddSprites(sector_t *sec)
{ {
for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext) for (precipthing = sec->preciplist; precipthing; precipthing = precipthing->snext)
{ {
if (R_PrecipThingVisible(precipthing, limit_dist)) if (R_PrecipThingVisible(viewx, viewy, precipthing, limit_dist))
HWR_ProjectPrecipitationSprite(precipthing); HWR_ProjectPrecipitationSprite(precipthing);
} }
} }
...@@ -5271,7 +4538,7 @@ static void HWR_ProjectSprite(mobj_t *thing) ...@@ -5271,7 +4538,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
if ((thing->flags2 & MF2_LINKDRAW) && thing->tracer) if ((thing->flags2 & MF2_LINKDRAW) && thing->tracer)
{ {
if (! R_ThingVisible(thing->tracer)) if (! R_ThingVisible(thing->tracer, r_viewmobj))
return; return;
// calculate tz for tracer, same way it is calculated for this sprite // calculate tz for tracer, same way it is calculated for this sprite
...@@ -5725,7 +4992,7 @@ static void HWR_DrawSkyBackground(player_t *player) ...@@ -5725,7 +4992,7 @@ static void HWR_DrawSkyBackground(player_t *player)
// software doesn't draw any further than 1024 for skies anyway, but this doesn't overlap properly // software doesn't draw any further than 1024 for skies anyway, but this doesn't overlap properly
// The only time this will probably be an issue is when a sky wider than 1024 is used as a sky AND a regular wall texture // The only time this will probably be an issue is when a sky wider than 1024 is used as a sky AND a regular wall texture
angle = (dup_viewangle + gl_xtoviewangle[0]); angle = (gl_viewcontext.angle + xtoviewangle[0]);
dimensionmultiply = ((float)textures[texturetranslation[skytexture]]->width/256.0f); dimensionmultiply = ((float)textures[texturetranslation[skytexture]]->width/256.0f);
...@@ -5902,10 +5169,12 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) ...@@ -5902,10 +5169,12 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player)
R_SkyboxFrame(player); R_SkyboxFrame(player);
// copy view cam position for local use // copy view cam position for local use
dup_viewx = viewx; gl_viewcontext.x = viewx;
dup_viewy = viewy; gl_viewcontext.y = viewy;
dup_viewz = viewz; gl_viewcontext.z = viewz;
dup_viewangle = viewangle; gl_viewcontext.angle = viewangle;
gl_viewcontext.player = viewplayer;
gl_viewcontext.mobj = r_viewmobj;
// set window position // set window position
gl_centery = gl_basecentery; gl_centery = gl_basecentery;
...@@ -5920,9 +5189,9 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) ...@@ -5920,9 +5189,9 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player)
// check for new console commands. // check for new console commands.
NetUpdate(); NetUpdate();
gl_viewx = FIXED_TO_FLOAT(dup_viewx); gl_viewx = FIXED_TO_FLOAT(gl_viewcontext.x);
gl_viewy = FIXED_TO_FLOAT(dup_viewy); gl_viewy = FIXED_TO_FLOAT(gl_viewcontext.y);
gl_viewz = FIXED_TO_FLOAT(dup_viewz); gl_viewz = FIXED_TO_FLOAT(gl_viewcontext.z);
gl_viewsin = FIXED_TO_FLOAT(viewsin); gl_viewsin = FIXED_TO_FLOAT(viewsin);
gl_viewcos = FIXED_TO_FLOAT(viewcos); gl_viewcos = FIXED_TO_FLOAT(viewcos);
...@@ -5973,8 +5242,7 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) ...@@ -5973,8 +5242,7 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player)
drawcount = 0; drawcount = 0;
#ifdef NEWCLIP // if (rendermode == render_opengl)
if (rendermode == render_opengl)
{ {
angle_t a1 = gld_FrustumAngle(gl_aimingangle); angle_t a1 = gld_FrustumAngle(gl_aimingangle);
gld_clipper_Clear(); gld_clipper_Clear();
...@@ -5983,9 +5251,6 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) ...@@ -5983,9 +5251,6 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player)
gld_FrustrumSetup(); gld_FrustrumSetup();
#endif #endif
} }
#else
HWR_ClearClipSegs();
#endif
//04/01/2000: Hurdler: added for T&L //04/01/2000: Hurdler: added for T&L
// Actually it only works on Walls and Planes // Actually it only works on Walls and Planes
...@@ -6001,35 +5266,6 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player) ...@@ -6001,35 +5266,6 @@ void HWR_RenderSkyboxView(INT32 viewnumber, player_t *player)
HWR_RenderBSPNode((INT32)numnodes-1); HWR_RenderBSPNode((INT32)numnodes-1);
#ifndef NEWCLIP
// Make a viewangle int so we can render things based on mouselook
if (player == &players[consoleplayer])
viewangle = localaiming;
else if (splitscreen && player == &players[secondarydisplayplayer])
viewangle = localaiming2;
// Handle stuff when you are looking farther up or down.
if ((gl_aimingangle || cv_fov.value+player->fovadd > 90*FRACUNIT))
{
dup_viewangle += ANGLE_90;
HWR_ClearClipSegs();
HWR_RenderBSPNode((INT32)numnodes-1); //left
dup_viewangle += ANGLE_90;
if (((INT32)gl_aimingangle > ANGLE_45 || (INT32)gl_aimingangle<-ANGLE_45))
{
HWR_ClearClipSegs();
HWR_RenderBSPNode((INT32)numnodes-1); //back
}
dup_viewangle += ANGLE_90;
HWR_ClearClipSegs();
HWR_RenderBSPNode((INT32)numnodes-1); //right
dup_viewangle += ANGLE_90;
}
#endif
if (cv_glbatching.value) if (cv_glbatching.value)
HWR_RenderBatches(); HWR_RenderBatches();
...@@ -6116,10 +5352,12 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ...@@ -6116,10 +5352,12 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
framecount++; // timedemo framecount++; // timedemo
// copy view cam position for local use // copy view cam position for local use
dup_viewx = viewx; gl_viewcontext.x = viewx;
dup_viewy = viewy; gl_viewcontext.y = viewy;
dup_viewz = viewz; gl_viewcontext.z = viewz;
dup_viewangle = viewangle; gl_viewcontext.angle = viewangle;
gl_viewcontext.player = viewplayer;
gl_viewcontext.mobj = r_viewmobj;
// set window position // set window position
gl_centery = gl_basecentery; gl_centery = gl_basecentery;
...@@ -6134,9 +5372,9 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ...@@ -6134,9 +5372,9 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
// check for new console commands. // check for new console commands.
NetUpdate(); NetUpdate();
gl_viewx = FIXED_TO_FLOAT(dup_viewx); gl_viewx = FIXED_TO_FLOAT(gl_viewcontext.x);
gl_viewy = FIXED_TO_FLOAT(dup_viewy); gl_viewy = FIXED_TO_FLOAT(gl_viewcontext.y);
gl_viewz = FIXED_TO_FLOAT(dup_viewz); gl_viewz = FIXED_TO_FLOAT(gl_viewcontext.z);
gl_viewsin = FIXED_TO_FLOAT(viewsin); gl_viewsin = FIXED_TO_FLOAT(viewsin);
gl_viewcos = FIXED_TO_FLOAT(viewcos); gl_viewcos = FIXED_TO_FLOAT(viewcos);
...@@ -6187,8 +5425,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ...@@ -6187,8 +5425,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
drawcount = 0; drawcount = 0;
#ifdef NEWCLIP // if (rendermode == render_opengl)
if (rendermode == render_opengl)
{ {
angle_t a1 = gld_FrustumAngle(gl_aimingangle); angle_t a1 = gld_FrustumAngle(gl_aimingangle);
gld_clipper_Clear(); gld_clipper_Clear();
...@@ -6197,9 +5434,6 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ...@@ -6197,9 +5434,6 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
gld_FrustrumSetup(); gld_FrustrumSetup();
#endif #endif
} }
#else
HWR_ClearClipSegs();
#endif
//04/01/2000: Hurdler: added for T&L //04/01/2000: Hurdler: added for T&L
// Actually it only works on Walls and Planes // Actually it only works on Walls and Planes
...@@ -6208,9 +5442,9 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ...@@ -6208,9 +5442,9 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
// Reset the shader state. // Reset the shader state.
HWR_SetShaderState(); HWR_SetShaderState();
ps_numbspcalls = 0; ps_numbspcalls[0] = 0;
ps_numpolyobjects = 0; ps_numpolyobjects[0] = 0;
ps_bsptime = I_GetPreciseTime(); ps_bsptime[0] = I_GetPreciseTime();
validcount++; validcount++;
...@@ -6219,36 +5453,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ...@@ -6219,36 +5453,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
HWR_RenderBSPNode((INT32)numnodes-1); HWR_RenderBSPNode((INT32)numnodes-1);
#ifndef NEWCLIP ps_bsptime[0] = I_GetPreciseTime() - ps_bsptime[0];
// Make a viewangle int so we can render things based on mouselook
if (player == &players[consoleplayer])
viewangle = localaiming;
else if (splitscreen && player == &players[secondarydisplayplayer])
viewangle = localaiming2;
// Handle stuff when you are looking farther up or down.
if ((gl_aimingangle || cv_fov.value+player->fovadd > 90*FRACUNIT))
{
dup_viewangle += ANGLE_90;
HWR_ClearClipSegs();
HWR_RenderBSPNode((INT32)numnodes-1); //left
dup_viewangle += ANGLE_90;
if (((INT32)gl_aimingangle > ANGLE_45 || (INT32)gl_aimingangle<-ANGLE_45))
{
HWR_ClearClipSegs();
HWR_RenderBSPNode((INT32)numnodes-1); //back
}
dup_viewangle += ANGLE_90;
HWR_ClearClipSegs();
HWR_RenderBSPNode((INT32)numnodes-1); //right
dup_viewangle += ANGLE_90;
}
#endif
ps_bsptime = I_GetPreciseTime() - ps_bsptime;
if (cv_glbatching.value) if (cv_glbatching.value)
HWR_RenderBatches(); HWR_RenderBatches();
...@@ -6263,7 +5468,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ...@@ -6263,7 +5468,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
#endif #endif
// Draw MD2 and sprites // Draw MD2 and sprites
ps_numsprites = gl_visspritecount; ps_numsprites[0] = gl_visspritecount;
ps_hw_spritesorttime = I_GetPreciseTime(); ps_hw_spritesorttime = I_GetPreciseTime();
HWR_SortVisSprites(); HWR_SortVisSprites();
ps_hw_spritesorttime = I_GetPreciseTime() - ps_hw_spritesorttime; ps_hw_spritesorttime = I_GetPreciseTime() - ps_hw_spritesorttime;
...@@ -6276,7 +5481,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player) ...@@ -6276,7 +5481,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
HWR_DrawCoronas(); HWR_DrawCoronas();
#endif #endif
ps_numdrawnodes = 0; ps_numdrawnodes[0] = 0;
ps_hw_nodesorttime = 0; ps_hw_nodesorttime = 0;
ps_hw_nodedrawtime = 0; ps_hw_nodedrawtime = 0;
if (numplanes || numpolyplanes || numwalls) //Hurdler: render 3D water and transparent walls after everything if (numplanes || numpolyplanes || numwalls) //Hurdler: render 3D water and transparent walls after everything
...@@ -6400,10 +5605,6 @@ void HWR_AddCommands(void) ...@@ -6400,10 +5605,6 @@ void HWR_AddCommands(void)
CV_RegisterVar(&cv_glsolvetjoin); CV_RegisterVar(&cv_glsolvetjoin);
CV_RegisterVar(&cv_glbatching); CV_RegisterVar(&cv_glbatching);
#ifndef NEWCLIP
CV_RegisterVar(&cv_glclipwalls);
#endif
} }
void HWR_AddSessionCommands(void) void HWR_AddSessionCommands(void)
......
...@@ -35,7 +35,6 @@ void HWR_ClearSkyDome(void); ...@@ -35,7 +35,6 @@ void HWR_ClearSkyDome(void);
void HWR_BuildSkyDome(void); void HWR_BuildSkyDome(void);
void HWR_DrawViewBorder(INT32 clearlines); void HWR_DrawViewBorder(INT32 clearlines);
void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum); void HWR_DrawFlatFill(INT32 x, INT32 y, INT32 w, INT32 h, lumpnum_t flatlumpnum);
void HWR_InitTextureMapping(void);
void HWR_SetViewSize(void); void HWR_SetViewSize(void);
void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option); void HWR_DrawPatch(patch_t *gpatch, INT32 x, INT32 y, INT32 option);
void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap); void HWR_DrawStretchyFixedPatch(patch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, fixed_t vscale, INT32 option, const UINT8 *colormap);
......
...@@ -15,25 +15,39 @@ ...@@ -15,25 +15,39 @@
#define I_THREADS_H #define I_THREADS_H
typedef void (*I_thread_fn)(void *userdata); typedef void (*I_thread_fn)(void *userdata);
typedef void * I_thread_handle;
#ifdef HAVE_SDL
#include <SDL.h>
#define ATOMIC_TYPE SDL_atomic_t
#else
#define ATOMIC_TYPE UINT32
#endif
typedef ATOMIC_TYPE I_Atomicval_t;
typedef I_Atomicval_t * I_Atomicptr_t;
typedef void * I_mutex; typedef void * I_mutex;
typedef void * I_cond; typedef void * I_cond;
void I_start_threads (void); void I_start_threads (void);
void I_stop_threads (void); void I_stop_threads (void);
void I_spawn_thread (const char *name, I_thread_fn, void *userdata); I_thread_handle I_spawn_thread (const char *name, I_thread_fn, void *userdata);
/* check in your thread whether to return early */ /* check in your thread whether to return early */
int I_thread_is_stopped (void); int I_thread_is_stopped (void);
void I_lock_mutex (I_mutex *);
void I_unlock_mutex (I_mutex);
void I_lock_mutex (I_mutex *); void I_hold_cond (I_cond *, I_mutex);
void I_unlock_mutex (I_mutex);
void I_hold_cond (I_cond *, I_mutex); void I_wake_one_cond (I_cond *);
void I_wake_all_cond (I_cond *);
void I_wake_one_cond (I_cond *); INT32 I_atomic_load (I_Atomicptr_t atomic);
void I_wake_all_cond (I_cond *); INT32 I_atomic_exchange (I_Atomicptr_t atomic, INT32 val);
#endif/*I_THREADS_H*/ #endif/*I_THREADS_H*/
#endif/*HAVE_THREADS*/ #endif/*HAVE_THREADS*/
...@@ -100,7 +100,30 @@ enum { ...@@ -100,7 +100,30 @@ enum {
PERF_COUNT, PERF_COUNT,
}; };
static void M_DrawPerfString(perfstatcol_t *col, int type) static void M_DrawPerfString(const char *string, INT32 lores_x, INT32 hires_x, INT32 flags)
{
const boolean hires = M_HighResolution();
INT32 draw_flags = V_MONOSPACE | flags;
if (hires)
draw_flags |= V_ALLOWLOWERCASE;
if (hires)
{
V_DrawFillConsoleMap(hires_x, draw_row, V_SmallStringWidth(string, draw_flags), 5, 0);
V_DrawSmallString(hires_x, draw_row, draw_flags, string);
draw_row += 5;
}
else
{
V_DrawFillConsoleMap(lores_x, draw_row, V_ThinStringWidth(string, draw_flags), 8, 0);
V_DrawThinString(lores_x, draw_row, draw_flags, string);
draw_row += 8;
}
}
static void M_DrawPerfMeasurement(perfstatcol_t *col, int type)
{ {
const boolean hires = M_HighResolution(); const boolean hires = M_HighResolution();
...@@ -122,15 +145,19 @@ static void M_DrawPerfString(perfstatcol_t *col, int type) ...@@ -122,15 +145,19 @@ static void M_DrawPerfString(perfstatcol_t *col, int type)
if (hires) if (hires)
{ {
V_DrawSmallString(col->hires_x, draw_row, draw_flags, const char *string = va("%s %d", row->hires_label, value);
va("%s %d", row->hires_label, value));
V_DrawFillConsoleMap(col->hires_x, draw_row, V_SmallStringWidth(string, draw_flags), 5, 0);
V_DrawSmallString(col->hires_x, draw_row, draw_flags, string);
draw_row += 5; draw_row += 5;
} }
else else
{ {
V_DrawThinString(col->lores_x, draw_row, draw_flags, const char *string = va("%s %d", row->lores_label, value);
va("%s %d", row->lores_label, value));
V_DrawFillConsoleMap(col->lores_x, draw_row, V_SmallStringWidth(string, draw_flags), 8, 0);
V_DrawThinString(col->lores_x, draw_row, draw_flags, string);
draw_row += 8; draw_row += 8;
} }
...@@ -139,12 +166,12 @@ static void M_DrawPerfString(perfstatcol_t *col, int type) ...@@ -139,12 +166,12 @@ static void M_DrawPerfString(perfstatcol_t *col, int type)
static void M_DrawPerfTiming(perfstatcol_t *col) static void M_DrawPerfTiming(perfstatcol_t *col)
{ {
M_DrawPerfString(col, PERF_TIME); M_DrawPerfMeasurement(col, PERF_TIME);
} }
static void M_DrawPerfCount(perfstatcol_t *col) static void M_DrawPerfCount(perfstatcol_t *col)
{ {
M_DrawPerfString(col, PERF_COUNT); M_DrawPerfMeasurement(col, PERF_COUNT);
} }
static void M_DrawRenderStats(void) static void M_DrawRenderStats(void)
...@@ -161,7 +188,7 @@ static void M_DrawRenderStats(void) ...@@ -161,7 +188,7 @@ static void M_DrawRenderStats(void)
}; };
perfstatrow_t rendercalltime_row[] = { perfstatrow_t rendercalltime_row[] = {
{"drwtime", "3d rendering: ", &ps_rendercalltime}, {"drwtime", "3D rendering: ", &ps_rendercalltime},
{0} {0}
}; };
...@@ -176,16 +203,6 @@ static void M_DrawRenderStats(void) ...@@ -176,16 +203,6 @@ static void M_DrawRenderStats(void)
{0} {0}
}; };
perfstatrow_t softwaretime_row[] = {
{"bsptime", "RenderBSPNode: ", &ps_bsptime},
{"sprclip", "R_ClipSprites: ", &ps_sw_spritecliptime},
{"portals", "Portals+Skybox:", &ps_sw_portaltime},
{"planes ", "R_DrawPlanes: ", &ps_sw_planetime},
{"masked ", "R_DrawMasked: ", &ps_sw_maskedtime},
{"other ", "Other: ", &extrarendertime},
{0}
};
perfstatrow_t uiswaptime_row[] = { perfstatrow_t uiswaptime_row[] = {
{"ui ", "UI render: ", &ps_uitime}, {"ui ", "UI render: ", &ps_uitime},
{"finupdt", "I_FinishUpdate:", &ps_swaptime}, {"finupdt", "I_FinishUpdate:", &ps_swaptime},
...@@ -197,14 +214,6 @@ static void M_DrawRenderStats(void) ...@@ -197,14 +214,6 @@ static void M_DrawRenderStats(void)
{0} {0}
}; };
perfstatrow_t rendercalls_row[] = {
{"bspcall", "BSP calls: ", &ps_numbspcalls},
{"sprites", "Sprites: ", &ps_numsprites},
{"drwnode", "Drawnodes: ", &ps_numdrawnodes},
{"plyobjs", "Polyobjects: ", &ps_numpolyobjects},
{0}
};
perfstatrow_t batchtime_row[] = { perfstatrow_t batchtime_row[] = {
{"batsort", "Batch sort: ", &ps_hw_batchsorttime}, {"batsort", "Batch sort: ", &ps_hw_batchsorttime},
{"batdraw", "Batch render:", &ps_hw_batchdrawtime}, {"batdraw", "Batch render:", &ps_hw_batchdrawtime},
...@@ -230,13 +239,10 @@ static void M_DrawRenderStats(void) ...@@ -230,13 +239,10 @@ static void M_DrawRenderStats(void)
perfstatcol_t rendercalltime_col = {20, 20, V_YELLOWMAP, rendercalltime_row}; perfstatcol_t rendercalltime_col = {20, 20, V_YELLOWMAP, rendercalltime_row};
perfstatcol_t opengltime_col = {24, 24, V_YELLOWMAP, opengltime_row}; perfstatcol_t opengltime_col = {24, 24, V_YELLOWMAP, opengltime_row};
perfstatcol_t softwaretime_col = {24, 24, V_YELLOWMAP, softwaretime_row};
perfstatcol_t uiswaptime_col = {20, 20, V_YELLOWMAP, uiswaptime_row}; perfstatcol_t uiswaptime_col = {20, 20, V_YELLOWMAP, uiswaptime_row};
perfstatcol_t tictime_col = {20, 20, V_GRAYMAP, tictime_row}; perfstatcol_t tictime_col = {20, 20, V_GRAYMAP, tictime_row};
perfstatcol_t rendercalls_col = {90, 115, V_BLUEMAP, rendercalls_row};
perfstatcol_t batchtime_col = {90, 115, V_REDMAP, batchtime_row}; perfstatcol_t batchtime_col = {90, 115, V_REDMAP, batchtime_row};
perfstatcol_t batchcount_col = {155, 200, V_PURPLEMAP, batchcount_row}; perfstatcol_t batchcount_col = {155, 200, V_PURPLEMAP, batchcount_row};
...@@ -256,12 +262,13 @@ static void M_DrawRenderStats(void) ...@@ -256,12 +262,13 @@ static void M_DrawRenderStats(void)
M_DrawPerfTiming(&rendercalltime_col); M_DrawPerfTiming(&rendercalltime_col);
// Remember to update this calculation when adding more 3d rendering stats! // Remember to update this calculation when adding more 3d rendering stats!
extrarendertime = ps_rendercalltime - ps_bsptime; extrarendertime = ps_rendercalltime;
#ifdef HWRENDER #ifdef HWRENDER
if (rendermode == render_opengl) if (rendermode == render_opengl)
{ {
extrarendertime -= extrarendertime =
ps_bsptime[0] +
ps_hw_skyboxtime + ps_hw_skyboxtime +
ps_hw_nodesorttime + ps_hw_nodesorttime +
ps_hw_nodedrawtime + ps_hw_nodedrawtime +
...@@ -280,13 +287,32 @@ static void M_DrawRenderStats(void) ...@@ -280,13 +287,32 @@ static void M_DrawRenderStats(void)
else else
#endif #endif
{ {
extrarendertime -= INT32 i = 0;
ps_sw_spritecliptime +
ps_sw_portaltime + perfstatrow_t other_row[] = {
ps_sw_planetime + {"postprc", "Postprocessing:", &ps_postprocesstime},
ps_sw_maskedtime; {0}
};
perfstatcol_t other_col = {24, 24, V_YELLOWMAP, other_row};
for (i = 0; i < numusablerendercontexts; i++) {
perfstatrow_t softwaretime_row[] = {
{"bsptime", "RenderBSPNode: ", &ps_bsptime[i]},
{"sprclip", "R_ClipSprites: ", &ps_sw_spritecliptime[i]},
{"portals", "Portals+Skybox:", &ps_sw_portaltime[i]},
{"planes ", "R_DrawPlanes: ", &ps_sw_planetime[i]},
{"masked ", "R_DrawMasked: ", &ps_sw_maskedtime[i]},
{0}
};
perfstatcol_t softwaretime_col = {28, 28, V_YELLOWMAP, softwaretime_row};
M_DrawPerfString(va("Thread %d:", i+1), 24, 24, V_REDMAP);
M_DrawPerfTiming(&softwaretime_col);
}
M_DrawPerfTiming(&softwaretime_col); M_DrawPerfTiming(&other_col);
} }
} }
...@@ -297,8 +323,41 @@ static void M_DrawRenderStats(void) ...@@ -297,8 +323,41 @@ static void M_DrawRenderStats(void)
if (rendering) if (rendering)
{ {
draw_row = 10; draw_row = 10;
M_DrawPerfCount(&rendercalls_col);
#ifdef HWRENDER
if (rendermode == render_opengl) {
perfstatrow_t rendercalls_row[] = {
{"bspcall", "BSP calls: ", &ps_numbspcalls},
{"sprites", "Sprites: ", &ps_numsprites},
{"drwnode", "Drawnodes: ", &ps_numdrawnodes},
{"plyobjs", "Polyobjects: ", &ps_numpolyobjects},
{0}
};
perfstatcol_t rendercalls_col = {90, 115, V_BLUEMAP, rendercalls_row};
M_DrawPerfCount(&rendercalls_col);
} else
#endif
{
INT32 i;
for (i = 0; i < numusablerendercontexts; i++) {
perfstatrow_t rendercalls_row[] = {
{"bspcall", "BSP calls: ", &ps_numbspcalls[i]},
{"sprites", "Sprites: ", &ps_numsprites[i]},
{"drwnode", "Drawnodes: ", &ps_numdrawnodes[i]},
{"plyobjs", "Polyobjects: ", &ps_numpolyobjects[i]},
{0}
};
perfstatcol_t rendercalls_col = {94, 120, V_BLUEMAP, rendercalls_row};
M_DrawPerfString(va("Thread %d:", i+1), 90, 115, V_REDMAP);
M_DrawPerfCount(&rendercalls_col);
}
}
#ifdef HWRENDER #ifdef HWRENDER
if (rendermode == render_opengl && cv_glbatching.value) if (rendermode == render_opengl && cv_glbatching.value)
......
...@@ -23,50 +23,37 @@ ...@@ -23,50 +23,37 @@
#include "z_zone.h" // Check R_Prep3DFloors #include "z_zone.h" // Check R_Prep3DFloors
#include "taglist.h" #include "taglist.h"
seg_t *curline; #ifdef HAVE_THREADS
side_t *sidedef; static I_mutex R_BSP_mutex;
line_t *linedef; # define Lock_state() I_lock_mutex(&R_BSP_mutex)
sector_t *frontsector; # define Unlock_state() I_unlock_mutex(R_BSP_mutex)
sector_t *backsector; #else
# define Lock_state()
// very ugly realloc() of drawsegs at run-time, I upped it to 512 # define Unlock_state()
// instead of 256.. and someone managed to send me a level with #endif
// 896 drawsegs! So too bad here's a limit removal a-la-Boom
drawseg_t *curdrawsegs = NULL; /**< This is used to handle multiple lists for masked drawsegs. */
drawseg_t *drawsegs = NULL;
drawseg_t *ds_p = NULL;
// indicates doors closed wrt automap bugfix:
INT32 doorclosed;
// //
// R_ClearDrawSegs // R_ClearDrawSegs
// //
void R_ClearDrawSegs(void) void R_ClearDrawSegs(bspcontext_t *context)
{ {
ds_p = drawsegs; context->ds_p = context->drawsegs;
} }
// Fix from boom.
#define MAXSEGS (MAXVIDWIDTH/2+1)
// newend is one past the last valid seg
static cliprange_t *newend;
static cliprange_t solidsegs[MAXSEGS];
// //
// R_ClipSolidWallSegment // R_ClipSolidWallSegment
// Does handle solid walls, // Does handle solid walls,
// e.g. single sided LineDefs (middle texture) // e.g. single sided LineDefs (middle texture)
// that entirely block the view. // that entirely block the view.
// //
static void R_ClipSolidWallSegment(INT32 first, INT32 last) static void R_ClipSolidWallSegment(rendercontext_t *context, wallcontext_t *wallcontext, INT32 first, INT32 last)
{ {
bspcontext_t *bspcontext = &context->bspcontext;
cliprange_t *next; cliprange_t *next;
cliprange_t *start; cliprange_t *start;
// Find the first range that touches the range (adjacent pixels are touching). // Find the first range that touches the range (adjacent pixels are touching).
start = solidsegs; start = bspcontext->solidsegs;
while (start->last < first - 1) while (start->last < first - 1)
start++; start++;
...@@ -75,11 +62,11 @@ static void R_ClipSolidWallSegment(INT32 first, INT32 last) ...@@ -75,11 +62,11 @@ static void R_ClipSolidWallSegment(INT32 first, INT32 last)
if (last < start->first - 1) if (last < start->first - 1)
{ {
// Post is entirely visible (above start), so insert a new clippost. // Post is entirely visible (above start), so insert a new clippost.
R_StoreWallRange(first, last); R_StoreWallRange(context, wallcontext, first, last);
next = newend; next = bspcontext->newend;
newend++; bspcontext->newend++;
// NO MORE CRASHING! // NO MORE CRASHING!
if (newend - solidsegs > MAXSEGS) if (bspcontext->newend - bspcontext->solidsegs > MAXSEGS)
I_Error("R_ClipSolidWallSegment: Solid Segs overflow!\n"); I_Error("R_ClipSolidWallSegment: Solid Segs overflow!\n");
while (next != start) while (next != start)
...@@ -93,7 +80,7 @@ static void R_ClipSolidWallSegment(INT32 first, INT32 last) ...@@ -93,7 +80,7 @@ static void R_ClipSolidWallSegment(INT32 first, INT32 last)
} }
// There is a fragment above *start. // There is a fragment above *start.
R_StoreWallRange(first, start->first - 1); R_StoreWallRange(context, wallcontext, first, start->first - 1);
// Now adjust the clip size. // Now adjust the clip size.
start->first = first; start->first = first;
} }
...@@ -106,7 +93,7 @@ static void R_ClipSolidWallSegment(INT32 first, INT32 last) ...@@ -106,7 +93,7 @@ static void R_ClipSolidWallSegment(INT32 first, INT32 last)
while (last >= (next+1)->first - 1) while (last >= (next+1)->first - 1)
{ {
// There is a fragment between two posts. // There is a fragment between two posts.
R_StoreWallRange(next->last + 1, (next+1)->first - 1); R_StoreWallRange(context, wallcontext, next->last + 1, (next+1)->first - 1);
next++; next++;
if (last <= next->last) if (last <= next->last)
...@@ -119,7 +106,7 @@ static void R_ClipSolidWallSegment(INT32 first, INT32 last) ...@@ -119,7 +106,7 @@ static void R_ClipSolidWallSegment(INT32 first, INT32 last)
} }
// There is a fragment after *next. // There is a fragment after *next.
R_StoreWallRange(next->last + 1, last); R_StoreWallRange(context, wallcontext, next->last + 1, last);
// Adjust the clip size. // Adjust the clip size.
start->last = last; start->last = last;
...@@ -128,13 +115,13 @@ crunch: ...@@ -128,13 +115,13 @@ crunch:
if (next == start) if (next == start)
return; // Post just extended past the bottom of one post. return; // Post just extended past the bottom of one post.
while (next++ != newend) while (next++ != bspcontext->newend)
*++start = *next; // Remove a post. *++start = *next; // Remove a post.
newend = start + 1; bspcontext->newend = start + 1;
// NO MORE CRASHING! // NO MORE CRASHING!
if (newend - solidsegs > MAXSEGS) if (bspcontext->newend - bspcontext->solidsegs > MAXSEGS)
I_Error("R_ClipSolidWallSegment: Solid Segs overflow!\n"); I_Error("R_ClipSolidWallSegment: Solid Segs overflow!\n");
} }
...@@ -143,13 +130,13 @@ crunch: ...@@ -143,13 +130,13 @@ crunch:
// Clips the given range of columns, but does not include it in the clip list. // Clips the given range of columns, but does not include it in the clip list.
// Does handle windows, e.g. LineDefs with upper and lower texture. // Does handle windows, e.g. LineDefs with upper and lower texture.
// //
static inline void R_ClipPassWallSegment(INT32 first, INT32 last) static inline void R_ClipPassWallSegment(rendercontext_t *context, wallcontext_t *wallcontext, INT32 first, INT32 last)
{ {
cliprange_t *start; cliprange_t *start;
// Find the first range that touches the range // Find the first range that touches the range
// (adjacent pixels are touching). // (adjacent pixels are touching).
start = solidsegs; start = context->bspcontext.solidsegs;
while (start->last < first - 1) while (start->last < first - 1)
start++; start++;
...@@ -158,12 +145,12 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last) ...@@ -158,12 +145,12 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last)
if (last < start->first - 1) if (last < start->first - 1)
{ {
// Post is entirely visible (above start). // Post is entirely visible (above start).
R_StoreWallRange(first, last); R_StoreWallRange(context, wallcontext, first, last);
return; return;
} }
// There is a fragment above *start. // There is a fragment above *start.
R_StoreWallRange(first, start->first - 1); R_StoreWallRange(context, wallcontext, first, start->first - 1);
} }
// Bottom contained in start? // Bottom contained in start?
...@@ -173,7 +160,7 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last) ...@@ -173,7 +160,7 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last)
while (last >= (start+1)->first - 1) while (last >= (start+1)->first - 1)
{ {
// There is a fragment between two posts. // There is a fragment between two posts.
R_StoreWallRange(start->last + 1, (start+1)->first - 1); R_StoreWallRange(context, wallcontext, start->last + 1, (start+1)->first - 1);
start++; start++;
if (last <= start->last) if (last <= start->last)
...@@ -181,27 +168,19 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last) ...@@ -181,27 +168,19 @@ static inline void R_ClipPassWallSegment(INT32 first, INT32 last)
} }
// There is a fragment after *next. // There is a fragment after *next.
R_StoreWallRange(start->last + 1, last); R_StoreWallRange(context, wallcontext, start->last + 1, last);
} }
// //
// R_ClearClipSegs // R_ClearClipSegs
// //
void R_ClearClipSegs(void) void R_ClearClipSegs(bspcontext_t *context, INT32 start, INT32 end)
{
solidsegs[0].first = -0x7fffffff;
solidsegs[0].last = -1;
solidsegs[1].first = viewwidth;
solidsegs[1].last = 0x7fffffff;
newend = solidsegs + 2;
}
void R_PortalClearClipSegs(INT32 start, INT32 end)
{ {
solidsegs[0].first = -0x7fffffff; context->solidsegs[0].first = -0x7fffffff;
solidsegs[0].last = start-1; context->solidsegs[0].last = start-1;
solidsegs[1].first = end; context->solidsegs[1].first = end;
solidsegs[1].last = 0x7fffffff; context->solidsegs[1].last = 0x7fffffff;
newend = solidsegs + 2; context->newend = context->solidsegs + 2;
} }
...@@ -212,17 +191,17 @@ void R_PortalClearClipSegs(INT32 start, INT32 end) ...@@ -212,17 +191,17 @@ void R_PortalClearClipSegs(INT32 start, INT32 end)
// //
// It assumes that Doom has already ruled out a door being closed because // It assumes that Doom has already ruled out a door being closed because
// of front-back closure (e.g. front floor is taller than back ceiling). // of front-back closure (e.g. front floor is taller than back ceiling).
static INT32 R_DoorClosed(void) static INT32 R_DoorClosed(bspcontext_t *bspcontext)
{ {
return return
// if door is closed because back is shut: // if door is closed because back is shut:
backsector->ceilingheight <= backsector->floorheight bspcontext->backsector->ceilingheight <= bspcontext->backsector->floorheight
// preserve a kind of transparent door/lift special effect: // preserve a kind of transparent door/lift special effect:
&& (backsector->ceilingheight >= frontsector->ceilingheight || curline->sidedef->toptexture) && (bspcontext->backsector->ceilingheight >= bspcontext->frontsector->ceilingheight || bspcontext->curline->sidedef->toptexture)
&& (backsector->floorheight <= frontsector->floorheight || curline->sidedef->bottomtexture); && (bspcontext->backsector->floorheight <= bspcontext->frontsector->floorheight || bspcontext->curline->sidedef->bottomtexture);
} }
// //
...@@ -233,8 +212,8 @@ static INT32 R_DoorClosed(void) ...@@ -233,8 +212,8 @@ static INT32 R_DoorClosed(void)
// //
// Similar for ceiling, only reflected. // Similar for ceiling, only reflected.
// //
sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, sector_t *R_FakeFlat(viewcontext_t *viewcontext, sector_t *sec, sector_t *tempsec,
INT32 *ceilinglightlevel, boolean back) INT32 *floorlightlevel, INT32 *ceilinglightlevel, boolean back)
{ {
if (floorlightlevel) if (floorlightlevel)
*floorlightlevel = sec->floorlightsec == -1 ? *floorlightlevel = sec->floorlightsec == -1 ?
...@@ -250,19 +229,19 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, ...@@ -250,19 +229,19 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
if (!sec->extra_colormap && sec->heightsec != -1) if (!sec->extra_colormap && sec->heightsec != -1)
{ {
const sector_t *s = &sectors[sec->heightsec]; const sector_t *s = &sectors[sec->heightsec];
mobj_t *viewmobj = viewplayer->mo; mobj_t *viewmobj = viewcontext->player->mo;
INT32 heightsec; INT32 heightsec;
boolean underwater; boolean underwater;
if (splitscreen && viewplayer == &players[secondarydisplayplayer] && camera2.chase) if (splitscreen && viewcontext->player == &players[secondarydisplayplayer] && camera2.chase)
heightsec = R_PointInSubsector(camera2.x, camera2.y)->sector->heightsec; heightsec = R_PointInSubsector(camera2.x, camera2.y)->sector->heightsec;
else if (camera.chase && viewplayer == &players[displayplayer]) else if (camera.chase && viewcontext->player == &players[displayplayer])
heightsec = R_PointInSubsector(camera.x, camera.y)->sector->heightsec; heightsec = R_PointInSubsector(camera.x, camera.y)->sector->heightsec;
else if (viewmobj) else if (viewmobj)
heightsec = R_PointInSubsector(viewmobj->x, viewmobj->y)->sector->heightsec; heightsec = R_PointInSubsector(viewmobj->x, viewmobj->y)->sector->heightsec;
else else
return sec; return sec;
underwater = heightsec != -1 && viewz <= sectors[heightsec].floorheight; underwater = heightsec != -1 && viewcontext->z <= sectors[heightsec].floorheight;
// Replace sector being drawn, with a copy to be hacked // Replace sector being drawn, with a copy to be hacked
*tempsec = *sec; *tempsec = *sec;
...@@ -272,7 +251,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, ...@@ -272,7 +251,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
tempsec->ceilingheight = s->ceilingheight; tempsec->ceilingheight = s->ceilingheight;
if ((underwater && (tempsec-> floorheight = sec->floorheight, if ((underwater && (tempsec-> floorheight = sec->floorheight,
tempsec->ceilingheight = s->floorheight - 1, !back)) || viewz <= s->floorheight) tempsec->ceilingheight = s->floorheight - 1, !back)) || viewcontext->z <= s->floorheight)
{ // head-below-floor hack { // head-below-floor hack
tempsec->floorpic = s->floorpic; tempsec->floorpic = s->floorpic;
tempsec->floor_xoffs = s->floor_xoffs; tempsec->floor_xoffs = s->floor_xoffs;
...@@ -308,7 +287,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, ...@@ -308,7 +287,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel,
*ceilinglightlevel = s->ceilinglightsec == -1 ? s->lightlevel *ceilinglightlevel = s->ceilinglightsec == -1 ? s->lightlevel
: sectors[s->ceilinglightsec].lightlevel; : sectors[s->ceilinglightsec].lightlevel;
} }
else if (heightsec != -1 && viewz >= sectors[heightsec].ceilingheight else if (heightsec != -1 && viewcontext->z >= sectors[heightsec].ceilingheight
&& sec->ceilingheight > s->ceilingheight) && sec->ceilingheight > s->ceilingheight)
{ // Above-ceiling hack { // Above-ceiling hack
tempsec->ceilingheight = s->ceilingheight; tempsec->ceilingheight = s->ceilingheight;
...@@ -382,22 +361,25 @@ boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back) ...@@ -382,22 +361,25 @@ boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back)
// R_AddLine // R_AddLine
// Clips the given segment and adds any visible pieces to the line list. // Clips the given segment and adds any visible pieces to the line list.
// //
static void R_AddLine(seg_t *line) static void R_AddLine(rendercontext_t *rendercontext, seg_t *line)
{ {
INT32 x1, x2; INT32 x1, x2;
angle_t angle1, angle2, span, tspan; angle_t angle1, angle2, span, tspan;
static sector_t tempsec;
boolean bothceilingssky = false, bothfloorssky = false; boolean bothceilingssky = false, bothfloorssky = false;
portalline = false; bspcontext_t *bspcontext = &rendercontext->bspcontext;
viewcontext_t *viewcontext = &rendercontext->viewcontext;
wallcontext_t wallcontext;
bspcontext->portalline = false;
if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES))
return; return;
// big room fix // big room fix
angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); angle1 = R_PointToAngleEx(viewcontext->x, viewcontext->y, line->v1->x, line->v1->y);
angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); angle2 = R_PointToAngleEx(viewcontext->x, viewcontext->y, line->v2->x, line->v2->y);
curline = line; bspcontext->curline = line;
// Clip to view edges. // Clip to view edges.
span = angle1 - angle2; span = angle1 - angle2;
...@@ -407,9 +389,9 @@ static void R_AddLine(seg_t *line) ...@@ -407,9 +389,9 @@ static void R_AddLine(seg_t *line)
return; return;
// Global angle needed by segcalc. // Global angle needed by segcalc.
rw_angle1 = angle1; wallcontext.angle1 = angle1;
angle1 -= viewangle; angle1 -= viewcontext->angle;
angle2 -= viewangle; angle2 -= viewcontext->angle;
tspan = angle1 + clipangle; tspan = angle1 + clipangle;
if (tspan > doubleclipangle) if (tspan > doubleclipangle)
...@@ -440,18 +422,21 @@ static void R_AddLine(seg_t *line) ...@@ -440,18 +422,21 @@ static void R_AddLine(seg_t *line)
x1 = viewangletox[angle1]; x1 = viewangletox[angle1];
x2 = viewangletox[angle2]; x2 = viewangletox[angle2];
x1 = max(rendercontext->begincolumn, x1);
x2 = min(rendercontext->endcolumn, x2);
// Does not cross a pixel? // Does not cross a pixel?
if (x1 >= x2) // killough 1/31/98 -- change == to >= for robustness if (x1 >= x2) // killough 1/31/98 -- change == to >= for robustness
return; return;
backsector = line->backsector; bspcontext->backsector = line->backsector;
// Portal line // Portal line
if (line->linedef->special == 40 && line->side == 0) if (line->linedef->special == 40 && line->side == 0)
{ {
// Render portal if recursiveness limit hasn't been reached. // Render portal if recursiveness limit hasn't been reached.
// Otherwise, render the wall normally. // Otherwise, render the wall normally.
if (portalrender < cv_maxportals.value) if (bspcontext->portalrender < cv_maxportals.value)
{ {
size_t p; size_t p;
mtag_t tag = Tag_FGet(&line->linedef->tags); mtag_t tag = Tag_FGet(&line->linedef->tags);
...@@ -464,38 +449,40 @@ static void R_AddLine(seg_t *line) ...@@ -464,38 +449,40 @@ static void R_AddLine(seg_t *line)
if ((tag != Tag_FGet(&lines[li2].tags)) || (lines[li1].special != lines[li2].special) || (li1 == li2)) if ((tag != Tag_FGet(&lines[li2].tags)) || (lines[li1].special != lines[li2].special) || (li1 == li2))
continue; continue;
Portal_Add2Lines(li1, li2, x1, x2); Portal_Add2Lines(rendercontext, li1, li2, x1, x2);
goto clipsolid; goto clipsolid;
} }
} }
} }
// Single sided line? // Single sided line?
if (!backsector) if (!bspcontext->backsector)
goto clipsolid; goto clipsolid;
backsector = R_FakeFlat(backsector, &tempsec, NULL, NULL, true); bspcontext->backsector = R_FakeFlat(viewcontext, bspcontext->backsector, &bspcontext->btempsec, NULL, NULL, true);
doorclosed = 0; // indicates doors closed wrt automap bugfix:
bspcontext->doorclosed = 0;
if (backsector->ceilingpic == skyflatnum && frontsector->ceilingpic == skyflatnum) if (bspcontext->backsector->ceilingpic == skyflatnum && bspcontext->frontsector->ceilingpic == skyflatnum)
bothceilingssky = true; bothceilingssky = true;
if (backsector->floorpic == skyflatnum && frontsector->floorpic == skyflatnum) if (bspcontext->backsector->floorpic == skyflatnum && bspcontext->frontsector->floorpic == skyflatnum)
bothfloorssky = true; bothfloorssky = true;
if (bothceilingssky && bothfloorssky) // everything's sky? let's save us a bit of time then if (bothceilingssky && bothfloorssky) // everything's sky? let's save us a bit of time then
{ {
if (!line->polyseg && if (!line->polyseg &&
!line->sidedef->midtexture !line->sidedef->midtexture
&& ((!frontsector->ffloors && !backsector->ffloors) && ((!bspcontext->frontsector->ffloors && !bspcontext->backsector->ffloors)
|| Tag_Compare(&frontsector->tags, &backsector->tags))) || Tag_Compare(&bspcontext->frontsector->tags, &bspcontext->backsector->tags)))
return; // line is empty, don't even bother return; // line is empty, don't even bother
goto clippass; // treat like wide open window instead goto clippass; // treat like wide open window instead
} }
// Closed door. // Closed door.
if (frontsector->f_slope || frontsector->c_slope || backsector->f_slope || backsector->c_slope) if (bspcontext->frontsector->f_slope || bspcontext->frontsector->c_slope
|| bspcontext->backsector->f_slope || bspcontext->backsector->c_slope)
{ {
fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends
fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends
...@@ -503,10 +490,10 @@ static void R_AddLine(seg_t *line) ...@@ -503,10 +490,10 @@ static void R_AddLine(seg_t *line)
end1 = P_GetZAt(slope, line->v1->x, line->v1->y, normalheight); \ end1 = P_GetZAt(slope, line->v1->x, line->v1->y, normalheight); \
end2 = P_GetZAt(slope, line->v2->x, line->v2->y, normalheight); end2 = P_GetZAt(slope, line->v2->x, line->v2->y, normalheight);
SLOPEPARAMS(frontsector->f_slope, frontf1, frontf2, frontsector-> floorheight) SLOPEPARAMS(bspcontext->frontsector->f_slope, frontf1, frontf2, bspcontext->frontsector-> floorheight)
SLOPEPARAMS(frontsector->c_slope, frontc1, frontc2, frontsector->ceilingheight) SLOPEPARAMS(bspcontext->frontsector->c_slope, frontc1, frontc2, bspcontext->frontsector->ceilingheight)
SLOPEPARAMS( backsector->f_slope, backf1, backf2, backsector-> floorheight) SLOPEPARAMS( bspcontext->backsector->f_slope, backf1, backf2, bspcontext->backsector-> floorheight)
SLOPEPARAMS( backsector->c_slope, backc1, backc2, backsector->ceilingheight) SLOPEPARAMS( bspcontext->backsector->c_slope, backc1, backc2, bspcontext->backsector->ceilingheight)
#undef SLOPEPARAMS #undef SLOPEPARAMS
// if both ceilings are skies, consider it always "open" // if both ceilings are skies, consider it always "open"
// same for floors // same for floors
...@@ -519,11 +506,11 @@ static void R_AddLine(seg_t *line) ...@@ -519,11 +506,11 @@ static void R_AddLine(seg_t *line)
} }
// Check for automap fix. Store in doorclosed for r_segs.c // Check for automap fix. Store in doorclosed for r_segs.c
doorclosed = (backc1 <= backf1 && backc2 <= backf2 bspcontext->doorclosed = (backc1 <= backf1 && backc2 <= backf2
&& ((backc1 >= frontc1 && backc2 >= frontc2) || curline->sidedef->toptexture) && ((backc1 >= frontc1 && backc2 >= frontc2) || bspcontext->curline->sidedef->toptexture)
&& ((backf1 <= frontf1 && backf2 >= frontf2) || curline->sidedef->bottomtexture)); && ((backf1 <= frontf1 && backf2 >= frontf2) || bspcontext->curline->sidedef->bottomtexture));
if (doorclosed) if (bspcontext->doorclosed)
goto clipsolid; goto clipsolid;
} }
...@@ -541,40 +528,39 @@ static void R_AddLine(seg_t *line) ...@@ -541,40 +528,39 @@ static void R_AddLine(seg_t *line)
// same for floors // same for floors
if (!bothceilingssky && !bothfloorssky) if (!bothceilingssky && !bothfloorssky)
{ {
if (backsector->ceilingheight <= frontsector->floorheight if (bspcontext->backsector->ceilingheight <= bspcontext->frontsector->floorheight
|| backsector->floorheight >= frontsector->ceilingheight) || bspcontext->backsector->floorheight >= bspcontext->frontsector->ceilingheight)
{ {
goto clipsolid; goto clipsolid;
} }
// Check for automap fix. Store in doorclosed for r_segs.c // Check for automap fix. Store in doorclosed for r_segs.c
doorclosed = R_DoorClosed(); bspcontext->doorclosed = R_DoorClosed(bspcontext);
if (doorclosed) if (bspcontext->doorclosed)
goto clipsolid; goto clipsolid;
} }
// Window. // Window.
if (!bothceilingssky) // ceilings are always the "same" when sky if (!bothceilingssky) // ceilings are always the "same" when sky
if (backsector->ceilingheight != frontsector->ceilingheight) if (bspcontext->backsector->ceilingheight != bspcontext->frontsector->ceilingheight)
goto clippass; goto clippass;
if (!bothfloorssky) // floors are always the "same" when sky if (!bothfloorssky) // floors are always the "same" when sky
if (backsector->floorheight != frontsector->floorheight) if (bspcontext->backsector->floorheight != bspcontext->frontsector->floorheight)
goto clippass; goto clippass;
} }
// Reject empty lines used for triggers and special events. // Reject empty lines used for triggers and special events.
// Identical floor and ceiling on both sides, identical light levels on both sides, // Identical floor and ceiling on both sides, identical light levels on both sides,
// and no middle texture. // and no middle texture.
if (R_IsEmptyLine(line, bspcontext->frontsector, bspcontext->backsector))
if (R_IsEmptyLine(line, frontsector, backsector))
return; return;
clippass: clippass:
R_ClipPassWallSegment(x1, x2 - 1); R_ClipPassWallSegment(rendercontext, &wallcontext, x1, x2 - 1);
return; return;
clipsolid: clipsolid:
R_ClipSolidWallSegment(x1, x2 - 1); R_ClipSolidWallSegment(rendercontext, &wallcontext, x1, x2 - 1);
} }
// //
...@@ -602,22 +588,24 @@ INT32 checkcoord[12][4] = ...@@ -602,22 +588,24 @@ INT32 checkcoord[12][4] =
{2, 1, 3, 0} {2, 1, 3, 0}
}; };
static boolean R_CheckBBox(const fixed_t *bspcoord) static boolean R_CheckBBox(rendercontext_t *context, const fixed_t *bspcoord)
{ {
angle_t angle1, angle2; angle_t angle1, angle2;
INT32 sx1, sx2, boxpos; INT32 sx1, sx2, boxpos;
const INT32* check; const INT32* check;
cliprange_t *start; cliprange_t *start;
viewcontext_t *viewcontext = &context->viewcontext;
// Find the corners of the box that define the edges from current viewpoint. // Find the corners of the box that define the edges from current viewpoint.
if ((boxpos = (viewx <= bspcoord[BOXLEFT] ? 0 : viewx < bspcoord[BOXRIGHT] ? 1 : 2) + (viewy >= bspcoord[BOXTOP] ? 0 : viewy > bspcoord[BOXBOTTOM] ? 4 : 8)) == 5) if ((boxpos = (viewcontext->x <= bspcoord[BOXLEFT] ? 0 : viewcontext->x < bspcoord[BOXRIGHT] ? 1 : 2)
+ (viewcontext->y >= bspcoord[BOXTOP] ? 0 : viewcontext->y > bspcoord[BOXBOTTOM] ? 4 : 8)) == 5)
return true; return true;
check = checkcoord[boxpos]; check = checkcoord[boxpos];
// big room fix // big room fix
angle1 = R_PointToAngleEx(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle; angle1 = R_PointToAngleEx(viewcontext->x, viewcontext->y, bspcoord[check[0]], bspcoord[check[1]]) - viewcontext->angle;
angle2 = R_PointToAngleEx(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle; angle2 = R_PointToAngleEx(viewcontext->x, viewcontext->y, bspcoord[check[2]], bspcoord[check[3]]) - viewcontext->angle;
if ((signed)angle1 < (signed)angle2) if ((signed)angle1 < (signed)angle2)
{ {
...@@ -641,7 +629,7 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) ...@@ -641,7 +629,7 @@ static boolean R_CheckBBox(const fixed_t *bspcoord)
// Does not cross a pixel. // Does not cross a pixel.
if (sx1 >= sx2) return false; if (sx1 >= sx2) return false;
start = solidsegs; start = context->bspcontext.solidsegs;
while (start->last < sx2) while (start->last < sx2)
start++; start++;
...@@ -789,7 +777,7 @@ static int R_PolysegCompare(const void *p1, const void *p2) ...@@ -789,7 +777,7 @@ static int R_PolysegCompare(const void *p1, const void *p2)
// haleyjd 02/19/06 // haleyjd 02/19/06
// Adds all segs in all polyobjects in the given subsector. // Adds all segs in all polyobjects in the given subsector.
// //
static void R_AddPolyObjects(subsector_t *sub) static void R_AddPolyObjects(rendercontext_t *context, subsector_t *sub)
{ {
polyobj_t *po = sub->polyList; polyobj_t *po = sub->polyList;
size_t i, j; size_t i, j;
...@@ -804,7 +792,7 @@ static void R_AddPolyObjects(subsector_t *sub) ...@@ -804,7 +792,7 @@ static void R_AddPolyObjects(subsector_t *sub)
} }
// for render stats // for render stats
ps_numpolyobjects += numpolys; ps_numpolyobjects[context->num] += numpolys;
// sort polyobjects // sort polyobjects
R_SortPolyObjects(sub); R_SortPolyObjects(sub);
...@@ -814,7 +802,7 @@ static void R_AddPolyObjects(subsector_t *sub) ...@@ -814,7 +802,7 @@ static void R_AddPolyObjects(subsector_t *sub)
{ {
qsort(po_ptrs[i]->segs, po_ptrs[i]->segCount, sizeof(seg_t *), R_PolysegCompare); qsort(po_ptrs[i]->segs, po_ptrs[i]->segCount, sizeof(seg_t *), R_PolysegCompare);
for (j = 0; j < po_ptrs[i]->segCount; ++j) for (j = 0; j < po_ptrs[i]->segCount; ++j)
R_AddLine(po_ptrs[i]->segs[j]); R_AddLine(context, po_ptrs[i]->segs[j]);
} }
} }
...@@ -825,17 +813,19 @@ static void R_AddPolyObjects(subsector_t *sub) ...@@ -825,17 +813,19 @@ static void R_AddPolyObjects(subsector_t *sub)
// Draw one or more line segments. // Draw one or more line segments.
// //
drawseg_t *firstseg; static void R_Subsector(rendercontext_t *context, size_t num)
static void R_Subsector(size_t num)
{ {
INT32 count, floorlightlevel, ceilinglightlevel, light; INT32 count, floorlightlevel, ceilinglightlevel, light;
seg_t *line; seg_t *line;
subsector_t *sub; subsector_t *sub;
static sector_t tempsec; // Deep water hack
extracolormap_t *floorcolormap; extracolormap_t *floorcolormap;
extracolormap_t *ceilingcolormap; extracolormap_t *ceilingcolormap;
fixed_t floorcenterz, ceilingcenterz; fixed_t floorcenterz, ceilingcenterz;
sector_t *frontsector;
bspcontext_t *bspcontext = &context->bspcontext;
planecontext_t *planecontext = &context->planecontext;
viewcontext_t *viewcontext = &context->viewcontext;
#ifdef RANGECHECK #ifdef RANGECHECK
if (num >= numsubsectors) if (num >= numsubsectors)
...@@ -847,12 +837,11 @@ static void R_Subsector(size_t num) ...@@ -847,12 +837,11 @@ static void R_Subsector(size_t num)
return; return;
sub = &subsectors[num]; sub = &subsectors[num];
frontsector = sub->sector;
count = sub->numlines; count = sub->numlines;
line = &segs[sub->firstline]; line = &segs[sub->firstline];
// Deep water/fake ceiling effect. // Deep water/fake ceiling effect.
frontsector = R_FakeFlat(frontsector, &tempsec, &floorlightlevel, &ceilinglightlevel, false); frontsector = R_FakeFlat(viewcontext, sub->sector, &bspcontext->ftempsec, &floorlightlevel, &ceilinglightlevel, false);
floorcolormap = ceilingcolormap = frontsector->extra_colormap; floorcolormap = ceilingcolormap = frontsector->extra_colormap;
...@@ -866,9 +855,12 @@ static void R_Subsector(size_t num) ...@@ -866,9 +855,12 @@ static void R_Subsector(size_t num)
{ {
frontsector->numlights = sub->sector->numlights = 0; frontsector->numlights = sub->sector->numlights = 0;
R_Prep3DFloors(frontsector); R_Prep3DFloors(frontsector);
Lock_state();
sub->sector->lightlist = frontsector->lightlist; sub->sector->lightlist = frontsector->lightlist;
sub->sector->numlights = frontsector->numlights; sub->sector->numlights = frontsector->numlights;
sub->sector->moved = frontsector->moved = false; sub->sector->moved = frontsector->moved = false;
Unlock_state();
} }
light = R_GetPlaneLight(frontsector, floorcenterz, false); light = R_GetPlaneLight(frontsector, floorcenterz, false);
...@@ -883,106 +875,109 @@ static void R_Subsector(size_t num) ...@@ -883,106 +875,109 @@ static void R_Subsector(size_t num)
sub->sector->extra_colormap = frontsector->extra_colormap; sub->sector->extra_colormap = frontsector->extra_colormap;
if (P_GetSectorFloorZAt(frontsector, viewx, viewy) < viewz if (P_GetSectorFloorZAt(frontsector, viewcontext->x, viewcontext->y) < viewcontext->z
|| frontsector->floorpic == skyflatnum || frontsector->floorpic == skyflatnum
|| (frontsector->heightsec != -1 && sectors[frontsector->heightsec].ceilingpic == skyflatnum)) || (frontsector->heightsec != -1 && sectors[frontsector->heightsec].ceilingpic == skyflatnum))
{ {
floorplane = R_FindPlane(frontsector->floorheight, frontsector->floorpic, floorlightlevel, planecontext->floorplane = R_FindPlane(planecontext, viewcontext, frontsector->floorheight, frontsector->floorpic, floorlightlevel,
frontsector->floor_xoffs, frontsector->floor_yoffs, frontsector->floorpic_angle, floorcolormap, NULL, NULL, frontsector->f_slope); frontsector->floor_xoffs, frontsector->floor_yoffs, frontsector->floorpic_angle, floorcolormap, NULL, NULL, frontsector->f_slope);
} }
else else
floorplane = NULL; planecontext->floorplane = NULL;
if (P_GetSectorCeilingZAt(frontsector, viewx, viewy) > viewz if (P_GetSectorCeilingZAt(frontsector, viewcontext->x, viewcontext->y) > viewcontext->z
|| frontsector->ceilingpic == skyflatnum || frontsector->ceilingpic == skyflatnum
|| (frontsector->heightsec != -1 && sectors[frontsector->heightsec].floorpic == skyflatnum)) || (frontsector->heightsec != -1 && sectors[frontsector->heightsec].floorpic == skyflatnum))
{ {
ceilingplane = R_FindPlane(frontsector->ceilingheight, frontsector->ceilingpic, planecontext->ceilingplane = R_FindPlane(planecontext, viewcontext, frontsector->ceilingheight, frontsector->ceilingpic,
ceilinglightlevel, frontsector->ceiling_xoffs, frontsector->ceiling_yoffs, frontsector->ceilingpic_angle, ceilinglightlevel, frontsector->ceiling_xoffs, frontsector->ceiling_yoffs, frontsector->ceilingpic_angle,
ceilingcolormap, NULL, NULL, frontsector->c_slope); ceilingcolormap, NULL, NULL, frontsector->c_slope);
} }
else else
ceilingplane = NULL; planecontext->ceilingplane = NULL;
planecontext->numffloors = 0;
planecontext->ffloor[0].slope = NULL;
planecontext->ffloor[0].plane = NULL;
planecontext->ffloor[0].polyobj = NULL;
numffloors = 0;
ffloor[numffloors].slope = NULL;
ffloor[numffloors].plane = NULL;
ffloor[numffloors].polyobj = NULL;
if (frontsector->ffloors) if (frontsector->ffloors)
{ {
ffloor_t *rover; ffloor_t *rover;
fixed_t heightcheck, planecenterz; fixed_t heightcheck, planecenterz;
for (rover = frontsector->ffloors; rover && numffloors < MAXFFLOORS; rover = rover->next) for (rover = frontsector->ffloors; rover && planecontext->numffloors < MAXFFLOORS; rover = rover->next)
{ {
if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES)) if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES))
continue; continue;
if (frontsector->cullheight) if (frontsector->cullheight)
{ {
if (R_DoCulling(frontsector->cullheight, viewsector->cullheight, viewz, *rover->bottomheight, *rover->topheight)) if (R_DoCulling(frontsector->cullheight, viewcontext->sector->cullheight, viewcontext->z, *rover->bottomheight, *rover->topheight))
{ {
rover->norender = leveltime; rover->norender = leveltime;
continue; continue;
} }
} }
ffloor[numffloors].plane = NULL; planecontext->ffloor[planecontext->numffloors].plane = NULL;
ffloor[numffloors].polyobj = NULL; planecontext->ffloor[planecontext->numffloors].polyobj = NULL;
heightcheck = P_GetFFloorBottomZAt(rover, viewx, viewy); heightcheck = P_GetFFloorBottomZAt(rover, viewcontext->x, viewcontext->y);
planecenterz = P_GetFFloorBottomZAt(rover, frontsector->soundorg.x, frontsector->soundorg.y); planecenterz = P_GetFFloorBottomZAt(rover, frontsector->soundorg.x, frontsector->soundorg.y);
if (planecenterz <= ceilingcenterz if (planecenterz <= ceilingcenterz
&& planecenterz >= floorcenterz && planecenterz >= floorcenterz
&& ((viewz < heightcheck && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES))) && ((viewcontext->z < heightcheck && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES)))
|| (viewz > heightcheck && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) || (viewcontext->z > heightcheck && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES))))
{ {
light = R_GetPlaneLight(frontsector, planecenterz, light = R_GetPlaneLight(frontsector, planecenterz,
viewz < heightcheck); viewcontext->z < heightcheck);
ffloor[numffloors].plane = R_FindPlane(*rover->bottomheight, *rover->bottompic, planecontext->ffloor[planecontext->numffloors].plane = R_FindPlane(planecontext, viewcontext,
*rover->bottomheight, *rover->bottompic,
*frontsector->lightlist[light].lightlevel, *rover->bottomxoffs, *frontsector->lightlist[light].lightlevel, *rover->bottomxoffs,
*rover->bottomyoffs, *rover->bottomangle, *frontsector->lightlist[light].extra_colormap, rover, NULL, *rover->b_slope); *rover->bottomyoffs, *rover->bottomangle, *frontsector->lightlist[light].extra_colormap, rover, NULL, *rover->b_slope);
ffloor[numffloors].slope = *rover->b_slope; planecontext->ffloor[planecontext->numffloors].slope = *rover->b_slope;
// Tell the renderer this sector has slopes in it. // Tell the renderer this sector has slopes in it.
if (ffloor[numffloors].slope) if (planecontext->ffloor[planecontext->numffloors].slope)
frontsector->hasslope = true; frontsector->hasslope = true;
ffloor[numffloors].height = heightcheck; planecontext->ffloor[planecontext->numffloors].height = heightcheck;
ffloor[numffloors].ffloor = rover; planecontext->ffloor[planecontext->numffloors].ffloor = rover;
numffloors++; planecontext->numffloors++;
} }
if (numffloors >= MAXFFLOORS) if (planecontext->numffloors >= MAXFFLOORS)
break; break;
ffloor[numffloors].plane = NULL; planecontext->ffloor[planecontext->numffloors].plane = NULL;
ffloor[numffloors].polyobj = NULL; planecontext->ffloor[planecontext->numffloors].polyobj = NULL;
heightcheck = P_GetFFloorTopZAt(rover, viewx, viewy); heightcheck = P_GetFFloorTopZAt(rover, viewcontext->x, viewcontext->y);
planecenterz = P_GetFFloorTopZAt(rover, frontsector->soundorg.x, frontsector->soundorg.y); planecenterz = P_GetFFloorTopZAt(rover, frontsector->soundorg.x, frontsector->soundorg.y);
if (planecenterz >= floorcenterz if (planecenterz >= floorcenterz
&& planecenterz <= ceilingcenterz && planecenterz <= ceilingcenterz
&& ((viewz > heightcheck && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES))) && ((viewcontext->z > heightcheck && (rover->flags & FF_BOTHPLANES || !(rover->flags & FF_INVERTPLANES)))
|| (viewz < heightcheck && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES)))) || (viewcontext->z < heightcheck && (rover->flags & FF_BOTHPLANES || rover->flags & FF_INVERTPLANES))))
{ {
light = R_GetPlaneLight(frontsector, planecenterz, viewz < heightcheck); light = R_GetPlaneLight(frontsector, planecenterz, viewcontext->z < heightcheck);
ffloor[numffloors].plane = R_FindPlane(*rover->topheight, *rover->toppic, planecontext->ffloor[planecontext->numffloors].plane = R_FindPlane(planecontext, viewcontext,
*rover->topheight, *rover->toppic,
*frontsector->lightlist[light].lightlevel, *rover->topxoffs, *rover->topyoffs, *rover->topangle, *frontsector->lightlist[light].lightlevel, *rover->topxoffs, *rover->topyoffs, *rover->topangle,
*frontsector->lightlist[light].extra_colormap, rover, NULL, *rover->t_slope); *frontsector->lightlist[light].extra_colormap, rover, NULL, *rover->t_slope);
ffloor[numffloors].slope = *rover->t_slope; planecontext->ffloor[planecontext->numffloors].slope = *rover->t_slope;
// Tell the renderer this sector has slopes in it. // Tell the renderer this sector has slopes in it.
if (ffloor[numffloors].slope) if (planecontext->ffloor[planecontext->numffloors].slope)
frontsector->hasslope = true; frontsector->hasslope = true;
ffloor[numffloors].height = heightcheck; planecontext->ffloor[planecontext->numffloors].height = heightcheck;
ffloor[numffloors].ffloor = rover; planecontext->ffloor[planecontext->numffloors].ffloor = rover;
numffloors++; planecontext->numffloors++;
} }
} }
} }
...@@ -995,7 +990,7 @@ static void R_Subsector(size_t num) ...@@ -995,7 +990,7 @@ static void R_Subsector(size_t num)
while (po) while (po)
{ {
if (numffloors >= MAXFFLOORS) if (planecontext->numffloors >= MAXFFLOORS)
break; break;
if (!(po->flags & POF_RENDERPLANES)) // Don't draw planes if (!(po->flags & POF_RENDERPLANES)) // Don't draw planes
...@@ -1005,81 +1000,84 @@ static void R_Subsector(size_t num) ...@@ -1005,81 +1000,84 @@ static void R_Subsector(size_t num)
} }
polysec = po->lines[0]->backsector; polysec = po->lines[0]->backsector;
ffloor[numffloors].plane = NULL; planecontext->ffloor[planecontext->numffloors].plane = NULL;
if (polysec->floorheight <= ceilingcenterz if (polysec->floorheight <= ceilingcenterz
&& polysec->floorheight >= floorcenterz && polysec->floorheight >= floorcenterz
&& (viewz < polysec->floorheight)) && (viewcontext->z < polysec->floorheight))
{ {
light = R_GetPlaneLight(frontsector, polysec->floorheight, viewz < polysec->floorheight); light = R_GetPlaneLight(frontsector, polysec->floorheight, viewcontext->z < polysec->floorheight);
ffloor[numffloors].plane = R_FindPlane(polysec->floorheight, polysec->floorpic, planecontext->ffloor[planecontext->numffloors].plane = R_FindPlane(planecontext, viewcontext,
polysec->floorheight, polysec->floorpic,
(light == -1 ? frontsector->lightlevel : *frontsector->lightlist[light].lightlevel), polysec->floor_xoffs, polysec->floor_yoffs, (light == -1 ? frontsector->lightlevel : *frontsector->lightlist[light].lightlevel), polysec->floor_xoffs, polysec->floor_yoffs,
polysec->floorpic_angle-po->angle, polysec->floorpic_angle-po->angle,
(light == -1 ? frontsector->extra_colormap : *frontsector->lightlist[light].extra_colormap), NULL, po, (light == -1 ? frontsector->extra_colormap : *frontsector->lightlist[light].extra_colormap), NULL, po,
NULL); // will ffloors be slopable eventually? NULL); // will ffloors be slopable eventually?
ffloor[numffloors].height = polysec->floorheight; planecontext->ffloor[planecontext->numffloors].height = polysec->floorheight;
ffloor[numffloors].polyobj = po; planecontext->ffloor[planecontext->numffloors].polyobj = po;
ffloor[numffloors].slope = NULL; planecontext->ffloor[planecontext->numffloors].slope = NULL;
//ffloor[numffloors].ffloor = rover; //planecontext->ffloor[planecontext->numffloors].ffloor = rover;
po->visplane = ffloor[numffloors].plane; po->visplane = planecontext->ffloor[planecontext->numffloors].plane;
numffloors++; planecontext->numffloors++;
} }
if (numffloors >= MAXFFLOORS) if (planecontext->numffloors >= MAXFFLOORS)
break; break;
ffloor[numffloors].plane = NULL; planecontext->ffloor[planecontext->numffloors].plane = NULL;
if (polysec->ceilingheight >= floorcenterz if (polysec->ceilingheight >= floorcenterz
&& polysec->ceilingheight <= ceilingcenterz && polysec->ceilingheight <= ceilingcenterz
&& (viewz > polysec->ceilingheight)) && (viewcontext->z > polysec->ceilingheight))
{ {
light = R_GetPlaneLight(frontsector, polysec->floorheight, viewz < polysec->floorheight); light = R_GetPlaneLight(frontsector, polysec->floorheight, viewcontext->z < polysec->floorheight);
ffloor[numffloors].plane = R_FindPlane(polysec->ceilingheight, polysec->ceilingpic, planecontext->ffloor[planecontext->numffloors].plane = R_FindPlane(planecontext, viewcontext,
polysec->ceilingheight, polysec->ceilingpic,
(light == -1 ? frontsector->lightlevel : *frontsector->lightlist[light].lightlevel), polysec->ceiling_xoffs, polysec->ceiling_yoffs, polysec->ceilingpic_angle-po->angle, (light == -1 ? frontsector->lightlevel : *frontsector->lightlist[light].lightlevel), polysec->ceiling_xoffs, polysec->ceiling_yoffs, polysec->ceilingpic_angle-po->angle,
(light == -1 ? frontsector->extra_colormap : *frontsector->lightlist[light].extra_colormap), NULL, po, (light == -1 ? frontsector->extra_colormap : *frontsector->lightlist[light].extra_colormap), NULL, po,
NULL); // will ffloors be slopable eventually? NULL); // will ffloors be slopable eventually?
ffloor[numffloors].polyobj = po; planecontext->ffloor[planecontext->numffloors].polyobj = po;
ffloor[numffloors].height = polysec->ceilingheight; planecontext->ffloor[planecontext->numffloors].height = polysec->ceilingheight;
ffloor[numffloors].slope = NULL; planecontext->ffloor[planecontext->numffloors].slope = NULL;
//ffloor[numffloors].ffloor = rover; //planecontext->ffloor[planecontext->numffloors].ffloor = rover;
po->visplane = ffloor[numffloors].plane; po->visplane = planecontext->ffloor[planecontext->numffloors].plane;
numffloors++; planecontext->numffloors++;
} }
po = (polyobj_t *)(po->link.next); po = (polyobj_t *)(po->link.next);
} }
} }
// killough 9/18/98: Fix underwater slowdown, by passing real sector bspcontext->frontsector = frontsector;
// instead of fake one. Improve sprite lighting by basing sprite
// lightlevels on floor & ceiling lightlevels in the surrounding area. // killough 9/18/98: Fix underwater slowdown, by passing real sector
// // instead of fake one. Improve sprite lighting by basing sprite
// 10/98 killough: // lightlevels on floor & ceiling lightlevels in the surrounding area.
// //
// NOTE: TeamTNT fixed this bug incorrectly, messing up sprite lighting!!! // 10/98 killough:
// That is part of the 242 effect!!! If you simply pass sub->sector to //
// the old code you will not get correct lighting for underwater sprites!!! // NOTE: TeamTNT fixed this bug incorrectly, messing up sprite lighting!!!
// Either you must pass the fake sector and handle validcount here, on the // That is part of the 242 effect!!! If you simply pass sub->sector to
// real sector, or you must account for the lighting in some other way, // the old code you will not get correct lighting for underwater sprites!!!
// like passing it as an argument. // Either you must pass the fake sector and handle validcount here, on the
R_AddSprites(sub->sector, (floorlightlevel+ceilinglightlevel)/2); // real sector, or you must account for the lighting in some other way,
// like passing it as an argument.
firstseg = NULL; R_AddSprites(context, sub->sector, (floorlightlevel+ceilinglightlevel)/2);
bspcontext->firstseg = NULL;
// haleyjd 02/19/06: draw polyobjects before static lines // haleyjd 02/19/06: draw polyobjects before static lines
if (sub->polyList) if (sub->polyList)
R_AddPolyObjects(sub); R_AddPolyObjects(context, sub);
while (count--) while (count--)
{ {
// CONS_Debug(DBG_GAMELOGIC, "Adding normal line %d...(%d)\n", line->linedef-lines, leveltime);
if (!line->glseg && !line->polyseg) // ignore segs that belong to polyobjects if (!line->glseg && !line->polyseg) // ignore segs that belong to polyobjects
R_AddLine(line); R_AddLine(context, line);
line++; line++;
curline = NULL; /* cph 2001/11/18 - must clear curline now we're done with it, so stuff doesn't try using it for other things */ bspcontext->curline = NULL; /* cph 2001/11/18 - must clear curline now we're done with it, so stuff doesn't try using it for other things */
} }
} }
...@@ -1234,37 +1232,37 @@ INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside) ...@@ -1234,37 +1232,37 @@ INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside)
// //
// killough 5/2/98: reformatted, removed tail recursion // killough 5/2/98: reformatted, removed tail recursion
void R_RenderBSPNode(INT32 bspnum) void R_RenderBSPNode(rendercontext_t *context, INT32 bspnum)
{ {
node_t *bsp; node_t *bsp;
INT32 side; INT32 side;
ps_numbspcalls++; ps_numbspcalls[context->num]++;
while (!(bspnum & NF_SUBSECTOR)) // Found a subsector? while (!(bspnum & NF_SUBSECTOR)) // Found a subsector?
{ {
bsp = &nodes[bspnum]; bsp = &nodes[bspnum];
// Decide which side the view point is on. // Decide which side the view point is on.
side = R_PointOnSide(viewx, viewy, bsp); side = R_PointOnSide(context->viewcontext.x, context->viewcontext.y, bsp);
// Recursively divide front space. // Recursively divide front space.
R_RenderBSPNode(bsp->children[side]); R_RenderBSPNode(context, bsp->children[side]);
// Possibly divide back space. // Possibly divide back space.
if (!R_CheckBBox(context, bsp->bbox[side^1]))
if (!R_CheckBBox(bsp->bbox[side^1]))
return; return;
bspnum = bsp->children[side^1]; bspnum = bsp->children[side^1];
} }
// PORTAL CULLING // PORTAL CULLING
if (portalcullsector) { if (context->bspcontext.portalcullsector) {
sector_t *sect = subsectors[bspnum & ~NF_SUBSECTOR].sector; sector_t *sect = subsectors[bspnum & ~NF_SUBSECTOR].sector;
if (sect != portalcullsector) if (sect != context->bspcontext.portalcullsector)
return; return;
portalcullsector = NULL; context->bspcontext.portalcullsector = NULL;
} }
R_Subsector(bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR); R_Subsector(context, bspnum == -1 ? 0 : bspnum & ~NF_SUBSECTOR);
} }
...@@ -18,27 +18,16 @@ ...@@ -18,27 +18,16 @@
#pragma interface #pragma interface
#endif #endif
extern seg_t *curline;
extern side_t *sidedef;
extern line_t *linedef;
extern sector_t *frontsector;
extern sector_t *backsector;
extern boolean portalline; // is curline a portal seg?
// drawsegs are allocated on the fly... see r_segs.c
extern INT32 checkcoord[12][4]; extern INT32 checkcoord[12][4];
extern drawseg_t *curdrawsegs; struct bspcontext_s;
extern drawseg_t *drawsegs; struct rendercontext_s;
extern drawseg_t *ds_p; struct viewcontext_s;
extern INT32 doorclosed;
// BSP? // BSP?
void R_ClearClipSegs(void); void R_ClearClipSegs(struct bspcontext_s *context, INT32 start, INT32 end);
void R_PortalClearClipSegs(INT32 start, INT32 end); void R_ClearDrawSegs(struct bspcontext_s *context);
void R_ClearDrawSegs(void); void R_RenderBSPNode(struct rendercontext_s *context, INT32 bspnum);
void R_RenderBSPNode(INT32 bspnum);
void R_SortPolyObjects(subsector_t *sub); void R_SortPolyObjects(subsector_t *sub);
...@@ -46,8 +35,8 @@ extern size_t numpolys; // number of polyobjects in current subsector ...@@ -46,8 +35,8 @@ extern size_t numpolys; // number of polyobjects in current subsector
extern size_t num_po_ptrs; // number of polyobject pointers allocated extern size_t num_po_ptrs; // number of polyobject pointers allocated
extern polyobj_t **po_ptrs; // temp ptr array to sort polyobject pointers extern polyobj_t **po_ptrs; // temp ptr array to sort polyobject pointers
sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, sector_t *R_FakeFlat(struct viewcontext_s *viewcontext, sector_t *sec, sector_t *tempsec,
INT32 *ceilinglightlevel, boolean back); INT32 *floorlightlevel, INT32 *ceilinglightlevel, boolean back);
boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back); boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back);
INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside); INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside);
......
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2020 by Ethan Watson.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file r_context.h
/// \brief Render context
#ifndef __R_CONTEXT__
#define __R_CONTEXT__
#include "r_defs.h"
#include "r_bsp.h"
#include "r_plane.h"
#include "r_splats.h"
#include "r_things.h"
//
// Render context is required for threaded rendering.
// So everything "global" goes in here. Everything.
//
typedef struct viewcontext_s
{
fixed_t x, y, z;
angle_t angle, aimingangle;
fixed_t cos, sin;
sector_t *sector;
player_t *player;
mobj_t *mobj;
} viewcontext_t;
typedef struct bspcontext_s
{
seg_t *curline;
side_t *sidedef;
line_t *linedef;
sector_t *frontsector;
sector_t *backsector;
// very ugly realloc() of drawsegs at run-time, I upped it to 512
// instead of 256.. and someone managed to send me a level with
// 896 drawsegs! So too bad here's a limit removal a-la-Boom
drawseg_t *curdrawsegs; /**< This is used to handle multiple lists for masked drawsegs. */
drawseg_t *drawsegs;
drawseg_t *ds_p;
drawseg_t *firstseg;
size_t maxdrawsegs;
// newend is one past the last valid seg
cliprange_t *newend;
cliprange_t solidsegs[MAXSEGS];
sector_t ftempsec;
sector_t btempsec;
UINT8 doorclosed;
// Linked list for portals.
struct portal_s *portal_base, *portal_cap;
// When rendering a portal, it establishes the depth of the current BSP traversal.
UINT8 portalrender;
boolean portalline;
line_t *portalclipline;
sector_t *portalcullsector;
INT32 portalclipstart, portalclipend;
} bspcontext_t;
typedef struct planecontext_s
{
//SoM: 3/23/2000: Use Boom visplane hashing.
visplane_t *visplanes[MAXVISPLANES];
visplane_t *freetail;
visplane_t **freehead;
visplane_t *floorplane;
visplane_t *ceilingplane;
visplane_t *currentplane;
planemgr_t ffloor[MAXFFLOORS];
INT32 numffloors;
//SoM: 3/23/2000: Use boom opening limit removal
size_t maxopenings;
INT16 *openings, *lastopening; /// \todo free leak
//
// Clip values are the solid pixel bounding the range.
// floorclip starts out SCREENHEIGHT
// ceilingclip starts out -1
//
INT16 floorclip[MAXVIDWIDTH], ceilingclip[MAXVIDWIDTH];
fixed_t frontscale[MAXVIDWIDTH];
//
// spanstart holds the start of a plane span
// initialized to 0 at start
//
INT32 spanstart[MAXVIDHEIGHT];
//
// texture mapping
//
lighttable_t **zlight;
fixed_t planeheight;
fixed_t cachedheight[MAXVIDHEIGHT];
fixed_t cacheddistance[MAXVIDHEIGHT];
fixed_t cachedxstep[MAXVIDHEIGHT];
fixed_t cachedystep[MAXVIDHEIGHT];
fixed_t xoffs, yoffs;
struct
{
INT32 offset;
fixed_t xfrac, yfrac;
boolean active;
} ripple;
struct rastery_s *prastertab;
struct rastery_s rastertab[MAXVIDHEIGHT];
} planecontext_t;
typedef struct spritecontext_s
{
UINT32 visspritecount;
UINT32 clippedvissprites;
vissprite_t *visspritechunks[MAXVISSPRITES >> VISSPRITECHUNKBITS];
vissprite_t overflowsprite;
lighttable_t **spritelights;
boolean *sectorvisited;
drawnode_t nodebankhead;
vissprite_t vsprsortedhead;
} spritecontext_t;
typedef struct wallcontext_s
{
angle_t normalangle;
// angle to line origin
angle_t angle1;
fixed_t distance;
//
// regular wall
//
angle_t centerangle;
fixed_t offset;
fixed_t offset2; // for splats
fixed_t scale, scalestep;
fixed_t midtexturemid, toptexturemid, bottomtexturemid;
fixed_t toptextureslide, midtextureslide, bottomtextureslide; // Defines how to adjust Y offsets along the wall for slopes
fixed_t midtextureback, midtexturebackslide; // Values for masked midtexture height calculation
INT32 *silhouette;
fixed_t *tsilheight;
fixed_t *bsilheight;
} wallcontext_t;
typedef struct rendercontext_s
{
// Setup
vbuffer_t buffer;
INT32 num;
INT32 begincolumn;
INT32 endcolumn;
viewcontext_t viewcontext;
bspcontext_t bspcontext;
planecontext_t planecontext;
spritecontext_t spritecontext;
colcontext_t colcontext;
spancontext_t spancontext;
} rendercontext_t;
#endif
...@@ -1240,8 +1240,8 @@ void R_PrecacheLevel(void) ...@@ -1240,8 +1240,8 @@ void R_PrecacheLevel(void)
return; return;
// do not flush the memory, Z_Malloc twice with same user will cause error in Z_CheckHeap() // do not flush the memory, Z_Malloc twice with same user will cause error in Z_CheckHeap()
if (rendermode != render_soft) // if (rendermode != render_soft)
return; // return;
// Precache flats. // Precache flats.
flatmemory = P_PrecacheLevelFlats(); flatmemory = P_PrecacheLevelFlats();
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
// SECTORS do store MObjs anyway. // SECTORS do store MObjs anyway.
#include "p_mobj.h" #include "p_mobj.h"
#include "screen.h" // MAXVIDWIDTH, MAXVIDHEIGHT #include "screen.h"
#ifdef HWRENDER #ifdef HWRENDER
#include "m_aatree.h" #include "m_aatree.h"
...@@ -41,6 +41,9 @@ typedef struct ...@@ -41,6 +41,9 @@ typedef struct
INT32 last; INT32 last;
} cliprange_t; } cliprange_t;
// Fix from boom.
#define MAXSEGS (MAXVIDWIDTH/2+1)
// Silhouette, needed for clipping segs (mainly) and sprites representing things. // Silhouette, needed for clipping segs (mainly) and sprites representing things.
#define SIL_NONE 0 #define SIL_NONE 0
#define SIL_BOTTOM 1 #define SIL_BOTTOM 1
...@@ -56,6 +59,15 @@ typedef UINT8 lighttable_t; ...@@ -56,6 +59,15 @@ typedef UINT8 lighttable_t;
#define CMF_FADEFULLBRIGHTSPRITES 1 #define CMF_FADEFULLBRIGHTSPRITES 1
#define CMF_FOG 4 #define CMF_FOG 4
typedef struct vbuffer_s
{
UINT8 *screens[5];
} vbuffer_t;
typedef struct {
float x, y, z;
} floatv3_t;
// ExtraColormap type. Use for extra_colormaps from now on. // ExtraColormap type. Use for extra_colormaps from now on.
typedef struct extracolormap_s typedef struct extracolormap_s
{ {
......
...@@ -62,14 +62,6 @@ UINT8 *topleft; ...@@ -62,14 +62,6 @@ UINT8 *topleft;
// COLUMN DRAWING CODE STUFF // COLUMN DRAWING CODE STUFF
// ========================================================================= // =========================================================================
lighttable_t *dc_colormap;
INT32 dc_x = 0, dc_yl = 0, dc_yh = 0;
fixed_t dc_iscale, dc_texturemid;
UINT8 dc_hires; // under MSVC boolean is a byte, while on other systems, it a bit,
// soo lets make it a byte on all system for the ASM code
UINT8 *dc_source;
// ----------------------- // -----------------------
// translucency stuff here // translucency stuff here
// ----------------------- // -----------------------
...@@ -78,48 +70,11 @@ UINT8 *dc_source; ...@@ -78,48 +70,11 @@ UINT8 *dc_source;
UINT8 *transtables; // translucency tables UINT8 *transtables; // translucency tables
UINT8 *blendtables[NUMBLENDMAPS]; UINT8 *blendtables[NUMBLENDMAPS];
/** \brief R_DrawTransColumn uses this
*/
UINT8 *dc_transmap; // one of the translucency tables
// ----------------------
// translation stuff here
// ----------------------
/** \brief R_DrawTranslatedColumn uses this
*/
UINT8 *dc_translation;
struct r_lightlist_s *dc_lightlist = NULL;
INT32 dc_numlights = 0, dc_maxlights, dc_texheight;
// ========================================================================= // =========================================================================
// SPAN DRAWING CODE STUFF // SPAN DRAWING CODE STUFF
// ========================================================================= // =========================================================================
INT32 ds_y, ds_x1, ds_x2; float focallengthf;
lighttable_t *ds_colormap;
lighttable_t *ds_translation; // Lactozilla: Sprite splat drawer
fixed_t ds_xfrac, ds_yfrac, ds_xstep, ds_ystep;
INT32 ds_waterofs, ds_bgofs;
UINT16 ds_flatwidth, ds_flatheight;
boolean ds_powersoftwo;
UINT8 *ds_source; // points to the start of a flat
UINT8 *ds_transmap; // one of the translucency tables
// Vectors for Software's tilted slope drawers
floatv3_t *ds_su, *ds_sv, *ds_sz;
floatv3_t *ds_sup, *ds_svp, *ds_szp;
float focallengthf, zeroheight;
/** \brief Variable flat sizes
*/
UINT32 nflatxshift, nflatyshift, nflatshiftup, nflatmask;
// ========================================================================= // =========================================================================
// TRANSLATION COLORMAP CODE // TRANSLATION COLORMAP CODE
...@@ -572,6 +527,15 @@ static void R_GenerateTranslationColormap(UINT8 *dest_colormap, INT32 skinnum, U ...@@ -572,6 +527,15 @@ static void R_GenerateTranslationColormap(UINT8 *dest_colormap, INT32 skinnum, U
dest_colormap[starttranscolor + i] = (UINT8)skincolors[color].ramp[i]; dest_colormap[starttranscolor + i] = (UINT8)skincolors[color].ramp[i];
} }
#ifdef HAVE_THREADS
static I_mutex r_colormap_mutex;
# define Lock_state() I_lock_mutex(&r_colormap_mutex)
# define Unlock_state() I_unlock_mutex(r_colormap_mutex)
#else/*HAVE_THREADS*/
# define Lock_state()
# define Unlock_state()
#endif/*HAVE_THREADS*/
/** \brief Retrieves a translation colormap from the cache. /** \brief Retrieves a translation colormap from the cache.
...@@ -589,13 +553,16 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolornum_t color, UINT8 flags ...@@ -589,13 +553,16 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolornum_t color, UINT8 flags
if (flags & GTC_CACHE) if (flags & GTC_CACHE)
{ {
Lock_state();
// Allocate table for skin if necessary // Allocate table for skin if necessary
if (!translationtablecache[skintableindex]) if (!translationtablecache[skintableindex])
translationtablecache[skintableindex] = Z_Calloc(MAXSKINCOLORS * sizeof(UINT8**), PU_STATIC, NULL); translationtablecache[skintableindex] = Z_Calloc(MAXSKINCOLORS * sizeof(UINT8**), PU_STATIC, NULL);
Unlock_state();
// Get colormap // Get colormap
ret = translationtablecache[skintableindex][color]; ret = translationtablecache[skintableindex][color];
Lock_state();
// Rebuild the cache if necessary // Rebuild the cache if necessary
if (skincolor_modified[color]) if (skincolor_modified[color])
{ {
...@@ -605,18 +572,21 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolornum_t color, UINT8 flags ...@@ -605,18 +572,21 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolornum_t color, UINT8 flags
skincolor_modified[color] = false; skincolor_modified[color] = false;
} }
Unlock_state();
} }
else ret = NULL; else ret = NULL;
// Generate the colormap if necessary // Generate the colormap if necessary
if (!ret) if (!ret)
{ {
Lock_state();
ret = Z_MallocAlign(NUM_PALETTE_ENTRIES, (flags & GTC_CACHE) ? PU_LEVEL : PU_STATIC, NULL, 8); ret = Z_MallocAlign(NUM_PALETTE_ENTRIES, (flags & GTC_CACHE) ? PU_LEVEL : PU_STATIC, NULL, 8);
R_GenerateTranslationColormap(ret, skinnum, color); R_GenerateTranslationColormap(ret, skinnum, color);
// Cache the colormap if desired // Cache the colormap if desired
if (flags & GTC_CACHE) if (flags & GTC_CACHE)
translationtablecache[skintableindex][color] = ret; translationtablecache[skintableindex][color] = ret;
Unlock_state();
} }
return ret; return ret;
...@@ -887,13 +857,37 @@ void R_DrawViewBorder(void) ...@@ -887,13 +857,37 @@ void R_DrawViewBorder(void)
// INCLUDE 8bpp DRAWING CODE HERE // INCLUDE 8bpp DRAWING CODE HERE
// ========================================================================== // ==========================================================================
#include "r_draw8.c" // R_CalcTiltedLighting
#include "r_draw8_npo2.c" // Exactly what it says on the tin. I wish I wasn't too lazy to explain things properly.
static void R_CalcTiltedLighting(spancontext_t *ds, fixed_t start, fixed_t end)
{
// ZDoom uses a different lighting setup to us, and I couldn't figure out how to adapt their version
// of this function. Here's my own.
INT32 left = ds->x1, right = ds->x2;
fixed_t step = (end-start)/(ds->x2-ds->x1+1);
INT32 i;
// ========================================================================== // I wanna do some optimizing by checking for out-of-range segments on either side to fill in all at once,
// INCLUDE 16bpp DRAWING CODE HERE // but I'm too bad at coding to not crash the game trying to do that. I guess this is fast enough for now...
// ==========================================================================
#ifdef HIGHCOLOR for (i = left; i <= right; i++) {
#include "r_draw16.c" ds->tiltlighting[i] = (start += step) >> FRACBITS;
#endif if (ds->tiltlighting[i] < 0)
ds->tiltlighting[i] = 0;
else if (ds->tiltlighting[i] >= MAXLIGHTSCALE)
ds->tiltlighting[i] = MAXLIGHTSCALE-1;
}
}
#define PLANELIGHTFLOAT (BASEVIDWIDTH * BASEVIDWIDTH / vid.width / ds->zeroheight / 21.0f * FIXED_TO_FLOAT(fovtan))
// Lighting is simple. It's just linear interpolation from start to end
#define CALC_TILTED_LIGHTING { \
float planelightfloat = PLANELIGHTFLOAT; \
float lightend = (iz + ds->szp->x*width) * planelightfloat; \
float lightstart = iz * planelightfloat; \
R_CalcTiltedLighting(ds, FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend)); \
}
#include "r_draw8.c"
#include "r_draw8_npo2.c"
...@@ -25,61 +25,7 @@ extern UINT8 *ylookup2[MAXVIDHEIGHT*4]; ...@@ -25,61 +25,7 @@ extern UINT8 *ylookup2[MAXVIDHEIGHT*4];
extern INT32 columnofs[MAXVIDWIDTH*4]; extern INT32 columnofs[MAXVIDWIDTH*4];
extern UINT8 *topleft; extern UINT8 *topleft;
// ------------------------- extern float focallengthf;
// COLUMN DRAWING CODE STUFF
// -------------------------
extern lighttable_t *dc_colormap;
extern INT32 dc_x, dc_yl, dc_yh;
extern fixed_t dc_iscale, dc_texturemid;
extern UINT8 dc_hires;
extern UINT8 *dc_source; // first pixel in a column
// translucency stuff here
extern UINT8 *dc_transmap;
// translation stuff here
extern UINT8 *dc_translation;
extern struct r_lightlist_s *dc_lightlist;
extern INT32 dc_numlights, dc_maxlights;
//Fix TUTIFRUTI
extern INT32 dc_texheight;
// -----------------------
// SPAN DRAWING CODE STUFF
// -----------------------
extern INT32 ds_y, ds_x1, ds_x2;
extern lighttable_t *ds_colormap;
extern lighttable_t *ds_translation;
extern fixed_t ds_xfrac, ds_yfrac, ds_xstep, ds_ystep;
extern INT32 ds_waterofs, ds_bgofs;
extern UINT16 ds_flatwidth, ds_flatheight;
extern boolean ds_powersoftwo;
extern UINT8 *ds_source;
extern UINT8 *ds_transmap;
typedef struct {
float x, y, z;
} floatv3_t;
// Vectors for Software's tilted slope drawers
extern floatv3_t *ds_su, *ds_sv, *ds_sz;
extern floatv3_t *ds_sup, *ds_svp, *ds_szp;
extern float focallengthf, zeroheight;
// Variable flat sizes
extern UINT32 nflatxshift;
extern UINT32 nflatyshift;
extern UINT32 nflatshiftup;
extern UINT32 nflatmask;
/// \brief Top border /// \brief Top border
#define BRDR_T 0 #define BRDR_T 0
...@@ -163,85 +109,180 @@ void R_DrawViewBorder(void); ...@@ -163,85 +109,180 @@ void R_DrawViewBorder(void);
#define TRANSPARENTPIXEL 255 #define TRANSPARENTPIXEL 255
// ----------------- typedef struct colcontext_s
// 8bpp DRAWING CODE {
// ----------------- void (*func) (struct colcontext_s *);
vbuffer_t *dest;
void R_DrawColumn_8(void); INT32 x, yl, yh;
void R_DrawShadeColumn_8(void); fixed_t iscale, texturemid;
void R_DrawTranslucentColumn_8(void); lighttable_t *colormap;
void R_DrawTranslatedColumn_8(void);
void R_DrawTranslatedTranslucentColumn_8(void);
void R_Draw2sMultiPatchColumn_8(void);
void R_Draw2sMultiPatchTranslucentColumn_8(void);
void R_DrawFogColumn_8(void);
void R_DrawColumnShadowed_8(void);
#define PLANELIGHTFLOAT (BASEVIDWIDTH * BASEVIDWIDTH / vid.width / zeroheight / 21.0f * FIXED_TO_FLOAT(fovtan)) UINT8 *source; // first pixel in a column
void R_DrawSpan_8(void); // translucency stuff here
void R_DrawTranslucentSpan_8(void); UINT8 *transmap;
void R_DrawTiltedSpan_8(void);
void R_DrawTiltedTranslucentSpan_8(void);
void R_DrawSplat_8(void); // translation stuff here
void R_DrawTranslucentSplat_8(void); UINT8 *translation;
void R_DrawTiltedSplat_8(void);
void R_DrawFloorSprite_8(void); struct r_lightlist_s *lightlist;
void R_DrawTranslucentFloorSprite_8(void); INT32 numlights, maxlights;
void R_DrawTiltedFloorSprite_8(void);
void R_DrawTiltedTranslucentFloorSprite_8(void);
void R_CalcTiltedLighting(fixed_t start, fixed_t end); //Fix TUTIFRUTI
extern INT32 tiltlighting[MAXVIDWIDTH]; INT32 texheight;
void R_DrawTranslucentWaterSpan_8(void); // vars for R_DrawMaskedColumn
void R_DrawTiltedTranslucentWaterSpan_8(void); // Rum and Raisin put these on the sprite context.
// I put them on the column context because it felt
// more appropriate (for [REDACTED] anyway)
INT16 *mfloorclip;
INT16 *mceilingclip;
void R_DrawFogSpan_8(void); fixed_t spryscale, sprtopscreen, sprbotscreen;
fixed_t windowtop, windowbottom;
// Lactozilla: Non-powers-of-two // column->length : for flipped column function pointers and multi-patch on 2sided wall = texture->height
void R_DrawSpan_NPO2_8(void); INT32 lengthcol;
void R_DrawTranslucentSpan_NPO2_8(void); } colcontext_t;
void R_DrawTiltedSpan_NPO2_8(void);
void R_DrawTiltedTranslucentSpan_NPO2_8(void);
void R_DrawSplat_NPO2_8(void); typedef struct spancontext_s
void R_DrawTranslucentSplat_NPO2_8(void); {
void R_DrawTiltedSplat_NPO2_8(void); void (*func) (struct spancontext_s *);
vbuffer_t *dest;
void R_DrawFloorSprite_NPO2_8(void); INT32 y, x1, x2;
void R_DrawTranslucentFloorSprite_NPO2_8(void); lighttable_t *colormap;
void R_DrawTiltedFloorSprite_NPO2_8(void); lighttable_t *translation;
void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void);
void R_DrawTranslucentWaterSpan_NPO2_8(void); fixed_t xfrac, yfrac, xstep, ystep;
void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void); INT32 waterofs, bgofs;
#ifdef USEASM UINT16 flatwidth, flatheight;
void ASMCALL R_DrawColumn_8_ASM(void); boolean powersoftwo;
void ASMCALL R_DrawShadeColumn_8_ASM(void);
void ASMCALL R_DrawTranslucentColumn_8_ASM(void);
void ASMCALL R_Draw2sMultiPatchColumn_8_ASM(void);
void ASMCALL R_DrawColumn_8_MMX(void); UINT8 *source;
UINT8 *transmap;
void ASMCALL R_Draw2sMultiPatchColumn_8_MMX(void); // Vectors for Software's tilted slope drawers
void ASMCALL R_DrawSpan_8_MMX(void); floatv3_t *su, *sv, *sz;
#endif floatv3_t *sup, *svp, *szp;
floatv3_t slope_origin, slope_u, slope_v;
float zeroheight;
// ------------------ // Variable flat sizes
// 16bpp DRAWING CODE UINT32 nflatxshift;
// ------------------ UINT32 nflatyshift;
UINT32 nflatshiftup;
UINT32 nflatmask;
#ifdef HIGHCOLOR lighttable_t **zlight;
void R_DrawColumn_16(void); INT32 tiltlighting[MAXVIDWIDTH];
void R_DrawWallColumn_16(void); } spancontext_t;
void R_DrawTranslucentColumn_16(void);
void R_DrawTranslatedColumn_16(void); typedef void (*colfunc_t) (colcontext_t *);
void R_DrawSpan_16(void); typedef void (*spanfunc_t) (spancontext_t *);
#endif
// ---------------------------------------------
// color mode dependent drawer function pointers
// ---------------------------------------------
#define BASEDRAWFUNC 0
enum
{
COLDRAWFUNC_BASE = BASEDRAWFUNC,
COLDRAWFUNC_FUZZY,
COLDRAWFUNC_TRANS,
COLDRAWFUNC_SHADE,
COLDRAWFUNC_SHADOWED,
COLDRAWFUNC_TRANSTRANS,
COLDRAWFUNC_TWOSMULTIPATCH,
COLDRAWFUNC_TWOSMULTIPATCHTRANS,
COLDRAWFUNC_FOG,
COLDRAWFUNC_MAX
};
extern colfunc_t colfuncs[COLDRAWFUNC_MAX];
enum
{
SPANDRAWFUNC_BASE = BASEDRAWFUNC,
SPANDRAWFUNC_TRANS,
SPANDRAWFUNC_TILTED,
SPANDRAWFUNC_TILTEDTRANS,
SPANDRAWFUNC_SPLAT,
SPANDRAWFUNC_TRANSSPLAT,
SPANDRAWFUNC_TILTEDSPLAT,
SPANDRAWFUNC_SPRITE,
SPANDRAWFUNC_TRANSSPRITE,
SPANDRAWFUNC_TILTEDSPRITE,
SPANDRAWFUNC_TILTEDTRANSSPRITE,
SPANDRAWFUNC_WATER,
SPANDRAWFUNC_TILTEDWATER,
SPANDRAWFUNC_FOG,
SPANDRAWFUNC_MAX
};
extern spanfunc_t spanfuncs[SPANDRAWFUNC_MAX];
extern spanfunc_t spanfuncs_npo2[SPANDRAWFUNC_MAX];
// -----------------
// 8bpp DRAWING CODE
// -----------------
void R_DrawColumn_8(colcontext_t *dc);
void R_DrawShadeColumn_8(colcontext_t *dc);
void R_DrawTranslucentColumn_8(colcontext_t *dc);
void R_DrawTranslatedColumn_8(colcontext_t *dc);
void R_DrawTranslatedTranslucentColumn_8(colcontext_t *dc);
void R_Draw2sMultiPatchColumn_8(colcontext_t *dc);
void R_Draw2sMultiPatchTranslucentColumn_8(colcontext_t *dc);
void R_DrawFogColumn_8(colcontext_t *dc);
void R_DrawColumnShadowed_8(colcontext_t *dc);
void R_DrawSpan_8(spancontext_t *ds);
void R_DrawTranslucentSpan_8(spancontext_t *ds);
void R_DrawTiltedSpan_8(spancontext_t *ds);
void R_DrawTiltedTranslucentSpan_8(spancontext_t *ds);
void R_DrawSplat_8(spancontext_t *ds);
void R_DrawTranslucentSplat_8(spancontext_t *ds);
void R_DrawTiltedSplat_8(spancontext_t *ds);
void R_DrawFloorSprite_8(spancontext_t *ds);
void R_DrawTranslucentFloorSprite_8(spancontext_t *ds);
void R_DrawTiltedFloorSprite_8(spancontext_t *ds);
void R_DrawTiltedTranslucentFloorSprite_8(spancontext_t *ds);
void R_DrawTranslucentWaterSpan_8(spancontext_t *ds);
void R_DrawTiltedTranslucentWaterSpan_8(spancontext_t *ds);
void R_DrawFogSpan_8(spancontext_t *ds);
// Lactozilla: Non-powers-of-two
void R_DrawSpan_NPO2_8(spancontext_t *ds);
void R_DrawTranslucentSpan_NPO2_8(spancontext_t *ds);
void R_DrawTiltedSpan_NPO2_8(spancontext_t *ds);
void R_DrawTiltedTranslucentSpan_NPO2_8(spancontext_t *ds);
void R_DrawSplat_NPO2_8(spancontext_t *ds);
void R_DrawTranslucentSplat_NPO2_8(spancontext_t *ds);
void R_DrawTiltedSplat_NPO2_8(spancontext_t *ds);
void R_DrawFloorSprite_NPO2_8(spancontext_t *ds);
void R_DrawTranslucentFloorSprite_NPO2_8(spancontext_t *ds);
void R_DrawTiltedFloorSprite_NPO2_8(spancontext_t *ds);
void R_DrawTiltedTranslucentFloorSprite_NPO2_8(spancontext_t *ds);
void R_DrawTranslucentWaterSpan_NPO2_8(spancontext_t *ds);
void R_DrawTiltedTranslucentWaterSpan_NPO2_8(spancontext_t *ds);
// ========================================================================= // =========================================================================
#endif // __R_DRAW__ #endif // __R_DRAW__
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 1999-2021 by Sonic Team Junior.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file r_draw16.c
/// \brief 16bpp (HIGHCOLOR) span/column drawer functions
/// \note no includes because this is included as part of r_draw.c
// ==========================================================================
// COLUMNS
// ==========================================================================
/// \brief kick out the upper bit of each component (we're in 5 : 5 : 5)
#define HIMASK1 0x7bde
/** \brief The R_DrawColumn_16 function
standard upto 128high posts column drawer
*/
void R_DrawColumn_16(void)
{
INT32 count;
INT16 *dest;
fixed_t frac, fracstep;
count = dc_yh - dc_yl + 1;
// Zero length, column does not exceed a pixel.
if (count <= 0)
return;
#ifdef RANGECHECK
if (dc_x >= vid.width || dc_yl < 0 || dc_yh >= vid.height)
I_Error("R_DrawColumn_16: %d to %d at %d", dc_yl, dc_yh, dc_x);
#endif
// Framebuffer destination address.
// Use ylookup LUT to avoid multiply with ScreenWidth.
// Use columnofs LUT for subwindows?
dest = (INT16 *)(void *)(ylookup[dc_yl] + columnofs[dc_x]);
// Determine scaling, which is the only mapping to be done.
fracstep = dc_iscale;
frac = dc_texturemid + (dc_yl - centery)*fracstep;
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets.
do
{
// Re-map color indices from wall texture column using a lighting/special effects LUT.
*dest = hicolormaps[((INT16 *)(void *)dc_source)[(frac>>FRACBITS)&127]>>1];
dest += vid.width;
frac += fracstep;
} while (--count);
}
/** \brief The R_DrawWallColumn_16 function
LAME cutnpaste: same as R_DrawColumn_16 but wraps around 256
instead of 128 for the tall sky textures (256x240)
*/
void R_DrawWallColumn_16(void)
{
INT32 count;
INT16 *dest;
fixed_t frac, fracstep;
count = dc_yh - dc_yl + 1;
// Zero length, column does not exceed a pixel.
if (count <= 0)
return;
#ifdef RANGECHECK
if (dc_x >= vid.width || dc_yl < 0 || dc_yh >= vid.height)
I_Error("R_DrawWallColumn_16: %d to %d at %d", dc_yl, dc_yh, dc_x);
#endif
dest = (INT16 *)(void *)(ylookup[dc_yl] + columnofs[dc_x]);
fracstep = dc_iscale;
frac = dc_texturemid + (dc_yl - centery)*fracstep;
do
{
*dest = hicolormaps[((INT16 *)(void *)dc_source)[(frac>>FRACBITS)&255]>>1];
dest += vid.width;
frac += fracstep;
} while (--count);
}
/** \brief The R_DrawTranslucentColumn_16 function
LAME cutnpaste: same as R_DrawColumn_16 but does
translucent
*/
void R_DrawTranslucentColumn_16(void)
{
INT32 count;
INT16 *dest;
fixed_t frac, fracstep;
// check out coords for src*
if ((dc_yl < 0) || (dc_x >= vid.width))
return;
count = dc_yh - dc_yl;
if (count < 0)
return;
#ifdef RANGECHECK
if (dc_x >= vid.width || dc_yl < 0 || dc_yh >= vid.height)
I_Error("R_DrawTranslucentColumn_16: %d to %d at %d", dc_yl, dc_yh, dc_x);
#endif
// FIXME. As above.
dest = (INT16 *)(void *)(ylookup[dc_yl] + columnofs[dc_x]);
// Looks familiar.
fracstep = dc_iscale;
frac = dc_texturemid + (dc_yl - centery)*fracstep;
// Here we do an additional index re-mapping.
do
{
*dest = (INT16)((INT16)((color8to16[dc_source[frac>>FRACBITS]]>>1) & 0x39ce)
+ (INT16)(((*dest & HIMASK1)) & 0x7fff));
dest += vid.width;
frac += fracstep;
} while (count--);
}
/** \brief The R_DrawTranslatedColumn_16 function
?
*/
void R_DrawTranslatedColumn_16(void)
{
INT32 count;
INT16 *dest;
fixed_t frac, fracstep;
count = dc_yh - dc_yl;
if (count < 0)
return;
#ifdef RANGECHECK
if (dc_x >= vid.width || dc_yl < 0 || dc_yh >= vid.height)
I_Error("R_DrawTranslatedColumn_16: %d to %d at %d", dc_yl, dc_yh, dc_x);
#endif
dest = (INT16 *)(void *)(ylookup[dc_yl] + columnofs[dc_x]);
// Looks familiar.
fracstep = dc_iscale;
frac = dc_texturemid + (dc_yl - centery)*fracstep;
// Here we do an additional index re-mapping.
do
{
*dest = color8to16[dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]];
dest += vid.width;
frac += fracstep;
} while (count--);
}
// ==========================================================================
// SPANS
// ==========================================================================
/** \brief The R_*_16 function
Draws the actual span.
*/
void R_DrawSpan_16(void)
{
fixed_t xfrac, yfrac;
INT16 *dest;
INT32 count, spot;
#ifdef RANGECHECK
if (ds_x2 < ds_x1 || ds_x1 < 0 || ds_x2 >= vid.width || ds_y > vid.height)
I_Error("R_DrawSpan_16: %d to %d at %d", ds_x1, ds_x2, ds_y);
#endif
xfrac = ds_xfrac;
yfrac = ds_yfrac;
dest = (INT16 *)(void *)(ylookup[ds_y] + columnofs[ds_x1]);
// We do not check for zero spans here?
count = ds_x2 - ds_x1;
if (count <= 0) // We do now!
return;
do
{
// Current texture index in u, v.
spot = ((yfrac>>(16-6))&(63*64)) + ((xfrac>>16)&63);
// Lookup pixel from flat texture tile, re-index using light/colormap.
*dest++ = hicolormaps[((INT16 *)(void *)ds_source)[spot]>>1];
// Next step in u, v.
xfrac += ds_xstep;
yfrac += ds_ystep;
} while (count--);
}
...@@ -22,20 +22,20 @@ ...@@ -22,20 +22,20 @@
/** \brief The R_DrawColumn_8 function /** \brief The R_DrawColumn_8 function
Experiment to make software go faster. Taken from the Boom source Experiment to make software go faster. Taken from the Boom source
*/ */
void R_DrawColumn_8(void) void R_DrawColumn_8(colcontext_t *dc)
{ {
INT32 count; INT32 count;
register UINT8 *dest; register UINT8 *dest;
register fixed_t frac; register fixed_t frac;
fixed_t fracstep; fixed_t fracstep;
count = dc_yh - dc_yl; count = dc->yh - dc->yl;
if (count < 0) // Zero length, column does not exceed a pixel. if (count < 0) // Zero length, column does not exceed a pixel.
return; return;
#ifdef RANGECHECK #ifdef RANGECHECK
if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
return; return;
#endif #endif
...@@ -43,23 +43,23 @@ void R_DrawColumn_8(void) ...@@ -43,23 +43,23 @@ void R_DrawColumn_8(void)
// Use ylookup LUT to avoid multiply with ScreenWidth. // Use ylookup LUT to avoid multiply with ScreenWidth.
// Use columnofs LUT for subwindows? // Use columnofs LUT for subwindows?
//dest = ylookup[dc_yl] + columnofs[dc_x]; //dest = ylookup[dc->yl] + columnofs[dc->x];
dest = &topleft[dc_yl*vid.width + dc_x]; dest = &topleft[dc->yl*vid.width + dc->x];
count++; count++;
// Determine scaling, which is the only mapping to be done. // Determine scaling, which is the only mapping to be done.
fracstep = dc_iscale; fracstep = dc->iscale;
//frac = dc_texturemid + (dc_yl - centery)*fracstep; //frac = dc->texturemid + (dc->yl - centery)*fracstep;
frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets. // This is as fast as it gets.
{ {
register const UINT8 *source = dc_source; register const UINT8 *source = dc->source;
register const lighttable_t *colormap = dc_colormap; register const lighttable_t *colormap = dc->colormap;
register INT32 heightmask = dc_texheight-1; register INT32 heightmask = dc->texheight-1;
if (dc_texheight & heightmask) // not a power of 2 -- killough if (dc->texheight & heightmask) // not a power of 2 -- killough
{ {
heightmask++; heightmask++;
heightmask <<= FRACBITS; heightmask <<= FRACBITS;
...@@ -105,20 +105,20 @@ void R_DrawColumn_8(void) ...@@ -105,20 +105,20 @@ void R_DrawColumn_8(void)
} }
} }
void R_Draw2sMultiPatchColumn_8(void) void R_Draw2sMultiPatchColumn_8(colcontext_t *dc)
{ {
INT32 count; INT32 count;
register UINT8 *dest; register UINT8 *dest;
register fixed_t frac; register fixed_t frac;
fixed_t fracstep; fixed_t fracstep;
count = dc_yh - dc_yl; count = dc->yh - dc->yl;
if (count < 0) // Zero length, column does not exceed a pixel. if (count < 0) // Zero length, column does not exceed a pixel.
return; return;
#ifdef RANGECHECK #ifdef RANGECHECK
if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
return; return;
#endif #endif
...@@ -126,24 +126,24 @@ void R_Draw2sMultiPatchColumn_8(void) ...@@ -126,24 +126,24 @@ void R_Draw2sMultiPatchColumn_8(void)
// Use ylookup LUT to avoid multiply with ScreenWidth. // Use ylookup LUT to avoid multiply with ScreenWidth.
// Use columnofs LUT for subwindows? // Use columnofs LUT for subwindows?
//dest = ylookup[dc_yl] + columnofs[dc_x]; //dest = ylookup[dc->yl] + columnofs[dc->x];
dest = &topleft[dc_yl*vid.width + dc_x]; dest = &topleft[dc->yl*vid.width + dc->x];
count++; count++;
// Determine scaling, which is the only mapping to be done. // Determine scaling, which is the only mapping to be done.
fracstep = dc_iscale; fracstep = dc->iscale;
//frac = dc_texturemid + (dc_yl - centery)*fracstep; //frac = dc->texturemid + (dc->yl - centery)*fracstep;
frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets. // This is as fast as it gets.
{ {
register const UINT8 *source = dc_source; register const UINT8 *source = dc->source;
register const lighttable_t *colormap = dc_colormap; register const lighttable_t *colormap = dc->colormap;
register INT32 heightmask = dc_texheight-1; register INT32 heightmask = dc->texheight-1;
register UINT8 val; register UINT8 val;
if (dc_texheight & heightmask) // not a power of 2 -- killough if (dc->texheight & heightmask) // not a power of 2 -- killough
{ {
heightmask++; heightmask++;
heightmask <<= FRACBITS; heightmask <<= FRACBITS;
...@@ -201,20 +201,20 @@ void R_Draw2sMultiPatchColumn_8(void) ...@@ -201,20 +201,20 @@ void R_Draw2sMultiPatchColumn_8(void)
} }
} }
void R_Draw2sMultiPatchTranslucentColumn_8(void) void R_Draw2sMultiPatchTranslucentColumn_8(colcontext_t *dc)
{ {
INT32 count; INT32 count;
register UINT8 *dest; register UINT8 *dest;
register fixed_t frac; register fixed_t frac;
fixed_t fracstep; fixed_t fracstep;
count = dc_yh - dc_yl; count = dc->yh - dc->yl;
if (count < 0) // Zero length, column does not exceed a pixel. if (count < 0) // Zero length, column does not exceed a pixel.
return; return;
#ifdef RANGECHECK #ifdef RANGECHECK
if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
return; return;
#endif #endif
...@@ -222,25 +222,25 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) ...@@ -222,25 +222,25 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void)
// Use ylookup LUT to avoid multiply with ScreenWidth. // Use ylookup LUT to avoid multiply with ScreenWidth.
// Use columnofs LUT for subwindows? // Use columnofs LUT for subwindows?
//dest = ylookup[dc_yl] + columnofs[dc_x]; //dest = ylookup[dc->yl] + columnofs[dc->x];
dest = &topleft[dc_yl*vid.width + dc_x]; dest = &topleft[dc->yl*vid.width + dc->x];
count++; count++;
// Determine scaling, which is the only mapping to be done. // Determine scaling, which is the only mapping to be done.
fracstep = dc_iscale; fracstep = dc->iscale;
//frac = dc_texturemid + (dc_yl - centery)*fracstep; //frac = dc->texturemid + (dc->yl - centery)*fracstep;
frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets. // This is as fast as it gets.
{ {
register const UINT8 *source = dc_source; register const UINT8 *source = dc->source;
register const UINT8 *transmap = dc_transmap; register const UINT8 *transmap = dc->transmap;
register const lighttable_t *colormap = dc_colormap; register const lighttable_t *colormap = dc->colormap;
register INT32 heightmask = dc_texheight-1; register INT32 heightmask = dc->texheight-1;
register UINT8 val; register UINT8 val;
if (dc_texheight & heightmask) // not a power of 2 -- killough if (dc->texheight & heightmask) // not a power of 2 -- killough
{ {
heightmask++; heightmask++;
heightmask <<= FRACBITS; heightmask <<= FRACBITS;
...@@ -301,38 +301,38 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) ...@@ -301,38 +301,38 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void)
/** \brief The R_DrawShadeColumn_8 function /** \brief The R_DrawShadeColumn_8 function
Experiment to make software go faster. Taken from the Boom source Experiment to make software go faster. Taken from the Boom source
*/ */
void R_DrawShadeColumn_8(void) void R_DrawShadeColumn_8(colcontext_t *dc)
{ {
register INT32 count; register INT32 count;
register UINT8 *dest; register UINT8 *dest;
register fixed_t frac, fracstep; register fixed_t frac, fracstep;
// check out coords for src* // check out coords for src*
if ((dc_yl < 0) || (dc_x >= vid.width)) if ((dc->yl < 0) || (dc->x >= vid.width))
return; return;
count = dc_yh - dc_yl; count = dc->yh - dc->yl;
if (count < 0) if (count < 0)
return; return;
#ifdef RANGECHECK #ifdef RANGECHECK
if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
I_Error("R_DrawShadeColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); I_Error("R_DrawShadeColumn_8: %d to %d at %d", dc->yl, dc->yh, dc->x);
#endif #endif
// FIXME. As above. // FIXME. As above.
//dest = ylookup[dc_yl] + columnofs[dc_x]; //dest = ylookup[dc->yl] + columnofs[dc->x];
dest = &topleft[dc_yl*vid.width + dc_x]; dest = &topleft[dc->yl*vid.width + dc->x];
// Looks familiar. // Looks familiar.
fracstep = dc_iscale; fracstep = dc->iscale;
//frac = dc_texturemid + (dc_yl - centery)*fracstep; //frac = dc->texturemid + (dc->yl - centery)*fracstep;
frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Here we do an additional index re-mapping. // Here we do an additional index re-mapping.
do do
{ {
*dest = colormaps[(dc_source[frac>>FRACBITS] <<8) + (*dest)]; *dest = colormaps[(dc->source[frac>>FRACBITS] <<8) + (*dest)];
dest += vid.width; dest += vid.width;
frac += fracstep; frac += fracstep;
} while (count--); } while (count--);
...@@ -343,39 +343,39 @@ void R_DrawShadeColumn_8(void) ...@@ -343,39 +343,39 @@ void R_DrawShadeColumn_8(void)
a lot in 640x480 with big sprites (bfg on all screen, or transparent a lot in 640x480 with big sprites (bfg on all screen, or transparent
walls on fullscreen) walls on fullscreen)
*/ */
void R_DrawTranslucentColumn_8(void) void R_DrawTranslucentColumn_8(colcontext_t *dc)
{ {
register INT32 count; register INT32 count;
register UINT8 *dest; register UINT8 *dest;
register fixed_t frac, fracstep; register fixed_t frac, fracstep;
count = dc_yh - dc_yl + 1; count = dc->yh - dc->yl + 1;
if (count <= 0) // Zero length, column does not exceed a pixel. if (count <= 0) // Zero length, column does not exceed a pixel.
return; return;
#ifdef RANGECHECK #ifdef RANGECHECK
if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
I_Error("R_DrawTranslucentColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); I_Error("R_DrawTranslucentColumn_8: %d to %d at %d", dc->yl, dc->yh, dc->x);
#endif #endif
// FIXME. As above. // FIXME. As above.
//dest = ylookup[dc_yl] + columnofs[dc_x]; //dest = ylookup[dc->yl] + columnofs[dc->x];
dest = &topleft[dc_yl*vid.width + dc_x]; dest = &topleft[dc->yl*vid.width + dc->x];
// Looks familiar. // Looks familiar.
fracstep = dc_iscale; fracstep = dc->iscale;
//frac = dc_texturemid + (dc_yl - centery)*fracstep; //frac = dc->texturemid + (dc->yl - centery)*fracstep;
frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets. // This is as fast as it gets.
{ {
register const UINT8 *source = dc_source; register const UINT8 *source = dc->source;
register const UINT8 *transmap = dc_transmap; register const UINT8 *transmap = dc->transmap;
register const lighttable_t *colormap = dc_colormap; register const lighttable_t *colormap = dc->colormap;
register INT32 heightmask = dc_texheight - 1; register INT32 heightmask = dc->texheight - 1;
if (dc_texheight & heightmask) if (dc->texheight & heightmask)
{ {
heightmask++; heightmask++;
heightmask <<= FRACBITS; heightmask <<= FRACBITS;
...@@ -420,31 +420,31 @@ void R_DrawTranslucentColumn_8(void) ...@@ -420,31 +420,31 @@ void R_DrawTranslucentColumn_8(void)
Spiffy function. Not only does it colormap a sprite, but does translucency as well. Spiffy function. Not only does it colormap a sprite, but does translucency as well.
Uber-kudos to Cyan Helkaraxe Uber-kudos to Cyan Helkaraxe
*/ */
void R_DrawTranslatedTranslucentColumn_8(void) void R_DrawTranslatedTranslucentColumn_8(colcontext_t *dc)
{ {
register INT32 count; register INT32 count;
register UINT8 *dest; register UINT8 *dest;
register fixed_t frac, fracstep; register fixed_t frac, fracstep;
count = dc_yh - dc_yl + 1; count = dc->yh - dc->yl + 1;
if (count <= 0) // Zero length, column does not exceed a pixel. if (count <= 0) // Zero length, column does not exceed a pixel.
return; return;
// FIXME. As above. // FIXME. As above.
//dest = ylookup[dc_yl] + columnofs[dc_x]; //dest = ylookup[dc->yl] + columnofs[dc->x];
dest = &topleft[dc_yl*vid.width + dc_x]; dest = &topleft[dc->yl*vid.width + dc->x];
// Looks familiar. // Looks familiar.
fracstep = dc_iscale; fracstep = dc->iscale;
//frac = dc_texturemid + (dc_yl - centery)*fracstep; //frac = dc->texturemid + (dc->yl - centery)*fracstep;
frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling.
// This is as fast as it gets. // This is as fast as it gets.
{ {
register INT32 heightmask = dc_texheight - 1; register INT32 heightmask = dc->texheight - 1;
if (dc_texheight & heightmask) if (dc->texheight & heightmask)
{ {
heightmask++; heightmask++;
heightmask <<= FRACBITS; heightmask <<= FRACBITS;
...@@ -462,7 +462,7 @@ void R_DrawTranslatedTranslucentColumn_8(void) ...@@ -462,7 +462,7 @@ void R_DrawTranslatedTranslucentColumn_8(void)
// using a lighting/special effects LUT. // using a lighting/special effects LUT.
// heightmask is the Tutti-Frutti fix // heightmask is the Tutti-Frutti fix
*dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]<<8) + (*dest)); *dest = *(dc->transmap + (dc->colormap[dc->translation[dc->source[frac>>FRACBITS]]]<<8) + (*dest));
dest += vid.width; dest += vid.width;
if ((frac += fracstep) >= heightmask) if ((frac += fracstep) >= heightmask)
...@@ -474,15 +474,15 @@ void R_DrawTranslatedTranslucentColumn_8(void) ...@@ -474,15 +474,15 @@ void R_DrawTranslatedTranslucentColumn_8(void)
{ {
while ((count -= 2) >= 0) // texture height is a power of 2 while ((count -= 2) >= 0) // texture height is a power of 2
{ {
*dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); *dest = *(dc->transmap + (dc->colormap[dc->translation[dc->source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest));
dest += vid.width; dest += vid.width;
frac += fracstep; frac += fracstep;
*dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); *dest = *(dc->transmap + (dc->colormap[dc->translation[dc->source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest));
dest += vid.width; dest += vid.width;
frac += fracstep; frac += fracstep;
} }
if (count & 1) if (count & 1)
*dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); *dest = *(dc->transmap + (dc->colormap[dc->translation[dc->source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest));
} }
} }
} }
...@@ -492,29 +492,29 @@ void R_DrawTranslatedTranslucentColumn_8(void) ...@@ -492,29 +492,29 @@ void R_DrawTranslatedTranslucentColumn_8(void)
\warning STILL NOT IN ASM, TO DO.. \warning STILL NOT IN ASM, TO DO..
*/ */
void R_DrawTranslatedColumn_8(void) void R_DrawTranslatedColumn_8(colcontext_t *dc)
{ {
register INT32 count; register INT32 count;
register UINT8 *dest; register UINT8 *dest;
register fixed_t frac, fracstep; register fixed_t frac, fracstep;
count = dc_yh - dc_yl; count = dc->yh - dc->yl;
if (count < 0) if (count < 0)
return; return;
#ifdef RANGECHECK #ifdef RANGECHECK
if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
I_Error("R_DrawTranslatedColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); I_Error("R_DrawTranslatedColumn_8: %d to %d at %d", dc->yl, dc->yh, dc->x);
#endif #endif
// FIXME. As above. // FIXME. As above.
//dest = ylookup[dc_yl] + columnofs[dc_x]; //dest = ylookup[dc->yl] + columnofs[dc->x];
dest = &topleft[dc_yl*vid.width + dc_x]; dest = &topleft[dc->yl*vid.width + dc->x];
// Looks familiar. // Looks familiar.
fracstep = dc_iscale; fracstep = dc->iscale;
//frac = dc_texturemid + (dc_yl-centery)*fracstep; //frac = dc->texturemid + (dc->yl-centery)*fracstep;
frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); frac = (dc->texturemid + FixedMul((dc->yl << FRACBITS) - centeryfrac, fracstep));
// Here we do an additional index re-mapping. // Here we do an additional index re-mapping.
do do
...@@ -524,7 +524,7 @@ void R_DrawTranslatedColumn_8(void) ...@@ -524,7 +524,7 @@ void R_DrawTranslatedColumn_8(void)
// used with PLAY sprites. // used with PLAY sprites.
// Thus the "green" ramp of the player 0 sprite // Thus the "green" ramp of the player 0 sprite
// is mapped to gray, red, black/indigo. // is mapped to gray, red, black/indigo.
*dest = dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]; *dest = dc->colormap[dc->translation[dc->source[frac>>FRACBITS]]];
dest += vid.width; dest += vid.width;
...@@ -542,7 +542,7 @@ void R_DrawTranslatedColumn_8(void) ...@@ -542,7 +542,7 @@ void R_DrawTranslatedColumn_8(void)
/** \brief The R_DrawSpan_8 function /** \brief The R_DrawSpan_8 function
Draws the actual span. Draws the actual span.
*/ */
void R_DrawSpan_8 (void) void R_DrawSpan_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -553,10 +553,10 @@ void R_DrawSpan_8 (void) ...@@ -553,10 +553,10 @@ void R_DrawSpan_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
// SoM: we only need 6 bits for the integer part (0 thru 63) so the rest // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest
// can be used for the fraction part. This allows calculation of the memory address in the // can be used for the fraction part. This allows calculation of the memory address in the
...@@ -565,12 +565,12 @@ void R_DrawSpan_8 (void) ...@@ -565,12 +565,12 @@ void R_DrawSpan_8 (void)
// bit per power of two (obviously) // bit per power of two (obviously)
// Ok, because I was able to eliminate the variable spot below, this function is now FASTER // Ok, because I was able to eliminate the variable spot below, this function is now FASTER
// than the original span renderer. Whodathunkit? // than the original span renderer. Whodathunkit?
xposition <<= nflatshiftup; yposition <<= nflatshiftup; xposition <<= ds->nflatshiftup; yposition <<= ds->nflatshiftup;
xstep <<= nflatshiftup; ystep <<= nflatshiftup; xstep <<= ds->nflatshiftup; ystep <<= ds->nflatshiftup;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
if (dest+8 > deststop) if (dest+8 > deststop)
return; return;
...@@ -580,35 +580,35 @@ void R_DrawSpan_8 (void) ...@@ -580,35 +580,35 @@ void R_DrawSpan_8 (void)
// SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't
// have the uber complicated math to calculate it now, so that was a memory write we didn't // have the uber complicated math to calculate it now, so that was a memory write we didn't
// need! // need!
dest[0] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; dest[0] = colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[1] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; dest[1] = colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[2] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; dest[2] = colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[3] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; dest[3] = colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[4] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; dest[4] = colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[5] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; dest[5] = colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[6] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; dest[6] = colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[7] = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; dest[7] = colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
...@@ -617,42 +617,19 @@ void R_DrawSpan_8 (void) ...@@ -617,42 +617,19 @@ void R_DrawSpan_8 (void)
} }
while (count-- && dest <= deststop) while (count-- && dest <= deststop)
{ {
*dest++ = colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]]; *dest++ = colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
} }
} }
// R_CalcTiltedLighting
// Exactly what it says on the tin. I wish I wasn't too lazy to explain things properly.
INT32 tiltlighting[MAXVIDWIDTH];
void R_CalcTiltedLighting(fixed_t start, fixed_t end)
{
// ZDoom uses a different lighting setup to us, and I couldn't figure out how to adapt their version
// of this function. Here's my own.
INT32 left = ds_x1, right = ds_x2;
fixed_t step = (end-start)/(ds_x2-ds_x1+1);
INT32 i;
// I wanna do some optimizing by checking for out-of-range segments on either side to fill in all at once,
// but I'm too bad at coding to not crash the game trying to do that. I guess this is fast enough for now...
for (i = left; i <= right; i++) {
tiltlighting[i] = (start += step) >> FRACBITS;
if (tiltlighting[i] < 0)
tiltlighting[i] = 0;
else if (tiltlighting[i] >= MAXLIGHTSCALE)
tiltlighting[i] = MAXLIGHTSCALE-1;
}
}
/** \brief The R_DrawTiltedSpan_8 function /** \brief The R_DrawTiltedSpan_8 function
Draw slopes! Holy sheit! Draw slopes! Holy sheit!
*/ */
void R_DrawTiltedSpan_8(void) void R_DrawTiltedSpan_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -666,26 +643,16 @@ void R_DrawTiltedSpan_8(void) ...@@ -666,26 +643,16 @@ void R_DrawTiltedSpan_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds_szp->x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
}
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
source = ds_source; source = ds->source;
//colormap = ds_colormap; //colormap = ds->colormap;
#if 0 // The "perfect" reference version of this routine. Pretty slow. #if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look. // Use it only to see how things are supposed to look.
...@@ -696,22 +663,22 @@ void R_DrawTiltedSpan_8(void) ...@@ -696,22 +663,22 @@ void R_DrawTiltedSpan_8(void)
u = (INT64)(uz*z); u = (INT64)(uz*z);
v = (INT64)(vz*z); v = (INT64)(vz*z);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; *dest = colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]];
dest++; dest++;
iz += ds_szp->x; iz += ds->szp->x;
uz += ds_sup->x; uz += ds->sup->x;
vz += ds_svp->x; vz += ds->svp->x;
} while (--width >= 0); } while (--width >= 0);
#else #else
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -731,8 +698,8 @@ void R_DrawTiltedSpan_8(void) ...@@ -731,8 +698,8 @@ void R_DrawTiltedSpan_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; *dest = colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]];
dest++; dest++;
u += stepu; u += stepu;
v += stepv; v += stepv;
...@@ -747,15 +714,15 @@ void R_DrawTiltedSpan_8(void) ...@@ -747,15 +714,15 @@ void R_DrawTiltedSpan_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; *dest = colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]];
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -768,8 +735,8 @@ void R_DrawTiltedSpan_8(void) ...@@ -768,8 +735,8 @@ void R_DrawTiltedSpan_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]]; *dest = colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]];
dest++; dest++;
u += stepu; u += stepu;
v += stepv; v += stepv;
...@@ -782,10 +749,10 @@ void R_DrawTiltedSpan_8(void) ...@@ -782,10 +749,10 @@ void R_DrawTiltedSpan_8(void)
/** \brief The R_DrawTiltedTranslucentSpan_8 function /** \brief The R_DrawTiltedTranslucentSpan_8 function
Like DrawTiltedSpan, but translucent Like DrawTiltedSpan, but translucent
*/ */
void R_DrawTiltedTranslucentSpan_8(void) void R_DrawTiltedTranslucentSpan_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -799,26 +766,16 @@ void R_DrawTiltedTranslucentSpan_8(void) ...@@ -799,26 +766,16 @@ void R_DrawTiltedTranslucentSpan_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds_szp->x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend)); CALC_TILTED_LIGHTING
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
}
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
source = ds_source; source = ds->source;
//colormap = ds_colormap; //colormap = ds->colormap;
#if 0 // The "perfect" reference version of this routine. Pretty slow. #if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look. // Use it only to see how things are supposed to look.
...@@ -829,21 +786,21 @@ void R_DrawTiltedTranslucentSpan_8(void) ...@@ -829,21 +786,21 @@ void R_DrawTiltedTranslucentSpan_8(void)
u = (INT64)(uz*z); u = (INT64)(uz*z);
v = (INT64)(vz*z); v = (INT64)(vz*z);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]] << 8) + *dest);
dest++; dest++;
iz += ds_szp->x; iz += ds->szp->x;
uz += ds_sup->x; uz += ds->sup->x;
vz += ds_svp->x; vz += ds->svp->x;
} while (--width >= 0); } while (--width >= 0);
#else #else
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -863,8 +820,8 @@ void R_DrawTiltedTranslucentSpan_8(void) ...@@ -863,8 +820,8 @@ void R_DrawTiltedTranslucentSpan_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]] << 8) + *dest);
dest++; dest++;
u += stepu; u += stepu;
v += stepv; v += stepv;
...@@ -879,15 +836,15 @@ void R_DrawTiltedTranslucentSpan_8(void) ...@@ -879,15 +836,15 @@ void R_DrawTiltedTranslucentSpan_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]] << 8) + *dest);
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -900,8 +857,8 @@ void R_DrawTiltedTranslucentSpan_8(void) ...@@ -900,8 +857,8 @@ void R_DrawTiltedTranslucentSpan_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]] << 8) + *dest);
dest++; dest++;
u += stepu; u += stepu;
v += stepv; v += stepv;
...@@ -914,10 +871,10 @@ void R_DrawTiltedTranslucentSpan_8(void) ...@@ -914,10 +871,10 @@ void R_DrawTiltedTranslucentSpan_8(void)
/** \brief The R_DrawTiltedTranslucentWaterSpan_8 function /** \brief The R_DrawTiltedTranslucentWaterSpan_8 function
Like DrawTiltedTranslucentSpan, but for water Like DrawTiltedTranslucentSpan, but for water
*/ */
void R_DrawTiltedTranslucentWaterSpan_8(void) void R_DrawTiltedTranslucentWaterSpan_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -932,27 +889,17 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) ...@@ -932,27 +889,17 @@ void R_DrawTiltedTranslucentWaterSpan_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end CALC_TILTED_LIGHTING
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds_szp->x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
}
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1; dsrc = screens[1] + (ds->y+ds->bgofs)*vid.width + ds->x1;
source = ds_source; source = ds->source;
//colormap = ds_colormap; //colormap = ds->colormap;
#if 0 // The "perfect" reference version of this routine. Pretty slow. #if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look. // Use it only to see how things are supposed to look.
...@@ -963,21 +910,21 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) ...@@ -963,21 +910,21 @@ void R_DrawTiltedTranslucentWaterSpan_8(void)
u = (INT64)(uz*z); u = (INT64)(uz*z);
v = (INT64)(vz*z); v = (INT64)(vz*z);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++); *dest = *(ds->transmap + (colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]] << 8) + *dsrc++);
dest++; dest++;
iz += ds_szp->x; iz += ds->szp->x;
uz += ds_sup->x; uz += ds->sup->x;
vz += ds_svp->x; vz += ds->svp->x;
} while (--width >= 0); } while (--width >= 0);
#else #else
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -997,8 +944,8 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) ...@@ -997,8 +944,8 @@ void R_DrawTiltedTranslucentWaterSpan_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++); *dest = *(ds->transmap + (colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]] << 8) + *dsrc++);
dest++; dest++;
u += stepu; u += stepu;
v += stepv; v += stepv;
...@@ -1013,15 +960,15 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) ...@@ -1013,15 +960,15 @@ void R_DrawTiltedTranslucentWaterSpan_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++); *dest = *(ds->transmap + (colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]] << 8) + *dsrc++);
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -1034,8 +981,8 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) ...@@ -1034,8 +981,8 @@ void R_DrawTiltedTranslucentWaterSpan_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
*dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dsrc++); *dest = *(ds->transmap + (colormap[source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)]] << 8) + *dsrc++);
dest++; dest++;
u += stepu; u += stepu;
v += stepv; v += stepv;
...@@ -1045,10 +992,10 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) ...@@ -1045,10 +992,10 @@ void R_DrawTiltedTranslucentWaterSpan_8(void)
#endif #endif
} }
void R_DrawTiltedSplat_8(void) void R_DrawTiltedSplat_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -1064,26 +1011,16 @@ void R_DrawTiltedSplat_8(void) ...@@ -1064,26 +1011,16 @@ void R_DrawTiltedSplat_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end CALC_TILTED_LIGHTING
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds_szp->x*width) * planelightfloat; uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
lightstart = iz * planelightfloat; vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend)); dest = ylookup[ds->y] + columnofs[ds->x1];
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf); source = ds->source;
} //colormap = ds->colormap;
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1];
source = ds_source;
//colormap = ds_colormap;
#if 0 // The "perfect" reference version of this routine. Pretty slow. #if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look. // Use it only to see how things are supposed to look.
...@@ -1094,25 +1031,25 @@ void R_DrawTiltedSplat_8(void) ...@@ -1094,25 +1031,25 @@ void R_DrawTiltedSplat_8(void)
u = (INT64)(uz*z); u = (INT64)(uz*z);
v = (INT64)(vz*z); v = (INT64)(vz*z);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
dest++; dest++;
iz += ds_szp->x; iz += ds->szp->x;
uz += ds_sup->x; uz += ds->sup->x;
vz += ds_svp->x; vz += ds->svp->x;
} while (--width >= 0); } while (--width >= 0);
#else #else
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -1132,8 +1069,8 @@ void R_DrawTiltedSplat_8(void) ...@@ -1132,8 +1069,8 @@ void R_DrawTiltedSplat_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
dest++; dest++;
...@@ -1150,17 +1087,17 @@ void R_DrawTiltedSplat_8(void) ...@@ -1150,17 +1087,17 @@ void R_DrawTiltedSplat_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -1173,8 +1110,8 @@ void R_DrawTiltedSplat_8(void) ...@@ -1173,8 +1110,8 @@ void R_DrawTiltedSplat_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
dest++; dest++;
...@@ -1189,7 +1126,7 @@ void R_DrawTiltedSplat_8(void) ...@@ -1189,7 +1126,7 @@ void R_DrawTiltedSplat_8(void)
/** \brief The R_DrawSplat_8 function /** \brief The R_DrawSplat_8 function
Just like R_DrawSpan_8, but skips transparent pixels. Just like R_DrawSpan_8, but skips transparent pixels.
*/ */
void R_DrawSplat_8 (void) void R_DrawSplat_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -1200,11 +1137,11 @@ void R_DrawSplat_8 (void) ...@@ -1200,11 +1137,11 @@ void R_DrawSplat_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
// SoM: we only need 6 bits for the integer part (0 thru 63) so the rest // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest
// can be used for the fraction part. This allows calculation of the memory address in the // can be used for the fraction part. This allows calculation of the memory address in the
...@@ -1213,12 +1150,12 @@ void R_DrawSplat_8 (void) ...@@ -1213,12 +1150,12 @@ void R_DrawSplat_8 (void)
// bit per power of two (obviously) // bit per power of two (obviously)
// Ok, because I was able to eliminate the variable spot below, this function is now FASTER // Ok, because I was able to eliminate the variable spot below, this function is now FASTER
// than the original span renderer. Whodathunkit? // than the original span renderer. Whodathunkit?
xposition <<= nflatshiftup; yposition <<= nflatshiftup; xposition <<= ds->nflatshiftup; yposition <<= ds->nflatshiftup;
xstep <<= nflatshiftup; ystep <<= nflatshiftup; xstep <<= ds->nflatshiftup; ystep <<= ds->nflatshiftup;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
while (count >= 8) while (count >= 8)
{ {
...@@ -1228,7 +1165,7 @@ void R_DrawSplat_8 (void) ...@@ -1228,7 +1165,7 @@ void R_DrawSplat_8 (void)
// //
// <Callum> 4194303 = (2048x2048)-1 (2048x2048 is maximum flat size) // <Callum> 4194303 = (2048x2048)-1 (2048x2048 is maximum flat size)
// Why decimal? 0x3FFFFF == 4194303... ~Golden // Why decimal? 0x3FFFFF == 4194303... ~Golden
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val &= 0x3FFFFF; val &= 0x3FFFFF;
val = source[val]; val = source[val];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
...@@ -1236,7 +1173,7 @@ void R_DrawSplat_8 (void) ...@@ -1236,7 +1173,7 @@ void R_DrawSplat_8 (void)
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val &= 0x3FFFFF; val &= 0x3FFFFF;
val = source[val]; val = source[val];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
...@@ -1244,7 +1181,7 @@ void R_DrawSplat_8 (void) ...@@ -1244,7 +1181,7 @@ void R_DrawSplat_8 (void)
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val &= 0x3FFFFF; val &= 0x3FFFFF;
val = source[val]; val = source[val];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
...@@ -1252,7 +1189,7 @@ void R_DrawSplat_8 (void) ...@@ -1252,7 +1189,7 @@ void R_DrawSplat_8 (void)
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val &= 0x3FFFFF; val &= 0x3FFFFF;
val = source[val]; val = source[val];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
...@@ -1260,7 +1197,7 @@ void R_DrawSplat_8 (void) ...@@ -1260,7 +1197,7 @@ void R_DrawSplat_8 (void)
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val &= 0x3FFFFF; val &= 0x3FFFFF;
val = source[val]; val = source[val];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
...@@ -1268,7 +1205,7 @@ void R_DrawSplat_8 (void) ...@@ -1268,7 +1205,7 @@ void R_DrawSplat_8 (void)
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val &= 0x3FFFFF; val &= 0x3FFFFF;
val = source[val]; val = source[val];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
...@@ -1276,7 +1213,7 @@ void R_DrawSplat_8 (void) ...@@ -1276,7 +1213,7 @@ void R_DrawSplat_8 (void)
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val &= 0x3FFFFF; val &= 0x3FFFFF;
val = source[val]; val = source[val];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
...@@ -1284,7 +1221,7 @@ void R_DrawSplat_8 (void) ...@@ -1284,7 +1221,7 @@ void R_DrawSplat_8 (void)
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val &= 0x3FFFFF; val &= 0x3FFFFF;
val = source[val]; val = source[val];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
...@@ -1297,7 +1234,7 @@ void R_DrawSplat_8 (void) ...@@ -1297,7 +1234,7 @@ void R_DrawSplat_8 (void)
} }
while (count-- && dest <= deststop) while (count-- && dest <= deststop)
{ {
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
dest++; dest++;
...@@ -1309,7 +1246,7 @@ void R_DrawSplat_8 (void) ...@@ -1309,7 +1246,7 @@ void R_DrawSplat_8 (void)
/** \brief The R_DrawTranslucentSplat_8 function /** \brief The R_DrawTranslucentSplat_8 function
Just like R_DrawSplat_8, but is translucent! Just like R_DrawSplat_8, but is translucent!
*/ */
void R_DrawTranslucentSplat_8 (void) void R_DrawTranslucentSplat_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -1320,11 +1257,11 @@ void R_DrawTranslucentSplat_8 (void) ...@@ -1320,11 +1257,11 @@ void R_DrawTranslucentSplat_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
// SoM: we only need 6 bits for the integer part (0 thru 63) so the rest // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest
// can be used for the fraction part. This allows calculation of the memory address in the // can be used for the fraction part. This allows calculation of the memory address in the
...@@ -1333,63 +1270,63 @@ void R_DrawTranslucentSplat_8 (void) ...@@ -1333,63 +1270,63 @@ void R_DrawTranslucentSplat_8 (void)
// bit per power of two (obviously) // bit per power of two (obviously)
// Ok, because I was able to eliminate the variable spot below, this function is now FASTER // Ok, because I was able to eliminate the variable spot below, this function is now FASTER
// than the original span renderer. Whodathunkit? // than the original span renderer. Whodathunkit?
xposition <<= nflatshiftup; yposition <<= nflatshiftup; xposition <<= ds->nflatshiftup; yposition <<= ds->nflatshiftup;
xstep <<= nflatshiftup; ystep <<= nflatshiftup; xstep <<= ds->nflatshiftup; ystep <<= ds->nflatshiftup;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
while (count >= 8) while (count >= 8)
{ {
// SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't
// have the uber complicated math to calculate it now, so that was a memory write we didn't // have the uber complicated math to calculate it now, so that was a memory write we didn't
// need! // need!
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
dest[0] = *(ds_transmap + (colormap[val] << 8) + dest[0]); dest[0] = *(ds->transmap + (colormap[val] << 8) + dest[0]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
dest[1] = *(ds_transmap + (colormap[val] << 8) + dest[1]); dest[1] = *(ds->transmap + (colormap[val] << 8) + dest[1]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
dest[2] = *(ds_transmap + (colormap[val] << 8) + dest[2]); dest[2] = *(ds->transmap + (colormap[val] << 8) + dest[2]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
dest[3] = *(ds_transmap + (colormap[val] << 8) + dest[3]); dest[3] = *(ds->transmap + (colormap[val] << 8) + dest[3]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
dest[4] = *(ds_transmap + (colormap[val] << 8) + dest[4]); dest[4] = *(ds->transmap + (colormap[val] << 8) + dest[4]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
dest[5] = *(ds_transmap + (colormap[val] << 8) + dest[5]); dest[5] = *(ds->transmap + (colormap[val] << 8) + dest[5]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
dest[6] = *(ds_transmap + (colormap[val] << 8) + dest[6]); dest[6] = *(ds->transmap + (colormap[val] << 8) + dest[6]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
dest[7] = *(ds_transmap + (colormap[val] << 8) + dest[7]); dest[7] = *(ds->transmap + (colormap[val] << 8) + dest[7]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
...@@ -1398,9 +1335,9 @@ void R_DrawTranslucentSplat_8 (void) ...@@ -1398,9 +1335,9 @@ void R_DrawTranslucentSplat_8 (void)
} }
while (count-- && dest <= deststop) while (count-- && dest <= deststop)
{ {
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = *(ds_transmap + (colormap[val] << 8) + *dest); *dest = *(ds->transmap + (colormap[val] << 8) + *dest);
dest++; dest++;
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
...@@ -1410,7 +1347,7 @@ void R_DrawTranslucentSplat_8 (void) ...@@ -1410,7 +1347,7 @@ void R_DrawTranslucentSplat_8 (void)
/** \brief The R_DrawFloorSprite_8 function /** \brief The R_DrawFloorSprite_8 function
Just like R_DrawSplat_8, but for floor sprites. Just like R_DrawSplat_8, but for floor sprites.
*/ */
void R_DrawFloorSprite_8 (void) void R_DrawFloorSprite_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -1422,11 +1359,11 @@ void R_DrawFloorSprite_8 (void) ...@@ -1422,11 +1359,11 @@ void R_DrawFloorSprite_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
// SoM: we only need 6 bits for the integer part (0 thru 63) so the rest // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest
// can be used for the fraction part. This allows calculation of the memory address in the // can be used for the fraction part. This allows calculation of the memory address in the
...@@ -1435,69 +1372,69 @@ void R_DrawFloorSprite_8 (void) ...@@ -1435,69 +1372,69 @@ void R_DrawFloorSprite_8 (void)
// bit per power of two (obviously) // bit per power of two (obviously)
// Ok, because I was able to eliminate the variable spot below, this function is now FASTER // Ok, because I was able to eliminate the variable spot below, this function is now FASTER
// than the original span renderer. Whodathunkit? // than the original span renderer. Whodathunkit?
xposition <<= nflatshiftup; yposition <<= nflatshiftup; xposition <<= ds->nflatshiftup; yposition <<= ds->nflatshiftup;
xstep <<= nflatshiftup; ystep <<= nflatshiftup; xstep <<= ds->nflatshiftup; ystep <<= ds->nflatshiftup;
source = (UINT16 *)ds_source; source = (UINT16 *)ds->source;
colormap = ds_colormap; colormap = ds->colormap;
translation = ds_translation; translation = ds->translation;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
while (count >= 8) while (count >= 8)
{ {
// SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't
// have the uber complicated math to calculate it now, so that was a memory write we didn't // have the uber complicated math to calculate it now, so that was a memory write we didn't
// need! // need!
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val = source[val]; val = source[val];
if (val & 0xFF00) if (val & 0xFF00)
dest[0] = colormap[translation[val & 0xFF]]; dest[0] = colormap[translation[val & 0xFF]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val = source[val]; val = source[val];
if (val & 0xFF00) if (val & 0xFF00)
dest[1] = colormap[translation[val & 0xFF]]; dest[1] = colormap[translation[val & 0xFF]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val = source[val]; val = source[val];
if (val & 0xFF00) if (val & 0xFF00)
dest[2] = colormap[translation[val & 0xFF]]; dest[2] = colormap[translation[val & 0xFF]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val = source[val]; val = source[val];
if (val & 0xFF00) if (val & 0xFF00)
dest[3] = colormap[translation[val & 0xFF]]; dest[3] = colormap[translation[val & 0xFF]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val = source[val]; val = source[val];
if (val & 0xFF00) if (val & 0xFF00)
dest[4] = colormap[translation[val & 0xFF]]; dest[4] = colormap[translation[val & 0xFF]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val = source[val]; val = source[val];
if (val & 0xFF00) if (val & 0xFF00)
dest[5] = colormap[translation[val & 0xFF]]; dest[5] = colormap[translation[val & 0xFF]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val = source[val]; val = source[val];
if (val & 0xFF00) if (val & 0xFF00)
dest[6] = colormap[translation[val & 0xFF]]; dest[6] = colormap[translation[val & 0xFF]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
val = source[val]; val = source[val];
if (val & 0xFF00) if (val & 0xFF00)
dest[7] = colormap[translation[val & 0xFF]]; dest[7] = colormap[translation[val & 0xFF]];
...@@ -1509,7 +1446,7 @@ void R_DrawFloorSprite_8 (void) ...@@ -1509,7 +1446,7 @@ void R_DrawFloorSprite_8 (void)
} }
while (count-- && dest <= deststop) while (count-- && dest <= deststop)
{ {
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = colormap[translation[val & 0xFF]]; *dest = colormap[translation[val & 0xFF]];
dest++; dest++;
...@@ -1521,7 +1458,7 @@ void R_DrawFloorSprite_8 (void) ...@@ -1521,7 +1458,7 @@ void R_DrawFloorSprite_8 (void)
/** \brief The R_DrawTranslucentFloorSplat_8 function /** \brief The R_DrawTranslucentFloorSplat_8 function
Just like R_DrawFloorSprite_8, but is translucent! Just like R_DrawFloorSprite_8, but is translucent!
*/ */
void R_DrawTranslucentFloorSprite_8 (void) void R_DrawTranslucentFloorSprite_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -1533,11 +1470,11 @@ void R_DrawTranslucentFloorSprite_8 (void) ...@@ -1533,11 +1470,11 @@ void R_DrawTranslucentFloorSprite_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
// SoM: we only need 6 bits for the integer part (0 thru 63) so the rest // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest
// can be used for the fraction part. This allows calculation of the memory address in the // can be used for the fraction part. This allows calculation of the memory address in the
...@@ -1546,64 +1483,64 @@ void R_DrawTranslucentFloorSprite_8 (void) ...@@ -1546,64 +1483,64 @@ void R_DrawTranslucentFloorSprite_8 (void)
// bit per power of two (obviously) // bit per power of two (obviously)
// Ok, because I was able to eliminate the variable spot below, this function is now FASTER // Ok, because I was able to eliminate the variable spot below, this function is now FASTER
// than the original span renderer. Whodathunkit? // than the original span renderer. Whodathunkit?
xposition <<= nflatshiftup; yposition <<= nflatshiftup; xposition <<= ds->nflatshiftup; yposition <<= ds->nflatshiftup;
xstep <<= nflatshiftup; ystep <<= nflatshiftup; xstep <<= ds->nflatshiftup; ystep <<= ds->nflatshiftup;
source = (UINT16 *)ds_source; source = (UINT16 *)ds->source;
colormap = ds_colormap; colormap = ds->colormap;
translation = ds_translation; translation = ds->translation;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
while (count >= 8) while (count >= 8)
{ {
// SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't
// have the uber complicated math to calculate it now, so that was a memory write we didn't // have the uber complicated math to calculate it now, so that was a memory write we didn't
// need! // need!
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
dest[0] = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + dest[0]); dest[0] = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + dest[0]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
dest[1] = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + dest[1]); dest[1] = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + dest[1]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
dest[2] = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + dest[2]); dest[2] = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + dest[2]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
dest[3] = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + dest[3]); dest[3] = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + dest[3]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
dest[4] = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + dest[4]); dest[4] = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + dest[4]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
dest[5] = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + dest[5]); dest[5] = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + dest[5]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
dest[6] = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + dest[6]); dest[6] = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + dest[6]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
dest[7] = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + dest[7]); dest[7] = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + dest[7]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
...@@ -1612,9 +1549,9 @@ void R_DrawTranslucentFloorSprite_8 (void) ...@@ -1612,9 +1549,9 @@ void R_DrawTranslucentFloorSprite_8 (void)
} }
while (count-- && dest <= deststop) while (count-- && dest <= deststop)
{ {
val = source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]; val = source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + *dest); *dest = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + *dest);
dest++; dest++;
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
...@@ -1624,10 +1561,10 @@ void R_DrawTranslucentFloorSprite_8 (void) ...@@ -1624,10 +1561,10 @@ void R_DrawTranslucentFloorSprite_8 (void)
/** \brief The R_DrawTiltedFloorSprite_8 function /** \brief The R_DrawTiltedFloorSprite_8 function
Draws a tilted floor sprite. Draws a tilted floor sprite.
*/ */
void R_DrawTiltedFloorSprite_8(void) void R_DrawTiltedFloorSprite_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -1643,22 +1580,22 @@ void R_DrawTiltedFloorSprite_8(void) ...@@ -1643,22 +1580,22 @@ void R_DrawTiltedFloorSprite_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
source = (UINT16 *)ds_source; source = (UINT16 *)ds->source;
colormap = ds_colormap; colormap = ds->colormap;
translation = ds_translation; translation = ds->translation;
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -1678,7 +1615,7 @@ void R_DrawTiltedFloorSprite_8(void) ...@@ -1678,7 +1615,7 @@ void R_DrawTiltedFloorSprite_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = colormap[translation[val & 0xFF]]; *dest = colormap[translation[val & 0xFF]];
dest++; dest++;
...@@ -1696,16 +1633,16 @@ void R_DrawTiltedFloorSprite_8(void) ...@@ -1696,16 +1633,16 @@ void R_DrawTiltedFloorSprite_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = colormap[translation[val & 0xFF]]; *dest = colormap[translation[val & 0xFF]];
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -1718,7 +1655,7 @@ void R_DrawTiltedFloorSprite_8(void) ...@@ -1718,7 +1655,7 @@ void R_DrawTiltedFloorSprite_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = colormap[translation[val & 0xFF]]; *dest = colormap[translation[val & 0xFF]];
dest++; dest++;
...@@ -1733,10 +1670,10 @@ void R_DrawTiltedFloorSprite_8(void) ...@@ -1733,10 +1670,10 @@ void R_DrawTiltedFloorSprite_8(void)
/** \brief The R_DrawTiltedTranslucentFloorSprite_8 function /** \brief The R_DrawTiltedTranslucentFloorSprite_8 function
Draws a tilted, translucent, floor sprite. Draws a tilted, translucent, floor sprite.
*/ */
void R_DrawTiltedTranslucentFloorSprite_8(void) void R_DrawTiltedTranslucentFloorSprite_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -1752,22 +1689,22 @@ void R_DrawTiltedTranslucentFloorSprite_8(void) ...@@ -1752,22 +1689,22 @@ void R_DrawTiltedTranslucentFloorSprite_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
source = (UINT16 *)ds_source; source = (UINT16 *)ds->source;
colormap = ds_colormap; colormap = ds->colormap;
translation = ds_translation; translation = ds->translation;
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -1787,9 +1724,9 @@ void R_DrawTiltedTranslucentFloorSprite_8(void) ...@@ -1787,9 +1724,9 @@ void R_DrawTiltedTranslucentFloorSprite_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + *dest); *dest = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + *dest);
dest++; dest++;
u += stepu; u += stepu;
...@@ -1805,16 +1742,16 @@ void R_DrawTiltedTranslucentFloorSprite_8(void) ...@@ -1805,16 +1742,16 @@ void R_DrawTiltedTranslucentFloorSprite_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + *dest); *dest = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + *dest);
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -1827,9 +1764,9 @@ void R_DrawTiltedTranslucentFloorSprite_8(void) ...@@ -1827,9 +1764,9 @@ void R_DrawTiltedTranslucentFloorSprite_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]; val = source[((v >> ds->nflatyshift) & ds->nflatmask) | (u >> ds->nflatxshift)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + *dest); *dest = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + *dest);
dest++; dest++;
u += stepu; u += stepu;
...@@ -1842,7 +1779,7 @@ void R_DrawTiltedTranslucentFloorSprite_8(void) ...@@ -1842,7 +1779,7 @@ void R_DrawTiltedTranslucentFloorSprite_8(void)
/** \brief The R_DrawTranslucentSpan_8 function /** \brief The R_DrawTranslucentSpan_8 function
Draws the actual span with translucency. Draws the actual span with translucency.
*/ */
void R_DrawTranslucentSpan_8 (void) void R_DrawTranslucentSpan_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -1853,11 +1790,11 @@ void R_DrawTranslucentSpan_8 (void) ...@@ -1853,11 +1790,11 @@ void R_DrawTranslucentSpan_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
// SoM: we only need 6 bits for the integer part (0 thru 63) so the rest // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest
// can be used for the fraction part. This allows calculation of the memory address in the // can be used for the fraction part. This allows calculation of the memory address in the
...@@ -1866,47 +1803,47 @@ void R_DrawTranslucentSpan_8 (void) ...@@ -1866,47 +1803,47 @@ void R_DrawTranslucentSpan_8 (void)
// bit per power of two (obviously) // bit per power of two (obviously)
// Ok, because I was able to eliminate the variable spot below, this function is now FASTER // Ok, because I was able to eliminate the variable spot below, this function is now FASTER
// than the original span renderer. Whodathunkit? // than the original span renderer. Whodathunkit?
xposition <<= nflatshiftup; yposition <<= nflatshiftup; xposition <<= ds->nflatshiftup; yposition <<= ds->nflatshiftup;
xstep <<= nflatshiftup; ystep <<= nflatshiftup; xstep <<= ds->nflatshiftup; ystep <<= ds->nflatshiftup;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
while (count >= 8) while (count >= 8)
{ {
// SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't
// have the uber complicated math to calculate it now, so that was a memory write we didn't // have the uber complicated math to calculate it now, so that was a memory write we didn't
// need! // need!
dest[0] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[0]); dest[0] = *(ds->transmap + (colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]] << 8) + dest[0]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[1] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[1]); dest[1] = *(ds->transmap + (colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]] << 8) + dest[1]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[2] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[2]); dest[2] = *(ds->transmap + (colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]] << 8) + dest[2]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[3] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[3]); dest[3] = *(ds->transmap + (colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]] << 8) + dest[3]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[4] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[4]); dest[4] = *(ds->transmap + (colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]] << 8) + dest[4]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[5] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[5]); dest[5] = *(ds->transmap + (colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]] << 8) + dest[5]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[6] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[6]); dest[6] = *(ds->transmap + (colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]] << 8) + dest[6]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[7] = *(ds_transmap + (colormap[source[(((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift)]] << 8) + dest[7]); dest[7] = *(ds->transmap + (colormap[source[(((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift)]] << 8) + dest[7]);
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
...@@ -1915,15 +1852,15 @@ void R_DrawTranslucentSpan_8 (void) ...@@ -1915,15 +1852,15 @@ void R_DrawTranslucentSpan_8 (void)
} }
while (count-- && dest <= deststop) while (count-- && dest <= deststop)
{ {
val = (((UINT32)yposition >> nflatyshift) & nflatmask) | ((UINT32)xposition >> nflatxshift); val = (((UINT32)yposition >> ds->nflatyshift) & ds->nflatmask) | ((UINT32)xposition >> ds->nflatxshift);
*dest = *(ds_transmap + (colormap[source[val]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[val]] << 8) + *dest);
dest++; dest++;
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
} }
} }
void R_DrawTranslucentWaterSpan_8(void) void R_DrawTranslucentWaterSpan_8(spancontext_t *ds)
{ {
UINT32 xposition; UINT32 xposition;
UINT32 yposition; UINT32 yposition;
...@@ -1943,49 +1880,49 @@ void R_DrawTranslucentWaterSpan_8(void) ...@@ -1943,49 +1880,49 @@ void R_DrawTranslucentWaterSpan_8(void)
// bit per power of two (obviously) // bit per power of two (obviously)
// Ok, because I was able to eliminate the variable spot below, this function is now FASTER // Ok, because I was able to eliminate the variable spot below, this function is now FASTER
// than the original span renderer. Whodathunkit? // than the original span renderer. Whodathunkit?
xposition = ds_xfrac << nflatshiftup; yposition = (ds_yfrac + ds_waterofs) << nflatshiftup; xposition = ds->xfrac << ds->nflatshiftup; yposition = (ds->yfrac + ds->waterofs) << ds->nflatshiftup;
xstep = ds_xstep << nflatshiftup; ystep = ds_ystep << nflatshiftup; xstep = ds->xstep << ds->nflatshiftup; ystep = ds->ystep << ds->nflatshiftup;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1; dsrc = screens[1] + (ds->y+ds->bgofs)*vid.width + ds->x1;
count = ds_x2 - ds_x1 + 1; count = ds->x2 - ds->x1 + 1;
while (count >= 8) while (count >= 8)
{ {
// SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't
// have the uber complicated math to calculate it now, so that was a memory write we didn't // have the uber complicated math to calculate it now, so that was a memory write we didn't
// need! // need!
dest[0] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; dest[0] = colormap[*(ds->transmap + (source[((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[1] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; dest[1] = colormap[*(ds->transmap + (source[((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[2] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; dest[2] = colormap[*(ds->transmap + (source[((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[3] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; dest[3] = colormap[*(ds->transmap + (source[((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[4] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; dest[4] = colormap[*(ds->transmap + (source[((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[5] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; dest[5] = colormap[*(ds->transmap + (source[((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[6] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; dest[6] = colormap[*(ds->transmap + (source[((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
dest[7] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; dest[7] = colormap[*(ds->transmap + (source[((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
...@@ -1994,7 +1931,7 @@ void R_DrawTranslucentWaterSpan_8(void) ...@@ -1994,7 +1931,7 @@ void R_DrawTranslucentWaterSpan_8(void)
} }
while (count--) while (count--)
{ {
*dest++ = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dsrc++)]; *dest++ = colormap[*(ds->transmap + (source[((yposition >> ds->nflatyshift) & ds->nflatmask) | (xposition >> ds->nflatxshift)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
} }
...@@ -2003,18 +1940,18 @@ void R_DrawTranslucentWaterSpan_8(void) ...@@ -2003,18 +1940,18 @@ void R_DrawTranslucentWaterSpan_8(void)
/** \brief The R_DrawFogSpan_8 function /** \brief The R_DrawFogSpan_8 function
Draws the actual span with fogging. Draws the actual span with fogging.
*/ */
void R_DrawFogSpan_8(void) void R_DrawFogSpan_8(spancontext_t *ds)
{ {
UINT8 *colormap; UINT8 *colormap;
UINT8 *dest; UINT8 *dest;
size_t count; size_t count;
colormap = ds_colormap; colormap = ds->colormap;
//dest = ylookup[ds_y] + columnofs[ds_x1]; //dest = ylookup[ds->y] + columnofs[ds->x1];
dest = &topleft[ds_y *vid.width + ds_x1]; dest = &topleft[ds->y *vid.width + ds->x1];
count = ds_x2 - ds_x1 + 1; count = ds->x2 - ds->x1 + 1;
while (count >= 4) while (count >= 4)
{ {
...@@ -2037,33 +1974,33 @@ void R_DrawFogSpan_8(void) ...@@ -2037,33 +1974,33 @@ void R_DrawFogSpan_8(void)
/** \brief The R_DrawFogColumn_8 function /** \brief The R_DrawFogColumn_8 function
Fog wall. Fog wall.
*/ */
void R_DrawFogColumn_8(void) void R_DrawFogColumn_8(colcontext_t *dc)
{ {
INT32 count; INT32 count;
UINT8 *dest; UINT8 *dest;
count = dc_yh - dc_yl; count = dc->yh - dc->yl;
// Zero length, column does not exceed a pixel. // Zero length, column does not exceed a pixel.
if (count < 0) if (count < 0)
return; return;
#ifdef RANGECHECK #ifdef RANGECHECK
if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
I_Error("R_DrawFogColumn_8: %d to %d at %d", dc_yl, dc_yh, dc_x); I_Error("R_DrawFogColumn_8: %d to %d at %d", dc->yl, dc->yh, dc->x);
#endif #endif
// Framebuffer destination address. // Framebuffer destination address.
// Use ylookup LUT to avoid multiply with ScreenWidth. // Use ylookup LUT to avoid multiply with ScreenWidth.
// Use columnofs LUT for subwindows? // Use columnofs LUT for subwindows?
//dest = ylookup[dc_yl] + columnofs[dc_x]; //dest = ylookup[dc->yl] + columnofs[dc->x];
dest = &topleft[dc_yl*vid.width + dc_x]; dest = &topleft[dc->yl*vid.width + dc->x];
// Determine scaling, which is the only mapping to be done. // Determine scaling, which is the only mapping to be done.
do do
{ {
// Simple. Apply the colormap to what's already on the screen. // Simple. Apply the colormap to what's already on the screen.
*dest = dc_colormap[*dest]; *dest = dc->colormap[*dest];
dest += vid.width; dest += vid.width;
} while (count--); } while (count--);
} }
...@@ -2073,34 +2010,32 @@ void R_DrawFogColumn_8(void) ...@@ -2073,34 +2010,32 @@ void R_DrawFogColumn_8(void)
This function just cuts the column up into sections and calls R_DrawColumn_8 This function just cuts the column up into sections and calls R_DrawColumn_8
*/ */
void R_DrawColumnShadowed_8(void) void R_DrawColumnShadowed_8(colcontext_t *dc)
{ {
INT32 count, realyh, i, height, bheight = 0, solid = 0; INT32 i, height, bheight = 0, solid = 0;
INT32 realyh = dc->yh;
realyh = dc_yh; INT32 count = dc->yh - dc->yl;
count = dc_yh - dc_yl;
// Zero length, column does not exceed a pixel. // Zero length, column does not exceed a pixel.
if (count < 0) if (count < 0)
return; return;
#ifdef RANGECHECK #ifdef RANGECHECK
if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) if ((unsigned)dc->x >= (unsigned)vid.width || dc->yl < 0 || dc->yh >= vid.height)
I_Error("R_DrawColumnShadowed_8: %d to %d at %d", dc_yl, dc_yh, dc_x); I_Error("R_DrawColumnShadowed_8: %d to %d at %d", dc->yl, dc->yh, dc->x);
#endif #endif
// This runs through the lightlist from top to bottom and cuts up the column accordingly. // This runs through the lightlist from top to bottom and cuts up the column accordingly.
for (i = 0; i < dc_numlights; i++) for (i = 0; i < dc->numlights; i++)
{ {
// If the height of the light is above the column, get the colormap // If the height of the light is above the column, get the colormap
// anyway because the lighting of the top should be affected. // anyway because the lighting of the top should be affected.
solid = dc_lightlist[i].flags & FF_CUTSOLIDS; solid = dc->lightlist[i].flags & FF_CUTSOLIDS;
height = dc_lightlist[i].height >> LIGHTSCALESHIFT; height = dc->lightlist[i].height >> LIGHTSCALESHIFT;
if (solid) if (solid)
{ {
bheight = dc_lightlist[i].botheight >> LIGHTSCALESHIFT; bheight = dc->lightlist[i].botheight >> LIGHTSCALESHIFT;
if (bheight < height) if (bheight < height)
{ {
// confounded slopes sometimes allow partial invertedness, // confounded slopes sometimes allow partial invertedness,
...@@ -2112,27 +2047,28 @@ void R_DrawColumnShadowed_8(void) ...@@ -2112,27 +2047,28 @@ void R_DrawColumnShadowed_8(void)
bheight = temp; bheight = temp;
} }
} }
if (height <= dc_yl) if (height <= dc->yl)
{ {
dc_colormap = dc_lightlist[i].rcolormap; dc->colormap = dc->lightlist[i].rcolormap;
if (solid && dc_yl < bheight) if (solid && dc->yl < bheight)
dc_yl = bheight; dc->yl = bheight;
continue; continue;
} }
// Found a break in the column! // Found a break in the column!
dc_yh = height; dc->yh = height;
if (dc_yh > realyh) if (dc->yh > realyh)
dc_yh = realyh; dc->yh = realyh;
(colfuncs[BASEDRAWFUNC])(); // R_DrawColumn_8 for the appropriate architecture (colfuncs[BASEDRAWFUNC])(dc); // R_DrawColumn_8 for the appropriate architecture
if (solid) if (solid)
dc_yl = bheight; dc->yl = bheight;
else else
dc_yl = dc_yh + 1; dc->yl = dc->yh + 1;
dc_colormap = dc_lightlist[i].rcolormap; dc->colormap = dc->lightlist[i].rcolormap;
} }
dc_yh = realyh;
if (dc_yl <= realyh) dc->yh = realyh;
(colfuncs[BASEDRAWFUNC])(); // R_DrawWallColumn_8 for the appropriate architecture if (dc->yl <= realyh)
(colfuncs[BASEDRAWFUNC])(dc); // R_DrawColumn_8 for the appropriate architecture
} }
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
/** \brief The R_DrawSpan_NPO2_8 function /** \brief The R_DrawSpan_NPO2_8 function
Draws the actual span. Draws the actual span.
*/ */
void R_DrawSpan_NPO2_8 (void) void R_DrawSpan_NPO2_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -34,20 +34,20 @@ void R_DrawSpan_NPO2_8 (void) ...@@ -34,20 +34,20 @@ void R_DrawSpan_NPO2_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
if (dest+8 > deststop) if (dest+8 > deststop)
return; return;
fixedwidth = ds_flatwidth << FRACBITS; fixedwidth = ds->flatwidth << FRACBITS;
fixedheight = ds_flatheight << FRACBITS; fixedheight = ds->flatheight << FRACBITS;
// Fix xposition and yposition if they are out of bounds. // Fix xposition and yposition if they are out of bounds.
if (xposition < 0) if (xposition < 0)
...@@ -80,7 +80,7 @@ void R_DrawSpan_NPO2_8 (void) ...@@ -80,7 +80,7 @@ void R_DrawSpan_NPO2_8 (void)
x = (xposition >> FRACBITS); x = (xposition >> FRACBITS);
y = (yposition >> FRACBITS); y = (yposition >> FRACBITS);
*dest++ = colormap[source[((y * ds_flatwidth) + x)]]; *dest++ = colormap[source[((y * ds->flatwidth) + x)]];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
} }
...@@ -89,10 +89,10 @@ void R_DrawSpan_NPO2_8 (void) ...@@ -89,10 +89,10 @@ void R_DrawSpan_NPO2_8 (void)
/** \brief The R_DrawTiltedSpan_NPO2_8 function /** \brief The R_DrawTiltedSpan_NPO2_8 function
Draw slopes! Holy sheit! Draw slopes! Holy sheit!
*/ */
void R_DrawTiltedSpan_NPO2_8(void) void R_DrawTiltedSpan_NPO2_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -106,29 +106,19 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -106,29 +106,19 @@ void R_DrawTiltedSpan_NPO2_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
struct libdivide_u32_t x_divider = libdivide_u32_gen(ds_flatwidth); struct libdivide_u32_t x_divider = libdivide_u32_gen(ds->flatwidth);
struct libdivide_u32_t y_divider = libdivide_u32_gen(ds_flatheight); struct libdivide_u32_t y_divider = libdivide_u32_gen(ds->flatheight);
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end CALC_TILTED_LIGHTING
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds_szp->x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
}
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
source = ds_source; source = ds->source;
//colormap = ds_colormap; //colormap = ds->colormap;
#if 0 // The "perfect" reference version of this routine. Pretty slow. #if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look. // Use it only to see how things are supposed to look.
...@@ -139,7 +129,7 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -139,7 +129,7 @@ void R_DrawTiltedSpan_NPO2_8(void)
u = (INT64)(uz*z); u = (INT64)(uz*z);
v = (INT64)(vz*z); v = (INT64)(vz*z);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
...@@ -148,29 +138,29 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -148,29 +138,29 @@ void R_DrawTiltedSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = colormap[source[((y * ds_flatwidth) + x)]]; *dest = colormap[source[((y * ds->flatwidth) + x)]];
} }
dest++; dest++;
iz += ds_szp->x; iz += ds->szp->x;
uz += ds_sup->x; uz += ds->sup->x;
vz += ds_svp->x; vz += ds->svp->x;
} while (--width >= 0); } while (--width >= 0);
#else #else
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -190,7 +180,7 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -190,7 +180,7 @@ void R_DrawTiltedSpan_NPO2_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -198,15 +188,15 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -198,15 +188,15 @@ void R_DrawTiltedSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = colormap[source[((y * ds_flatwidth) + x)]]; *dest = colormap[source[((y * ds->flatwidth) + x)]];
} }
dest++; dest++;
u += stepu; u += stepu;
...@@ -222,7 +212,7 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -222,7 +212,7 @@ void R_DrawTiltedSpan_NPO2_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -230,23 +220,23 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -230,23 +220,23 @@ void R_DrawTiltedSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = colormap[source[((y * ds_flatwidth) + x)]]; *dest = colormap[source[((y * ds->flatwidth) + x)]];
} }
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -259,7 +249,7 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -259,7 +249,7 @@ void R_DrawTiltedSpan_NPO2_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -267,15 +257,15 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -267,15 +257,15 @@ void R_DrawTiltedSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = colormap[source[((y * ds_flatwidth) + x)]]; *dest = colormap[source[((y * ds->flatwidth) + x)]];
} }
dest++; dest++;
u += stepu; u += stepu;
...@@ -289,10 +279,10 @@ void R_DrawTiltedSpan_NPO2_8(void) ...@@ -289,10 +279,10 @@ void R_DrawTiltedSpan_NPO2_8(void)
/** \brief The R_DrawTiltedTranslucentSpan_NPO2_8 function /** \brief The R_DrawTiltedTranslucentSpan_NPO2_8 function
Like DrawTiltedSpan_NPO2, but translucent Like DrawTiltedSpan_NPO2, but translucent
*/ */
void R_DrawTiltedTranslucentSpan_NPO2_8(void) void R_DrawTiltedTranslucentSpan_NPO2_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -306,29 +296,19 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -306,29 +296,19 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
struct libdivide_u32_t x_divider = libdivide_u32_gen(ds_flatwidth); struct libdivide_u32_t x_divider = libdivide_u32_gen(ds->flatwidth);
struct libdivide_u32_t y_divider = libdivide_u32_gen(ds_flatheight); struct libdivide_u32_t y_divider = libdivide_u32_gen(ds->flatheight);
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end CALC_TILTED_LIGHTING
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds_szp->x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
}
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
source = ds_source; source = ds->source;
//colormap = ds_colormap; //colormap = ds->colormap;
#if 0 // The "perfect" reference version of this routine. Pretty slow. #if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look. // Use it only to see how things are supposed to look.
...@@ -339,7 +319,7 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -339,7 +319,7 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
u = (INT64)(uz*z); u = (INT64)(uz*z);
v = (INT64)(vz*z); v = (INT64)(vz*z);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -347,29 +327,29 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -347,29 +327,29 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[((y * ds->flatwidth) + x)]] << 8) + *dest);
} }
dest++; dest++;
iz += ds_szp->x; iz += ds->szp->x;
uz += ds_sup->x; uz += ds->sup->x;
vz += ds_svp->x; vz += ds->svp->x;
} while (--width >= 0); } while (--width >= 0);
#else #else
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -389,7 +369,7 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -389,7 +369,7 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -397,15 +377,15 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -397,15 +377,15 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[((y * ds->flatwidth) + x)]] << 8) + *dest);
} }
dest++; dest++;
u += stepu; u += stepu;
...@@ -421,7 +401,7 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -421,7 +401,7 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -429,23 +409,23 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -429,23 +409,23 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[((y * ds->flatwidth) + x)]] << 8) + *dest);
} }
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -458,7 +438,7 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -458,7 +438,7 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -466,15 +446,15 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -466,15 +446,15 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[((y * ds->flatwidth) + x)]] << 8) + *dest);
} }
dest++; dest++;
u += stepu; u += stepu;
...@@ -485,10 +465,10 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void) ...@@ -485,10 +465,10 @@ void R_DrawTiltedTranslucentSpan_NPO2_8(void)
#endif #endif
} }
void R_DrawTiltedSplat_NPO2_8(void) void R_DrawTiltedSplat_NPO2_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -504,29 +484,19 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -504,29 +484,19 @@ void R_DrawTiltedSplat_NPO2_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
struct libdivide_u32_t x_divider = libdivide_u32_gen(ds_flatwidth); struct libdivide_u32_t x_divider = libdivide_u32_gen(ds->flatwidth);
struct libdivide_u32_t y_divider = libdivide_u32_gen(ds_flatheight); struct libdivide_u32_t y_divider = libdivide_u32_gen(ds->flatheight);
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end CALC_TILTED_LIGHTING
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds_szp->x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
}
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
source = ds_source; source = ds->source;
//colormap = ds_colormap; //colormap = ds->colormap;
#if 0 // The "perfect" reference version of this routine. Pretty slow. #if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look. // Use it only to see how things are supposed to look.
...@@ -537,7 +507,7 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -537,7 +507,7 @@ void R_DrawTiltedSplat_NPO2_8(void)
u = (INT64)(uz*z); u = (INT64)(uz*z);
v = (INT64)(vz*z); v = (INT64)(vz*z);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
...@@ -546,33 +516,33 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -546,33 +516,33 @@ void R_DrawTiltedSplat_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
} }
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
dest++; dest++;
iz += ds_szp->x; iz += ds->szp->x;
uz += ds_sup->x; uz += ds->sup->x;
vz += ds_svp->x; vz += ds->svp->x;
} while (--width >= 0); } while (--width >= 0);
#else #else
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -592,7 +562,7 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -592,7 +562,7 @@ void R_DrawTiltedSplat_NPO2_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -600,15 +570,15 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -600,15 +570,15 @@ void R_DrawTiltedSplat_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
} }
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
...@@ -626,7 +596,7 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -626,7 +596,7 @@ void R_DrawTiltedSplat_NPO2_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -634,15 +604,15 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -634,15 +604,15 @@ void R_DrawTiltedSplat_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
} }
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
...@@ -650,9 +620,9 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -650,9 +620,9 @@ void R_DrawTiltedSplat_NPO2_8(void)
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -665,8 +635,7 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -665,8 +635,7 @@ void R_DrawTiltedSplat_NPO2_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
val = source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)];
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -674,15 +643,15 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -674,15 +643,15 @@ void R_DrawTiltedSplat_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
} }
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
...@@ -698,7 +667,7 @@ void R_DrawTiltedSplat_NPO2_8(void) ...@@ -698,7 +667,7 @@ void R_DrawTiltedSplat_NPO2_8(void)
/** \brief The R_DrawSplat_NPO2_8 function /** \brief The R_DrawSplat_NPO2_8 function
Just like R_DrawSpan_NPO2_8, but skips transparent pixels. Just like R_DrawSpan_NPO2_8, but skips transparent pixels.
*/ */
void R_DrawSplat_NPO2_8 (void) void R_DrawSplat_NPO2_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -711,18 +680,18 @@ void R_DrawSplat_NPO2_8 (void) ...@@ -711,18 +680,18 @@ void R_DrawSplat_NPO2_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
fixedwidth = ds_flatwidth << FRACBITS; fixedwidth = ds->flatwidth << FRACBITS;
fixedheight = ds_flatheight << FRACBITS; fixedheight = ds->flatheight << FRACBITS;
// Fix xposition and yposition if they are out of bounds. // Fix xposition and yposition if they are out of bounds.
if (xposition < 0) if (xposition < 0)
...@@ -754,7 +723,7 @@ void R_DrawSplat_NPO2_8 (void) ...@@ -754,7 +723,7 @@ void R_DrawSplat_NPO2_8 (void)
x = (xposition >> FRACBITS); x = (xposition >> FRACBITS);
y = (yposition >> FRACBITS); y = (yposition >> FRACBITS);
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = colormap[val]; *dest = colormap[val];
dest++; dest++;
...@@ -766,7 +735,7 @@ void R_DrawSplat_NPO2_8 (void) ...@@ -766,7 +735,7 @@ void R_DrawSplat_NPO2_8 (void)
/** \brief The R_DrawTranslucentSplat_NPO2_8 function /** \brief The R_DrawTranslucentSplat_NPO2_8 function
Just like R_DrawSplat_NPO2_8, but is translucent! Just like R_DrawSplat_NPO2_8, but is translucent!
*/ */
void R_DrawTranslucentSplat_NPO2_8 (void) void R_DrawTranslucentSplat_NPO2_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -779,18 +748,18 @@ void R_DrawTranslucentSplat_NPO2_8 (void) ...@@ -779,18 +748,18 @@ void R_DrawTranslucentSplat_NPO2_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
fixedwidth = ds_flatwidth << FRACBITS; fixedwidth = ds->flatwidth << FRACBITS;
fixedheight = ds_flatheight << FRACBITS; fixedheight = ds->flatheight << FRACBITS;
// Fix xposition and yposition if they are out of bounds. // Fix xposition and yposition if they are out of bounds.
if (xposition < 0) if (xposition < 0)
...@@ -822,9 +791,9 @@ void R_DrawTranslucentSplat_NPO2_8 (void) ...@@ -822,9 +791,9 @@ void R_DrawTranslucentSplat_NPO2_8 (void)
x = (xposition >> FRACBITS); x = (xposition >> FRACBITS);
y = (yposition >> FRACBITS); y = (yposition >> FRACBITS);
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val != TRANSPARENTPIXEL) if (val != TRANSPARENTPIXEL)
*dest = *(ds_transmap + (colormap[val] << 8) + *dest); *dest = *(ds->transmap + (colormap[val] << 8) + *dest);
dest++; dest++;
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
...@@ -834,7 +803,7 @@ void R_DrawTranslucentSplat_NPO2_8 (void) ...@@ -834,7 +803,7 @@ void R_DrawTranslucentSplat_NPO2_8 (void)
/** \brief The R_DrawFloorSprite_NPO2_8 function /** \brief The R_DrawFloorSprite_NPO2_8 function
Just like R_DrawSplat_NPO2_8, but for floor sprites. Just like R_DrawSplat_NPO2_8, but for floor sprites.
*/ */
void R_DrawFloorSprite_NPO2_8 (void) void R_DrawFloorSprite_NPO2_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -848,19 +817,19 @@ void R_DrawFloorSprite_NPO2_8 (void) ...@@ -848,19 +817,19 @@ void R_DrawFloorSprite_NPO2_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
source = (UINT16 *)ds_source; source = (UINT16 *)ds->source;
colormap = ds_colormap; colormap = ds->colormap;
translation = ds_translation; translation = ds->translation;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
fixedwidth = ds_flatwidth << FRACBITS; fixedwidth = ds->flatwidth << FRACBITS;
fixedheight = ds_flatheight << FRACBITS; fixedheight = ds->flatheight << FRACBITS;
// Fix xposition and yposition if they are out of bounds. // Fix xposition and yposition if they are out of bounds.
if (xposition < 0) if (xposition < 0)
...@@ -892,7 +861,7 @@ void R_DrawFloorSprite_NPO2_8 (void) ...@@ -892,7 +861,7 @@ void R_DrawFloorSprite_NPO2_8 (void)
x = (xposition >> FRACBITS); x = (xposition >> FRACBITS);
y = (yposition >> FRACBITS); y = (yposition >> FRACBITS);
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = colormap[translation[val & 0xFF]]; *dest = colormap[translation[val & 0xFF]];
dest++; dest++;
...@@ -904,7 +873,7 @@ void R_DrawFloorSprite_NPO2_8 (void) ...@@ -904,7 +873,7 @@ void R_DrawFloorSprite_NPO2_8 (void)
/** \brief The R_DrawTranslucentFloorSprite_NPO2_8 function /** \brief The R_DrawTranslucentFloorSprite_NPO2_8 function
Just like R_DrawFloorSprite_NPO2_8, but is translucent! Just like R_DrawFloorSprite_NPO2_8, but is translucent!
*/ */
void R_DrawTranslucentFloorSprite_NPO2_8 (void) void R_DrawTranslucentFloorSprite_NPO2_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -918,19 +887,19 @@ void R_DrawTranslucentFloorSprite_NPO2_8 (void) ...@@ -918,19 +887,19 @@ void R_DrawTranslucentFloorSprite_NPO2_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
source = (UINT16 *)ds_source; source = (UINT16 *)ds->source;
colormap = ds_colormap; colormap = ds->colormap;
translation = ds_translation; translation = ds->translation;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
fixedwidth = ds_flatwidth << FRACBITS; fixedwidth = ds->flatwidth << FRACBITS;
fixedheight = ds_flatheight << FRACBITS; fixedheight = ds->flatheight << FRACBITS;
// Fix xposition and yposition if they are out of bounds. // Fix xposition and yposition if they are out of bounds.
if (xposition < 0) if (xposition < 0)
...@@ -962,9 +931,9 @@ void R_DrawTranslucentFloorSprite_NPO2_8 (void) ...@@ -962,9 +931,9 @@ void R_DrawTranslucentFloorSprite_NPO2_8 (void)
x = (xposition >> FRACBITS); x = (xposition >> FRACBITS);
y = (yposition >> FRACBITS); y = (yposition >> FRACBITS);
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + *dest); *dest = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + *dest);
dest++; dest++;
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
...@@ -974,10 +943,10 @@ void R_DrawTranslucentFloorSprite_NPO2_8 (void) ...@@ -974,10 +943,10 @@ void R_DrawTranslucentFloorSprite_NPO2_8 (void)
/** \brief The R_DrawTiltedFloorSprite_NPO2_8 function /** \brief The R_DrawTiltedFloorSprite_NPO2_8 function
Draws a tilted floor sprite. Draws a tilted floor sprite.
*/ */
void R_DrawTiltedFloorSprite_NPO2_8(void) void R_DrawTiltedFloorSprite_NPO2_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -993,22 +962,22 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) ...@@ -993,22 +962,22 @@ void R_DrawTiltedFloorSprite_NPO2_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
source = (UINT16 *)ds_source; source = (UINT16 *)ds->source;
colormap = ds_colormap; colormap = ds->colormap;
translation = ds_translation; translation = ds->translation;
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -1034,14 +1003,14 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) ...@@ -1034,14 +1003,14 @@ void R_DrawTiltedFloorSprite_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); x = ds->flatwidth - ((UINT32)(ds->flatwidth - x) % ds->flatwidth);
if (y < 0) if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); y = ds->flatheight - ((UINT32)(ds->flatheight - y) % ds->flatheight);
x %= ds_flatwidth; x %= ds->flatwidth;
y %= ds_flatheight; y %= ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = colormap[translation[val & 0xFF]]; *dest = colormap[translation[val & 0xFF]];
dest++; dest++;
...@@ -1066,14 +1035,14 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) ...@@ -1066,14 +1035,14 @@ void R_DrawTiltedFloorSprite_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); x = ds->flatwidth - ((UINT32)(ds->flatwidth - x) % ds->flatwidth);
if (y < 0) if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); y = ds->flatheight - ((UINT32)(ds->flatheight - y) % ds->flatheight);
x %= ds_flatwidth; x %= ds->flatwidth;
y %= ds_flatheight; y %= ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = colormap[translation[val & 0xFF]]; *dest = colormap[translation[val & 0xFF]];
} }
...@@ -1081,9 +1050,9 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) ...@@ -1081,9 +1050,9 @@ void R_DrawTiltedFloorSprite_NPO2_8(void)
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -1102,14 +1071,14 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) ...@@ -1102,14 +1071,14 @@ void R_DrawTiltedFloorSprite_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); x = ds->flatwidth - ((UINT32)(ds->flatwidth - x) % ds->flatwidth);
if (y < 0) if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); y = ds->flatheight - ((UINT32)(ds->flatheight - y) % ds->flatheight);
x %= ds_flatwidth; x %= ds->flatwidth;
y %= ds_flatheight; y %= ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = colormap[translation[val & 0xFF]]; *dest = colormap[translation[val & 0xFF]];
dest++; dest++;
...@@ -1124,10 +1093,10 @@ void R_DrawTiltedFloorSprite_NPO2_8(void) ...@@ -1124,10 +1093,10 @@ void R_DrawTiltedFloorSprite_NPO2_8(void)
/** \brief The R_DrawTiltedTranslucentFloorSprite_NPO2_8 function /** \brief The R_DrawTiltedTranslucentFloorSprite_NPO2_8 function
Draws a tilted, translucent, floor sprite. Draws a tilted, translucent, floor sprite.
*/ */
void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) void R_DrawTiltedTranslucentFloorSprite_NPO2_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -1143,22 +1112,22 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) ...@@ -1143,22 +1112,22 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
source = (UINT16 *)ds_source; source = (UINT16 *)ds->source;
colormap = ds_colormap; colormap = ds->colormap;
translation = ds_translation; translation = ds->translation;
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -1184,16 +1153,16 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) ...@@ -1184,16 +1153,16 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); x = ds->flatwidth - ((UINT32)(ds->flatwidth - x) % ds->flatwidth);
if (y < 0) if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); y = ds->flatheight - ((UINT32)(ds->flatheight - y) % ds->flatheight);
x %= ds_flatwidth; x %= ds->flatwidth;
y %= ds_flatheight; y %= ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + *dest); *dest = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + *dest);
dest++; dest++;
u += stepu; u += stepu;
...@@ -1216,24 +1185,24 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) ...@@ -1216,24 +1185,24 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); x = ds->flatwidth - ((UINT32)(ds->flatwidth - x) % ds->flatwidth);
if (y < 0) if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); y = ds->flatheight - ((UINT32)(ds->flatheight - y) % ds->flatheight);
x %= ds_flatwidth; x %= ds->flatwidth;
y %= ds_flatheight; y %= ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + *dest); *dest = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + *dest);
} }
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -1252,16 +1221,16 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) ...@@ -1252,16 +1221,16 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x = ds_flatwidth - ((UINT32)(ds_flatwidth - x) % ds_flatwidth); x = ds->flatwidth - ((UINT32)(ds->flatwidth - x) % ds->flatwidth);
if (y < 0) if (y < 0)
y = ds_flatheight - ((UINT32)(ds_flatheight - y) % ds_flatheight); y = ds->flatheight - ((UINT32)(ds->flatheight - y) % ds->flatheight);
x %= ds_flatwidth; x %= ds->flatwidth;
y %= ds_flatheight; y %= ds->flatheight;
val = source[((y * ds_flatwidth) + x)]; val = source[((y * ds->flatwidth) + x)];
if (val & 0xFF00) if (val & 0xFF00)
*dest = *(ds_transmap + (colormap[translation[val & 0xFF]] << 8) + *dest); *dest = *(ds->transmap + (colormap[translation[val & 0xFF]] << 8) + *dest);
dest++; dest++;
u += stepu; u += stepu;
...@@ -1274,7 +1243,7 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void) ...@@ -1274,7 +1243,7 @@ void R_DrawTiltedTranslucentFloorSprite_NPO2_8(void)
/** \brief The R_DrawTranslucentSpan_NPO2_8 function /** \brief The R_DrawTranslucentSpan_NPO2_8 function
Draws the actual span with translucency. Draws the actual span with translucency.
*/ */
void R_DrawTranslucentSpan_NPO2_8 (void) void R_DrawTranslucentSpan_NPO2_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -1287,18 +1256,18 @@ void R_DrawTranslucentSpan_NPO2_8 (void) ...@@ -1287,18 +1256,18 @@ void R_DrawTranslucentSpan_NPO2_8 (void)
UINT8 *dest; UINT8 *dest;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
UINT32 val; UINT32 val;
xposition = ds_xfrac; yposition = ds_yfrac; xposition = ds->xfrac; yposition = ds->yfrac;
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
fixedwidth = ds_flatwidth << FRACBITS; fixedwidth = ds->flatwidth << FRACBITS;
fixedheight = ds_flatheight << FRACBITS; fixedheight = ds->flatheight << FRACBITS;
// Fix xposition and yposition if they are out of bounds. // Fix xposition and yposition if they are out of bounds.
if (xposition < 0) if (xposition < 0)
...@@ -1330,15 +1299,15 @@ void R_DrawTranslucentSpan_NPO2_8 (void) ...@@ -1330,15 +1299,15 @@ void R_DrawTranslucentSpan_NPO2_8 (void)
x = (xposition >> FRACBITS); x = (xposition >> FRACBITS);
y = (yposition >> FRACBITS); y = (yposition >> FRACBITS);
val = ((y * ds_flatwidth) + x); val = ((y * ds->flatwidth) + x);
*dest = *(ds_transmap + (colormap[source[val]] << 8) + *dest); *dest = *(ds->transmap + (colormap[source[val]] << 8) + *dest);
dest++; dest++;
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
} }
} }
void R_DrawTranslucentWaterSpan_NPO2_8(void) void R_DrawTranslucentWaterSpan_NPO2_8(spancontext_t *ds)
{ {
fixed_t xposition; fixed_t xposition;
fixed_t yposition; fixed_t yposition;
...@@ -1352,18 +1321,18 @@ void R_DrawTranslucentWaterSpan_NPO2_8(void) ...@@ -1352,18 +1321,18 @@ void R_DrawTranslucentWaterSpan_NPO2_8(void)
UINT8 *dsrc; UINT8 *dsrc;
const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height;
size_t count = (ds_x2 - ds_x1 + 1); size_t count = (ds->x2 - ds->x1 + 1);
xposition = ds_xfrac; yposition = (ds_yfrac + ds_waterofs); xposition = ds->xfrac; yposition = (ds->yfrac + ds->waterofs);
xstep = ds_xstep; ystep = ds_ystep; xstep = ds->xstep; ystep = ds->ystep;
source = ds_source; source = ds->source;
colormap = ds_colormap; colormap = ds->colormap;
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1; dsrc = screens[1] + (ds->y+ds->bgofs)*vid.width + ds->x1;
fixedwidth = ds_flatwidth << FRACBITS; fixedwidth = ds->flatwidth << FRACBITS;
fixedheight = ds_flatheight << FRACBITS; fixedheight = ds->flatheight << FRACBITS;
// Fix xposition and yposition if they are out of bounds. // Fix xposition and yposition if they are out of bounds.
if (xposition < 0) if (xposition < 0)
...@@ -1395,7 +1364,7 @@ void R_DrawTranslucentWaterSpan_NPO2_8(void) ...@@ -1395,7 +1364,7 @@ void R_DrawTranslucentWaterSpan_NPO2_8(void)
x = (xposition >> FRACBITS); x = (xposition >> FRACBITS);
y = (yposition >> FRACBITS); y = (yposition >> FRACBITS);
*dest++ = colormap[*(ds_transmap + (source[((y * ds_flatwidth) + x)] << 8) + *dsrc++)]; *dest++ = colormap[*(ds->transmap + (source[((y * ds->flatwidth) + x)] << 8) + *dsrc++)];
xposition += xstep; xposition += xstep;
yposition += ystep; yposition += ystep;
} }
...@@ -1404,10 +1373,10 @@ void R_DrawTranslucentWaterSpan_NPO2_8(void) ...@@ -1404,10 +1373,10 @@ void R_DrawTranslucentWaterSpan_NPO2_8(void)
/** \brief The R_DrawTiltedTranslucentWaterSpan_NPO2_8 function /** \brief The R_DrawTiltedTranslucentWaterSpan_NPO2_8 function
Like DrawTiltedTranslucentSpan_NPO2, but for water Like DrawTiltedTranslucentSpan_NPO2, but for water
*/ */
void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) void R_DrawTiltedTranslucentWaterSpan_NPO2_8(spancontext_t *ds)
{ {
// x1, x2 = ds_x1, ds_x2 // x1, x2 = ds->x1, ds->x2
int width = ds_x2 - ds_x1; int width = ds->x2 - ds->x1;
double iz, uz, vz; double iz, uz, vz;
UINT32 u, v; UINT32 u, v;
int i; int i;
...@@ -1422,30 +1391,20 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) ...@@ -1422,30 +1391,20 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void)
double endz, endu, endv; double endz, endu, endv;
UINT32 stepu, stepv; UINT32 stepu, stepv;
struct libdivide_u32_t x_divider = libdivide_u32_gen(ds_flatwidth); struct libdivide_u32_t x_divider = libdivide_u32_gen(ds->flatwidth);
struct libdivide_u32_t y_divider = libdivide_u32_gen(ds_flatheight); struct libdivide_u32_t y_divider = libdivide_u32_gen(ds->flatheight);
iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); iz = ds->szp->z + ds->szp->y*(centery-ds->y) + ds->szp->x*(ds->x1-centerx);
// Lighting is simple. It's just linear interpolation from start to end CALC_TILTED_LIGHTING
{
float planelightfloat = PLANELIGHTFLOAT;
float lightstart, lightend;
lightend = (iz + ds_szp->x*width) * planelightfloat;
lightstart = iz * planelightfloat;
R_CalcTiltedLighting(FLOAT_TO_FIXED(lightstart), FLOAT_TO_FIXED(lightend));
//CONS_Printf("tilted lighting %f to %f (foc %f)\n", lightstart, lightend, focallengthf);
}
uz = ds_sup->z + ds_sup->y*(centery-ds_y) + ds_sup->x*(ds_x1-centerx); uz = ds->sup->z + ds->sup->y*(centery-ds->y) + ds->sup->x*(ds->x1-centerx);
vz = ds_svp->z + ds_svp->y*(centery-ds_y) + ds_svp->x*(ds_x1-centerx); vz = ds->svp->z + ds->svp->y*(centery-ds->y) + ds->svp->x*(ds->x1-centerx);
dest = ylookup[ds_y] + columnofs[ds_x1]; dest = ylookup[ds->y] + columnofs[ds->x1];
dsrc = screens[1] + (ds_y+ds_bgofs)*vid.width + ds_x1; dsrc = screens[1] + (ds->y+ds->bgofs)*vid.width + ds->x1;
source = ds_source; source = ds->source;
//colormap = ds_colormap; //colormap = ds->colormap;
#if 0 // The "perfect" reference version of this routine. Pretty slow. #if 0 // The "perfect" reference version of this routine. Pretty slow.
// Use it only to see how things are supposed to look. // Use it only to see how things are supposed to look.
...@@ -1456,7 +1415,7 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) ...@@ -1456,7 +1415,7 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void)
u = (INT64)(uz*z); u = (INT64)(uz*z);
v = (INT64)(vz*z); v = (INT64)(vz*z);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -1464,29 +1423,29 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) ...@@ -1464,29 +1423,29 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dsrc++); *dest = *(ds->transmap + (colormap[source[((y * ds->flatwidth) + x)]] << 8) + *dsrc++);
} }
dest++; dest++;
iz += ds_szp->x; iz += ds->szp->x;
uz += ds_sup->x; uz += ds->sup->x;
vz += ds_svp->x; vz += ds->svp->x;
} while (--width >= 0); } while (--width >= 0);
#else #else
startz = 1.f/iz; startz = 1.f/iz;
startu = uz*startz; startu = uz*startz;
startv = vz*startz; startv = vz*startz;
izstep = ds_szp->x * SPANSIZE; izstep = ds->szp->x * SPANSIZE;
uzstep = ds_sup->x * SPANSIZE; uzstep = ds->sup->x * SPANSIZE;
vzstep = ds_svp->x * SPANSIZE; vzstep = ds->svp->x * SPANSIZE;
//x1 = 0; //x1 = 0;
width++; width++;
...@@ -1506,7 +1465,7 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) ...@@ -1506,7 +1465,7 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void)
for (i = SPANSIZE-1; i >= 0; i--) for (i = SPANSIZE-1; i >= 0; i--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -1514,15 +1473,15 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) ...@@ -1514,15 +1473,15 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dsrc++); *dest = *(ds->transmap + (colormap[source[((y * ds->flatwidth) + x)]] << 8) + *dsrc++);
} }
dest++; dest++;
u += stepu; u += stepu;
...@@ -1538,7 +1497,7 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) ...@@ -1538,7 +1497,7 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void)
{ {
u = (INT64)(startu); u = (INT64)(startu);
v = (INT64)(startv); v = (INT64)(startv);
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -1546,23 +1505,23 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) ...@@ -1546,23 +1505,23 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dsrc++); *dest = *(ds->transmap + (colormap[source[((y * ds->flatwidth) + x)]] << 8) + *dsrc++);
} }
} }
else else
{ {
double left = width; double left = width;
iz += ds_szp->x * left; iz += ds->szp->x * left;
uz += ds_sup->x * left; uz += ds->sup->x * left;
vz += ds_svp->x * left; vz += ds->svp->x * left;
endz = 1.f/iz; endz = 1.f/iz;
endu = uz*endz; endu = uz*endz;
...@@ -1575,7 +1534,7 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) ...@@ -1575,7 +1534,7 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void)
for (; width != 0; width--) for (; width != 0; width--)
{ {
colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); colormap = ds->zlight[ds->tiltlighting[ds->x1++]] + (ds->colormap - colormaps);
// Lactozilla: Non-powers-of-two // Lactozilla: Non-powers-of-two
{ {
fixed_t x = (((fixed_t)u) >> FRACBITS); fixed_t x = (((fixed_t)u) >> FRACBITS);
...@@ -1583,15 +1542,15 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void) ...@@ -1583,15 +1542,15 @@ void R_DrawTiltedTranslucentWaterSpan_NPO2_8(void)
// Carefully align all of my Friends. // Carefully align all of my Friends.
if (x < 0) if (x < 0)
x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds_flatwidth; x += (libdivide_u32_do((UINT32)(-x-1), &x_divider) + 1) * ds->flatwidth;
else else
x -= libdivide_u32_do((UINT32)x, &x_divider) * ds_flatwidth; x -= libdivide_u32_do((UINT32)x, &x_divider) * ds->flatwidth;
if (y < 0) if (y < 0)
y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds_flatheight; y += (libdivide_u32_do((UINT32)(-y-1), &y_divider) + 1) * ds->flatheight;
else else
y -= libdivide_u32_do((UINT32)y, &y_divider) * ds_flatheight; y -= libdivide_u32_do((UINT32)y, &y_divider) * ds->flatheight;
*dest = *(ds_transmap + (colormap[source[((y * ds_flatwidth) + x)]] << 8) + *dsrc++); *dest = *(ds->transmap + (colormap[source[((y * ds->flatwidth) + x)]] << 8) + *dsrc++);
} }
dest++; dest++;
u += stepu; u += stepu;
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
#include "r_textures.h" #include "r_textures.h"
#include "r_things.h" #include "r_things.h"
#include "r_draw.h" #include "r_draw.h"
#include "r_context.h"
extern drawseg_t *firstseg;
void SplitScreen_OnChange(void); void SplitScreen_OnChange(void);
......