adapt mouselook from PrBoom+ (#1389)

* reduce recoil pitch values
This commit is contained in:
Roman Fomin 2024-01-15 21:47:15 +07:00 committed by GitHub
parent 0d73d370fd
commit b05273d319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 116 additions and 148 deletions

View File

@ -182,7 +182,7 @@ typedef struct player_s
char* secretmessage;
// [crispy] free look / mouse look
int lookdir, oldlookdir;
fixed_t pitch, oldpitch;
boolean centering;
fixed_t slope;

View File

@ -36,7 +36,7 @@ typedef struct
byte chatchar;
byte buttons;
int lookdir;
int pitch;
} ticcmd_t;
#endif

View File

@ -158,7 +158,7 @@ fixed_t forwardmove[2] = {0x19, 0x32};
fixed_t sidemove[2] = {0x18, 0x28};
fixed_t angleturn[3] = {640, 1280, 320}; // + slow turn
static fixed_t lookspeed[] = {160, 320};
#define LOOKSPEED 640
boolean gamekeydown[NUMKEYS];
int turnheld; // for accelerative turning
@ -368,22 +368,6 @@ static void G_DemoSkipTics(void)
}
}
static double PitchToShearingHeight(double pitch)
{
int angle;
fixed_t slope;
// Scale up to BAM and clamp to sane range.
angle = pitch * FRACUNIT;
angle = BETWEEN(-ANG75, ANG75, angle);
// Convert angle to y-shearing height and apply aspect ratio correction.
slope = -finetangent[(ANG90 - angle) >> ANGLETOFINESHIFT];
pitch = (160.0 * FIXED2DOUBLE(slope)) * (lookdirmax / 100.0) / 1.2;
return pitch;
}
static int CarryError(double value, const double *prevcarry, double *carry)
{
const double desired = value + *prevcarry;
@ -441,7 +425,7 @@ static double CalcMousePitch(int mousey)
pitch = I_AccelerateMouse(mousey) * (mouseSensitivity_vert_look + 5) * 8 / 10;
return (PitchToShearingHeight(pitch) * direction[mouse_y_invert]);
return pitch * FRACUNIT * direction[mouse_y_invert];
}
static double CalcMouseSide(int mousex)
@ -479,8 +463,8 @@ void G_PrepTiccmd(void)
if (mouselook)
{
const double pitch = CalcMousePitch(mousey);
cmd->lookdir = CarryMousePitch(pitch);
localview.pitch = cmd->lookdir;
cmd->pitch = CarryMousePitch(pitch);
localview.pitch = cmd->pitch;
}
}
@ -610,7 +594,7 @@ void G_BuildTiccmd(ticcmd_t* cmd)
y = FixedMul(FixedMul(y, y), y);
y = direction[invert_look] * axis_look_sens * y / 10;
pitch -= FixedMul(lookspeed[0], y);
pitch -= FixedMul(LOOKSPEED, y);
}
}
@ -643,7 +627,7 @@ void G_BuildTiccmd(ticcmd_t* cmd)
if (pitch)
{
cmd->lookdir = pitch;
cmd->pitch = pitch * FRACUNIT;
localview.usepitch = false;
}
@ -1354,7 +1338,7 @@ static void G_PlayerFinishLevel(int player)
p->damagecount = 0; // no palette changes
p->bonuscount = 0;
// [crispy] reset additional player properties
p->oldlookdir = p->lookdir = 0;
p->oldpitch = p->pitch = 0;
p->centering = false;
p->slope = 0;
p->recoilpitch = p->oldrecoilpitch = 0;

View File

@ -19,9 +19,6 @@
#include "SDL.h"
#include "doomtype.h"
#include "d_event.h"
void I_OpenController(int which);
void I_CloseController(int which);

View File

