From c4b3523f05f2c429d2902b10396c6553e3384f37 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 18 Mar 2021 12:49:33 +0100 Subject: [PATCH] - moving utilities to more appropriate places. --- source/core/gamefuncs.cpp | 32 +++++++++ source/core/gamefuncs.h | 60 +++++++++++++++++ source/core/rendering/render.cpp | 66 +------------------ source/core/rendering/render.h | 63 ------------------ .../core/rendering/scene/hw_bunchdrawer.cpp | 2 +- source/core/rendering/scene/hw_walls.cpp | 2 +- 6 files changed, 95 insertions(+), 130 deletions(-) diff --git a/source/core/gamefuncs.cpp b/source/core/gamefuncs.cpp index 9a8879a31..42373dda7 100644 --- a/source/core/gamefuncs.cpp +++ b/source/core/gamefuncs.cpp @@ -169,3 +169,35 @@ bool spriteIsModelOrVoxel(const spritetype * tspr) return (slabalign && voxmodels[tspr->picnum]); } +//========================================================================== +// +// note that this returns values in renderer coordinate space with inverted sign! +// +//========================================================================== + +void PlanesAtPoint(usectorptr_t sec, float dax, float day, float* pceilz, float* pflorz) +{ + float ceilz = float(sec->ceilingz); + float florz = float(sec->floorz); + + if (((sec->ceilingstat | sec->floorstat) & CSTAT_SECTOR_SLOPE) == CSTAT_SECTOR_SLOPE) + { + auto wal = &wall[sec->wallptr]; + auto wal2 = &wall[wal->point2]; + + float dx = wal2->x - wal->x; + float dy = wal2->y - wal->y; + + int i = (int)sqrt(dx * dx + dy * dy) << 5; // length of sector's first wall. + if (i != 0) + { + float const j = (dx * (day - wal->y) - dy * (dax - wal->x)) * (1.f / 8.f); + if (sec->ceilingstat & CSTAT_SECTOR_SLOPE) ceilz += (sec->ceilingheinum * j) / i; + if (sec->floorstat & CSTAT_SECTOR_SLOPE) florz += (sec->floorheinum * j) / i; + } + } + // Scale to render coordinates. + if (pceilz) *pceilz = ceilz * -(1.f / 256.f); + if (pflorz) *pflorz = florz * -(1.f / 256.f); +} + diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 8d118f788..0f390ccda 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -8,3 +8,63 @@ extern int cameradist, cameraclock; bool calcChaseCamPos(int* px, int* py, int* pz, spritetype* pspr, short *psectnum, binangle ang, fixedhoriz horiz, double const smoothratio); bool spriteIsModelOrVoxel(const spritetype* tspr); +void PlanesAtPoint(usectorptr_t sec, float dax, float day, float* ceilz, float* florz); + +// y is negated so that the orientation is the same as in GZDoom, in order to use its utilities. +// The render code should NOT use Build coordinates for anything! + +inline double WallStartX(int wallnum) +{ + return wall[wallnum].x * (1 / 16.); +} + +inline double WallStartY(int wallnum) +{ + return wall[wallnum].y * (1 / -16.); +} + +inline double WallEndX(int wallnum) +{ + return wall[wall[wallnum].point2].x * (1 / 16.); +} + +inline double WallEndY(int wallnum) +{ + return wall[wall[wallnum].point2].y * (1 / -16.); +} + +inline double WallStartX(const walltype* wallnum) +{ + return wallnum->x * (1 / 16.); +} + +inline double WallStartY(const walltype* wallnum) +{ + return wallnum->y * (1 / -16.); +} + +inline double WallEndX(const walltype* wallnum) +{ + return wall[wallnum->point2].x * (1 / 16.); +} + +inline double WallEndY(const walltype* wallnum) +{ + return wall[wallnum->point2].y * (1 / -16.); +} + +inline double SpriteX(int wallnum) +{ + return sprite[wallnum].x * (1 / 16.); +} + +inline double SpriteY(int wallnum) +{ + return sprite[wallnum].y * (1 / -16.); +} + +inline double PointOnLineSide(double x, double y, double linex, double liney, double deltax, double deltay) +{ + return (x - linex) * deltay - (y - liney) * deltax; +} + diff --git a/source/core/rendering/render.cpp b/source/core/rendering/render.cpp index f23437e54..d982b6dbe 100644 --- a/source/core/rendering/render.cpp +++ b/source/core/rendering/render.cpp @@ -13,6 +13,7 @@ #include "printf.h" #include "v_video.h" #include "flatvertices.h" +#include "gamefuncs.h" angle_t FrustumAngle(float ratio, float fov, float pitch) { @@ -30,71 +31,6 @@ angle_t FrustumAngle(float ratio, float fov, float pitch) return a1; } -//========================================================================== -// -// note that these return values in renderer coordinate space with inverted sign! -// -//========================================================================== - -float CeilingAtPoint(sectortype* sec, float dax, float day) -{ - if (!(sec->ceilingstat & CSTAT_SECTOR_SLOPE)) - return float(sec->ceilingz); - - auto wal = &wall[sec->wallptr]; - auto wal2 = &wall[wal->point2]; - - vec2_t d = { wal2->x - wal->x, wal2->y - wal->y }; - - int i = ksqrt(uhypsq(d.x, d.y)) << 5; - if (i == 0) return sec->ceilingz; - - float const j = (d.x * (day - wal->y) - d.y * (dax - wal->x)) * (1.f / 8.f); - return -float(sec->ceilingz) + (sec->ceilingheinum * j) / i; -} - -float FloorAtPoint(usectorptr_t sec, float dax, float day) -{ - if (!(sec->floorstat & CSTAT_SECTOR_SLOPE)) - return float(sec->floorz); - - auto wal = &wall[sec->wallptr]; - auto wal2 = &wall[wal->point2]; - - vec2_t d = { wal2->x - wal->x, wal2->y - wal->y }; - - int i = ksqrt(uhypsq(d.x, d.y)) << 5; - if (i == 0) return sec->floorz; - - float const j = (d.x * (day - wal->y) - d.y * (dax - wal->x)) * (1.f / 8.f); - return -float(sec->floorz) + (sec->floorheinum * j) / i; -} - -void PlanesAtPoint(usectorptr_t sec, float dax, float day, float* pceilz, float* pflorz) -{ - float ceilz = float(sec->ceilingz); - float florz = float(sec->floorz); - - if (((sec->ceilingstat | sec->floorstat) & CSTAT_SECTOR_SLOPE) == CSTAT_SECTOR_SLOPE) - { - auto wal = &wall[sec->wallptr]; - auto wal2 = &wall[wal->point2]; - - vec2_t d = { wal2->x - wal->x, wal2->y - wal->y }; - - int i = ksqrt(uhypsq(d.x, d.y)) << 5; - if (i != 0) - { - float const j = (d.x * (day - wal->y) - d.y * (dax - wal->x)) * (1.f / 8.f); - if (sec->ceilingstat & CSTAT_SECTOR_SLOPE) ceilz += (sec->ceilingheinum * j) / i; - if (sec->floorstat & CSTAT_SECTOR_SLOPE) florz += (sec->floorheinum * j) / i; - } - } - // Scale to render coordinates. - *pceilz = ceilz * -(1.f / 256.f); - *pflorz = florz * -(1.f / 256.f); -} - #define NS namespace Newrender { // auto-format blocking #define. NS diff --git a/source/core/rendering/render.h b/source/core/rendering/render.h index 192b55f98..b92958f07 100644 --- a/source/core/rendering/render.h +++ b/source/core/rendering/render.h @@ -1,68 +1,5 @@ #pragma once #include "build.h" - -// y is negated so that the orientation is the same as in GZDoom, in order to use its utilities. -// The render code should NOT use Build coordinates for anything! - -inline double WallStartX(int wallnum) -{ - return wall[wallnum].x * (1 / 16.); -} - -inline double WallStartY(int wallnum) -{ - return wall[wallnum].y * (1 / -16.); -} - -inline double WallEndX(int wallnum) -{ - return wall[wall[wallnum].point2].x * (1 / 16.); -} - -inline double WallEndY(int wallnum) -{ - return wall[wall[wallnum].point2].y * (1 / -16.); -} - -inline double WallStartX(const walltype* wallnum) -{ - return wallnum->x * (1 / 16.); -} - -inline double WallStartY(const walltype* wallnum) -{ - return wallnum->y * (1 / -16.); -} - -inline double WallEndX(const walltype* wallnum) -{ - return wall[wallnum->point2].x * (1 / 16.); -} - -inline double WallEndY(const walltype* wallnum) -{ - return wall[wallnum->point2].y * (1 / -16.); -} - -inline double SpriteX(int wallnum) -{ - return sprite[wallnum].x * (1 / 16.); -} - -inline double SpriteY(int wallnum) -{ - return sprite[wallnum].y * (1 / -16.); -} - -inline double PointOnLineSide(double x, double y, double linex, double liney, double deltax, double deltay) -{ - return (x - linex) * deltay - (y - liney) * deltax; -} - -float CeilingAtPoint(sectortype* sec, float dax, float day); -float FloorAtPoint(usectorptr_t sec, float dax, float day); -void PlanesAtPoint(usectorptr_t sec, float dax, float day, float* ceilz, float* florz); - void render_drawrooms(vec3_t& position, int sectnum, fixed_t q16angle, fixed_t q16horizon, float rollang, float fov, bool mirror, bool planemirror); diff --git a/source/core/rendering/scene/hw_bunchdrawer.cpp b/source/core/rendering/scene/hw_bunchdrawer.cpp index 058cf31ac..3781c2790 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.cpp +++ b/source/core/rendering/scene/hw_bunchdrawer.cpp @@ -37,7 +37,7 @@ #include "hw_clock.h" #include "hw_drawstructs.h" #include "automap.h" -#include "render.h" +#include "gamefuncs.h" diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index 3e4d21c38..a5550c86c 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -33,7 +33,7 @@ #include "hw_renderstate.h" #include "hw_skydome.h" #include "hw_drawstructs.h" -#include "render.h" +#include "gamefuncs.h" #include "cmdlib.h" #include "v_video.h"