- Eliminate __interpvalue() and clean up Q16.16 smoothratio values where it made sense to do so.

* Also eliminates a now empty header.
This commit is contained in:
Mitchell Richters 2022-09-07 15:49:17 +10:00 committed by Christoph Oelckers
parent f02035b15a
commit 45d4d3e41a
16 changed files with 50 additions and 99 deletions

View file

@ -4,7 +4,6 @@
#include "maptypes.h"
#include "build.h"
#include "actorinfo.h"
#include "interphelpers.h"
enum
{

View file

@ -3,6 +3,7 @@
#include "gamecontrol.h"
#include "build.h"
#include "coreactor.h"
#include "fixedhorizon.h"
#include "intrect.h"
extern IntRect viewport3d;

View file

@ -2,7 +2,6 @@
#include "m_fixed.h"
#include "fixedhorizon.h"
#include "interphelpers.h"
#include "gamecvars.h"
#include "gamestruct.h"
#include "gamefuncs.h"

View file

@ -1,48 +0,0 @@
/*
** interphelpers.h
**
** Interpolation helpers for use throughout Build games.
**
**---------------------------------------------------------------------------
** Copyright 2022 Christoph Oelckers, Mitchell Richters
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** 1. Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** 2. Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** 3. The name of the author may not be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**---------------------------------------------------------------------------
**
*/
#pragma once
#include "fixedhorizon.h"
inline constexpr int32_t __interpvalue(int32_t oval, int32_t val, double const smoothratio, int const scale = 16)
{
return oval + MulScale(val - oval, int(smoothratio), scale);
}
inline constexpr int32_t __interpvalue(int32_t oval, int32_t val, int const smoothratio, int const scale = 16)
{
return oval + MulScale(val - oval, smoothratio, scale);
}

View file

@ -1863,14 +1863,14 @@ void playerProcess(PLAYER* pPlayer)
}
ProcessInput(pPlayer);
int nSpeed = approxDist(actor->int_vel().X, actor->int_vel().Y);
pPlayer->zViewVel = __interpvalue(pPlayer->zViewVel, actor->int_vel().Z, 0x7000);
pPlayer->zViewVel = interpolatedvalue(pPlayer->zViewVel, actor->int_vel().Z, 0x7000 * (1. / MaxSmoothRatio));
int dz = pPlayer->actor->int_pos().Z - pPosture->eyeAboveZ - pPlayer->zView;
if (dz > 0)
pPlayer->zViewVel += MulScale(dz << 8, 0xa000, 16);
else
pPlayer->zViewVel += MulScale(dz << 8, 0x1800, 16);
pPlayer->zView += pPlayer->zViewVel >> 8;
pPlayer->zWeaponVel = __interpvalue(pPlayer->zWeaponVel, actor->int_vel().Z, 0x5000);
pPlayer->zWeaponVel = interpolatedvalue(pPlayer->zWeaponVel, actor->int_vel().Z, 0x5000 * (1. / MaxSmoothRatio));
dz = pPlayer->actor->int_pos().Z - pPosture->weaponAboveZ - pPlayer->zWeapon;
if (dz > 0)
pPlayer->zWeaponVel += MulScale(dz << 8, 0x8000, 16);

View file

@ -287,7 +287,7 @@ void fakePlayerProcess(PLAYER* pPlayer, InputPacket* pInput)
int nSpeed = approxDist(predict.xvel, predict.yvel);
predict.at3c = __interpvalue(predict.at3c, predict.zvel, 0x7000);
predict.at3c = interpolatedvalue(predict.at3c, predict.zvel, 0x7000 * (1. / MaxSmoothRatio));
int dz = predict.z - pPosture->eyeAboveZ - predict.viewz;
if (dz > 0)
predict.at3c += MulScale(dz << 8, 0xa000, 16);
@ -295,7 +295,7 @@ void fakePlayerProcess(PLAYER* pPlayer, InputPacket* pInput)
predict.at3c += MulScale(dz << 8, 0x1800, 16);
predict.viewz += predict.at3c >> 8;
predict.at44 = __interpvalue(predict.at44, predict.zvel, 0x5000);
predict.at44 = interpolatedvalue(predict.at44, predict.zvel, 0x5000 * (1. / MaxSmoothRatio));
dz = predict.z - pPosture->weaponAboveZ - predict.at40;
if (dz > 0)
predict.at44 += MulScale(dz << 8, 0x8000, 16);

