From 9973bedd5f3711773b5b5f2e276e400893398b99 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 5 Feb 2016 16:38:33 +0000 Subject: [PATCH 01/10] Free the memory of all clipping arrays for each portal properly Not the actual fix I'm intending to make with this branch, but it's needed anyway --- src/r_main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/r_main.c b/src/r_main.c index a4e72cba9..ccaa14b8e 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1360,6 +1360,9 @@ void R_RenderPlayerView(player_t *player) // okay done. free it. portalcullsector = NULL; // Just in case... portal_base = portal->next; + Z_Free(portal->ceilingclip); + Z_Free(portal->floorclip); + Z_Free(portal->frontscale); Z_Free(portal); } // END PORTAL RENDERING From 166fafd71708553539c753783b924496387ba4d0 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 6 Feb 2016 18:57:26 +0000 Subject: [PATCH 02/10] Fixed div-by-zero crash relating to portals, drawsegs and midtextures Had to remove Red's scale hack in order to do so, because it utterly fails when the drawseg doesn't actually belong to the portal in the first place. --- src/r_bsp.c | 4 +++- src/r_bsp.h | 1 + src/r_defs.h | 2 ++ src/r_main.c | 11 +---------- src/r_segs.c | 5 +++++ src/r_things.c | 3 +++ 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/r_bsp.c b/src/r_bsp.c index c87d8baa7..52be9a0e3 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -26,6 +26,7 @@ side_t *sidedef; line_t *linedef; sector_t *frontsector; sector_t *backsector; +boolean portalline; // is curline a portal seg? // very ugly realloc() of drawsegs at run-time, I upped it to 512 // instead of 256.. and someone managed to send me a level with @@ -378,6 +379,7 @@ static void R_AddLine(seg_t *line) return; curline = line; + portalline = false; // OPTIMIZE: quickly reject orthogonal back sides. angle1 = R_PointToAngle(line->v1->x, line->v1->y); @@ -431,7 +433,7 @@ static void R_AddLine(seg_t *line) backsector = line->backsector; // Portal line - if (line->linedef->special == 40 && P_PointOnLineSide(viewx, viewy, line->linedef) == 0) + if (line->linedef->special == 40 && line->side == 0) { if (portalrender < cv_maxportals.value) { diff --git a/src/r_bsp.h b/src/r_bsp.h index 14b11ea77..3d0429fec 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -23,6 +23,7 @@ extern side_t *sidedef; extern line_t *linedef; extern sector_t *frontsector; extern sector_t *backsector; +extern boolean portalline; // is curline a portal seg? // drawsegs are allocated on the fly... see r_segs.c diff --git a/src/r_defs.h b/src/r_defs.h index f18410fe8..a982a598b 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -675,6 +675,8 @@ typedef struct drawseg_s INT32 numthicksides; fixed_t frontscale[MAXVIDWIDTH]; + UINT8 portalpass; // if > 0 and == portalrender, do not clip sprites + #ifdef ESLOPE fixed_t maskedtextureheight[MAXVIDWIDTH]; // For handling sloped midtextures diff --git a/src/r_main.c b/src/r_main.c index ccaa14b8e..a6b13302e 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -91,7 +91,6 @@ typedef struct portal_pair INT16 *ceilingclip; INT16 *floorclip; fixed_t *frontscale; - size_t seg; } portal_pair; portal_pair *portal_base, *portal_cap; line_t *portalclipline; @@ -1230,7 +1229,7 @@ void R_AddPortal(INT32 line1, INT32 line2, INT32 x1, INT32 x2) portal->start = x1; portal->end = x2; - portal->seg = ds_p-drawsegs; + portalline = true; // this tells R_StoreWallRange that curline is a portal seg portal->viewx = viewx; portal->viewy = viewy; @@ -1344,14 +1343,6 @@ void R_RenderPlayerView(player_t *player) validcount++; - if (portal->seg) - { - // Push the portal's old drawseg out of the way so it isn't interfering with sprite clipping. -Red - drawseg_t *seg = drawsegs+portal->seg; - seg->scale1 = 0; - seg->scale2 = 0; - } - R_RenderBSPNode((INT32)numnodes - 1); R_ClipSprites(); //R_DrawPlanes(); diff --git a/src/r_segs.c b/src/r_segs.c index 04873b29c..0106a1bac 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -2887,6 +2887,11 @@ void R_StoreWallRange(INT32 start, INT32 stop) R_RenderSegLoop(); colfunc = wallcolfunc; + if (portalline) // if curline is a portal, set portalrender for drawseg + ds_p->portalpass = portalrender+1; + else + ds_p->portalpass = 0; + // save sprite clipping info if (((ds_p->silhouette & SIL_TOP) || maskedtexture) && !ds_p->sprtopclip) { diff --git a/src/r_things.c b/src/r_things.c index 2a3f8e771..667a26e0f 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2058,6 +2058,9 @@ void R_ClipSprites(void) continue; } + if (ds->portalpass > 0 && ds->portalpass == portalrender) + continue; // is a portal + r1 = ds->x1 < spr->x1 ? spr->x1 : ds->x1; r2 = ds->x2 > spr->x2 ? spr->x2 : ds->x2; From ae2b1e8ea1ba860107d036e316011f0427ec329d Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 6 Feb 2016 21:06:52 +0000 Subject: [PATCH 03/10] Use <= instead of ==, so that sprites for second-tier portals and beyond still display thx Red for spotting this --- src/r_defs.h | 2 +- src/r_things.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_defs.h b/src/r_defs.h index a982a598b..107b8a83f 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -675,7 +675,7 @@ typedef struct drawseg_s INT32 numthicksides; fixed_t frontscale[MAXVIDWIDTH]; - UINT8 portalpass; // if > 0 and == portalrender, do not clip sprites + UINT8 portalpass; // if > 0 and <= portalrender, do not affect sprite clipping #ifdef ESLOPE fixed_t maskedtextureheight[MAXVIDWIDTH]; // For handling sloped midtextures diff --git a/src/r_things.c b/src/r_things.c index 667a26e0f..3767b02be 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2058,7 +2058,7 @@ void R_ClipSprites(void) continue; } - if (ds->portalpass > 0 && ds->portalpass == portalrender) + if (ds->portalpass > 0 && ds->portalpass <= portalrender) continue; // is a portal r1 = ds->x1 < spr->x1 ? spr->x1 : ds->x1; From dabc4415af553ec8a1bc14e381635e7d9879d279 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 13 Feb 2016 18:11:50 +0000 Subject: [PATCH 04/10] Fix crash caused by drawing scaled, mirrored sprites semi-covered on the left side by portal edge I suspect this crash was possible even outside the context of portals, but whatever --- src/r_things.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 3767b02be..87879a415 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -839,10 +839,10 @@ static void R_DrawVisSprite(vissprite_t *vis) dc_texturemid = FixedDiv(dc_texturemid,this_scale); //Oh lordy, mercy me. Don't freak out if sprites go offscreen! - if (vis->xiscale > 0) + /*if (vis->xiscale > 0) frac = FixedDiv(frac, this_scale); else if (vis->x1 <= 0) - frac = (vis->x1 - vis->x2) * vis->xiscale; + frac = (vis->x1 - vis->x2) * vis->xiscale;*/ sprtopscreen = centeryfrac - FixedMul(dc_texturemid, spryscale); //dc_hires = 1; @@ -1306,7 +1306,7 @@ static void R_ProjectSprite(mobj_t *thing) } if (vis->x1 > x1) - vis->startfrac += vis->xiscale*(vis->x1-x1); + vis->startfrac += FixedDiv(vis->xiscale, this_scale)*(vis->x1-x1); //Fab: lumppat is the lump number of the patch to use, this is different // than lumpid for sprites-in-pwad : the graphics are patched From 4b447b3d0db33c92ca1e542cc6a955af3dec45ea Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 28 Feb 2016 18:30:29 +0000 Subject: [PATCH 05/10] Don't add polyobjects to a mobj's sector nodes list. This causes the player to teeter whenever they are above the polyobject's bottom, whether or not it is solid Also, a minor tweak for the teetering code itself, though it looks a right mess and probably should be redone in the future --- src/p_map.c | 6 ++++++ src/p_user.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index 61d57dcd1..760252c8b 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -3712,6 +3712,9 @@ static inline boolean PIT_GetSectors(line_t *ld) if (P_BoxOnLineSide(tmbbox, ld) != -1) return true; + if (ld->polyobj) // line belongs to a polyobject, don't add it + return true; + // This line crosses through the object. // Collect the sector(s) from the line and add to the @@ -3744,6 +3747,9 @@ static inline boolean PIT_GetPrecipSectors(line_t *ld) if (P_BoxOnLineSide(preciptmbbox, ld) != -1) return true; + if (ld->polyobj) // line belongs to a polyobject, don't add it + return true; + // This line crosses through the object. // Collect the sector(s) from the line and add to the diff --git a/src/p_user.c b/src/p_user.c index da65b7cb4..b3ba5f61f 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3087,7 +3087,7 @@ static void P_DoTeeter(player_t *player) } if (polybottom > player->mo->z + player->mo->height + tiptop - || (polybottom < player->mo->z + || (polytop < player->mo->z && player->mo->z + player->mo->height < player->mo->ceilingz - tiptop)) teeter = true; else @@ -3105,7 +3105,7 @@ static void P_DoTeeter(player_t *player) } if (polytop < player->mo->z - tiptop - || (polytop > player->mo->z + player->mo->height + || (polybottom > player->mo->z + player->mo->height && player->mo->z > player->mo->floorz + tiptop)) teeter = true; else From 668cc85d7b3f828ef723289939ac134b57ce191d Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 2 Mar 2016 20:31:04 +0000 Subject: [PATCH 06/10] P_ClosestPointOnLine can now (optionally) take custom coordinates that you want to make up your line --- src/lua_baselib.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 5e2d31b10..be06982f3 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -140,14 +140,38 @@ static int lib_pAproxDistance(lua_State *L) static int lib_pClosestPointOnLine(lua_State *L) { + int n = lua_gettop(L); fixed_t x = luaL_checkfixed(L, 1); fixed_t y = luaL_checkfixed(L, 2); - line_t *line = *((line_t **)luaL_checkudata(L, 3, META_LINE)); vertex_t result; //HUDSAFE - if (!line) - return LUA_ErrInvalid(L, "line_t"); - P_ClosestPointOnLine(x, y, line, &result); + if (lua_isuserdata(L, 3)) // use a real linedef to get our points + { + line_t *line = *((line_t **)luaL_checkudata(L, 3, META_LINE)); + if (!line) + return LUA_ErrInvalid(L, "line_t"); + P_ClosestPointOnLine(x, y, line, &result); + } + else // use custom coordinates of our own! + { + vertex_t v1, v2; // fake vertexes + line_t junk; // fake linedef + + if (n < 6) + return luaL_error(L, "arguments 3 to 6 not all given (expected 4 fixed-point integers)"); + + v1.x = luaL_checkfixed(L, 3); + v1.y = luaL_checkfixed(L, 4); + v2.x = luaL_checkfixed(L, 5); + v2.y = luaL_checkfixed(L, 6); + + junk.v1 = &v1; + junk.v2 = &v2; + junk.dx = v2.x - v1.x; + junk.dy = v2.y - v1.y; + P_ClosestPointOnLine(x, y, &junk, &result); + } + lua_pushfixed(L, result.x); lua_pushfixed(L, result.y); return 2; From 5b89164cf7e4ada2ac999ed41d163059c2a1ec76 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 10 Mar 2016 20:50:54 +0000 Subject: [PATCH 07/10] Fix camera going nuts around intangible polyobjects --- src/p_map.c | 2 +- src/p_user.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index 61d57dcd1..5c5d9cdfd 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1616,7 +1616,7 @@ boolean P_CheckCameraPosition(fixed_t x, fixed_t y, camera_t *thiscam) po->validcount = validcount; - if (!P_PointInsidePolyobj(po, x, y)) + if (!P_PointInsidePolyobj(po, x, y) || !(po->flags & POF_SOLID)) { plink = (polymaplink_t *)(plink->link.next); continue; diff --git a/src/p_user.c b/src/p_user.c index 03b2c1dd8..c08eea5c6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8163,7 +8163,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall po->validcount = validcount; - if (!P_PointInsidePolyobj(po, x, y)) + if (!P_PointInsidePolyobj(po, x, y) || !(po->flags & POF_SOLID)) { plink = (polymaplink_t *)(plink->link.next); continue; From 76d71bda926d11eb1315bf1e0fe36fa39d87ec59 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 25 Mar 2016 19:43:17 +0000 Subject: [PATCH 08/10] destend now scales the added-on patch width properly if needed --- src/v_video.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index df81ac6d6..3eb71bb06 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -477,7 +477,16 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t } deststart = desttop; - destend = desttop + SHORT(patch->width) * dupx; + if (pscale != FRACUNIT) // scale width properly + { + fixed_t pwidth = SHORT(patch->width)<>= FRACBITS; + destend = desttop + pwidth; + } + else + destend = desttop + SHORT(patch->width) * dupx; for (col = 0; (col>>FRACBITS) < SHORT(patch->width); col += colfrac, ++x, desttop++) { From 3698c2583d36a0d302e2b005cea221d838ad80af Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 25 Mar 2016 20:04:49 +0000 Subject: [PATCH 09/10] wrap prevention code now takes flipped patches into account --- src/v_video.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 3eb71bb06..b9bdb271f 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -336,6 +336,8 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t const column_t *column; UINT8 *desttop, *dest, *deststart, *destend; const UINT8 *source, *deststop; + fixed_t pwidth; // patch width + fixed_t offx = 0; // x offset if (rendermode == render_none) return; @@ -476,25 +478,36 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t } } - deststart = desttop; if (pscale != FRACUNIT) // scale width properly { - fixed_t pwidth = SHORT(patch->width)<width)<>= FRACBITS; - destend = desttop + pwidth; } else - destend = desttop + SHORT(patch->width) * dupx; + pwidth = SHORT(patch->width) * dupx; - for (col = 0; (col>>FRACBITS) < SHORT(patch->width); col += colfrac, ++x, desttop++) + deststart = desttop; + destend = desttop + pwidth; + + for (col = 0; (col>>FRACBITS) < SHORT(patch->width); col += colfrac, ++offx, desttop++) { INT32 topdelta, prevdelta = -1; - if (x < 0) // don't draw off the left of the screen (WRAP PREVENTION) - continue; - if (x >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION) - break; + if (flip) // offx is measured from right edge instead of left + { + if (x+pwidth-offx < 0) // don't draw off the left of the screen (WRAP PREVENTION) + break; + if (x+pwidth-offx >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION) + continue; + } + else + { + if (x+offx < 0) // don't draw off the left of the screen (WRAP PREVENTION) + continue; + if (x+offx >= vid.width) // don't draw off the right of the screen (WRAP PREVENTION) + break; + } column = (const column_t *)((const UINT8 *)(patch) + LONG(patch->columnofs[col>>FRACBITS])); while (column->topdelta != 0xff) From f3f2c5962255b2f731c6acefd1067bb49b03c980 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Thu, 31 Mar 2016 20:42:01 -0500 Subject: [PATCH 10/10] Remove p_fab.c --- src/CMakeLists.txt | 1 - src/Makefile | 1 - src/p_fab.c | 15 --------------- 3 files changed, 17 deletions(-) delete mode 100644 src/p_fab.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 13d3312dd..035b46556 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -139,7 +139,6 @@ set(SRB2_CORE_RENDER_SOURCES set(SRB2_CORE_GAME_SOURCES p_ceilng.c p_enemy.c - p_fab.c p_floor.c p_inter.c p_lights.c diff --git a/src/Makefile b/src/Makefile index 449b4065d..0c034143d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -437,7 +437,6 @@ OBJS:=$(i_main_o) \ $(OBJDIR)/info.o \ $(OBJDIR)/p_ceilng.o \ $(OBJDIR)/p_enemy.o \ - $(OBJDIR)/p_fab.o \ $(OBJDIR)/p_floor.o \ $(OBJDIR)/p_inter.o \ $(OBJDIR)/p_lights.o \ diff --git a/src/p_fab.c b/src/p_fab.c deleted file mode 100644 index 7ccb93a94..000000000 --- a/src/p_fab.c +++ /dev/null @@ -1,15 +0,0 @@ -// SONIC ROBO BLAST 2 -//----------------------------------------------------------------------------- -// Copyright (C) 1998-2000 by DooM Legacy Team. -// Copyright (C) 1999-2014 by Sonic Team Junior. -// -// This program is free software distributed under the -// terms of the GNU General Public License, version 2. -// See the 'LICENSE' file for more details. -//----------------------------------------------------------------------------- -/// \file p_fab.c -/// \brief some new action routines, separated from the original doom -/// sources, so that you can include it or remove it easy. - -/// \todo -/// This file is now unused, please remove at some point