@ -1032,12 +1032,9 @@ void I_UpdateFOV(void)
if (custom_fov)
{
const double slope = tan(custom_fov * M_PI / 360);
const double dist = (CurrentAspectRatio() * ACTUALHEIGHT / 2) / slope;
video.fov = custom_fov * ANG1;
pov_slope = slope * FRACUNIT;
pov_distance = dist * FRACUNIT;
lookdirmax = lround(dist * 100 / 160);
}
else
{
@ -1053,12 +1050,7 @@ void I_UpdateFOV(void)
video.fov = 2 * atan(slope) / M_PI * ANG180;
pov_slope = slope * FRACUNIT;
}
pov_distance = (SCREENWIDTH / 2) << FRACBITS;
lookdirmax = 100;
}
lookdirs = 2 * lookdirmax + 1;
}
static void ResetResolution(int height)

View File

@ -3787,7 +3787,7 @@ static void M_UpdateFOV(void)
}
I_UpdateFOV();
R_ExecuteSetViewSize();
setsizeneeded = true; // run R_ExecuteSetViewSize;
}
static void M_ResetScreen(void)

View File

@ -1674,12 +1674,13 @@ fixed_t P_AimLineAttack(mobj_t *t1,angle_t angle,fixed_t distance,int mask)
if (t1->player && direct_vertical_aiming && (mask & CROSSHAIR_AIM))
{
bottomslope = (topslope = t1->player->slope + 1) - 2;
topslope = t1->player->slope + 1;
bottomslope = t1->player->slope - 1;
}
else
{
topslope = 100*FRACUNIT/160;
bottomslope = -100*FRACUNIT/160;
topslope = 100*FRACUNIT/160;
bottomslope = -100*FRACUNIT/160;
}
attackrange = distance;

View File

@ -36,8 +36,6 @@
#include "g_game.h"
#include "p_inter.h"
#include "v_video.h"
#include "m_swap.h"
#include "w_wad.h"
// [FG] colored blood and gibs
boolean colored_blood;

View File

@ -419,13 +419,6 @@ extern int iquetail;
// [FG] colored blood and gibs
extern boolean colored_blood;
// The value `160` is used for the denominator because in Vanilla Doom
// the horizontal FOV is 90° and spans 320 px, so the height of the
// resulting triangle is 160.
// Heretic/Hexen used value `173` presumably because Raven assumed an
// equilateral triangle (i.e. 60°) for the vertical FOV which spans
// 200 px, so the height of that triangle would be 100*sqrt(3) = 173.
#define PLAYER_SLOPE(a) (FixedDiv((a)->lookdir << FRACBITS, pov_distance))
extern boolean direct_vertical_aiming, default_direct_vertical_aiming;
void P_UpdateDirectVerticalAiming(void);

View File

@ -50,14 +50,14 @@ static struct
int pitch;
} recoil_values[] = { // phares
{ 10, 0 }, // wp_fist
{ 10, 4 }, // wp_pistol
{ 30, 8 }, // wp_shotgun
{ 10, 4 }, // wp_chaingun
{ 100, 16 }, // wp_missile
{ 20, 4 }, // wp_plasma
{ 100, 20 }, // wp_bfg
{ 0, -2 }, // wp_chainsaw
{ 80, 16 } // wp_supershotgun
{ 10, 2 }, // wp_pistol
{ 30, 4 }, // wp_shotgun
{ 10, 2 }, // wp_chaingun
{ 100, 8 }, // wp_missile
{ 20, 2 }, // wp_plasma
{ 100, 10 }, // wp_bfg
{ 0, -1 }, // wp_chainsaw
{ 80, 8 } // wp_supershotgun
};
// [crispy] add weapon recoil pitch
@ -67,7 +67,7 @@ void A_Recoil(player_t* player)
{
if (player && weapon_recoilpitch)
{
player->recoilpitch = recoil_values[player->readyweapon].pitch;
player->recoilpitch = recoil_values[player->readyweapon].pitch * ANG1;
}
}
@ -780,7 +780,7 @@ void A_FireOldBFG(player_t *player, pspdef_t *psp)
if (weapon_recoilpitch && (leveltime & 2))
{
player->recoilpitch = recoil_values[wp_plasma].pitch;
player->recoilpitch = recoil_values[wp_plasma].pitch * ANG1;
}
P_SubtractAmmo(player, 1);

View File