View file

@ -842,14 +842,14 @@ void PathSound(sectortype* pSector, int nSound)
void TranslateSector(sectortype* pSector, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, bool bAllWalls)
{
XSECTOR* pXSector = &pSector->xs();
int v20 = __interpvalue(a6, a9, a2);
int vc = __interpvalue(a6, a9, a3);
int v20 = interpolatedvalue(a6, a9, a2 * (1. / MaxSmoothRatio));
int vc = interpolatedvalue(a6, a9, a3 * (1. / MaxSmoothRatio));
int v28 = vc - v20;
int v24 = __interpvalue(a7, a10, a2);
int v8 = __interpvalue(a7, a10, a3);
int v24 = interpolatedvalue(a7, a10, a2 * (1. / MaxSmoothRatio));
int v8 = interpolatedvalue(a7, a10, a3 * (1. / MaxSmoothRatio));
int v2c = v8 - v24;
int v44 = __interpvalue(a8, a11, a2);
int ang = __interpvalue(a8, a11, a3);
int v44 = interpolatedvalue(a8, a11, a2 * (1. / MaxSmoothRatio));
int ang = interpolatedvalue(a8, a11, a3 * (1. / MaxSmoothRatio));
int v14 = ang - v44;
DVector2 pivot = { a4 * inttoworld, a5 * inttoworld };

View file

@ -472,7 +472,7 @@ static void DrawMap(DBloodActor* view)
tm = 1;
}
VIEW* pView = &gPrevView[gViewIndex];
auto xy = DVector2(__interpvalue(pView->x, view->int_pos().X, gInterpolate), __interpvalue(pView->y, view->int_pos().Y, gInterpolate))* inttoworld;
auto xy = DVector2(interpolatedvalue(pView->x, view->int_pos().X, gInterpolate * (1. / MaxSmoothRatio)), interpolatedvalue(pView->y, view->int_pos().Y, gInterpolate * (1. / MaxSmoothRatio)))* inttoworld;
auto ang = !SyncInput() ? gView->angle.sum() : gView->angle.interpolatedsum(gInterpolate * (1. / MaxSmoothRatio));
DrawOverheadMap(xy, ang, gInterpolate);
if (tm)
@ -494,12 +494,12 @@ void SetupView(int& cX, int& cY, int& cZ, DAngle& cA, fixedhoriz& cH, sectortype
if (numplayers > 1 && gView == gMe && gPrediction && gMe->actor->xspr.health > 0)
{
nSectnum = predict.sectnum;
cX = __interpvalue(predictOld.x, predict.x, gInterpolate);
cY = __interpvalue(predictOld.y, predict.y, gInterpolate);
cZ = __interpvalue(predictOld.viewz, predict.viewz, gInterpolate);
cX = interpolatedvalue(predictOld.x, predict.x, gInterpolate * (1. / MaxSmoothRatio));
cY = interpolatedvalue(predictOld.y, predict.y, gInterpolate * (1. / MaxSmoothRatio));
cZ = interpolatedvalue(predictOld.viewz, predict.viewz, gInterpolate * (1. / MaxSmoothRatio));
zDelta = interpolatedvalue(predictOld.weaponZ, predict.weaponZ, gInterpolate * (1. / MaxSmoothRatio));
bobWidth = __interpvalue(predictOld.bobWidth, predict.bobWidth, gInterpolate);
bobHeight = __interpvalue(predictOld.bobHeight, predict.bobHeight, gInterpolate);
bobWidth = interpolatedvalue(predictOld.bobWidth, predict.bobWidth, gInterpolate * (1. / MaxSmoothRatio));
bobHeight = interpolatedvalue(predictOld.bobHeight, predict.bobHeight, gInterpolate * (1. / MaxSmoothRatio));
shakeX = interpolatedvalue(predictOld.shakeBobX, predict.shakeBobX, gInterpolate * (1. / MaxSmoothRatio));
shakeY = interpolatedvalue(predictOld.shakeBobY, predict.shakeBobY, gInterpolate * (1. / MaxSmoothRatio));
@ -520,12 +520,12 @@ void SetupView(int& cX, int& cY, int& cZ, DAngle& cA, fixedhoriz& cH, sectortype
#endif
{
VIEW* pView = &gPrevView[gViewIndex];
cX = __interpvalue(pView->x, gView->actor->int_pos().X, gInterpolate);
cY = __interpvalue(pView->y, gView->actor->int_pos().Y, gInterpolate);
cZ = __interpvalue(pView->viewz, gView->zView, gInterpolate);
cX = interpolatedvalue(pView->x, gView->actor->int_pos().X, gInterpolate * (1. / MaxSmoothRatio));
cY = interpolatedvalue(pView->y, gView->actor->int_pos().Y, gInterpolate * (1. / MaxSmoothRatio));
cZ = interpolatedvalue(pView->viewz, gView->zView, gInterpolate * (1. / MaxSmoothRatio));
zDelta = interpolatedvalue<double>(pView->weaponZ, gView->zWeapon - gView->zView - (12 << 8), gInterpolate * (1. / MaxSmoothRatio));
bobWidth = __interpvalue(pView->bobWidth, gView->bobWidth, gInterpolate);
bobHeight = __interpvalue(pView->bobHeight, gView->bobHeight, gInterpolate);
bobWidth = interpolatedvalue(pView->bobWidth, gView->bobWidth, gInterpolate * (1. / MaxSmoothRatio));
bobHeight = interpolatedvalue(pView->bobHeight, gView->bobHeight, gInterpolate * (1. / MaxSmoothRatio));
shakeX = interpolatedvalue<double>(pView->shakeBobX, gView->swayWidth, gInterpolate * (1. / MaxSmoothRatio));
shakeY = interpolatedvalue<double>(pView->shakeBobY, gView->swayHeight, gInterpolate * (1. / MaxSmoothRatio));
@ -655,7 +655,7 @@ void viewDrawScreen(bool sceneonly)
if (cl_interpolate)
{
DoInterpolations(gInterpolate / MaxSmoothRatio);
DoInterpolations(gInterpolate * (1. / MaxSmoothRatio));
}
if (automapMode != am_full)

View file

@ -546,9 +546,9 @@ void UpdateAimVector(PLAYER* pPlayer)
aim2 = aim;
RotateVector((int*)&aim2.dx, (int*)&aim2.dy, -plActor->int_ang());
aim2.dz -= pPlayer->slope;
pPlayer->relAim.dx = __interpvalue(pPlayer->relAim.dx, aim2.dx, pWeaponTrack->aimSpeedHorz);
pPlayer->relAim.dy = __interpvalue(pPlayer->relAim.dy, aim2.dy, pWeaponTrack->aimSpeedHorz);
pPlayer->relAim.dz = __interpvalue(pPlayer->relAim.dz, aim2.dz, pWeaponTrack->aimSpeedVert);
pPlayer->relAim.dx = interpolatedvalue(pPlayer->relAim.dx, aim2.dx, pWeaponTrack->aimSpeedHorz * (1. / MaxSmoothRatio));
pPlayer->relAim.dy = interpolatedvalue(pPlayer->relAim.dy, aim2.dy, pWeaponTrack->aimSpeedHorz * (1. / MaxSmoothRatio));
pPlayer->relAim.dz = interpolatedvalue(pPlayer->relAim.dz, aim2.dz, pWeaponTrack->aimSpeedVert * (1. / MaxSmoothRatio));
pPlayer->aim = pPlayer->relAim;
RotateVector((int*)&pPlayer->aim.dx, (int*)&pPlayer->aim.dy, plActor->int_ang());
pPlayer->aim.dz += pPlayer->slope;

View file

@ -305,9 +305,9 @@ void animatesprites_d(tspriteArray& tsprites, int x, int y, int a, double interp
#if 0 // multiplayer only
if (screenpeek == myconnectindex && numplayers >= 2)
{
t->x = __interpvalue(omyx, myx, interpfrac * MaxSmoothRatio);
t->y = __interpvalue(omyy, myy, interpfrac * MaxSmoothRatio);
t->z = __interpvalue(omyz, myz, interpfrac * MaxSmoothRatio) + gs_playerheight;
t->x = interpolatedvalue(omyx, myx, interpfrac);
t->y = interpolatedvalue(omyy, myy, interpfrac);
t->z = interpolatedvalue(omyz, myz, interpfrac) + gs_playerheight;
t->ang = interpolatedvalue(omyang, myang, interpfrac).asbuild();
t->sector = mycursectnum;
}

View file

@ -347,9 +347,9 @@ void animatesprites_r(tspriteArray& tsprites, int x, int y, int a, double interp
#if 0 // multiplayer only
if (screenpeek == myconnectindex && numplayers >= 2)
{
t->x = __interpvalue(omyx, myx, interpfrac * MaxSmoothRatio);
t->y = __interpvalue(omyy, myy, interpfrac * MaxSmoothRatio);
t->z = __interpvalue(omyz, myz, interpfrac * MaxSmoothRatio) + gs.playerheight;
t->x = interpolatedvalue(omyx, myx, interpfrac);
t->y = interpolatedvalue(omyy, myy, interpfrac);
t->z = interpolatedvalue(omyz, myz, interpfrac) + gs.playerheight;
t->ang = interpolatedvalue(omyang, myang, interpfrac).asbuild();
t->sector = mycursectnum;
}

View file

@ -225,7 +225,7 @@ void cameratext(DDukeActor* i);
void dobonus(int bonusonly, const CompletionFunc& completion);
void drawweapon(double interpfrac);
void drawoverlays(double smoothratio);
void drawoverlays(double interpfrac);
void drawbackground(void);
void displayrooms(int32_t playerNum, double smoothratio, bool sceneonly);
void setgamepalette(int palid);

View file

@ -226,7 +226,7 @@ void V_AddBlend (float r, float g, float b, float a, float v_blend[4])
//
//---------------------------------------------------------------------------
void drawoverlays(double smoothratio)
void drawoverlays(double interpfrac)
{
player_struct* pp;
DVector2 cposxy;
@ -260,19 +260,19 @@ void drawoverlays(double smoothratio)
{
if (automapMode != am_off)
{
DoInterpolations(smoothratio * (1. / MaxSmoothRatio));
DoInterpolations(interpfrac);
if (pp->newOwner == nullptr && playrunning())
{
if (screenpeek == myconnectindex && numplayers > 1)
{
cposxy = DVector2(__interpvalue(omyx, myx, smoothratio), __interpvalue(omyy, myy, smoothratio)) * inttoworld;
cang = !SyncInput() ? myang : interpolatedvalue(omyang, myang, smoothratio * (1. / MaxSmoothRatio));
cposxy = DVector2(interpolatedvalue(omyx, myx, interpfrac), interpolatedvalue(omyy, myy, interpfrac)) * inttoworld;
cang = !SyncInput() ? myang : interpolatedvalue(omyang, myang, interpfrac);
}
else
{
cposxy = interpolatedvalue(pp->opos, pp->pos, smoothratio * (1. / MaxSmoothRatio)).XY();
cang = !SyncInput() ? pp->angle.ang : interpolatedvalue(pp->angle.oang, pp->angle.ang, smoothratio * (1. / MaxSmoothRatio));
cposxy = interpolatedvalue(pp->opos, pp->pos, interpfrac).XY();
cang = !SyncInput() ? pp->angle.ang : interpolatedvalue(pp->angle.oang, pp->angle.ang, interpfrac);
}
}
else
@ -280,7 +280,7 @@ void drawoverlays(double smoothratio)
cposxy = pp->opos.XY();
cang = pp->angle.oang;
}
DrawOverheadMap(cposxy, cang, smoothratio);
DrawOverheadMap(cposxy, cang, interpfrac * MaxSmoothRatio);
RestoreInterpolations();
}
}
@ -289,7 +289,7 @@ void drawoverlays(double smoothratio)
if (ps[myconnectindex].newOwner == nullptr && ud.cameraactor == nullptr)
{
DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -pp->angle.look_anghalf(smoothratio * (1. / MaxSmoothRatio)), pp->over_shoulder_on ? 2.5 : 0, isRR() ? 0.5 : 1);
DrawCrosshair(TILE_CROSSHAIR, ps[screenpeek].last_extra, -pp->angle.look_anghalf(interpfrac), pp->over_shoulder_on ? 2.5 : 0, isRR() ? 0.5 : 1);
}
if (paused == 2)

View file

@ -134,7 +134,7 @@ void GameInterface::Render()
moveclouds(smoothRatio);
displayrooms(screenpeek, smoothRatio, false);
drawoverlays(smoothRatio);
drawoverlays(smoothRatio * (1. / MaxSmoothRatio));
drawtime.Unclock();
}

View file

@ -286,9 +286,9 @@ void displayrooms(int snum, double smoothratio, bool sceneonly)
#if 0
if ((snum == myconnectindex) && (numplayers > 1))
{
cposx = __interpvalue(omyx, myx, smoothratio);
cposy = __interpvalue(omyy, myy, smoothratio);
cposz = __interpvalue(omyz, myz, smoothratio);
cposx = interpolatedvalue(omyx, myx, smoothratio * (1. / MaxSmoothRatio));
cposy = interpolatedvalue(omyy, myy, smoothratio * (1. / MaxSmoothRatio));
cposz = interpolatedvalue(omyz, myz, smoothratio * (1. / MaxSmoothRatio));
if (SyncInput())
{
choriz = interpolatedvalue(omyhoriz + omyhorizoff, myhoriz + myhorizoff, smoothratio * (1. / MaxSmoothRatio));
@ -304,9 +304,9 @@ void displayrooms(int snum, double smoothratio, bool sceneonly)
else
#endif
{
cposx = __interpvalue(p->player_int_opos().X, p->player_int_pos().X, smoothratio);
cposy = __interpvalue(p->player_int_opos().Y, p->player_int_pos().Y, smoothratio);
cposz = __interpvalue(p->player_int_opos().Z, p->player_int_pos().Z, smoothratio);;
cposx = interpolatedvalue(p->player_int_opos().X, p->player_int_pos().X, smoothratio * (1. / MaxSmoothRatio));
cposy = interpolatedvalue(p->player_int_opos().Y, p->player_int_pos().Y, smoothratio * (1. / MaxSmoothRatio));
cposz = interpolatedvalue(p->player_int_opos().Z, p->player_int_pos().Z, smoothratio * (1. / MaxSmoothRatio));;
if (SyncInput())
{
// Original code for when the values are passed through the sync struct

View file

@ -1465,11 +1465,11 @@ void drawscreen(PLAYER* pp, double smoothratio, bool sceneonly)
if (cl_viewbob)
{
tz += bobamt;
tz += __interpvalue(pp->obob_z, pp->bob_z, smoothratio) * zworldtoint;
tz += interpolatedvalue(pp->obob_z, pp->bob_z, smoothratio * (1. / MaxSmoothRatio)) * zworldtoint;
}
// recoil only when not in camera
thoriz = q16horiz(clamp(thoriz.asq16() + __interpvalue(pp->recoil_ohorizoff, pp->recoil_horizoff, smoothratio), gi->playerHorizMin(), gi->playerHorizMax()));
thoriz = q16horiz(clamp(thoriz.asq16() + interpolatedvalue(pp->recoil_ohorizoff, pp->recoil_horizoff, smoothratio * (1. / MaxSmoothRatio)), gi->playerHorizMin(), gi->playerHorizMax()));
}
if (automapMode != am_full)