From b05273d319c2e67279bd45563e9531a36dfdaf94 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 15 Jan 2024 21:47:15 +0700 Subject: [PATCH] adapt mouselook from PrBoom+ (#1389) * reduce recoil pitch values --- src/d_player.h | 2 +- src/d_ticcmd.h | 2 +- src/g_game.c | 30 ++++--------- src/i_input.h | 3 -- src/i_video.c | 8 ---- src/m_menu.c | 2 +- src/p_map.c | 7 ++-- src/p_mobj.c | 2 - src/p_mobj.h | 7 ---- src/p_pspr.c | 20 ++++----- src/p_user.c | 36 +++++++++------- src/r_data.h | 3 -- src/r_main.c | 112 +++++++++++++++++++++++++++---------------------- src/r_main.h | 5 +-- src/r_plane.c | 23 +++------- src/r_plane.h | 2 +- 16 files changed, 116 insertions(+), 148 deletions(-) diff --git a/src/d_player.h b/src/d_player.h index 37c41310..6875a748 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -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; diff --git a/src/d_ticcmd.h b/src/d_ticcmd.h index 17c0f065..9af1a5e0 100644 --- a/src/d_ticcmd.h +++ b/src/d_ticcmd.h @@ -36,7 +36,7 @@ typedef struct byte chatchar; byte buttons; - int lookdir; + int pitch; } ticcmd_t; #endif diff --git a/src/g_game.c b/src/g_game.c index 2ceeeb3d..c7fe65ae 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -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; diff --git a/src/i_input.h b/src/i_input.h index 6aa35707..4094866e 100644 --- a/src/i_input.h +++ b/src/i_input.h @@ -19,9 +19,6 @@ #include "SDL.h" -#include "doomtype.h" -#include "d_event.h" - void I_OpenController(int which); void I_CloseController(int which); diff --git a/src/i_video.c b/src/i_video.c index cabfaf93..ebcfd384 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -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) diff --git a/src/m_menu.c b/src/m_menu.c index a8d47028..87fb79ab 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3787,7 +3787,7 @@ static void M_UpdateFOV(void) } I_UpdateFOV(); - R_ExecuteSetViewSize(); + setsizeneeded = true; // run R_ExecuteSetViewSize; } static void M_ResetScreen(void) diff --git a/src/p_map.c b/src/p_map.c index 4dbbc8a4..0ee747f4 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -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; diff --git a/src/p_mobj.c b/src/p_mobj.c index 1d9c31bb..48dbe7f9 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -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; diff --git a/src/p_mobj.h b/src/p_mobj.h index e609bfd4..d9d1dcb8 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -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); diff --git a/src/p_pspr.c b/src/p_pspr.c index f914e38d..40be669a 100644 --- a/src/p_pspr.c +++ b/src/p_pspr.c @@ -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); diff --git a/src/p_user.c b/src/p_user.c index 79cd92a7..20ddc842 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -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; } } diff --git a/src/r_data.h b/src/r_data.h index f8fcba19..1050fb7b 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -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); diff --git a/src/r_main.c b/src/r_main.c index 342d8637..e6530a71 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -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<>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> 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]; diff --git a/src/r_main.h b/src/r_main.h index 2c6dddf3..ddd1fd40 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -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 diff --git a/src/r_plane.c b/src/r_plane.c index b57906af..a3a6e882 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -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); diff --git a/src/r_plane.h b/src/r_plane.h index eda116f4..b1c7603d 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -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);