@ -27,6 +27,12 @@
#include "p_user.h"
#include "g_game.h"
static fixed_t PlayerSlope(player_t *player)
{
const fixed_t pitch = player->pitch;
return pitch ? -finetangent[(ANG90 - pitch) >> ANGLETOFINESHIFT] : 0;
}
// Index of the special effects (INVUL inverse) map.
#define INVERSECOLORMAP 32
@ -238,9 +244,9 @@ void P_MovePlayer (player_t* player)
if (!menuactive && !demoplayback)
{
player->lookdir += cmd->lookdir;
player->lookdir = BETWEEN(-lookdirmax, lookdirmax, player->lookdir);
player->slope = PLAYER_SLOPE(player);
player->pitch += cmd->pitch;
player->pitch = BETWEEN(-MAX_PITCH_ANGLE, MAX_PITCH_ANGLE, player->pitch);
player->slope = PlayerSlope(player);
}
}
@ -355,7 +361,7 @@ void P_PlayerThink (player_t* player)
player->mo->oldz = player->mo->z;
player->mo->oldangle = player->mo->angle;
player->oldviewz = player->viewz;
player->oldlookdir = player->lookdir;
player->oldpitch = player->pitch;
player->oldrecoilpitch = player->recoilpitch;
if (player == &players[consoleplayer])
@ -383,27 +389,29 @@ void P_PlayerThink (player_t* player)
}
// [crispy] center view
#define CENTERING_VIEW_ANGLE (8 * ANG1)
if (player->centering)
{
if (player->lookdir > 0)
if (player->pitch > 0)
{
player->lookdir -= 8;
player->pitch -= CENTERING_VIEW_ANGLE;
}
else if (player->lookdir < 0)
else if (player->pitch < 0)
{
player->lookdir += 8;
player->pitch += CENTERING_VIEW_ANGLE;
}
if (abs(player->lookdir) < 8)
if (abs(player->pitch) < CENTERING_VIEW_ANGLE)
{
player->lookdir = 0;
player->pitch = 0;
if (player->oldlookdir == 0)
if (player->oldpitch == 0)
{
player->centering = false;
}
}
player->slope = PLAYER_SLOPE(player);
player->slope = PlayerSlope(player);
}
// [crispy] weapon recoil pitch
@ -411,11 +419,11 @@ void P_PlayerThink (player_t* player)
{
if (player->recoilpitch > 0)
{
player->recoilpitch -= 1;
player->recoilpitch -= ANG1;
}
else if (player->recoilpitch < 0)
{
player->recoilpitch += 1;
player->recoilpitch += ANG1;
}
}

View File

@ -24,9 +24,6 @@
#include "r_defs.h"
#include "r_state.h"
// Largest range at FOV 40, AR 3.6 (742 = (3.6*240/2)/tan(40*M_PI/360)*100/160).
#define LOOKDIRSMAX (2 * 742 + 1)
// Retrieve column data for span blitting.
byte *R_GetColumn(int tex, int col);
byte *R_GetColumnMod(int tex, int col);

View File

