- moving utilities to more appropriate places.

This commit is contained in:
Christoph Oelckers 2021-03-18 12:49:33 +01:00
parent 6068427270
commit c4b3523f05
6 changed files with 95 additions and 130 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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

View File

@ -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);

View File

@ -37,7 +37,7 @@
#include "hw_clock.h"
#include "hw_drawstructs.h"
#include "automap.h"
#include "render.h"
#include "gamefuncs.h"

View File

@ -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"