diff --git a/src/d_main.c b/src/d_main.c index b2591b948..b7a3b148d 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -110,6 +110,8 @@ int snprintf(char *str, size_t n, const char *fmt, ...); // platform independant focus loss UINT8 window_notinfocus = false; +INT32 window_x; +INT32 window_y; // // DEMO LOOP @@ -288,6 +290,9 @@ static void D_Display(void) if (vid.recalc) SCR_Recalc(); // NOTE! setsizeneeded is set by SCR_Recalc() + if (rendermode == render_soft && !splitscreen) + R_CheckViewMorph(); + // change the view size if needed if (setsizeneeded) { @@ -499,6 +504,9 @@ static void D_Display(void) if (rendermode == render_soft) { + if (!splitscreen) + R_ApplyViewMorph(); + for (i = 0; i <= splitscreen; i++) { if (postimgtype[i]) diff --git a/src/d_player.h b/src/d_player.h index c8e015d77..bf2ed58f8 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -369,6 +369,9 @@ typedef struct player_s // bounded/scaled total momentum. //fixed_t bob; + angle_t viewrollangle; + angle_t tilt; + // Mouse aiming, where the guy is looking at! // It is updated with cmd->aiming. angle_t aiming; diff --git a/src/doomdef.h b/src/doomdef.h index 5ed1e9ed3..b3bac65c1 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -518,6 +518,7 @@ extern INT32 cv_debug; #define DBG_MEMORY 0x0200 #define DBG_SETUP 0x0400 #define DBG_LUA 0x0800 +#define DBG_VIEWMORPH 0x2000 // ======================= // Misc stuff for later... @@ -528,7 +529,7 @@ extern UINT8 shiftdown, ctrldown, altdown; extern boolean capslock; // WARNING: a should be unsigned but to add with 2048, it isn't! -#define AIMINGTODY(a) (FINETANGENT((2048+(((INT32)a)>>ANGLETOFINESHIFT)) & FINEMASK)*160) +#define AIMINGTODY(a) FixedDiv((FINETANGENT((2048+(((INT32)a)>>ANGLETOFINESHIFT)) & FINEMASK)*160), fovtan) // if we ever make our alloc stuff... #define ZZ_Alloc(x) Z_Malloc(x, PU_STATIC, NULL) diff --git a/src/doomstat.h b/src/doomstat.h index 2e09232f0..fc4c38733 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -108,6 +108,8 @@ extern boolean digital_disabled; extern boolean menuactive; // Menu overlaid? extern UINT8 paused; // Game paused? extern UINT8 window_notinfocus; // are we in focus? (backend independant -- handles auto pausing and display of "focus lost" message) +extern INT32 window_x; +extern INT32 window_y; extern boolean nodrawers; extern boolean noblit; @@ -191,6 +193,7 @@ extern struct quake { // camera offsets and duration fixed_t x,y,z; + angle_t roll; UINT16 time; // location, radius, and intensity... diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 0392de554..6c2bcc354 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -155,6 +155,8 @@ typedef struct FLOAT fovxangle, fovyangle; UINT8 splitscreen; boolean flip; // screenflip + boolean roll; + FLOAT rollangle; #ifdef USE_FTRANSFORM_MIRROR boolean mirror; // SRB2Kart: Encore Mode #endif diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ae2df1aba..3c7c67991 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2298,8 +2298,11 @@ void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t } // reference point for flat texture coord for each vertex around the polygon - flatxref = (float)(((fixed_t)FIXED_TO_FLOAT(polysector->origVerts[0].x) & (~flatflag)) / fflatsize); - flatyref = (float)(((fixed_t)FIXED_TO_FLOAT(polysector->origVerts[0].y) & (~flatflag)) / fflatsize); + flatxref = FIXED_TO_FLOAT(polysector->origVerts[0].x); + flatyref = FIXED_TO_FLOAT(polysector->origVerts[0].y); + + flatxref = (float)(((fixed_t)flatxref & (~flatflag)) / fflatsize); + flatyref = (float)(((fixed_t)flatyref & (~flatflag)) / fflatsize); // transform v3d = planeVerts; @@ -4662,6 +4665,8 @@ void HWR_DrawSkyBackground(float fpov) dometransform.scalez = 1; dometransform.fovxangle = fpov; // Tails dometransform.fovyangle = fpov; // Tails + dometransform.rollangle = atransform.rollangle; + dometransform.roll = atransform.roll; dometransform.splitscreen = splitscreen; HWR_GetTexture(texturetranslation[skytexture]); @@ -4755,6 +4760,8 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) gr_viewsin = FIXED_TO_FLOAT(viewsin); gr_viewcos = FIXED_TO_FLOAT(viewcos); + memset(&atransform, 0x00, sizeof(FTransform)); + // Set T&L transform atransform.x = gr_viewx; atransform.y = gr_viewy; @@ -4785,7 +4792,7 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) atransform.fovyangle = fpov; // Tails if (player->viewrollangle != 0) { - fixed_t rol = AngleFixed(R_LerpAngle(player, viewrollangle)); + fixed_t rol = AngleFixed(player->viewrollangle); atransform.rollangle = FIXED_TO_FLOAT(rol); atransform.roll = true; } diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 854dbfc8e..7745052c9 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1093,6 +1093,8 @@ void HWR_DrawMD2(gr_vissprite_t *spr) if (spr->precip) return; + memset(&p, 0x00, sizeof(FTransform)); + // MD2 colormap fix // colormap test if (spr->mobj->subsector) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 4fdecd895..a0e6ed42e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -28,6 +28,8 @@ #include "../../p_tick.h" // for leveltime (NOTE: THIS IS BAD, FIGURE OUT HOW TO PROPERLY IMPLEMENT gl_leveltime) +extern fixed_t fovtan; // also extremely bad, I'm just too lazy!!! + #if defined (HWRENDER) && !defined (NOROPENGL) struct GLRGBAFloat @@ -3098,7 +3100,8 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) else pglScalef(stransform->scalex, stransform->scaley, -stransform->scalez); - pglMatrixMode(GL_MODELVIEW); + if (stransform->roll) + pglRotatef(stransform->rollangle, 0.0f, 0.0f, 1.0f); pglRotatef(stransform->anglex, 1.0f, 0.0f, 0.0f); pglRotatef(stransform->angley+270.0f, 0.0f, 1.0f, 0.0f); pglTranslatef(-stransform->x, -stransform->z, -stransform->y); diff --git a/src/i_system.h b/src/i_system.h index ba05d06ea..89ea1ae2d 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -369,4 +369,6 @@ const char *I_ClipboardPaste(void); void I_RegisterSysCommands(void); +void I_CursedWindowMovement(int xd, int yd); + #endif diff --git a/src/m_fixed.h b/src/m_fixed.h index 8145a6917..49f14f8f4 100644 --- a/src/m_fixed.h +++ b/src/m_fixed.h @@ -43,8 +43,20 @@ typedef INT32 fixed_t; /*! \brief convert fixed_t into floating number */ -#define FIXED_TO_FLOAT(x) (((float)(x)) / ((float)FRACUNIT)) -#define FLOAT_TO_FIXED(f) (fixed_t)((f) * ((float)FRACUNIT)) + +FUNCMATH FUNCINLINE static ATTRINLINE float FixedToFloat(fixed_t x) +{ + return x / (float)FRACUNIT; +} + +FUNCMATH FUNCINLINE static ATTRINLINE fixed_t FloatToFixed(float f) +{ + return (fixed_t)(f * FRACUNIT); +} + +// for backwards compat +#define FIXED_TO_FLOAT(x) FixedToFloat(x) // (((float)(x)) / ((float)FRACUNIT)) +#define FLOAT_TO_FIXED(f) FloatToFixed(f) // (fixed_t)((f) * ((float)FRACUNIT)) #if defined (__WATCOMC__) && FRACBITS == 16 diff --git a/src/p_tick.c b/src/p_tick.c index afb17c6fe..4075fba47 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -23,6 +23,7 @@ #include "lua_script.h" #include "lua_hook.h" #include "k_kart.h" +#include "i_system.h" #include "r_main.h" #include "r_fps.h" #include "i_video.h" // rendermode @@ -761,10 +762,19 @@ void P_Ticker(boolean run) quake.x = M_RandomRange(-ir,ir); quake.y = M_RandomRange(-ir,ir); quake.z = M_RandomRange(-ir,ir); + if (cv_windowquake.value) + I_CursedWindowMovement(FixedInt(quake.x), FixedInt(quake.y)); + ir >>= 2; + ir = M_RandomRange(-ir,ir); + if (ir < 0) + ir = ANGLE_MAX - FixedAngle(-ir); + else + ir = FixedAngle(ir); + quake.roll = ir; --quake.time; } else - quake.x = quake.y = quake.z = 0; + quake.x = quake.y = quake.z = quake.roll = 0; if (metalplayback) G_ReadMetalTic(metalplayback); diff --git a/src/p_user.c b/src/p_user.c index f029c6e01..4374a3817 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -5192,6 +5192,8 @@ static void P_NiGHTSMovement(player_t *player) else // AngleFixed(R_PointToAngle2()) results in slight inaccuracy! Don't use it unless movement is on both axises. newangle = (INT16)FixedInt(AngleFixed(R_PointToAngle2(0,0, cmd->sidemove*FRACUNIT, cmd->forwardmove*FRACUNIT))); + newangle -= player->viewrollangle / ANG1; + if (newangle < 0 && moved) newangle = (INT16)(360+newangle); } @@ -8993,6 +8995,8 @@ void P_PlayerThink(player_t *player) K_KartPlayerThink(player, cmd); // SRB2kart + DoABarrelRoll(player); + #ifdef HAVE_BLUA LUAh_PlayerThink(player); #endif diff --git a/src/r_draw.h b/src/r_draw.h index a9921028c..18ee9f06a 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -62,6 +62,8 @@ extern fixed_t ds_xfrac, ds_yfrac, ds_xstep, ds_ystep; extern UINT8 *ds_source; // start of a 64*64 tile image extern UINT8 *ds_transmap; +extern INT32 ds_bgofs; + typedef struct { float x, y, z; } floatv3_t; diff --git a/src/r_draw8.c b/src/r_draw8.c index 37d93d162..e6116863e 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -643,6 +643,7 @@ void R_CalcTiltedLighting(fixed_t start, fixed_t end) } } +#define PLANELIGHTFLOAT (BASEVIDWIDTH * BASEVIDWIDTH / vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f * FIXED_TO_FLOAT(fovtan)) /** \brief The R_DrawTiltedSpan_8 function Draw slopes! Holy sheit! @@ -668,7 +669,7 @@ void R_DrawTiltedSpan_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_sz.x*width) * planelightfloat; @@ -804,7 +805,7 @@ void R_DrawTiltedTranslucentSpan_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_sz.x*width) * planelightfloat; @@ -938,7 +939,7 @@ void R_DrawTiltedSplat_8(void) // Lighting is simple. It's just linear interpolation from start to end { - float planelightfloat = BASEVIDWIDTH*BASEVIDWIDTH/vid.width / (zeroheight - FIXED_TO_FLOAT(viewz)) / 21.0f; + float planelightfloat = PLANELIGHTFLOAT; float lightstart, lightend; lightend = (iz + ds_sz.x*width) * planelightfloat; diff --git a/src/r_main.c b/src/r_main.c index 1fcabfbd4..ce28d8d30 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -605,6 +605,8 @@ static inline void R_InitLightTables(void) } } +//#define WOUGHMP_WOUGHMP // I got a fish-eye lens - I'll make a rap video with a couple of friends +// it's kinda laggy sometimes static struct { angle_t rollangle; // pre-shifted by fineshift @@ -647,7 +649,7 @@ void R_CheckViewMorph(void) float fisheyemap[MAXVIDWIDTH/2 + 1]; #endif - angle_t rollangle = R_LerpAngle(&players[displayplayers[0]], viewrollangle); + angle_t rollangle = players[displayplayers[0]].viewrollangle; #ifdef WOUGHMP_WOUGHMP fixed_t fisheye = cv_cam2_turnmultiplier.value; // temporary test value #endif @@ -954,7 +956,7 @@ void R_ExecuteSetViewSize(void) centeryfrac = centery<> ANGLETOFINESHIFT); + fovtan = FixedMul(FINETANGENT(fov >> ANGLETOFINESHIFT), viewmorph.zoomneeded); if (splitscreen == 1) // Splitscreen FOV should be adjusted to maintain expected vertical view fovtan = 17*fovtan/10; @@ -1093,6 +1095,31 @@ subsector_t *R_IsPointInSubsector(fixed_t x, fixed_t y) static mobj_t *viewmobj; +// recalc necessary stuff for mouseaiming +// slopes are already calculated for the full possible view (which is 4*viewheight). +// 18/08/18: (No it's actually 16*viewheight, thanks Jimita for finding this out) +static void R_SetupFreelook(void) +{ + INT32 dy = 0; + + // clip it in the case we are looking a hardware 90 degrees full aiming + // (lmps, network and use F12...) + if (rendermode == render_soft +#ifdef HWRENDER + || cv_grshearing.value +#endif + ) + G_SoftwareClipAimingPitch((INT32 *)&aimingangle); + + if (rendermode == render_soft) + { + dy = (AIMINGTODY(aimingangle)>>FRACBITS) * viewwidth/BASEVIDWIDTH; + yslope = &yslopetab[viewheight*8 - (viewheight/2 + dy)]; + } + centery = (viewheight/2) + dy; + centeryfrac = centery<= 8) @@ -308,17 +308,17 @@ void R_MapPlane(INT32 y, INT32 x1, INT32 x2) { const INT32 yay = (wtofs + (distance>>9) ) & 8191; // ripples da water texture - bgofs = FixedDiv(FINESINE(yay), (1<<12) + (distance>>11))>>FRACBITS; + ds_bgofs = FixedDiv(FINESINE(yay), (1<<12) + (distance>>11))>>FRACBITS; angle = (currentplane->viewangle + currentplane->plangle + xtoviewangle[x1])>>ANGLETOFINESHIFT; angle = (angle + 2048) & 8191; // 90 degrees - ds_xfrac += FixedMul(FINECOSINE(angle), (bgofs<=viewheight) - bgofs = viewheight-y-1; - if (y+bgofs<0) - bgofs = -y; + if (y+ds_bgofs>=viewheight) + ds_bgofs = viewheight-y-1; + if (y+ds_bgofs<0) + ds_bgofs = -y; } #endif diff --git a/src/r_segs.c b/src/r_segs.c index c531be52d..8d99a4947 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -194,7 +194,7 @@ static void R_DrawWallSplats(void) // draw the columns for (dc_x = x1; dc_x <= x2; dc_x++, spryscale += rw_scalestep) { - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE - 1; dc_colormap = walllights[pindex]; @@ -547,7 +547,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) else xwalllights = scalelight[rlight->lightnum]; - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE - 1; @@ -596,7 +596,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) } // calculate lighting - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE - 1; @@ -1080,7 +1080,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) else xwalllights = scalelight[lightnum]; - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE-1; @@ -1181,7 +1181,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) } // calculate lighting - pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(spryscale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE - 1; @@ -1374,7 +1374,7 @@ static void R_RenderSegLoop (void) if (segtextured) { // calculate lighting - pindex = FixedMul(rw_scale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(rw_scale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE-1; @@ -1411,7 +1411,7 @@ static void R_RenderSegLoop (void) else xwalllights = scalelight[lightnum]; - pindex = FixedMul(rw_scale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; + pindex = FixedMul(rw_scale, LIGHTRESOLUTIONFIX)>>LIGHTSCALESHIFT; if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE-1; diff --git a/src/r_sky.c b/src/r_sky.c index fe1630e90..f42907a54 100644 --- a/src/r_sky.c +++ b/src/r_sky.c @@ -80,8 +80,5 @@ void R_SetupSkyDraw(void) void R_SetSkyScale(void) { fixed_t difference = vid.fdupx-(vid.dupx< 1) - scr *= 2; - skyscale = FixedDiv(scr, vid.fdupx+difference); + skyscale = FixedDiv(fovtan, vid.fdupx+difference); } diff --git a/src/r_things.c b/src/r_things.c index 1546e2cb1..7143ed4da 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1117,7 +1117,7 @@ static void R_SplitSprite(vissprite_t *sprite, mobj_t *thing) if (!((thing->frame & (FF_FULLBRIGHT|FF_TRANSMASK) || thing->flags2 & MF2_SHADOW) && (!newsprite->extra_colormap || !(newsprite->extra_colormap->fog & 1)))) { - lindex = FixedMul(sprite->xscale, FixedDiv(640, vid.width))>>(LIGHTSCALESHIFT); + lindex = FixedMul(sprite->xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT); if (lindex >= MAXLIGHTSCALE) lindex = MAXLIGHTSCALE-1; @@ -1514,7 +1514,7 @@ static void R_ProjectSprite(mobj_t *thing) else { // diminished light - lindex = FixedMul(xscale, FixedDiv(640, vid.width))>>(LIGHTSCALESHIFT); + lindex = FixedMul(xscale, LIGHTRESOLUTIONFIX)>>(LIGHTSCALESHIFT); if (lindex >= MAXLIGHTSCALE) lindex = MAXLIGHTSCALE-1; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 50204f3f7..5b76edddf 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -842,6 +842,12 @@ INT32 I_GetKey (void) return rc; } +void +I_CursedWindowMovement (int xd, int yd) +{ + SDL_SetWindowPosition(window, window_x + xd, window_y + yd); +} + // // I_JoyScale // diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index b7fd366d9..26fd041a6 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -623,6 +623,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) break; case SDL_WINDOWEVENT_MAXIMIZED: break; + case SDL_WINDOWEVENT_MOVED: + window_x = evt.data1; + window_y = evt.data2; } if (mousefocus && kbfocus)