@ -51,9 +51,6 @@ player_t *viewplayer;
extern lighttable_t **walllights;
fixed_t viewheightfrac; // [FG] sprite clipping optimizations
fixed_t pov_slope;
fixed_t pov_distance;
int lookdirmax;
int lookdirs;
//
// precalculated math tables
@ -441,7 +438,7 @@ void R_SetViewSize(int blocks)
void R_ExecuteSetViewSize (void)
{
int i, j;
int i;
vrect_t view;
setsizeneeded = false;
@ -495,44 +492,29 @@ void R_ExecuteSetViewSize (void)
viewblocks = (MIN(setblocks, 10) * video.yscale) >> FRACBITS;
centery = viewheight/2;
centerx = viewwidth/2;
centerxfrac = centerx<<FRACBITS;
centeryfrac = centery<<FRACBITS;
centerxfrac_nonwide = (viewwidth_nonwide/2)<<FRACBITS;
centerx = viewwidth / 2;
centerxfrac = centerx << FRACBITS;
centerxfrac_nonwide = (viewwidth_nonwide / 2) << FRACBITS;
projection = FixedDiv(centerxfrac, pov_slope);
viewheightfrac = viewheight<<(FRACBITS+1); // [FG] sprite clipping optimizations
viewheightfrac = viewheight << (FRACBITS + 1); // [FG] sprite clipping optimizations
R_InitBuffer(); // killough 11/98
R_InitTextureMapping(projection);
// psprite scales
pspritescale = FixedDiv(viewwidth_nonwide, SCREENWIDTH); // killough 11/98
pspriteiscale= FixedDiv(SCREENWIDTH, viewwidth_nonwide) + 1; // killough 11/98
pspriteiscale = FixedDiv(SCREENWIDTH, viewwidth_nonwide) + 1; // killough 11/98
// thing clipping
for (i=0 ; i<viewwidth ; i++)
screenheightarray[i] = viewheight;
// planes
for (i=0 ; i<viewheight ; i++)
{ // killough 5/2/98: reformatted
for (j = 0; j < lookdirs; j++)
{
// [crispy] re-generate lookup-table for yslope[] whenever "viewheight" or "hires" change
fixed_t dy = abs(((i-viewheight/2-(j-lookdirmax)*viewblocks/10)<<FRACBITS)+FRACUNIT/2);
yslopes[j][i] = FixedDiv(projection, dy);
}
}
yslope = yslopes[lookdirmax];
for (i=0 ; i<viewwidth ; i++)
{
fixed_t cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]);
distscale[i] = FixedDiv(FRACUNIT,cosadj);
// thing clipping
screenheightarray[i] = viewheight;
}
// Calculate the light levels to use
// for each level / scale combination.
for (i=0; i<LIGHTLEVELS; i++)
@ -621,15 +603,52 @@ angle_t R_InterpolateAngle(angle_t oangle, angle_t nangle, fixed_t scale)
}
}
static void R_SetupMouselook(fixed_t viewpitch)
{
static fixed_t old_viewpitch, old_viewheight, old_projection;
fixed_t dy;
int i;
if (viewpitch != old_viewpitch || viewheight != old_viewheight
|| projection != old_projection)
{
old_viewpitch = viewpitch;
old_viewheight = viewheight;
old_projection = projection;
}
else
{
return;
}
if (viewpitch)
{
dy = FixedMul(projection, -finetangent[(ANG90 - viewpitch) >> ANGLETOFINESHIFT]);
}
else
{
dy = 0;
}
centery = viewheight / 2 + (dy >> FRACBITS);
centeryfrac = centery << FRACBITS;
for (i = 0; i < viewheight; i++)
{
dy = abs(((i - centery) << FRACBITS) + FRACUNIT / 2);
yslope[i] = FixedDiv(projection, dy);
}
}
//
// R_SetupFrame
//
void R_SetupFrame (player_t *player)
{
{
int i, cm;
int tempCentery, pitch;
fixed_t pitch;
viewplayer = player;
// [AM] Interpolate the player camera if the feature is enabled.
if (uncapped &&
@ -674,9 +693,14 @@ void R_SetupFrame (player_t *player)
viewangle = R_InterpolateAngle(player->mo->oldangle, player->mo->angle, fractionaltic);
if (localview.usepitch && use_localview && !player->centering)
pitch = player->lookdir + localview.pitch;
{
pitch = player->pitch + localview.pitch;
pitch = BETWEEN(-MAX_PITCH_ANGLE, MAX_PITCH_ANGLE, pitch);
}
else
pitch = player->oldlookdir + (player->lookdir - player->oldlookdir) * FIXED2DOUBLE(fractionaltic);
{
pitch = player->oldpitch + FixedMul(player->pitch - player->oldpitch, fractionaltic);
}
// [crispy] pitch is actual lookdir and weapon pitch
pitch += player->oldrecoilpitch + FixedMul(player->recoilpitch - player->oldrecoilpitch, fractionaltic);
@ -688,29 +712,17 @@ void R_SetupFrame (player_t *player)
viewz = player->viewz; // [FG] moved here
viewangle = player->mo->angle;
// [crispy] pitch is actual lookdir and weapon pitch
pitch = player->lookdir + player->recoilpitch;
pitch = player->pitch + player->recoilpitch;
}
R_SetupMouselook(pitch);
// 3-screen display mode.
viewangle += viewangleoffset;
extralight = player->extralight;
extralight += STRICTMODE(LIGHTBRIGHT * extra_level_brightness);
if (pitch > lookdirmax)
pitch = lookdirmax;
else if (pitch < -lookdirmax)
pitch = -lookdirmax;
// apply new yslope[] whenever "lookdir", "viewheight" or "hires" change
tempCentery = viewheight/2 + pitch * viewblocks / 10;
if (centery != tempCentery)
{
centery = tempCentery;
centeryfrac = centery << FRACBITS;
yslope = yslopes[lookdirmax + pitch];
}
viewsin = finesine[viewangle>>ANGLETOFINESHIFT];
viewcos = finecosine[viewangle>>ANGLETOFINESHIFT];

View File

@ -27,6 +27,8 @@
// POV related.
//
#define MAX_PITCH_ANGLE (32 * ANG1)
extern fixed_t viewcos;
extern fixed_t viewsin;
extern int viewwindowx;
@ -41,9 +43,6 @@ extern int linecount;
extern int loopcount;
extern fixed_t viewheightfrac; // [FG] sprite clipping optimizations
extern fixed_t pov_slope; // For calculating projection.
extern fixed_t pov_distance; // Distance from POV to projection plane.
extern int lookdirmax;
extern int lookdirs;
//
// Rendering stats

View File

@ -87,7 +87,7 @@ static fixed_t *cachedxstep = NULL;
static fixed_t *cachedystep = NULL;
static fixed_t xoffs,yoffs; // killough 2/28/98: flat offsets
fixed_t *yslope = NULL, **yslopes = NULL, *distscale = NULL;
fixed_t *yslope = NULL, *distscale = NULL;
// [FG] linear horizontal sky scrolling
boolean linearsky;
@ -104,8 +104,6 @@ void R_InitPlanes (void)
void R_InitPlanesRes(void)
{
int i;
if (floorclip) Z_Free(floorclip);
if (ceilingclip) Z_Free(ceilingclip);
if (spanstart) Z_Free(spanstart);
@ -115,18 +113,11 @@ void R_InitPlanesRes(void)
if (cachedxstep) Z_Free(cachedxstep);
if (cachedystep) Z_Free(cachedystep);
if (openings) Z_Free(openings);
if (yslopes)
{
for (i = 0; i < LOOKDIRSMAX; ++i)
{
Z_Free(yslopes[i]);
}
Z_Free(yslopes);
}
if (yslope) Z_Free(yslope);
if (distscale) Z_Free(distscale);
if (openings) Z_Free(openings);
floorclip = Z_Calloc(1, video.width * sizeof(*floorclip), PU_STATIC, NULL);
ceilingclip = Z_Calloc(1, video.width * sizeof(*ceilingclip), PU_STATIC, NULL);
spanstart = Z_Calloc(1, video.height * sizeof(*spanstart), PU_STATIC, NULL);
@ -136,11 +127,7 @@ void R_InitPlanesRes(void)
cachedxstep = Z_Calloc(1, video.height * sizeof(*cachedxstep), PU_STATIC, NULL);
cachedystep = Z_Calloc(1, video.height * sizeof(*cachedystep), PU_STATIC, NULL);
yslopes = Z_Malloc(LOOKDIRSMAX * sizeof(*yslopes), PU_STATIC, NULL);
for (i = 0; i < LOOKDIRSMAX; ++i)
{
yslopes[i] = Z_Calloc(1, video.height * sizeof(**yslopes), PU_STATIC, NULL);
}
yslope = Z_Calloc(1, video.height * sizeof(*yslope), PU_STATIC, NULL);
distscale = Z_Calloc(1, video.width * sizeof(*distscale), PU_STATIC, NULL);
openings = Z_Calloc(1, video.width * video.height * sizeof(*openings), PU_STATIC, NULL);

View File

@ -29,7 +29,7 @@
extern int *lastopening; // [FG] 32-bit integer math
extern int *floorclip, *ceilingclip; // [FG] 32-bit integer math
extern fixed_t *yslope, **yslopes, *distscale;
extern fixed_t *yslope, *distscale;
void R_InitPlanes(void);
void R_ClearPlanes(void);