From 2d50dd1fd1ad65923acb271717027316c802d4bd Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 31 Oct 2016 00:02:38 +0000 Subject: [PATCH 001/223] A bunch of fixes that allow for proper handling of triggerspecial_touch. Not perfect, but I don't have any more time to spend tonight. --- src/p_floor.c | 39 +++++++++++++++++++++++++++++--- src/p_spec.c | 61 +++++++++++++++++++++++++++++---------------------- 2 files changed, 71 insertions(+), 29 deletions(-) diff --git a/src/p_floor.c b/src/p_floor.c index 911213014..1f3873d9f 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -2073,6 +2073,7 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) boolean inAndOut = false; boolean floortouch = false; fixed_t bottomheight, topheight; + msecnode_t *node; for (i = 0; i < MAXPLAYERS; i++) { @@ -2134,8 +2135,22 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) if ((netgame || multiplayer) && players[j].spectator) continue; - if (players[j].mo->subsector->sector != targetsec) - continue; + if (players[j].mo->subsector->sector == targetsec) + ; + else if (sec->flags & SF_TRIGGERSPECIAL_TOUCH) + { + boolean insector = false; + for (node = players[j].mo->touching_sectorlist; node; node = node->m_sectorlist_next) + { + if (node->m_sector == targetsec) + { + insector = true; + break; + } + } + if (!insector) + continue; + } topheight = P_GetSpecialTopZ(players[j].mo, sec, targetsec); bottomheight = P_GetSpecialBottomZ(players[j].mo, sec, targetsec); @@ -2184,7 +2199,25 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) if ((netgame || multiplayer) && players[i].spectator) continue; - if (players[i].mo->subsector->sector != sec) + if (players[i].mo->subsector->sector == targetsec) + ; + else if (sec->flags & SF_TRIGGERSPECIAL_TOUCH) + { + boolean insector = false; + for (node = players[i].mo->touching_sectorlist; node; node = node->m_sectorlist_next) + { + if (node->m_sector == targetsec) + { + insector = true; + break; + } + } + if (!insector) + continue; + } + + if (!(players[i].mo->subsector->sector == sec + || P_PlayerTouchingSectorSpecial(&players[i], 2, (GETSECSPECIAL(sec->special, 2))) == sec)) continue; if (floortouch == true && P_IsObjectOnGroundIn(players[i].mo, sec)) diff --git a/src/p_spec.c b/src/p_spec.c index b04c55881..10a8f7313 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3606,14 +3606,16 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers { if (roversector) { - if (players[i].mo->subsector->sector != roversector) + if (!(players[i].mo->subsector->sector == roversector + || sector->flags & SF_TRIGGERSPECIAL_TOUCH)) goto DoneSection2; if (!P_ThingIsOnThe3DFloor(players[i].mo, sector, roversector)) goto DoneSection2; } else { - if (players[i].mo->subsector->sector != sector) + if (!(players[i].mo->subsector->sector == sector + || sector->flags & SF_TRIGGERSPECIAL_TOUCH)) goto DoneSection2; if (special == 3 && !P_MobjReadyToTrigger(players[i].mo, sector)) @@ -4364,6 +4366,7 @@ sector_t *P_ThingOnSpecial3DFloor(mobj_t *mo) { sector_t *sector; ffloor_t *rover; + fixed_t topheight, bottomheight; sector = mo->subsector->sector; if (!sector->ffloors) @@ -4371,8 +4374,6 @@ sector_t *P_ThingOnSpecial3DFloor(mobj_t *mo) for (rover = sector->ffloors; rover; rover = rover->next) { - fixed_t topheight, bottomheight; - if (!rover->master->frontsector->special) continue; @@ -4420,20 +4421,21 @@ sector_t *P_ThingOnSpecial3DFloor(mobj_t *mo) return NULL; } +#define TELEPORTED (player->mo->subsector->sector != originalsector) + /** Checks if a player is standing on or is inside a 3D floor (e.g. water) and * applies any specials. * * \param player Player to check. * \sa P_ThingOnSpecial3DFloor, P_PlayerInSpecialSector */ -static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector) +static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector, sector_t *originalsector) { ffloor_t *rover; + fixed_t topheight, bottomheight; for (rover = sector->ffloors; rover; rover = rover->next) { - fixed_t topheight, bottomheight; - if (!rover->master->frontsector->special) continue; @@ -4477,7 +4479,10 @@ static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector) // This FOF has the special we're looking for, but are we allowed to touch it? if (sector == player->mo->subsector->sector || (rover->master->frontsector->flags & SF_TRIGGERSPECIAL_TOUCH)) + { P_ProcessSpecialSector(player, rover->master->frontsector, sector); + if TELEPORTED return; + } } // Allow sector specials to be applied to polyobjects! @@ -4488,7 +4493,7 @@ static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector) boolean touching = false; boolean inside = false; - while(po) + while (po) { if (po->flags & POF_NOSPECIALS) { @@ -4564,6 +4569,7 @@ static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector) } P_ProcessSpecialSector(player, polysec, sector); + if TELEPORTED return; po = (polyobj_t *)(po->link.next); } @@ -4668,40 +4674,43 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector) */ void P_PlayerInSpecialSector(player_t *player) { - sector_t *sector; + sector_t *originalsector; + sector_t *loopsector; msecnode_t *node; if (!player->mo) return; - // Do your ->subsector->sector first - sector = player->mo->subsector->sector; - P_PlayerOnSpecial3DFloor(player, sector); - // After P_PlayerOnSpecial3DFloor, recheck if the player is in that sector, - // because the player can be teleported in between these times. - if (sector == player->mo->subsector->sector) - P_RunSpecialSectorCheck(player, sector); + originalsector = player->mo->subsector->sector; - // Iterate through touching_sectorlist + P_PlayerOnSpecial3DFloor(player, originalsector, originalsector); // Handle FOFs first. + if TELEPORTED return; + + P_RunSpecialSectorCheck(player, originalsector); + if TELEPORTED return; + + // Iterate through touching_sectorlist for SF_TRIGGERSPECIAL_TOUCH for (node = player->mo->touching_sectorlist; node; node = node->m_sectorlist_next) { - sector = node->m_sector; + loopsector = node->m_sector; - if (sector == player->mo->subsector->sector) // Don't duplicate + if (loopsector == originalsector) // Don't duplicate continue; // Check 3D floors... - P_PlayerOnSpecial3DFloor(player, sector); + P_PlayerOnSpecial3DFloor(player, loopsector, originalsector); + if TELEPORTED return; - if (!(sector->flags & SF_TRIGGERSPECIAL_TOUCH)) - return; - // After P_PlayerOnSpecial3DFloor, recheck if the player is in that sector, - // because the player can be teleported in between these times. - if (sector == player->mo->subsector->sector) - P_RunSpecialSectorCheck(player, sector); + if (!(loopsector->flags & SF_TRIGGERSPECIAL_TOUCH)) + continue; + + P_RunSpecialSectorCheck(player, loopsector); + if TELEPORTED return; } } +#undef TELEPORTED + /** Animate planes, scroll walls, etc. and keeps track of level timelimit and exits if time is up. * * \sa P_CheckTimeLimit, P_CheckPointLimit From 6a2e101ebe0589c228ba0bdf990d8169250fd4ec Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 31 Oct 2016 00:03:07 +0000 Subject: [PATCH 002/223] Forcing on triggerspecial_touch for slopes, because pain slopes and it would be a pain to handle this manually. --- src/p_slopes.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/p_slopes.c b/src/p_slopes.c index d939fee98..c127001cd 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -281,6 +281,7 @@ void P_SpawnSlope_Line(int linenum) if(frontfloor || frontceil) { line->frontsector->hasslope = true; // Tell the software renderer that we're sloped + line->frontsector->flags |= SF_TRIGGERSPECIAL_TOUCH; // you're gonna want to get specials on contact origin.z = line->backsector->floorheight; direction.x = nx; @@ -407,6 +408,7 @@ void P_SpawnSlope_Line(int linenum) if(backfloor || backceil) { line->backsector->hasslope = true; // Tell the software renderer that we're sloped + line->backsector->flags |= SF_TRIGGERSPECIAL_TOUCH; // you're gonna want to get specials on contact origin.z = line->frontsector->floorheight; // Backsector @@ -599,6 +601,7 @@ void P_CopySectorSlope(line_t *line) } fsec->hasslope = true; + fsec->flags |= SF_TRIGGERSPECIAL_TOUCH; // you're gonna want to get specials on contact line->special = 0; // Linedef was use to set slopes, it finished its job, so now make it a normal linedef } @@ -718,6 +721,7 @@ void P_ResetDynamicSlopes(void) { *slopetoset = P_NewVertexSlope(lines[i].tag, lines[i].tag, lines[i].tag, flags); sides[lines[i].sidenum[which]].sector->hasslope = true; + sides[lines[i].sidenum[which]].sector->flags |= SF_TRIGGERSPECIAL_TOUCH; // you're gonna want to get specials on contact } break; From 1e1a6c32f0b8c0ee0d93b4f1008fe6ae0e956cf8 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 31 Oct 2016 09:34:24 +0000 Subject: [PATCH 003/223] Corrected non-complete set of cases. --- src/p_floor.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/p_floor.c b/src/p_floor.c index 1f3873d9f..b2c07bce7 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -2151,6 +2151,8 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) if (!insector) continue; } + else + continue; topheight = P_GetSpecialTopZ(players[j].mo, sec, targetsec); bottomheight = P_GetSpecialBottomZ(players[j].mo, sec, targetsec); @@ -2215,6 +2217,8 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) if (!insector) continue; } + else + continue; if (!(players[i].mo->subsector->sector == sec || P_PlayerTouchingSectorSpecial(&players[i], 2, (GETSECSPECIAL(sec->special, 2))) == sec)) From 1bbbe15ee52600b1404cd65bb9b95591a0728938 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 31 Oct 2016 13:53:52 +0000 Subject: [PATCH 004/223] Fixed a bug with being able to go under the lava because P_CheckSolidLava doesn't take slopes into account. (neither does P_CanRunOnWater, but I don't think it's necessary to make that check more complicated as you probably shouldn't be able to waterrun up steep surfaces anyways) --- src/lua_baselib.c | 5 ++++- src/p_local.h | 2 +- src/p_map.c | 2 +- src/p_maputl.c | 4 ++-- src/p_mobj.c | 6 +++--- src/p_user.c | 2 +- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index e8e8fd020..00a519272 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -560,12 +560,15 @@ static int lib_pCheckSolidLava(lua_State *L) { mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); ffloor_t *rover = *((ffloor_t **)luaL_checkudata(L, 2, META_FFLOOR)); + sector_t *bound = *((sector_t **)luaL_checkudata(L, 3, META_SECTOR)); //HUDSAFE if (!mo) return LUA_ErrInvalid(L, "mobj_t"); if (!rover) return LUA_ErrInvalid(L, "ffloor_t"); - lua_pushboolean(L, P_CheckSolidLava(mo, rover)); + if (!bound) + return LUA_ErrInvalid(L, "sector_t"); + lua_pushboolean(L, P_CheckSolidLava(mo, rover, bound)); return 1; } diff --git a/src/p_local.h b/src/p_local.h index 1fd7ada04..ce6aed028 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -238,7 +238,7 @@ fixed_t P_CameraCeilingZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, f boolean P_InsideANonSolidFFloor(mobj_t *mobj, ffloor_t *rover); boolean P_CheckDeathPitCollide(mobj_t *mo); -boolean P_CheckSolidLava(mobj_t *mo, ffloor_t *rover); +boolean P_CheckSolidLava(mobj_t *mo, ffloor_t *rover, sector_t *bound); mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type); mobj_t *P_SpawnXYZMissile(mobj_t *source, mobj_t *dest, mobjtype_t type, fixed_t x, fixed_t y, fixed_t z); diff --git a/src/p_map.c b/src/p_map.c index 6a555953e..7b5426605 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1323,7 +1323,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) continue; } - if (thing->player && (P_CheckSolidLava(thing, rover) || P_CanRunOnWater(thing->player, rover))) + if (thing->player && (P_CheckSolidLava(thing, rover, newsubsec->sector) || P_CanRunOnWater(thing->player, rover))) ; else if (thing->type == MT_SKIM && (rover->flags & FF_SWIMMABLE)) ; diff --git a/src/p_maputl.c b/src/p_maputl.c index fea8530a1..3aa9a994f 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -646,7 +646,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (!(rover->flags & FF_EXISTS)) continue; - if (mobj->player && (P_CheckSolidLava(mobj, rover) || P_CanRunOnWater(mobj->player, rover))) + if (mobj->player && (P_CheckSolidLava(mobj, rover, front) || P_CanRunOnWater(mobj->player, rover))) ; else if (!((rover->flags & FF_BLOCKPLAYER && mobj->player) || (rover->flags & FF_BLOCKOTHERS && !mobj->player))) @@ -690,7 +690,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (!(rover->flags & FF_EXISTS)) continue; - if (mobj->player && (P_CheckSolidLava(mobj, rover) || P_CanRunOnWater(mobj->player, rover))) + if (mobj->player && (P_CheckSolidLava(mobj, rover, back) || P_CanRunOnWater(mobj->player, rover))) ; else if (!((rover->flags & FF_BLOCKPLAYER && mobj->player) || (rover->flags & FF_BLOCKOTHERS && !mobj->player))) diff --git a/src/p_mobj.c b/src/p_mobj.c index e7ec2f8b8..4f0c84033 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1983,7 +1983,7 @@ static void P_AdjustMobjFloorZ_FFloors(mobj_t *mo, sector_t *sector, UINT8 motyp topheight = P_GetFOFTopZ(mo, sector, rover, mo->x, mo->y, NULL); bottomheight = P_GetFOFBottomZ(mo, sector, rover, mo->x, mo->y, NULL); - if (mo->player && (P_CheckSolidLava(mo, rover) || P_CanRunOnWater(mo->player, rover))) // only the player should be affected + if (mo->player && (P_CheckSolidLava(mo, rover, sector) || P_CanRunOnWater(mo->player, rover))) // only the player should be affected ; else if (motype != 0 && rover->flags & FF_SWIMMABLE) // "scenery" only continue; @@ -2133,14 +2133,14 @@ boolean P_CheckDeathPitCollide(mobj_t *mo) return false; } -boolean P_CheckSolidLava(mobj_t *mo, ffloor_t *rover) +boolean P_CheckSolidLava(mobj_t *mo, ffloor_t *rover, sector_t *bound) { I_Assert(mo != NULL); I_Assert(!P_MobjWasRemoved(mo)); if (rover->flags & FF_SWIMMABLE && GETSECSPECIAL(rover->master->frontsector->special, 1) == 3 && !(rover->master->flags & ML_BLOCKMONSTERS) - && ((rover->master->flags & ML_EFFECT3) || mo->z-mo->momz > *rover->topheight - FixedMul(16*FRACUNIT, mo->scale))) + && ((rover->master->flags & ML_EFFECT3) || mo->z-mo->momz > P_GetSpecialTopZ(mo, rover->master->frontsector, bound) - FixedMul(16*FRACUNIT, mo->scale))) return true; return false; diff --git a/src/p_user.c b/src/p_user.c index f8dc942c0..801eb5951 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2908,7 +2908,7 @@ static void P_DoTeeter(player_t *player) bottomheight = P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y); #endif - if (P_CheckSolidLava(player->mo, rover)) + if (P_CheckSolidLava(player->mo, rover, sec)) ; else if (!(rover->flags & FF_BLOCKPLAYER || rover->flags & FF_QUICKSAND)) continue; // intangible 3d floor From a2dabd70413ab9085d9b3af113e8aa0d86d1d27c Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 31 Oct 2016 14:03:53 +0000 Subject: [PATCH 005/223] Fixed a bunch of things MI pointed out. --- src/p_floor.c | 4 ++-- src/p_spec.c | 48 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/p_floor.c b/src/p_floor.c index b2c07bce7..0af81efee 100644 --- a/src/p_floor.c +++ b/src/p_floor.c @@ -2201,14 +2201,14 @@ void T_EachTimeThinker(levelspecthink_t *eachtime) if ((netgame || multiplayer) && players[i].spectator) continue; - if (players[i].mo->subsector->sector == targetsec) + if (players[i].mo->subsector->sector == sec) ; else if (sec->flags & SF_TRIGGERSPECIAL_TOUCH) { boolean insector = false; for (node = players[i].mo->touching_sectorlist; node; node = node->m_sectorlist_next) { - if (node->m_sector == targetsec) + if (node->m_sector == sec) { insector = true; break; diff --git a/src/p_spec.c b/src/p_spec.c index 10a8f7313..1fd94b2e8 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -3606,16 +3606,49 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers { if (roversector) { - if (!(players[i].mo->subsector->sector == roversector - || sector->flags & SF_TRIGGERSPECIAL_TOUCH)) + if (players[i].mo->subsector->sector == roversector) + ; + else if (sector->flags & SF_TRIGGERSPECIAL_TOUCH) + { + boolean insector = false; + msecnode_t *node; + for (node = players[i].mo->touching_sectorlist; node; node = node->m_sectorlist_next) + { + if (node->m_sector == roversector) + { + insector = true; + break; + } + } + if (!insector) + goto DoneSection2; + } + else goto DoneSection2; + if (!P_ThingIsOnThe3DFloor(players[i].mo, sector, roversector)) goto DoneSection2; } else { - if (!(players[i].mo->subsector->sector == sector - || sector->flags & SF_TRIGGERSPECIAL_TOUCH)) + if (players[i].mo->subsector->sector == sector) + ; + else if (sector->flags & SF_TRIGGERSPECIAL_TOUCH) + { + boolean insector = false; + msecnode_t *node; + for (node = players[i].mo->touching_sectorlist; node; node = node->m_sectorlist_next) + { + if (node->m_sector == sector) + { + insector = true; + break; + } + } + if (!insector) + goto DoneSection2; + } + else goto DoneSection2; if (special == 3 && !P_MobjReadyToTrigger(players[i].mo, sector)) @@ -4429,8 +4462,9 @@ sector_t *P_ThingOnSpecial3DFloor(mobj_t *mo) * \param player Player to check. * \sa P_ThingOnSpecial3DFloor, P_PlayerInSpecialSector */ -static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector, sector_t *originalsector) +static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector) { + sector_t *originalsector = player->mo->subsector->sector; ffloor_t *rover; fixed_t topheight, bottomheight; @@ -4683,7 +4717,7 @@ void P_PlayerInSpecialSector(player_t *player) originalsector = player->mo->subsector->sector; - P_PlayerOnSpecial3DFloor(player, originalsector, originalsector); // Handle FOFs first. + P_PlayerOnSpecial3DFloor(player, originalsector); // Handle FOFs first. if TELEPORTED return; P_RunSpecialSectorCheck(player, originalsector); @@ -4698,7 +4732,7 @@ void P_PlayerInSpecialSector(player_t *player) continue; // Check 3D floors... - P_PlayerOnSpecial3DFloor(player, loopsector, originalsector); + P_PlayerOnSpecial3DFloor(player, loopsector); if TELEPORTED return; if (!(loopsector->flags & SF_TRIGGERSPECIAL_TOUCH)) From 04a38a683bc436ad2e00ebebcc223b1acc059a28 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 31 Oct 2016 20:15:11 +0000 Subject: [PATCH 006/223] Okay, this is a biggun. Pay attention, everyone. Moved the handling of P_PlayerInSpecialSector to P_PlayerAfterThink from P_PlayerThink. * This allows the player to get hurt on sloped lava surfaces that are moving downwards. * Also prevents the player from standing on death pits for 1 tic. * Prevents the player moving 1 extra tic's worth of movement of pain when hit by sector. * Thankfully, no consequences re conveyors. * Like, the only consequences I've found have been positive. However, this DOES need to be thoroughly investigated before it can be allowed anywhere near Next itself. --- src/doomdef.h | 4 ++++ src/p_user.c | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/doomdef.h b/src/doomdef.h index fb8ab1ca2..7d883849d 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -495,4 +495,8 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// \note You should leave this enabled unless you're working with a future SRB2 version. #define MUSICSLOT_COMPATIBILITY +/// Handle touching sector specials in P_PlayerAfterThink instead of P_PlayerThink. +/// \note Required for proper collision with moving sloped surfaces that have sector specials on them. +#define SECTORSPECIALSAFTERTHINK + #endif // __DOOMDEF__ diff --git a/src/p_user.c b/src/p_user.c index 801eb5951..921f1240d 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8779,6 +8779,7 @@ void P_PlayerThink(player_t *player) // check water content, set stuff in mobj P_MobjCheckWater(player->mo); +#ifndef SECTORSPECIALSAFTERTHINK #ifdef POLYOBJECTS if (player->onconveyor != 1 || !P_IsObjectOnGround(player->mo)) #endif @@ -8787,6 +8788,7 @@ void P_PlayerThink(player_t *player) if (!player->spectator) P_PlayerInSpecialSector(player); +#endif if (player->playerstate == PST_DEAD) { @@ -9148,6 +9150,17 @@ void P_PlayerAfterThink(player_t *player) cmd = &player->cmd; +#ifdef SECTORSPECIALSAFTERTHINK +#ifdef POLYOBJECTS + if (player->onconveyor != 1 || !P_IsObjectOnGround(player->mo)) +#endif + player->onconveyor = 0; + // check special sectors : damage & secrets + + if (!player->spectator) + P_PlayerInSpecialSector(player); +#endif + if (splitscreen && player == &players[secondarydisplayplayer]) thiscam = &camera2; else if (player == &players[displayplayer]) From d13ca362d66360c87dc6f53a08b68f3d6501cb01 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 31 Oct 2016 21:34:43 +0000 Subject: [PATCH 007/223] Quicksand now supports slopes and also reverse gravity. --- src/p_user.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index 921f1240d..f2f0cb777 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1940,6 +1940,7 @@ static void P_CheckQuicksand(player_t *player) { ffloor_t *rover; fixed_t sinkspeed, friction; + fixed_t topheight, bottomheight; if (!(player->mo->subsector->sector->ffloors && player->mo->momz <= 0)) return; @@ -1951,16 +1952,33 @@ static void P_CheckQuicksand(player_t *player) if (!(rover->flags & FF_QUICKSAND)) continue; - if (*rover->topheight >= player->mo->z && *rover->bottomheight < player->mo->z + player->mo->height) + topheight = P_GetSpecialTopZ(player->mo, sectors + rover->secnum, player->mo->subsector->sector); + bottomheight = P_GetSpecialBottomZ(player->mo, sectors + rover->secnum, player->mo->subsector->sector); + + if (topheight >= player->mo->z && bottomheight < player->mo->z + player->mo->height) { sinkspeed = abs(rover->master->v1->x - rover->master->v2->x)>>1; sinkspeed = FixedDiv(sinkspeed,TICRATE*FRACUNIT); - player->mo->z -= sinkspeed; + if (player->mo->eflags & MFE_VERTICALFLIP) + { + fixed_t ceilingheight = P_GetCeilingZ(player->mo, player->mo->subsector->sector, player->mo->x, player->mo->y, NULL); - if (player->mo->z <= player->mo->subsector->sector->floorheight) - player->mo->z = player->mo->subsector->sector->floorheight; + player->mo->z += sinkspeed; + + if (player->mo->z + player->mo->height >= ceilingheight) + player->mo->z = ceilingheight - player->mo->height; + } + else + { + fixed_t floorheight = P_GetFloorZ(player->mo, player->mo->subsector->sector, player->mo->x, player->mo->y, NULL); + + player->mo->z -= sinkspeed; + + if (player->mo->z <= floorheight) + player->mo->z = floorheight; + } friction = abs(rover->master->v1->y - rover->master->v2->y)>>6; From d21b091b967d2d76d259347e8f6da6dab620fc03 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 31 Oct 2016 22:14:34 +0000 Subject: [PATCH 008/223] * Slope/gravity support for quicksand complete. * Space sector support complete, bounds of drowning now altered slightly. * Knuckles climb now has symmetrical slope support for both normal and reverse gravity. * All slope-determining topheight and bottomheight code is now identical in form. * Camera postimages now support slopes properly. --- src/p_user.c | 89 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index f2f0cb777..621122e2e 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1607,9 +1607,8 @@ void P_DoPlayerExit(player_t *player) #define SPACESPECIAL 12 boolean P_InSpaceSector(mobj_t *mo) // Returns true if you are in space { - sector_t *sector; - - sector = mo->subsector->sector; + sector_t *sector = mo->subsector->sector; + fixed_t topheight, bottomheight; if (GETSECSPECIAL(sector->special, 1) == SPACESPECIAL) return true; @@ -1622,11 +1621,18 @@ boolean P_InSpaceSector(mobj_t *mo) // Returns true if you are in space { if (GETSECSPECIAL(rover->master->frontsector->special, 1) != SPACESPECIAL) continue; +#ifdef ESLOPE + topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, mo->x, mo->y) : *rover->topheight; + bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, mo->x, mo->y) : *rover->bottomheight; +#else + topheight = *rover->topheight; + bottomheight = *rover->bottomheight; +#endif - if (mo->z > *rover->topheight) + if (mo->z + (mo->height/2) > topheight) continue; - if (mo->z + (mo->height/2) < *rover->bottomheight) + if (mo->z + (mo->height/2) < bottomheight) continue; return true; @@ -1638,9 +1644,10 @@ boolean P_InSpaceSector(mobj_t *mo) // Returns true if you are in space boolean P_InQuicksand(mobj_t *mo) // Returns true if you are in quicksand { - sector_t *sector; + sector_t *sector = mo->subsector->sector; + fixed_t topheight, bottomheight; - sector = mo->subsector->sector; + fixed_t flipoffset = ((mo->eflags & MFE_VERTICALFLIP) ? (mo->height/2) : 0); if (sector->ffloors) { @@ -1654,10 +1661,18 @@ boolean P_InQuicksand(mobj_t *mo) // Returns true if you are in quicksand if (!(rover->flags & FF_QUICKSAND)) continue; - if (mo->z > *rover->topheight) +#ifdef ESLOPE + topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, mo->x, mo->y) : *rover->topheight; + bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, mo->x, mo->y) : *rover->bottomheight; +#else + topheight = *rover->topheight; + bottomheight = *rover->bottomheight; +#endif + + if (mo->z + flipoffset > topheight) continue; - if (mo->z + (mo->height/2) < *rover->bottomheight) + if (mo->z + (mo->height/2) + flipoffset < bottomheight) continue; return true; @@ -1952,8 +1967,13 @@ static void P_CheckQuicksand(player_t *player) if (!(rover->flags & FF_QUICKSAND)) continue; - topheight = P_GetSpecialTopZ(player->mo, sectors + rover->secnum, player->mo->subsector->sector); - bottomheight = P_GetSpecialBottomZ(player->mo, sectors + rover->secnum, player->mo->subsector->sector); +#ifdef ESLOPE + topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y) : *rover->topheight; + bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y) : *rover->bottomheight; +#else + topheight = *rover->topheight; + bottomheight = *rover->bottomheight; +#endif if (topheight >= player->mo->z && bottomheight < player->mo->z + player->mo->height) { @@ -2339,11 +2359,11 @@ static void P_DoClimbing(player_t *player) floorclimb = true; #ifdef ESLOPE - bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y) : *rover->bottomheight; topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y) : *rover->topheight; + bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y) : *rover->bottomheight; #else - bottomheight = *rover->bottomheight; topheight = *rover->topheight; + bottomheight = *rover->bottomheight; #endif // Only supports rovers that are moving like an 'elevator', not just the top or bottom. @@ -2532,13 +2552,20 @@ static void P_DoClimbing(player_t *player) // Is there a FOF directly below that we can move onto? if (glidesector->sector->ffloors) { + fixed_t topheight; ffloor_t *rover; for (rover = glidesector->sector->ffloors; rover; rover = rover->next) { if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_BLOCKPLAYER) || (rover->flags & FF_BUSTUP)) continue; - if (*rover->topheight > ceilingheight - FixedMul(16*FRACUNIT, player->mo->scale)) +#ifdef ESLOPE + topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y) : *rover->topheight; +#else + topheight = *rover->topheight; +#endif + + if (topheight > ceilingheight - FixedMul(16*FRACUNIT, player->mo->scale)) { foundfof = true; break; @@ -2916,14 +2943,12 @@ static void P_DoTeeter(player_t *player) { if (!(rover->flags & FF_EXISTS)) continue; +#ifdef ESLOPE + topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y) : *rover->topheight; + bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y) : *rover->bottomheight; +#else topheight = *rover->topheight; bottomheight = *rover->bottomheight; - -#ifdef ESLOPE - if (*rover->t_slope) - topheight = P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y); - if (*rover->b_slope) - bottomheight = P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y); #endif if (P_CheckSolidLava(player->mo, rover, sec)) @@ -8549,13 +8574,23 @@ static void P_CalcPostImg(player_t *player) else if (sector->ffloors) { ffloor_t *rover; + fixed_t topheight; + fixed_t bottomheight; for (rover = sector->ffloors; rover; rover = rover->next) { if (!(rover->flags & FF_EXISTS)) continue; - if (pviewheight >= *rover->topheight || pviewheight <= *rover->bottomheight) +#ifdef ESLOPE + topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y) : *rover->topheight; + bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y) : *rover->bottomheight; +#else + topheight = *rover->topheight; + bottomheight = *rover->bottomheight; +#endif + + if (pviewheight >= topheight || pviewheight <= bottomheight) continue; if (P_FindSpecialLineFromTag(13, rover->master->frontsector->tag, -1) != -1) @@ -8567,13 +8602,23 @@ static void P_CalcPostImg(player_t *player) if (sector->ffloors) { ffloor_t *rover; + fixed_t topheight; + fixed_t bottomheight; for (rover = sector->ffloors; rover; rover = rover->next) { if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_SWIMMABLE) || rover->flags & FF_BLOCKPLAYER) continue; - if (pviewheight >= *rover->topheight || pviewheight <= *rover->bottomheight) +#ifdef ESLOPE + topheight = *rover->t_slope ? P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y) : *rover->topheight; + bottomheight = *rover->b_slope ? P_GetZAt(*rover->b_slope, player->mo->x, player->mo->y) : *rover->bottomheight; +#else + topheight = *rover->topheight; + bottomheight = *rover->bottomheight; +#endif + + if (pviewheight >= topheight || pviewheight <= bottomheight) continue; *type = postimg_water; From 7b12820c8298a2abfeb11e3c3f7c3e09839e5840 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Wed, 2 Nov 2016 20:32:36 +0000 Subject: [PATCH 009/223] Tweaked P_CheckSolidLava to avoid changing its function signature, and P_CanRunOnWater now supports slopes too. --- src/lua_baselib.c | 5 +---- src/p_local.h | 2 +- src/p_mobj.c | 30 ++++++++++++++++++++++-------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 00a519272..e8e8fd020 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -560,15 +560,12 @@ static int lib_pCheckSolidLava(lua_State *L) { mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); ffloor_t *rover = *((ffloor_t **)luaL_checkudata(L, 2, META_FFLOOR)); - sector_t *bound = *((sector_t **)luaL_checkudata(L, 3, META_SECTOR)); //HUDSAFE if (!mo) return LUA_ErrInvalid(L, "mobj_t"); if (!rover) return LUA_ErrInvalid(L, "ffloor_t"); - if (!bound) - return LUA_ErrInvalid(L, "sector_t"); - lua_pushboolean(L, P_CheckSolidLava(mo, rover, bound)); + lua_pushboolean(L, P_CheckSolidLava(mo, rover)); return 1; } diff --git a/src/p_local.h b/src/p_local.h index ce6aed028..1fd7ada04 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -238,7 +238,7 @@ fixed_t P_CameraCeilingZ(camera_t *mobj, sector_t *sector, sector_t *boundsec, f boolean P_InsideANonSolidFFloor(mobj_t *mobj, ffloor_t *rover); boolean P_CheckDeathPitCollide(mobj_t *mo); -boolean P_CheckSolidLava(mobj_t *mo, ffloor_t *rover, sector_t *bound); +boolean P_CheckSolidLava(mobj_t *mo, ffloor_t *rover); mobj_t *P_SpawnMissile(mobj_t *source, mobj_t *dest, mobjtype_t type); mobj_t *P_SpawnXYZMissile(mobj_t *source, mobj_t *dest, mobjtype_t type, fixed_t x, fixed_t y, fixed_t z); diff --git a/src/p_mobj.c b/src/p_mobj.c index 4f0c84033..6ad84de34 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -1983,7 +1983,7 @@ static void P_AdjustMobjFloorZ_FFloors(mobj_t *mo, sector_t *sector, UINT8 motyp topheight = P_GetFOFTopZ(mo, sector, rover, mo->x, mo->y, NULL); bottomheight = P_GetFOFBottomZ(mo, sector, rover, mo->x, mo->y, NULL); - if (mo->player && (P_CheckSolidLava(mo, rover, sector) || P_CanRunOnWater(mo->player, rover))) // only the player should be affected + if (mo->player && (P_CheckSolidLava(mo, rover) || P_CanRunOnWater(mo->player, rover))) // only the player should be affected ; else if (motype != 0 && rover->flags & FF_SWIMMABLE) // "scenery" only continue; @@ -2133,15 +2133,23 @@ boolean P_CheckDeathPitCollide(mobj_t *mo) return false; } -boolean P_CheckSolidLava(mobj_t *mo, ffloor_t *rover, sector_t *bound) +boolean P_CheckSolidLava(mobj_t *mo, ffloor_t *rover) { I_Assert(mo != NULL); I_Assert(!P_MobjWasRemoved(mo)); - if (rover->flags & FF_SWIMMABLE && GETSECSPECIAL(rover->master->frontsector->special, 1) == 3 - && !(rover->master->flags & ML_BLOCKMONSTERS) - && ((rover->master->flags & ML_EFFECT3) || mo->z-mo->momz > P_GetSpecialTopZ(mo, rover->master->frontsector, bound) - FixedMul(16*FRACUNIT, mo->scale))) - return true; + { + fixed_t topheight = + #ifdef ESLOPE + *rover->t_slope ? P_GetZAt(*rover->t_slope, mo->x, mo->y) : + #endif + *rover->topheight; + + if (rover->flags & FF_SWIMMABLE && GETSECSPECIAL(rover->master->frontsector->special, 1) == 3 + && !(rover->master->flags & ML_BLOCKMONSTERS) + && ((rover->master->flags & ML_EFFECT3) || mo->z-mo->momz > topheight - FixedMul(16*FRACUNIT, mo->scale))) + return true; + } return false; } @@ -3076,11 +3084,17 @@ static boolean P_SceneryZMovement(mobj_t *mo) // boolean P_CanRunOnWater(player_t *player, ffloor_t *rover) { + fixed_t topheight = +#ifdef ESLOPE + *rover->t_slope ? P_GetZAt(*rover->t_slope, player->mo->x, player->mo->y) : +#endif + *rover->topheight; + if (!(player->pflags & PF_NIGHTSMODE) && !player->homing - && (((player->charability == CA_SWIM) || player->powers[pw_super] || player->charflags & SF_RUNONWATER) && player->mo->ceilingz-*rover->topheight >= player->mo->height) + && (((player->charability == CA_SWIM) || player->powers[pw_super] || player->charflags & SF_RUNONWATER) && player->mo->ceilingz-topheight >= player->mo->height) && (rover->flags & FF_SWIMMABLE) && !(player->pflags & PF_SPINNING) && player->speed > FixedMul(player->runspeed, player->mo->scale) && !(player->pflags & PF_SLIDING) - && abs(player->mo->z - *rover->topheight) < FixedMul(30*FRACUNIT, player->mo->scale)) + && abs(player->mo->z - topheight) < FixedMul(30*FRACUNIT, player->mo->scale)) return true; return false; From e67f48df83cd82bc67a0d24fc00333e5d2bba62f Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Wed, 2 Nov 2016 20:35:53 +0000 Subject: [PATCH 010/223] Forgot to revert the other files. --- src/p_map.c | 2 +- src/p_maputl.c | 4 ++-- src/p_user.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index 7b5426605..6a555953e 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1323,7 +1323,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) continue; } - if (thing->player && (P_CheckSolidLava(thing, rover, newsubsec->sector) || P_CanRunOnWater(thing->player, rover))) + if (thing->player && (P_CheckSolidLava(thing, rover) || P_CanRunOnWater(thing->player, rover))) ; else if (thing->type == MT_SKIM && (rover->flags & FF_SWIMMABLE)) ; diff --git a/src/p_maputl.c b/src/p_maputl.c index 3aa9a994f..fea8530a1 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -646,7 +646,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (!(rover->flags & FF_EXISTS)) continue; - if (mobj->player && (P_CheckSolidLava(mobj, rover, front) || P_CanRunOnWater(mobj->player, rover))) + if (mobj->player && (P_CheckSolidLava(mobj, rover) || P_CanRunOnWater(mobj->player, rover))) ; else if (!((rover->flags & FF_BLOCKPLAYER && mobj->player) || (rover->flags & FF_BLOCKOTHERS && !mobj->player))) @@ -690,7 +690,7 @@ void P_LineOpening(line_t *linedef, mobj_t *mobj) if (!(rover->flags & FF_EXISTS)) continue; - if (mobj->player && (P_CheckSolidLava(mobj, rover, back) || P_CanRunOnWater(mobj->player, rover))) + if (mobj->player && (P_CheckSolidLava(mobj, rover) || P_CanRunOnWater(mobj->player, rover))) ; else if (!((rover->flags & FF_BLOCKPLAYER && mobj->player) || (rover->flags & FF_BLOCKOTHERS && !mobj->player))) diff --git a/src/p_user.c b/src/p_user.c index 621122e2e..56ecdf804 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2951,7 +2951,7 @@ static void P_DoTeeter(player_t *player) bottomheight = *rover->bottomheight; #endif - if (P_CheckSolidLava(player->mo, rover, sec)) + if (P_CheckSolidLava(player->mo, rover)) ; else if (!(rover->flags & FF_BLOCKPLAYER || rover->flags & FF_QUICKSAND)) continue; // intangible 3d floor From 795b3aa552080de6e25fbd0ef1362e831bdbf110 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 5 Sep 2016 22:14:51 +0100 Subject: [PATCH 011/223] Call V_DoPostProcessor only in software mode (it cancels itself in OGL anyway) --- src/d_main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index d9df1f544..e41e97ad2 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -384,10 +384,13 @@ static void D_Display(void) } // Image postprocessing effect - if (postimgtype) - V_DoPostProcessor(0, postimgtype, postimgparam); - if (postimgtype2) - V_DoPostProcessor(1, postimgtype2, postimgparam2); + if (rendermode == render_soft) + { + if (postimgtype) + V_DoPostProcessor(0, postimgtype, postimgparam); + if (postimgtype2) + V_DoPostProcessor(1, postimgtype2, postimgparam2); + } } if (lastdraw) From 43cdcc94f9d42e29913fa0c4e6039f28f9d3dffd Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 20 Sep 2016 17:51:09 +0100 Subject: [PATCH 012/223] remove commented-out HWRENDER code in V_DrawContinueIcon --- src/v_video.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 91d730513..fc423dee4 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -651,11 +651,7 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ // void V_DrawContinueIcon(INT32 x, INT32 y, INT32 flags, INT32 skinnum, UINT8 skincolor) { - if (skins[skinnum].flags & SF_HIRES -#ifdef HWRENDER -// || (rendermode != render_soft && rendermode != render_none) -#endif - ) + if (skins[skinnum].flags & SF_HIRES) V_DrawScaledPatch(x - 10, y - 14, flags, W_CachePatchName("CONTINS", PU_CACHE)); else { From b00c6804378c29841b501f7a367aa1edb8f7e61b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 5 Nov 2016 20:40:48 +0000 Subject: [PATCH 013/223] Add MD2_INDENT and MD2_VERSION so we can cleanly check that it's a valid MD2 from magic number/version --- src/hardware/hw_md2.c | 4 ++-- src/hardware/hw_md2.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index a5f262aea..bf9fd2dfe 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -298,8 +298,8 @@ static md2_model_t *md2_readModel(const char *filename) // initialize model and read header if (fread(&model->header, sizeof (model->header), 1, file) != 1 - || model->header.magic != - (INT32)(('2' << 24) + ('P' << 16) + ('D' << 8) + 'I')) + || model->header.magic != MD2_IDENT + || model->header.version != MD2_VERSION) { fclose(file); free(model); diff --git a/src/hardware/hw_md2.h b/src/hardware/hw_md2.h index 5a7e6d2b3..299d12400 100644 --- a/src/hardware/hw_md2.h +++ b/src/hardware/hw_md2.h @@ -23,6 +23,11 @@ #include "hw_glob.h" +// magic number "IDP2" or 844121161 +#define MD2_IDENT (INT32)(('2' << 24) + ('P' << 16) + ('D' << 8) + 'I') +// model version +#define MD2_VERSION 8 + #define MD2_MAX_TRIANGLES 8192 #define MD2_MAX_VERTICES 4096 #define MD2_MAX_TEXCOORDS 4096 From 05860b2fa17f2f926b75ce928463913967443cab Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 5 Nov 2016 20:51:48 +0000 Subject: [PATCH 014/223] Ensure file is closed whenever MD2 reading errors happen --- src/hardware/hw_md2.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index bf9fd2dfe..75e54edab 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -313,6 +313,7 @@ static md2_model_t *md2_readModel(const char *filename) { \ CONS_Alert(CONS_ERROR, "md2_readModel: %s has too many " msgname " (# found: %d, maximum: %d)\n", filename, field, max); \ md2_freeModel (model); \ + fclose(file); \ return 0; \ } @@ -334,6 +335,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(model->skins, sizeof (md2_skin_t), model->header.numSkins, file)) { md2_freeModel (model); + fclose(file); return 0; } } @@ -347,6 +349,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(model->texCoords, sizeof (md2_textureCoordinate_t), model->header.numTexCoords, file)) { md2_freeModel (model); + fclose(file); return 0; } } @@ -360,6 +363,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(model->triangles, sizeof (md2_triangle_t), model->header.numTriangles, file)) { md2_freeModel (model); + fclose(file); return 0; } } @@ -372,6 +376,7 @@ static md2_model_t *md2_readModel(const char *filename) if (!model->frames) { md2_freeModel (model); + fclose(file); return 0; } @@ -385,6 +390,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(frame, 1, model->header.frameSize, file)) { md2_freeModel (model); + fclose(file); return 0; } @@ -410,6 +416,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(model->glCommandBuffer, sizeof (INT32), model->header.numGlCommands, file)) { md2_freeModel (model); + fclose(file); return 0; } } From 817f0908e4f05ae1a7e4c20383ee10c1a4d85653 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 7 Nov 2016 18:34:51 +0000 Subject: [PATCH 015/223] made HWR_CreateBlendedTexture's color switch case take up not so many lines, and only one V_GetColor call is used now --- src/hardware/hw_md2.c | 284 ++++++++---------------------------------- 1 file changed, 50 insertions(+), 234 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index b76230d4d..18fc1bd6d 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -945,6 +945,7 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, { UINT16 w = gpatch->width, h = gpatch->height; UINT32 size = w*h; + UINT8 c = 255; RGBA_t *image, *blendimage, *cur, blendcolor; if (grmip->width == 0) @@ -968,244 +969,59 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, image = gpatch->mipmap.grInfo.data; blendimage = blendgpatch->mipmap.grInfo.data; +#define SUPERCOLORBLEND(name, c1, c2, c3, c4, c5) \ + case SKINCOLOR_SUPER ## name ## 1: c = c1; break; \ + case SKINCOLOR_SUPER ## name ## 2: c = c2; break; \ + case SKINCOLOR_SUPER ## name ## 3: c = c3; break; \ + case SKINCOLOR_SUPER ## name ## 4: c = c4; break; \ + case SKINCOLOR_SUPER ## name ## 5: c = c5; break; + switch (color) { - case SKINCOLOR_WHITE: - blendcolor = V_GetColor(3); - break; - case SKINCOLOR_SILVER: - blendcolor = V_GetColor(10); - break; - case SKINCOLOR_GREY: - blendcolor = V_GetColor(15); - break; - case SKINCOLOR_BLACK: - blendcolor = V_GetColor(27); - break; - case SKINCOLOR_BEIGE: - blendcolor = V_GetColor(247); - break; - case SKINCOLOR_PEACH: - blendcolor = V_GetColor(218); - break; - case SKINCOLOR_BROWN: - blendcolor = V_GetColor(234); - break; - case SKINCOLOR_RED: - blendcolor = V_GetColor(38); - break; - case SKINCOLOR_CRIMSON: - blendcolor = V_GetColor(45); - break; - case SKINCOLOR_ORANGE: - blendcolor = V_GetColor(54); - break; - case SKINCOLOR_RUST: - blendcolor = V_GetColor(60); - break; - case SKINCOLOR_GOLD: - blendcolor = V_GetColor(67); - break; - case SKINCOLOR_YELLOW: - blendcolor = V_GetColor(73); - break; - case SKINCOLOR_TAN: - blendcolor = V_GetColor(85); - break; - case SKINCOLOR_MOSS: - blendcolor = V_GetColor(92); - break; - case SKINCOLOR_PERIDOT: - blendcolor = V_GetColor(188); - break; - case SKINCOLOR_GREEN: - blendcolor = V_GetColor(101); - break; - case SKINCOLOR_EMERALD: - blendcolor = V_GetColor(112); - break; - case SKINCOLOR_AQUA: - blendcolor = V_GetColor(122); - break; - case SKINCOLOR_TEAL: - blendcolor = V_GetColor(141); - break; - case SKINCOLOR_CYAN: - blendcolor = V_GetColor(131); - break; - case SKINCOLOR_BLUE: - blendcolor = V_GetColor(152); - break; - case SKINCOLOR_AZURE: - blendcolor = V_GetColor(171); - break; - case SKINCOLOR_PASTEL: - blendcolor = V_GetColor(161); - break; - case SKINCOLOR_PURPLE: - blendcolor = V_GetColor(165); - break; - case SKINCOLOR_LAVENDER: - blendcolor = V_GetColor(195); - break; - case SKINCOLOR_MAGENTA: - blendcolor = V_GetColor(183); - break; - case SKINCOLOR_PINK: - blendcolor = V_GetColor(211); - break; - case SKINCOLOR_ROSY: - blendcolor = V_GetColor(202); - break; + case SKINCOLOR_WHITE: c = 3; break; + case SKINCOLOR_SILVER: c = 10; break; + case SKINCOLOR_GREY: c = 15; break; + case SKINCOLOR_BLACK: c = 27; break; + case SKINCOLOR_BEIGE: c = 247; break; + case SKINCOLOR_PEACH: c = 218; break; + case SKINCOLOR_BROWN: c = 234; break; + case SKINCOLOR_RED: c = 38; break; + case SKINCOLOR_CRIMSON: c = 45; break; + case SKINCOLOR_ORANGE: c = 54; break; + case SKINCOLOR_RUST: c = 60; break; + case SKINCOLOR_GOLD: c = 67; break; + case SKINCOLOR_YELLOW: c = 73; break; + case SKINCOLOR_TAN: c = 85; break; + case SKINCOLOR_MOSS: c = 92; break; + case SKINCOLOR_PERIDOT: c = 188; break; + case SKINCOLOR_GREEN: c = 101; break; + case SKINCOLOR_EMERALD: c = 112; break; + case SKINCOLOR_AQUA: c = 122; break; + case SKINCOLOR_TEAL: c = 141; break; + case SKINCOLOR_CYAN: c = 131; break; + case SKINCOLOR_BLUE: c = 152; break; + case SKINCOLOR_AZURE: c = 171; break; + case SKINCOLOR_PASTEL: c = 161; break; + case SKINCOLOR_PURPLE: c = 165; break; + case SKINCOLOR_LAVENDER: c = 195; break; + case SKINCOLOR_MAGENTA: c = 183; break; + case SKINCOLOR_PINK: c = 211; break; + case SKINCOLOR_ROSY: c = 202; break; - case SKINCOLOR_SUPERSILVER1: // Super silver - blendcolor = V_GetColor(0); - break; - case SKINCOLOR_SUPERSILVER2: - blendcolor = V_GetColor(2); - break; - case SKINCOLOR_SUPERSILVER3: - blendcolor = V_GetColor(4); - break; - case SKINCOLOR_SUPERSILVER4: - blendcolor = V_GetColor(7); - break; - case SKINCOLOR_SUPERSILVER5: - blendcolor = V_GetColor(10); - break; - - case SKINCOLOR_SUPERRED1: // Super red - blendcolor = V_GetColor(208); - break; - case SKINCOLOR_SUPERRED2: - blendcolor = V_GetColor(210); - break; - case SKINCOLOR_SUPERRED3: - blendcolor = V_GetColor(32); - break; - case SKINCOLOR_SUPERRED4: - blendcolor = V_GetColor(33); - break; - case SKINCOLOR_SUPERRED5: - blendcolor = V_GetColor(35); - break; - - case SKINCOLOR_SUPERORANGE1: // Super orange - blendcolor = V_GetColor(208); - break; - case SKINCOLOR_SUPERORANGE2: - blendcolor = V_GetColor(48); - break; - case SKINCOLOR_SUPERORANGE3: - blendcolor = V_GetColor(50); - break; - case SKINCOLOR_SUPERORANGE4: - blendcolor = V_GetColor(54); - break; - case SKINCOLOR_SUPERORANGE5: - blendcolor = V_GetColor(58); - break; - - case SKINCOLOR_SUPERGOLD1: // Super gold - blendcolor = V_GetColor(80); - break; - case SKINCOLOR_SUPERGOLD2: - blendcolor = V_GetColor(83); - break; - case SKINCOLOR_SUPERGOLD3: - blendcolor = V_GetColor(73); - break; - case SKINCOLOR_SUPERGOLD4: - blendcolor = V_GetColor(64); - break; - case SKINCOLOR_SUPERGOLD5: - blendcolor = V_GetColor(67); - break; - - case SKINCOLOR_SUPERPERIDOT1: // Super peridot - blendcolor = V_GetColor(88); - break; - case SKINCOLOR_SUPERPERIDOT2: - blendcolor = V_GetColor(188); - break; - case SKINCOLOR_SUPERPERIDOT3: - blendcolor = V_GetColor(189); - break; - case SKINCOLOR_SUPERPERIDOT4: - blendcolor = V_GetColor(190); - break; - case SKINCOLOR_SUPERPERIDOT5: - blendcolor = V_GetColor(191); - break; - - case SKINCOLOR_SUPERCYAN1: // Super cyan - blendcolor = V_GetColor(128); - break; - case SKINCOLOR_SUPERCYAN2: - blendcolor = V_GetColor(131); - break; - case SKINCOLOR_SUPERCYAN3: - blendcolor = V_GetColor(133); - break; - case SKINCOLOR_SUPERCYAN4: - blendcolor = V_GetColor(134); - break; - case SKINCOLOR_SUPERCYAN5: - blendcolor = V_GetColor(136); - break; - - case SKINCOLOR_SUPERPURPLE1: // Super purple - blendcolor = V_GetColor(144); - break; - case SKINCOLOR_SUPERPURPLE2: - blendcolor = V_GetColor(162); - break; - case SKINCOLOR_SUPERPURPLE3: - blendcolor = V_GetColor(164); - break; - case SKINCOLOR_SUPERPURPLE4: - blendcolor = V_GetColor(166); - break; - case SKINCOLOR_SUPERPURPLE5: - blendcolor = V_GetColor(168); - break; - - case SKINCOLOR_SUPERRUST1: // Super rust - blendcolor = V_GetColor(51); - break; - case SKINCOLOR_SUPERRUST2: - blendcolor = V_GetColor(54); - break; - case SKINCOLOR_SUPERRUST3: - blendcolor = V_GetColor(68); - break; - case SKINCOLOR_SUPERRUST4: - blendcolor = V_GetColor(70); - break; - case SKINCOLOR_SUPERRUST5: - blendcolor = V_GetColor(234); - break; - - case SKINCOLOR_SUPERTAN1: // Super tan - blendcolor = V_GetColor(80); - break; - case SKINCOLOR_SUPERTAN2: - blendcolor = V_GetColor(82); - break; - case SKINCOLOR_SUPERTAN3: - blendcolor = V_GetColor(84); - break; - case SKINCOLOR_SUPERTAN4: - blendcolor = V_GetColor(87); - break; - case SKINCOLOR_SUPERTAN5: - blendcolor = V_GetColor(247); - break; - - default: - blendcolor = V_GetColor(255); - break; + SUPERCOLORBLEND(SILVER, 0, 2, 4, 7, 10) // Super silver + SUPERCOLORBLEND(RED, 208, 210, 32, 33, 35) // Super red + SUPERCOLORBLEND(ORANGE, 208, 48, 50, 54, 58) // Super orange + SUPERCOLORBLEND(GOLD, 80, 83, 73, 64, 67) // Super gold + SUPERCOLORBLEND(PERIDOT, 88, 188, 189, 190, 191) // Super peridot + SUPERCOLORBLEND(CYAN, 128, 131, 133, 134, 136) // Super cyan + SUPERCOLORBLEND(PURPLE, 144, 162, 164, 166, 168) // Super purple + SUPERCOLORBLEND(RUST, 51, 54, 68, 70, 234) // Super rust + SUPERCOLORBLEND(TAN, 80, 82, 84, 87, 247) // Super tan + default: c = 255; break; } + blendcolor = V_GetColor(c); + +#undef SUPERCOLORBLEND while (size--) { From 5be8e4f1b0fe2a1525e9747bd691ee8fc42404f9 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 7 Nov 2016 21:55:56 +0000 Subject: [PATCH 016/223] Make new pv1/pv2 seg pointers, so AdjustSeg doesn't modify the v1/v2 pointers directly anymore Yes I know they're void * in r_defs.h's seg_t definition, it's quicker than trying to figure out if including hardware/hw_glob.h is a good idea or not --- src/hardware/hw_bsp.c | 12 ++++---- src/hardware/hw_main.c | 64 +++++++++++++++++++++--------------------- src/p_setup.c | 1 + src/r_defs.h | 3 ++ 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 17eb8761c..2a67f7d56 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -916,7 +916,7 @@ static void AdjustSegs(void) } if (nearv1 <= NEARDIST*NEARDIST) // share vertice with segs - lseg->v1 = (vertex_t *)&(p->pts[v1found]); + lseg->pv1 = &(p->pts[v1found]); else { // BP: here we can do better, using PointInSeg and compute @@ -927,24 +927,24 @@ static void AdjustSegs(void) polyvertex_t *pv = HWR_AllocVertex(); pv->x = FIXED_TO_FLOAT(lseg->v1->x); pv->y = FIXED_TO_FLOAT(lseg->v1->y); - lseg->v1 = (vertex_t *)pv; + lseg->pv1 = pv; } if (nearv2 <= NEARDIST*NEARDIST) - lseg->v2 = (vertex_t *)&(p->pts[v2found]); + lseg->pv2 = &(p->pts[v2found]); else { polyvertex_t *pv = HWR_AllocVertex(); pv->x = FIXED_TO_FLOAT(lseg->v2->x); pv->y = FIXED_TO_FLOAT(lseg->v2->y); - lseg->v2 = (vertex_t *)pv; + lseg->pv2 = pv; } // recompute length { float x,y; - x = ((polyvertex_t *)lseg->v2)->x - ((polyvertex_t *)lseg->v1)->x + x = ((polyvertex_t *)lseg->pv2)->x - ((polyvertex_t *)lseg->pv1)->x + FIXED_TO_FLOAT(FRACUNIT/2); - y = ((polyvertex_t *)lseg->v2)->y - ((polyvertex_t *)lseg->v1)->y + y = ((polyvertex_t *)lseg->pv2)->y - ((polyvertex_t *)lseg->pv1)->y + FIXED_TO_FLOAT(FRACUNIT/2); lseg->flength = (float)hypot(x, y); // BP: debug see this kind of segs diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 270229ad0..3d9b82b32 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -858,11 +858,11 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) M_ClearBox(segbbox); M_AddToBox(segbbox, - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y)); + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y)); M_AddToBox(segbbox, - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y)); + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y)); splat = (wallsplat_t *)gr_curline->linedef->splats; for (; splat; splat = splat->next) @@ -1468,10 +1468,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) gr_sidedef = gr_curline->sidedef; gr_linedef = gr_curline->linedef; - vs.x = ((polyvertex_t *)gr_curline->v1)->x; - vs.y = ((polyvertex_t *)gr_curline->v1)->y; - ve.x = ((polyvertex_t *)gr_curline->v2)->x; - ve.y = ((polyvertex_t *)gr_curline->v2)->y; + vs.x = ((polyvertex_t *)gr_curline->pv1)->x; + vs.y = ((polyvertex_t *)gr_curline->pv1)->y; + ve.x = ((polyvertex_t *)gr_curline->pv2)->x; + ve.y = ((polyvertex_t *)gr_curline->pv2)->y; #ifdef ESLOPE v1x = FLOAT_TO_FIXED(vs.x); @@ -2555,7 +2555,7 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last) } else { - highfrac = HWR_ClipViewSegment(start->first+1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + highfrac = HWR_ClipViewSegment(start->first+1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(0, highfrac); } // Now adjust the clip size. @@ -2579,8 +2579,8 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last) } else { - lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); - highfrac = HWR_ClipViewSegment((next+1)->first+1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); + highfrac = HWR_ClipViewSegment((next+1)->first+1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(lowfrac, highfrac); } next++; @@ -2614,7 +2614,7 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last) } else { - lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(lowfrac, 1); } } @@ -2677,8 +2677,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last) else { highfrac = HWR_ClipViewSegment(min(start->first + 1, - start->last), (polyvertex_t *)gr_curline->v1, - (polyvertex_t *)gr_curline->v2); + start->last), (polyvertex_t *)gr_curline->pv1, + (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(0, highfrac); } } @@ -2697,8 +2697,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last) } else { - lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); - highfrac = HWR_ClipViewSegment(min((start+1)->first+1,(start+1)->last), (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); + highfrac = HWR_ClipViewSegment(min((start+1)->first+1,(start+1)->last), (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(lowfrac, highfrac); } start++; @@ -2728,8 +2728,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last) else { lowfrac = HWR_ClipViewSegment(max(start->last - 1, - start->first), (polyvertex_t *)gr_curline->v1, - (polyvertex_t *)gr_curline->v2); + start->first), (polyvertex_t *)gr_curline->pv1, + (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(lowfrac, 1); } } @@ -2790,10 +2790,10 @@ static void HWR_AddLine(seg_t * line) gr_curline = line; // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y)); - angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y)); + angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y)); + angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y)); // Clip to view edges. span = angle1 - angle2; @@ -2835,8 +2835,8 @@ static void HWR_AddLine(seg_t * line) float fx1,fx2,fy1,fy2; //BP: test with a better projection than viewangletox[R_PointToAngle(angle)] // do not enable this at release 4 mul and 2 div - fx1 = ((polyvertex_t *)(line->v1))->x-gr_viewx; - fy1 = ((polyvertex_t *)(line->v1))->y-gr_viewy; + fx1 = ((polyvertex_t *)(line->pv1))->x-gr_viewx; + fy1 = ((polyvertex_t *)(line->pv1))->y-gr_viewy; fy2 = (fx1 * gr_viewcos + fy1 * gr_viewsin); if (fy2 < 0) // the point is back @@ -2844,8 +2844,8 @@ static void HWR_AddLine(seg_t * line) else fx1 = gr_windowcenterx + (fx1 * gr_viewsin - fy1 * gr_viewcos) * gr_centerx / fy2; - fx2 = ((polyvertex_t *)(line->v2))->x-gr_viewx; - fy2 = ((polyvertex_t *)(line->v2))->y-gr_viewy; + fx2 = ((polyvertex_t *)(line->pv2))->x-gr_viewx; + fy2 = ((polyvertex_t *)(line->pv2))->y-gr_viewy; fy1 = (fx2 * gr_viewcos + fy2 * gr_viewsin); if (fy1 < 0) // the point is back @@ -2888,10 +2888,10 @@ static void HWR_AddLine(seg_t * line) fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends - v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x); - v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y); - v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x); - v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y); + v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x); + v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y); + v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x); + v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); #define SLOPEPARAMS(slope, end1, end2, normalheight) \ if (slope) { \ end1 = P_GetZAt(slope, v1x, v1y); \ @@ -3086,8 +3086,8 @@ static inline void HWR_AddPolyObjectSegs(void) pv2->x = FIXED_TO_FLOAT(gr_fakeline->v2->x); pv2->y = FIXED_TO_FLOAT(gr_fakeline->v2->y); - gr_fakeline->v1 = (vertex_t *)pv1; - gr_fakeline->v2 = (vertex_t *)pv2; + gr_fakeline->pv1 = pv1; + gr_fakeline->pv2 = pv2; HWR_AddLine(gr_fakeline); } diff --git a/src/p_setup.c b/src/p_setup.c index f1d3a68c8..f8653502a 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -451,6 +451,7 @@ static void P_LoadSegs(lumpnum_t lumpnum) //Hurdler: 04/12/2000: for now, only used in hardware mode li->lightmaps = NULL; // list of static lightmap for this seg } + li->pv1 = li->pv2 = NULL; #endif li->angle = (SHORT(ml->angle))< Date: Tue, 6 Dec 2016 21:49:59 +0000 Subject: [PATCH 017/223] * Disabled #define SECTORSPECIALSAFTERTHINK. This did not need to be done in next, since it could have subtle consequences which we'd rather not deal with in the hyperextended patch cycle as-is. * Removed the adding of SF_TRIGGERSPECIAL_TOUCH for sectors with slopes in them. Too many undesired consequences, I'll handle them another way. --- src/doomdef.h | 2 +- src/p_slopes.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index f993dadf8..bccf433b2 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -500,6 +500,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Handle touching sector specials in P_PlayerAfterThink instead of P_PlayerThink. /// \note Required for proper collision with moving sloped surfaces that have sector specials on them. -#define SECTORSPECIALSAFTERTHINK +//#define SECTORSPECIALSAFTERTHINK #endif // __DOOMDEF__ diff --git a/src/p_slopes.c b/src/p_slopes.c index c127001cd..d939fee98 100644 --- a/src/p_slopes.c +++ b/src/p_slopes.c @@ -281,7 +281,6 @@ void P_SpawnSlope_Line(int linenum) if(frontfloor || frontceil) { line->frontsector->hasslope = true; // Tell the software renderer that we're sloped - line->frontsector->flags |= SF_TRIGGERSPECIAL_TOUCH; // you're gonna want to get specials on contact origin.z = line->backsector->floorheight; direction.x = nx; @@ -408,7 +407,6 @@ void P_SpawnSlope_Line(int linenum) if(backfloor || backceil) { line->backsector->hasslope = true; // Tell the software renderer that we're sloped - line->backsector->flags |= SF_TRIGGERSPECIAL_TOUCH; // you're gonna want to get specials on contact origin.z = line->frontsector->floorheight; // Backsector @@ -601,7 +599,6 @@ void P_CopySectorSlope(line_t *line) } fsec->hasslope = true; - fsec->flags |= SF_TRIGGERSPECIAL_TOUCH; // you're gonna want to get specials on contact line->special = 0; // Linedef was use to set slopes, it finished its job, so now make it a normal linedef } @@ -721,7 +718,6 @@ void P_ResetDynamicSlopes(void) { *slopetoset = P_NewVertexSlope(lines[i].tag, lines[i].tag, lines[i].tag, flags); sides[lines[i].sidenum[which]].sector->hasslope = true; - sides[lines[i].sidenum[which]].sector->flags |= SF_TRIGGERSPECIAL_TOUCH; // you're gonna want to get specials on contact } break; From 41dfba65c9e863953ea1f1ef50f96fe80849be56 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 21 Dec 2016 22:10:27 +0000 Subject: [PATCH 018/223] Hack to make sure even (extra)subsectors without planepolys have segs adjusted this fixes a crash in (old) GFZ2 at the ramp as a result of creating pv1/pv2. This probably means before pv1/pv2 there could have been some silly typecasting from vertex_t to polyvertex_t to get fixed vertex coords and such... --- src/hardware/hw_bsp.c | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 2a67f7d56..e9ec60254 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -880,8 +880,8 @@ static void AdjustSegs(void) count = subsectors[i].numlines; lseg = &segs[subsectors[i].firstline]; p = extrasubsectors[i].planepoly; - if (!p) - continue; + //if (!p) + //continue; for (; count--; lseg++) { float distv1,distv2,tmp; @@ -894,27 +894,29 @@ static void AdjustSegs(void) continue; #endif - for (j = 0; j < p->numpts; j++) - { - distv1 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v1->x); - tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v1->y); - distv1 = distv1*distv1+tmp*tmp; - if (distv1 <= nearv1) + if (p) { + for (j = 0; j < p->numpts; j++) { - v1found = j; - nearv1 = distv1; - } - // the same with v2 - distv2 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v2->x); - tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v2->y); - distv2 = distv2*distv2+tmp*tmp; - if (distv2 <= nearv2) - { - v2found = j; - nearv2 = distv2; + distv1 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v1->x); + tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v1->y); + distv1 = distv1*distv1+tmp*tmp; + if (distv1 <= nearv1) + { + v1found = j; + nearv1 = distv1; + } + // the same with v2 + distv2 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v2->x); + tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v2->y); + distv2 = distv2*distv2+tmp*tmp; + if (distv2 <= nearv2) + { + v2found = j; + nearv2 = distv2; + } } } - if (nearv1 <= NEARDIST*NEARDIST) + if (p && nearv1 <= NEARDIST*NEARDIST) // share vertice with segs lseg->pv1 = &(p->pts[v1found]); else @@ -929,7 +931,7 @@ static void AdjustSegs(void) pv->y = FIXED_TO_FLOAT(lseg->v1->y); lseg->pv1 = pv; } - if (nearv2 <= NEARDIST*NEARDIST) + if (p && nearv2 <= NEARDIST*NEARDIST) lseg->pv2 = &(p->pts[v2found]); else { From 0538c98251907096b7c23e06edb62acf11b5bcb1 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 21 Dec 2016 22:31:09 +0000 Subject: [PATCH 019/223] Added missing checks in HWR_AddLine from the software version, move v** vars to the top since R_PointToAngle calls use the same values anyway --- src/hardware/hw_main.c | 49 ++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 3d9b82b32..ac4f6af83 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2784,16 +2784,21 @@ static void HWR_AddLine(seg_t * line) // SoM: Backsector needs to be run through R_FakeFlat sector_t tempsec; + fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t + if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) return; gr_curline = line; + v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x); + v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y); + v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x); + v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); + // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y)); - angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y)); + angle1 = R_PointToAngle(v1x, v1y); + angle2 = R_PointToAngle(v2x, v2y); // Clip to view edges. span = angle1 - angle2; @@ -2884,14 +2889,9 @@ static void HWR_AddLine(seg_t * line) #ifdef ESLOPE if (gr_frontsector->f_slope || gr_frontsector->c_slope || gr_backsector->f_slope || gr_backsector->c_slope) { - fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends - v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x); - v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y); - v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x); - v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); #define SLOPEPARAMS(slope, end1, end2, normalheight) \ if (slope) { \ end1 = P_GetZAt(slope, v1x, v1y); \ @@ -2912,6 +2912,13 @@ static void HWR_AddLine(seg_t * line) goto clipsolid; } + // Check for automap fix. + if (backc1 <= backf1 && backc2 <= backf2 + && ((backc1 >= frontc1 && backc2 >= frontc2) || gr_curline->sidedef->toptexture) + && ((backf1 <= frontf1 && backf2 >= frontf2) || gr_curline->sidedef->bottomtexture) + && (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum)) + goto clipsolid; + // Window. if (backc1 != frontc1 || backc2 != frontc2 || backf1 != frontf1 || backf2 != frontf2) @@ -2927,6 +2934,13 @@ static void HWR_AddLine(seg_t * line) gr_backsector->floorheight >= gr_frontsector->ceilingheight) goto clipsolid; + // Check for automap fix. + if (gr_backsector->ceilingheight <= gr_backsector->floorheight + && ((gr_backsector->ceilingheight >= gr_frontsector->ceilingheight) || gr_curline->sidedef->toptexture) + && ((gr_backsector->floorheight <= gr_backsector->floorheight) || gr_curline->sidedef->bottomtexture) + && (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum)) + goto clipsolid; + // Window. if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight || gr_backsector->floorheight != gr_frontsector->floorheight) @@ -2948,8 +2962,21 @@ static void HWR_AddLine(seg_t * line) && gr_backsector->c_slope == gr_frontsector->c_slope #endif && gr_backsector->lightlevel == gr_frontsector->lightlevel - && gr_curline->sidedef->midtexture == 0 - && !gr_backsector->ffloors && !gr_frontsector->ffloors) + && !gr_curline->sidedef->midtexture + // Check offsets too! + && gr_backsector->floor_xoffs == gr_frontsector->floor_xoffs + && gr_backsector->floor_yoffs == gr_frontsector->floor_yoffs + && gr_backsector->floorpic_angle == gr_frontsector->floorpic_angle + && gr_backsector->ceiling_xoffs == gr_frontsector->ceiling_xoffs + && gr_backsector->ceiling_yoffs == gr_frontsector->ceiling_yoffs + && gr_backsector->ceilingpic_angle == gr_frontsector->ceilingpic_angle + // Consider altered lighting. + && gr_backsector->floorlightsec == gr_frontsector->floorlightsec + && gr_backsector->ceilinglightsec == gr_frontsector->ceilinglightsec + // Consider colormaps + && gr_backsector->extra_colormap == gr_frontsector->extra_colormap + && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) + || gr_frontsector->tag == gr_backsector->tag)) // SoM: For 3D sides... Boris, would you like to take a // crack at rendering 3D sides? You would need to add the // above check and add code to HWR_StoreWallRange... From fca88d2e98da1c73c04d460b372ae4e336084ffe Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Sun, 8 Jan 2017 13:54:52 -0500 Subject: [PATCH 020/223] Mingw: disable GetText support --- src/Makefile.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.cfg b/src/Makefile.cfg index 72404becc..3630c6367 100644 --- a/src/Makefile.cfg +++ b/src/Makefile.cfg @@ -328,7 +328,7 @@ ifdef MINGW INTERFACE=win32 NASMFORMAT=win32 ifndef NOGETTEXT - GETTEXT=1 + #GETTEXT=1 endif OBJDIR:=$(OBJDIR)/Mingw BIN:=$(BIN)/Mingw From 55925cabe829156847a27cb3a77d0d3609fa7dc5 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Sun, 8 Jan 2017 14:06:30 -0500 Subject: [PATCH 021/223] win32: fixup printf warnings --- src/win32/win_cd.c | 4 ++-- src/win32/win_main.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/win32/win_cd.c b/src/win32/win_cd.c index d73b95523..ae13d3e57 100644 --- a/src/win32/win_cd.c +++ b/src/win32/win_cd.c @@ -180,9 +180,9 @@ static LPSTR hms(UINT seconds) hours = minutes / 60; minutes %= 60; if (hours > 0) - sprintf (s, "%lu:%02lu:%02lu", hours, minutes, seconds); + sprintf (s, "%lu:%02lu:%02lu", (long unsigned int)hours, (long unsigned int)minutes, (long unsigned int)seconds); else - sprintf (s, "%2lu:%02lu", minutes, seconds); + sprintf (s, "%2lu:%02lu", (long unsigned int)minutes, (long unsigned int)seconds); return s; } diff --git a/src/win32/win_main.c b/src/win32/win_main.c index 663eddbd4..563466dc2 100644 --- a/src/win32/win_main.c +++ b/src/win32/win_main.c @@ -470,7 +470,7 @@ static inline BOOL tlErrorMessage(const TCHAR *err) // // warn user if there is one // - printf("Error %Ts..\n", err); + printf("Error %s..\n", err); fflush(stdout); MessageBox(hWndMain, err, TEXT("ERROR"), MB_OK); From e37d680a4a245e4b72db7a14f5357b222b2e1c10 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 9 Jan 2017 22:13:26 +0000 Subject: [PATCH 022/223] Starting work on porting hw_clip.c/h code, Makefiles and CMake can compile them at least Other notes: * Renamed all new functions to have HWR_ prefix instead of gld_, for consistency * HWR_FrustrumSetup and HWR_SphereInFrustum are disabled and require HAVE_SPHEREFRUSTRUM. This is because 1) SRB2CB did not need the code, so presumably neither will we, and 2) there are some OpenGL API functions used there that due to our way of using OpenGL we don't use outside of r_opengl.c, which makes dealing with HWR_FrustrumSetup complicated in theory * The new clipping functions are not added to OpenGL's "main" rendering code itself just yet, they're just available to use now once hw_clip.h is included --- src/CMakeLists.txt | 2 + src/Makefile | 12 +- src/hardware/hw_clip.c | 465 +++++++++++++++++++++++++++++++++++++++++ src/hardware/hw_clip.h | 24 +++ 4 files changed, 497 insertions(+), 6 deletions(-) create mode 100644 src/hardware/hw_clip.c create mode 100644 src/hardware/hw_clip.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ba354c289..358378ecd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -350,6 +350,7 @@ if(${SRB2_CONFIG_HWRENDER}) set(SRB2_HWRENDER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_light.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c @@ -358,6 +359,7 @@ if(${SRB2_CONFIG_HWRENDER}) ) set (SRB2_HWRENDER_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h diff --git a/src/Makefile b/src/Makefile index ce4b569ee..b41357f39 100644 --- a/src/Makefile +++ b/src/Makefile @@ -256,7 +256,7 @@ ifndef DC endif OPTS+=-DHWRENDER OBJS+=$(OBJDIR)/hw_bsp.o $(OBJDIR)/hw_draw.o $(OBJDIR)/hw_light.o \ - $(OBJDIR)/hw_main.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o + $(OBJDIR)/hw_main.o $(OBJDIR)/hw_clip.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o endif ifdef NOHS @@ -687,7 +687,7 @@ ifdef MINGW $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ @@ -695,7 +695,7 @@ else $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -I/usr/X11R6/include -c $< -o $@ @@ -848,7 +848,7 @@ ifndef NOHW $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ @@ -856,7 +856,7 @@ $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h $(OBJDIR)/ogl_win.o: hardware/r_opengl/ogl_win.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ @@ -864,7 +864,7 @@ $(OBJDIR)/ogl_win.o: hardware/r_opengl/ogl_win.c hardware/r_opengl/r_opengl.h \ $(OBJDIR)/r_minigl.o: hardware/r_minigl/r_minigl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c new file mode 100644 index 000000000..47cbbfa2b --- /dev/null +++ b/src/hardware/hw_clip.c @@ -0,0 +1,465 @@ +/* Emacs style mode select -*- C++ -*- + *----------------------------------------------------------------------------- + * + * + * PrBoom: a Doom port merged with LxDoom and LSDLDoom + * based on BOOM, a modified and improved DOOM engine + * Copyright (C) 1999 by + * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman + * Copyright (C) 1999-2000 by + * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze + * Copyright 2005, 2006 by + * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * DESCRIPTION: + * + *--------------------------------------------------------------------- + */ + +/* + * + ** gl_clipper.cpp + ** + ** Handles visibility checks. + ** Loosely based on the JDoom clipper. + ** + **--------------------------------------------------------------------------- + ** Copyright 2003 Tim Stump + ** 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. + **--------------------------------------------------------------------------- + ** + */ + +#include +#include "../v_video.h" +#include "hw_clip.h" +#include "hw_glob.h" +#include "../r_state.h" +#include "../tables.h" +#include "r_opengl/r_opengl.h" + +#ifdef HAVE_SPHEREFRUSTRUM +static GLdouble viewMatrix[16]; +static GLdouble projMatrix[16]; +float frustum[6][4]; +#endif + +typedef struct clipnode_s + { + struct clipnode_s *prev, *next; + angle_t start, end; + } clipnode_t; + +clipnode_t *freelist; +clipnode_t *clipnodes; +clipnode_t *cliphead; + +static clipnode_t * HWR_clipnode_GetNew(void); +static clipnode_t * HWR_clipnode_NewRange(angle_t start, angle_t end); +static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle); +static void HWR_clipper_AddClipRange(angle_t start, angle_t end); +static void HWR_clipper_RemoveRange(clipnode_t * range); +static void HWR_clipnode_Free(clipnode_t *node); + +static clipnode_t * HWR_clipnode_GetNew(void) +{ + if (freelist) + { + clipnode_t * p = freelist; + freelist = p->next; + return p; + } + else + { + return (clipnode_t*)malloc(sizeof(clipnode_t)); + } +} + +static clipnode_t * HWR_clipnode_NewRange(angle_t start, angle_t end) +{ + clipnode_t * c = HWR_clipnode_GetNew(); + c->start = start; + c->end = end; + c->next = c->prev=NULL; + return c; +} + +boolean HWR_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle) +{ + if(startAngle > endAngle) + { + return (HWR_clipper_IsRangeVisible(startAngle, ANGLE_MAX) || HWR_clipper_IsRangeVisible(0, endAngle)); + } + + return HWR_clipper_IsRangeVisible(startAngle, endAngle); +} + +static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle) +{ + clipnode_t *ci; + ci = cliphead; + + if (endAngle == 0 && ci && ci->start == 0) + return false; + + while (ci != NULL && ci->start < endAngle) + { + if (startAngle >= ci->start && endAngle <= ci->end) + { + return false; + } + ci = ci->next; + } + + return true; +} + +static void HWR_clipnode_Free(clipnode_t *node) +{ + node->next = freelist; + freelist = node; +} + +static void HWR_clipper_RemoveRange(clipnode_t *range) +{ + if (range == cliphead) + { + cliphead = cliphead->next; + } + else + { + if (range->prev) + { + range->prev->next = range->next; + } + if (range->next) + { + range->next->prev = range->prev; + } + } + + HWR_clipnode_Free(range); +} + +void HWR_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle) +{ + if(startangle > endangle) + { + // The range has to added in two parts. + HWR_clipper_AddClipRange(startangle, ANGLE_MAX); + HWR_clipper_AddClipRange(0, endangle); + } + else + { + // Add the range as usual. + HWR_clipper_AddClipRange(startangle, endangle); + } +} + +static void HWR_clipper_AddClipRange(angle_t start, angle_t end) +{ + clipnode_t *node, *temp, *prevNode, *node2, *delnode; + + if (cliphead) + { + //check to see if range contains any old ranges + node = cliphead; + while (node != NULL && node->start < end) + { + if (node->start >= start && node->end <= end) + { + temp = node; + node = node->next; + HWR_clipper_RemoveRange(temp); + } + else + { + if (node->start <= start && node->end >= end) + { + return; + } + else + { + node = node->next; + } + } + } + + //check to see if range overlaps a range (or possibly 2) + node = cliphead; + while (node != NULL && node->start <= end) + { + if (node->end >= start) + { + // we found the first overlapping node + if (node->start > start) + { + // the new range overlaps with this node's start point + node->start = start; + } + if (node->end < end) + { + node->end = end; + } + + node2 = node->next; + while (node2 && node2->start <= node->end) + { + if (node2->end > node->end) + { + node->end = node2->end; + } + + delnode = node2; + node2 = node2->next; + HWR_clipper_RemoveRange(delnode); + } + return; + } + node = node->next; + } + + //just add range + node = cliphead; + prevNode = NULL; + temp = HWR_clipnode_NewRange(start, end); + while (node != NULL && node->start < end) + { + prevNode = node; + node = node->next; + } + temp->next = node; + if (node == NULL) + { + temp->prev = prevNode; + if (prevNode) + { + prevNode->next = temp; + } + if (!cliphead) + { + cliphead = temp; + } + } + else + { + if (node == cliphead) + { + cliphead->prev = temp; + cliphead = temp; + } + else + { + temp->prev = prevNode; + prevNode->next = temp; + node->prev = temp; + } + } + } + else + { + temp = HWR_clipnode_NewRange(start, end); + cliphead = temp; + return; + } +} + +void HWR_clipper_Clear(void) +{ + clipnode_t *node = cliphead; + clipnode_t *temp; + + while (node != NULL) + { + temp = node; + node = node->next; + HWR_clipnode_Free(temp); + } + + cliphead = NULL; +} + +#define RMUL (1.6f/1.333333f) + +angle_t HWR_FrustumAngle(void) +{ + double floatangle; + angle_t a1; + + float tilt = (float)fabs(((double)(int)aimingangle) / ANG1); + + // NEWCLIP TODO: SRB2CBTODO: make a global render_fov for this function + + float render_fov = FIXED_TO_FLOAT(cv_grfov.value); + float render_fovratio = (float)BASEVIDWIDTH / (float)BASEVIDHEIGHT; // SRB2CBTODO: NEWCLIPTODO: Is this right? + float render_multiplier = 64.0f / render_fovratio / RMUL; + + if (tilt > 90.0f) + { + tilt = 90.0f; + } + + // If the pitch is larger than this you can look all around at a FOV of 90 + if (abs(aimingangle) > 46 * ANG1) + return 0xffffffff; + + // ok, this is a gross hack that barely works... + // but at least it doesn't overestimate too much... + floatangle = 2.0f + (45.0f + (tilt / 1.9f)) * (float)render_fov * 48.0f / render_multiplier / 90.0f; + a1 = ANG1 * (int)floatangle; + if (a1 >= ANGLE_180) + return 0xffffffff; + return a1; +} + +// SRB2CB I don't think used any of this stuff, let's disable for now since SRB2 probably doesn't want it either +// compiler complains about (p)glGetDoublev anyway, in case anyone wants this +// only r_opengl.c can use the base gl funcs as it turns out, that's a problem for whoever wants sphere frustum checks +// btw to renable define HAVE_SPHEREFRUSTRUM in hw_clip.h +#ifdef HAVE_SPHEREFRUSTRUM +// +// HWR_FrustrumSetup +// + +#define CALCMATRIX(a, b, c, d, e, f, g, h)\ +(float)(viewMatrix[a] * projMatrix[b] + \ +viewMatrix[c] * projMatrix[d] + \ +viewMatrix[e] * projMatrix[f] + \ +viewMatrix[g] * projMatrix[h]) + +#define NORMALIZE_PLANE(i)\ +t = (float)sqrt(\ +frustum[i][0] * frustum[i][0] + \ +frustum[i][1] * frustum[i][1] + \ +frustum[i][2] * frustum[i][2]); \ +frustum[i][0] /= t; \ +frustum[i][1] /= t; \ +frustum[i][2] /= t; \ +frustum[i][3] /= t + +void HWR_FrustrumSetup(void) +{ + float t; + float clip[16]; + + pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); + pglGetDoublev(GL_MODELVIEW_MATRIX, viewMatrix); + + clip[0] = CALCMATRIX(0, 0, 1, 4, 2, 8, 3, 12); + clip[1] = CALCMATRIX(0, 1, 1, 5, 2, 9, 3, 13); + clip[2] = CALCMATRIX(0, 2, 1, 6, 2, 10, 3, 14); + clip[3] = CALCMATRIX(0, 3, 1, 7, 2, 11, 3, 15); + + clip[4] = CALCMATRIX(4, 0, 5, 4, 6, 8, 7, 12); + clip[5] = CALCMATRIX(4, 1, 5, 5, 6, 9, 7, 13); + clip[6] = CALCMATRIX(4, 2, 5, 6, 6, 10, 7, 14); + clip[7] = CALCMATRIX(4, 3, 5, 7, 6, 11, 7, 15); + + clip[8] = CALCMATRIX(8, 0, 9, 4, 10, 8, 11, 12); + clip[9] = CALCMATRIX(8, 1, 9, 5, 10, 9, 11, 13); + clip[10] = CALCMATRIX(8, 2, 9, 6, 10, 10, 11, 14); + clip[11] = CALCMATRIX(8, 3, 9, 7, 10, 11, 11, 15); + + clip[12] = CALCMATRIX(12, 0, 13, 4, 14, 8, 15, 12); + clip[13] = CALCMATRIX(12, 1, 13, 5, 14, 9, 15, 13); + clip[14] = CALCMATRIX(12, 2, 13, 6, 14, 10, 15, 14); + clip[15] = CALCMATRIX(12, 3, 13, 7, 14, 11, 15, 15); + + // Right plane + frustum[0][0] = clip[ 3] - clip[ 0]; + frustum[0][1] = clip[ 7] - clip[ 4]; + frustum[0][2] = clip[11] - clip[ 8]; + frustum[0][3] = clip[15] - clip[12]; + NORMALIZE_PLANE(0); + + // Left plane + frustum[1][0] = clip[ 3] + clip[ 0]; + frustum[1][1] = clip[ 7] + clip[ 4]; + frustum[1][2] = clip[11] + clip[ 8]; + frustum[1][3] = clip[15] + clip[12]; + NORMALIZE_PLANE(1); + + // Bottom plane + frustum[2][0] = clip[ 3] + clip[ 1]; + frustum[2][1] = clip[ 7] + clip[ 5]; + frustum[2][2] = clip[11] + clip[ 9]; + frustum[2][3] = clip[15] + clip[13]; + NORMALIZE_PLANE(2); + + // Top plane + frustum[3][0] = clip[ 3] - clip[ 1]; + frustum[3][1] = clip[ 7] - clip[ 5]; + frustum[3][2] = clip[11] - clip[ 9]; + frustum[3][3] = clip[15] - clip[13]; + NORMALIZE_PLANE(3); + + // Far plane + frustum[4][0] = clip[ 3] - clip[ 2]; + frustum[4][1] = clip[ 7] - clip[ 6]; + frustum[4][2] = clip[11] - clip[10]; + frustum[4][3] = clip[15] - clip[14]; + NORMALIZE_PLANE(4); + + // Near plane + frustum[5][0] = clip[ 3] + clip[ 2]; + frustum[5][1] = clip[ 7] + clip[ 6]; + frustum[5][2] = clip[11] + clip[10]; + frustum[5][3] = clip[15] + clip[14]; + NORMALIZE_PLANE(5); +} + +boolean HWR_SphereInFrustum(float x, float y, float z, float radius) +{ + int p; + + for (p = 0; p < 4; p++) + { + if (frustum[p][0] * x + + frustum[p][1] * y + + frustum[p][2] * z + + frustum[p][3] <= -radius) + { + return false; + } + } + return true; +} +#endif diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h new file mode 100644 index 000000000..c55041b7e --- /dev/null +++ b/src/hardware/hw_clip.h @@ -0,0 +1,24 @@ +/* + * hw_clip.h + * SRB2CB + * + * PrBoom's OpenGL clipping + * + * + */ + +// OpenGL BSP clipping +#include "../doomdef.h" +#include "../tables.h" +#include "../doomtype.h" + +//#define HAVE_SPHEREFRUSTRUM // enable if you want HWR_SphereInFrustum and related code + +boolean HWR_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); +void HWR_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); +void HWR_clipper_Clear(void); +angle_t HWR_FrustumAngle(void); +#ifdef HAVE_SPHEREFRUSTRUM +void HWR_FrustrumSetup(void); +boolean HWR_SphereInFrustum(float x, float y, float z, float radius); +#endif From c5e99050fc28140f39cb8c8b23a85cabbe1a51d9 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 10 Jan 2017 18:01:03 +0000 Subject: [PATCH 023/223] More progress, NEWCLIP added to doomdef.h, sadly it actually all lags the game so I've disabled it for now Other notes: * on second thought I'll keep the hw_clip functions' gld prefixes rather than HWR, not like it matters either way * despite the extra lag it does fix the issues with translucent walls and such when displayed at different vertical angles, such as with the GFZ1 waterfall --- src/doomdef.h | 7 ++ src/hardware/hw_clip.c | 62 +++++------ src/hardware/hw_clip.h | 14 +-- src/hardware/hw_main.c | 240 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 280 insertions(+), 43 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 83576a12c..6b06a4cf1 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -543,4 +543,11 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Experimental attempts at preventing MF_PAPERCOLLISION objects from getting stuck in walls. //#define PAPER_COLLISIONCORRECTION +/// FINALLY some real clipping that doesn't make walls dissappear AND speeds the game up +/// (that was the original comment from SRB2CB, sadly it is a lie and actually slows game down) +/// on the bright side it fixes some weird issues with translucent walls +/// \note SRB2CB port. +/// SRB2CB itself ported this from PrBoom+ +//#define NEWCLIP + #endif // __DOOMDEF__ diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 47cbbfa2b..8b01cabd5 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -92,14 +92,14 @@ clipnode_t *freelist; clipnode_t *clipnodes; clipnode_t *cliphead; -static clipnode_t * HWR_clipnode_GetNew(void); -static clipnode_t * HWR_clipnode_NewRange(angle_t start, angle_t end); -static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle); -static void HWR_clipper_AddClipRange(angle_t start, angle_t end); -static void HWR_clipper_RemoveRange(clipnode_t * range); -static void HWR_clipnode_Free(clipnode_t *node); +static clipnode_t * gld_clipnode_GetNew(void); +static clipnode_t * gld_clipnode_NewRange(angle_t start, angle_t end); +static boolean gld_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle); +static void gld_clipper_AddClipRange(angle_t start, angle_t end); +static void gld_clipper_RemoveRange(clipnode_t * range); +static void gld_clipnode_Free(clipnode_t *node); -static clipnode_t * HWR_clipnode_GetNew(void) +static clipnode_t * gld_clipnode_GetNew(void) { if (freelist) { @@ -113,26 +113,26 @@ static clipnode_t * HWR_clipnode_GetNew(void) } } -static clipnode_t * HWR_clipnode_NewRange(angle_t start, angle_t end) +static clipnode_t * gld_clipnode_NewRange(angle_t start, angle_t end) { - clipnode_t * c = HWR_clipnode_GetNew(); + clipnode_t * c = gld_clipnode_GetNew(); c->start = start; c->end = end; c->next = c->prev=NULL; return c; } -boolean HWR_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle) +boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle) { if(startAngle > endAngle) { - return (HWR_clipper_IsRangeVisible(startAngle, ANGLE_MAX) || HWR_clipper_IsRangeVisible(0, endAngle)); + return (gld_clipper_IsRangeVisible(startAngle, ANGLE_MAX) || gld_clipper_IsRangeVisible(0, endAngle)); } - return HWR_clipper_IsRangeVisible(startAngle, endAngle); + return gld_clipper_IsRangeVisible(startAngle, endAngle); } -static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle) +static boolean gld_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle) { clipnode_t *ci; ci = cliphead; @@ -152,13 +152,13 @@ static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle) return true; } -static void HWR_clipnode_Free(clipnode_t *node) +static void gld_clipnode_Free(clipnode_t *node) { node->next = freelist; freelist = node; } -static void HWR_clipper_RemoveRange(clipnode_t *range) +static void gld_clipper_RemoveRange(clipnode_t *range) { if (range == cliphead) { @@ -176,25 +176,25 @@ static void HWR_clipper_RemoveRange(clipnode_t *range) } } - HWR_clipnode_Free(range); + gld_clipnode_Free(range); } -void HWR_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle) +void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle) { if(startangle > endangle) { // The range has to added in two parts. - HWR_clipper_AddClipRange(startangle, ANGLE_MAX); - HWR_clipper_AddClipRange(0, endangle); + gld_clipper_AddClipRange(startangle, ANGLE_MAX); + gld_clipper_AddClipRange(0, endangle); } else { // Add the range as usual. - HWR_clipper_AddClipRange(startangle, endangle); + gld_clipper_AddClipRange(startangle, endangle); } } -static void HWR_clipper_AddClipRange(angle_t start, angle_t end) +static void gld_clipper_AddClipRange(angle_t start, angle_t end) { clipnode_t *node, *temp, *prevNode, *node2, *delnode; @@ -208,7 +208,7 @@ static void HWR_clipper_AddClipRange(angle_t start, angle_t end) { temp = node; node = node->next; - HWR_clipper_RemoveRange(temp); + gld_clipper_RemoveRange(temp); } else { @@ -250,7 +250,7 @@ static void HWR_clipper_AddClipRange(angle_t start, angle_t end) delnode = node2; node2 = node2->next; - HWR_clipper_RemoveRange(delnode); + gld_clipper_RemoveRange(delnode); } return; } @@ -260,7 +260,7 @@ static void HWR_clipper_AddClipRange(angle_t start, angle_t end) //just add range node = cliphead; prevNode = NULL; - temp = HWR_clipnode_NewRange(start, end); + temp = gld_clipnode_NewRange(start, end); while (node != NULL && node->start < end) { prevNode = node; @@ -296,13 +296,13 @@ static void HWR_clipper_AddClipRange(angle_t start, angle_t end) } else { - temp = HWR_clipnode_NewRange(start, end); + temp = gld_clipnode_NewRange(start, end); cliphead = temp; return; } } -void HWR_clipper_Clear(void) +void gld_clipper_Clear(void) { clipnode_t *node = cliphead; clipnode_t *temp; @@ -311,7 +311,7 @@ void HWR_clipper_Clear(void) { temp = node; node = node->next; - HWR_clipnode_Free(temp); + gld_clipnode_Free(temp); } cliphead = NULL; @@ -319,7 +319,7 @@ void HWR_clipper_Clear(void) #define RMUL (1.6f/1.333333f) -angle_t HWR_FrustumAngle(void) +angle_t gld_FrustumAngle(void) { double floatangle; angle_t a1; @@ -356,7 +356,7 @@ angle_t HWR_FrustumAngle(void) // btw to renable define HAVE_SPHEREFRUSTRUM in hw_clip.h #ifdef HAVE_SPHEREFRUSTRUM // -// HWR_FrustrumSetup +// gld_FrustrumSetup // #define CALCMATRIX(a, b, c, d, e, f, g, h)\ @@ -375,7 +375,7 @@ frustum[i][1] /= t; \ frustum[i][2] /= t; \ frustum[i][3] /= t -void HWR_FrustrumSetup(void) +void gld_FrustrumSetup(void) { float t; float clip[16]; @@ -446,7 +446,7 @@ void HWR_FrustrumSetup(void) NORMALIZE_PLANE(5); } -boolean HWR_SphereInFrustum(float x, float y, float z, float radius) +boolean gld_SphereInFrustum(float x, float y, float z, float radius) { int p; diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h index c55041b7e..3ba26e5e5 100644 --- a/src/hardware/hw_clip.h +++ b/src/hardware/hw_clip.h @@ -12,13 +12,13 @@ #include "../tables.h" #include "../doomtype.h" -//#define HAVE_SPHEREFRUSTRUM // enable if you want HWR_SphereInFrustum and related code +//#define HAVE_SPHEREFRUSTRUM // enable if you want gld_SphereInFrustum and related code -boolean HWR_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); -void HWR_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); -void HWR_clipper_Clear(void); -angle_t HWR_FrustumAngle(void); +boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); +void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); +void gld_clipper_Clear(void); +angle_t gld_FrustumAngle(void); #ifdef HAVE_SPHEREFRUSTRUM -void HWR_FrustrumSetup(void); -boolean HWR_SphereInFrustum(float x, float y, float z, float radius); +void gld_FrustrumSetup(void); +boolean gld_SphereInFrustum(float x, float y, float z, float radius); #endif diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 9cf495da5..abbb32d25 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -44,6 +44,10 @@ #endif #include "hw_md2.h" +#ifdef NEWCLIP +#include "hw_clip.h" +#endif + #define R_FAKEFLOORS #define HWPRECIP #define SORTING @@ -99,8 +103,9 @@ CV_PossibleValue_t granisotropicmode_cons_t[] = {{1, "MIN"}, {16, "MAX"}, {0, NU boolean drawsky = true; // needs fix: walls are incorrectly clipped one column less +#ifndef NEWCLIP static consvar_t cv_grclipwalls = {"gr_clipwalls", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - +#endif //development variables for diverse uses static consvar_t cv_gralpha = {"gr_alpha", "160", 0, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; static consvar_t cv_grbeta = {"gr_beta", "0", 0, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -1035,6 +1040,7 @@ static void HWR_ProjectWall(wallVert3D * wallVerts, // (in fact a clipping plane that has a constant, so can clip with simple 2d) // with the wall segment // +#ifndef NEWCLIP static float HWR_ClipViewSegment(INT32 x, polyvertex_t *v1, polyvertex_t *v2) { float num, den; @@ -1063,6 +1069,7 @@ static float HWR_ClipViewSegment(INT32 x, polyvertex_t *v1, polyvertex_t *v2) return num / den; } +#endif // // HWR_SplitWall @@ -1437,7 +1444,11 @@ static void HWR_DrawSkyWall(wallVert3D *wallVerts, FSurfaceInfo *Surf, fixed_t b // Anything between means the wall segment has been clipped with solidsegs, // reducing wall overdraw to a minimum // +#ifdef NEWCLIP +static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom +#else static void HWR_StoreWallRange(double startfrac, double endfrac) +#endif { wallVert3D wallVerts[4]; v2d_t vs, ve; // start, end vertices of 2d line (view from above) @@ -1462,8 +1473,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) extracolormap_t *colormap; FSurfaceInfo Surf; +#ifndef NEWCLIP if (startfrac > endfrac) return; +#endif gr_sidedef = gr_curline->sidedef; gr_linedef = gr_curline->linedef; @@ -1536,15 +1549,19 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // x offset the texture fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset; +#ifndef NEWCLIP // clip texture s start/end coords with solidsegs if (startfrac > 0.0f && startfrac < 1.0f) cliplow = (float)(texturehpeg + (gr_curline->flength*FRACUNIT) * startfrac); else +#endif cliplow = (float)texturehpeg; +#ifndef NEWCLIP if (endfrac > 0.0f && endfrac < 1.0f) cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT) * endfrac); else +#endif cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT)); } @@ -2488,6 +2505,135 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) //Hurdler: end of 3d-floors test } +// From PrBoom: +// +// e6y: Check whether the player can look beyond this line +// +#ifdef NEWCLIP +// Don't modify anything here, just check +// Kalaron: Modified for sloped linedefs +static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacksector) +{ + fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends + fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends + + // GZDoom method of sloped line clipping + +#ifdef ESLOPE + if (afrontsector->f_slope || afrontsector->c_slope || abacksector->f_slope || abacksector->c_slope) + { + fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t + v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x); + v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y); + v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x); + v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); +#define SLOPEPARAMS(slope, end1, end2, normalheight) \ + if (slope) { \ + end1 = P_GetZAt(slope, v1x, v1y); \ + end2 = P_GetZAt(slope, v2x, v2y); \ + } else \ + end1 = end2 = normalheight; + + SLOPEPARAMS(afrontsector->f_slope, frontf1, frontf2, afrontsector->floorheight) + SLOPEPARAMS(afrontsector->c_slope, frontc1, frontc2, afrontsector->ceilingheight) + SLOPEPARAMS( abacksector->f_slope, backf1, backf2, abacksector->floorheight) + SLOPEPARAMS( abacksector->c_slope, backc1, backc2, abacksector->ceilingheight) +#undef SLOPEPARAMS + } + else +#endif + { + frontf1 = frontf2 = afrontsector->floorheight; + frontc1 = frontc2 = afrontsector->ceilingheight; + backf1 = backf2 = abacksector->floorheight; + backc1 = backc2 = abacksector->ceilingheight; + } + + // now check for closed sectors! + if (backc1 <= frontf1 && backc2 <= frontf2) + { + if (!seg->sidedef->toptexture) + return false; + + if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) + return false; + + return true; + } + + if (backf1 >= frontc1 && backf2 >= frontc2) + { + if (!seg->sidedef->bottomtexture) + return false; + + // properly render skies (consider door "open" if both floors are sky): + if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) + return false; + + return true; + } + + if (backc1 <= backf1 && backc2 <= backf2) + { + // preserve a kind of transparent door/lift special effect: + if (backc1 < frontc1 || backc2 < frontc2) + { + if (!seg->sidedef->toptexture) + return false; + } + if (backf1 > frontf1 || backf2 > frontf2) + { + if (!seg->sidedef->bottomtexture) + return false; + } + if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) + return false; + + if (abacksector->floorpic == skyflatnum && afrontsector->floorpic == skyflatnum) + return false; + + return true; + } + + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if ( +#ifdef POLYOBJECTS + !seg->polyseg && +#endif + gr_backsector->ceilingpic == gr_frontsector->ceilingpic + && gr_backsector->floorpic == gr_frontsector->floorpic +#ifdef ESLOPE + && gr_backsector->f_slope == gr_frontsector->f_slope + && gr_backsector->c_slope == gr_frontsector->c_slope +#endif + && gr_backsector->lightlevel == gr_frontsector->lightlevel + && !gr_curline->sidedef->midtexture + // Check offsets too! + && gr_backsector->floor_xoffs == gr_frontsector->floor_xoffs + && gr_backsector->floor_yoffs == gr_frontsector->floor_yoffs + && gr_backsector->floorpic_angle == gr_frontsector->floorpic_angle + && gr_backsector->ceiling_xoffs == gr_frontsector->ceiling_xoffs + && gr_backsector->ceiling_yoffs == gr_frontsector->ceiling_yoffs + && gr_backsector->ceilingpic_angle == gr_frontsector->ceilingpic_angle + // Consider altered lighting. + && gr_backsector->floorlightsec == gr_frontsector->floorlightsec + && gr_backsector->ceilinglightsec == gr_frontsector->ceilinglightsec + // Consider colormaps + && gr_backsector->extra_colormap == gr_frontsector->extra_colormap + && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) + || gr_frontsector->tag == gr_backsector->tag)) + { + return false; + } + + + return false; +} +#else //Hurdler: just like in r_bsp.c #if 1 #define MAXSEGS MAXVIDWIDTH/2+1 @@ -2773,6 +2919,7 @@ static void HWR_ClearClipSegs(void) gr_solidsegs[1].last = 0x7fffffff; hw_newend = gr_solidsegs+2; } +#endif // NEWCLIP // -----------------+ // HWR_AddLine : Clips the given segment and adds any visible pieces to the line list. @@ -2781,17 +2928,20 @@ static void HWR_ClearClipSegs(void) // -----------------+ static void HWR_AddLine(seg_t * line) { - INT32 x1, x2; angle_t angle1, angle2; +#ifndef NEWCLIP + INT32 x1, x2; angle_t span, tspan; +#endif // SoM: Backsector needs to be run through R_FakeFlat sector_t tempsec; fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t - +#ifdef POLYOBJECTS if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) return; +#endif gr_curline = line; @@ -2804,6 +2954,18 @@ static void HWR_AddLine(seg_t * line) angle1 = R_PointToAngle(v1x, v1y); angle2 = R_PointToAngle(v2x, v2y); +#ifdef NEWCLIP + // PrBoom: Back side, i.e. backface culling - read: endAngle >= startAngle! + if (angle2 - angle1 < ANGLE_180) + return; + + // PrBoom: use REAL clipping math YAYYYYYYY!!! + + if (!gld_clipper_SafeCheckRange(angle2, angle1)) + { + return; + } +#else // Clip to view edges. span = angle1 - angle2; @@ -2882,8 +3044,35 @@ static void HWR_AddLine(seg_t * line) return; } */ +#endif + gr_backsector = line->backsector; +#ifdef NEWCLIP + if (!line->backsector) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + else + { + gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); + if (line->frontsector == line->backsector) + { + if (!line->sidedef->midtexture) + { + //e6y: nothing to do here! + //return; + } + } + if (CheckClip(line, gr_frontsector, gr_backsector)) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + } + + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + return; +#else // Single sided line? if (!gr_backsector) goto clipsolid; @@ -2998,6 +3187,7 @@ clipsolid: if (x1 == x2) goto clippass; HWR_ClipSolidWallSegment(x1, x2-1); +#endif } // HWR_CheckBBox @@ -3009,9 +3199,13 @@ clipsolid: static boolean HWR_CheckBBox(fixed_t *bspcoord) { - INT32 boxpos, sx1, sx2; + INT32 boxpos; fixed_t px1, py1, px2, py2; - angle_t angle1, angle2, span, tspan; + angle_t angle1, angle2; +#ifndef NEWCLIP + INT32 sx1, sx2; + angle_t span, tspan; +#endif // Find the corners of the box // that define the edges from current viewpoint. @@ -3037,6 +3231,11 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) px2 = bspcoord[checkcoord[boxpos][2]]; py2 = bspcoord[checkcoord[boxpos][3]]; +#ifdef NEWCLIP + angle1 = R_PointToAngle(px1, py1); + angle2 = R_PointToAngle(px2, py2); + return gld_clipper_SafeCheckRange(angle2, angle1); +#else // check clip list for an open space angle1 = R_PointToAngle(px1, py1) - dup_viewangle; angle2 = R_PointToAngle(px2, py2) - dup_viewangle; @@ -3084,6 +3283,7 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) return false; return HWR_ClipToSolidSegs(sx1, sx2 - 1); +#endif } #ifdef POLYOBJECTS @@ -5624,7 +5824,19 @@ if (0) #ifdef SORTING drawcount = 0; #endif +#ifdef NEWCLIP + if (rendermode == render_opengl) + { + angle_t a1 = gld_FrustumAngle(); + gld_clipper_Clear(); + gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); +#ifdef HAVE_SPHEREFRUSTRUM + gld_FrustrumSetup(); +#endif + } +#else HWR_ClearClipSegs(); +#endif //04/01/2000: Hurdler: added for T&L // Actually it only works on Walls and Planes @@ -5634,6 +5846,7 @@ if (0) HWR_RenderBSPNode((INT32)numnodes-1); +#ifndef NEWCLIP // Make a viewangle int so we can render things based on mouselook if (player == &players[consoleplayer]) viewangle = localaiming; @@ -5660,6 +5873,7 @@ if (0) dup_viewangle += ANGLE_90; } +#endif // Check for new console commands. NetUpdate(); @@ -5854,7 +6068,19 @@ if (0) #ifdef SORTING drawcount = 0; #endif +#ifdef NEWCLIP + if (rendermode == render_opengl) + { + angle_t a1 = gld_FrustumAngle(); + gld_clipper_Clear(); + gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); +#ifdef HAVE_SPHEREFRUSTRUM + gld_FrustrumSetup(); +#endif + } +#else HWR_ClearClipSegs(); +#endif //04/01/2000: Hurdler: added for T&L // Actually it only works on Walls and Planes @@ -5864,6 +6090,7 @@ if (0) HWR_RenderBSPNode((INT32)numnodes-1); +#ifndef NEWCLIP // Make a viewangle int so we can render things based on mouselook if (player == &players[consoleplayer]) viewangle = localaiming; @@ -5890,6 +6117,7 @@ if (0) dup_viewangle += ANGLE_90; } +#endif // Check for new console commands. NetUpdate(); @@ -6035,7 +6263,9 @@ static inline void HWR_AddEngineCommands(void) { // engine state variables //CV_RegisterVar(&cv_grzbuffer); +#ifndef NEWCLIP CV_RegisterVar(&cv_grclipwalls); +#endif // engine development mode variables // - usage may vary from version to version.. From e87324b8148a2b1b0a7fafb6962b57897d02a1a6 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 10 Jan 2017 20:07:02 +0000 Subject: [PATCH 024/223] Made some efforts to improve efficiency of new code, hard to tell if I've made it better or worse though honestly R_IsEmptyLine is now a thing too btw --- src/hardware/hw_main.c | 94 +++++++++--------------------------------- src/r_bsp.c | 62 ++++++++++++++-------------- src/r_bsp.h | 1 + 3 files changed, 53 insertions(+), 104 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index abbb32d25..b920a5c59 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2510,6 +2510,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // e6y: Check whether the player can look beyond this line // #ifdef NEWCLIP +boolean checkforemptylines = true; // Don't modify anything here, just check // Kalaron: Modified for sloped linedefs static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacksector) @@ -2552,6 +2553,7 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks // now check for closed sectors! if (backc1 <= frontf1 && backc2 <= frontf2) { + checkforemptylines = false; if (!seg->sidedef->toptexture) return false; @@ -2563,6 +2565,7 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks if (backf1 >= frontc1 && backf2 >= frontc2) { + checkforemptylines = false; if (!seg->sidedef->bottomtexture) return false; @@ -2575,6 +2578,7 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks if (backc1 <= backf1 && backc2 <= backf2) { + checkforemptylines = false; // preserve a kind of transparent door/lift special effect: if (backc1 < frontc1 || backc2 < frontc2) { @@ -2595,41 +2599,12 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks return true; } - - // Reject empty lines used for triggers and special events. - // Identical floor and ceiling on both sides, - // identical light levels on both sides, - // and no middle texture. - if ( -#ifdef POLYOBJECTS - !seg->polyseg && -#endif - gr_backsector->ceilingpic == gr_frontsector->ceilingpic - && gr_backsector->floorpic == gr_frontsector->floorpic -#ifdef ESLOPE - && gr_backsector->f_slope == gr_frontsector->f_slope - && gr_backsector->c_slope == gr_frontsector->c_slope -#endif - && gr_backsector->lightlevel == gr_frontsector->lightlevel - && !gr_curline->sidedef->midtexture - // Check offsets too! - && gr_backsector->floor_xoffs == gr_frontsector->floor_xoffs - && gr_backsector->floor_yoffs == gr_frontsector->floor_yoffs - && gr_backsector->floorpic_angle == gr_frontsector->floorpic_angle - && gr_backsector->ceiling_xoffs == gr_frontsector->ceiling_xoffs - && gr_backsector->ceiling_yoffs == gr_frontsector->ceiling_yoffs - && gr_backsector->ceilingpic_angle == gr_frontsector->ceilingpic_angle - // Consider altered lighting. - && gr_backsector->floorlightsec == gr_frontsector->floorlightsec - && gr_backsector->ceilinglightsec == gr_frontsector->ceilinglightsec - // Consider colormaps - && gr_backsector->extra_colormap == gr_frontsector->extra_colormap - && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) - || gr_frontsector->tag == gr_backsector->tag)) - { - return false; - } - + if (backc1 != frontc1 || backc2 != frontc2 + || backf1 != frontf1 || backf2 != frontf2) + { + checkforemptylines = false; + return false; + } return false; } @@ -2965,6 +2940,8 @@ static void HWR_AddLine(seg_t * line) { return; } + + checkforemptylines = true; #else // Clip to view edges. span = angle1 - angle2; @@ -3056,18 +3033,17 @@ static void HWR_AddLine(seg_t * line) else { gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); - if (line->frontsector == line->backsector) - { - if (!line->sidedef->midtexture) - { - //e6y: nothing to do here! - //return; - } - } if (CheckClip(line, gr_frontsector, gr_backsector)) { gld_clipper_SafeAddClipRange(angle2, angle1); + checkforemptylines = false; } + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if (checkforemptylines && R_IsEmptyLine(line, gr_frontsector, gr_backsector)) + return; } HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D @@ -3144,38 +3120,8 @@ static void HWR_AddLine(seg_t * line) // Identical floor and ceiling on both sides, // identical light levels on both sides, // and no middle texture. - if ( -#ifdef POLYOBJECTS - !line->polyseg && -#endif - gr_backsector->ceilingpic == gr_frontsector->ceilingpic - && gr_backsector->floorpic == gr_frontsector->floorpic -#ifdef ESLOPE - && gr_backsector->f_slope == gr_frontsector->f_slope - && gr_backsector->c_slope == gr_frontsector->c_slope -#endif - && gr_backsector->lightlevel == gr_frontsector->lightlevel - && !gr_curline->sidedef->midtexture - // Check offsets too! - && gr_backsector->floor_xoffs == gr_frontsector->floor_xoffs - && gr_backsector->floor_yoffs == gr_frontsector->floor_yoffs - && gr_backsector->floorpic_angle == gr_frontsector->floorpic_angle - && gr_backsector->ceiling_xoffs == gr_frontsector->ceiling_xoffs - && gr_backsector->ceiling_yoffs == gr_frontsector->ceiling_yoffs - && gr_backsector->ceilingpic_angle == gr_frontsector->ceilingpic_angle - // Consider altered lighting. - && gr_backsector->floorlightsec == gr_frontsector->floorlightsec - && gr_backsector->ceilinglightsec == gr_frontsector->ceilinglightsec - // Consider colormaps - && gr_backsector->extra_colormap == gr_frontsector->extra_colormap - && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) - || gr_frontsector->tag == gr_backsector->tag)) - // SoM: For 3D sides... Boris, would you like to take a - // crack at rendering 3D sides? You would need to add the - // above check and add code to HWR_StoreWallRange... - { + if (R_IsEmptyLine(curline, frontsector, backsector)) return; - } clippass: if (x1 == x2) diff --git a/src/r_bsp.c b/src/r_bsp.c index 2562cff66..f63707ea2 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -210,7 +210,7 @@ void R_PortalClearClipSegs(INT32 start, INT32 end) // // It assumes that Doom has already ruled out a door being closed because // of front-back closure (e.g. front floor is taller than back ceiling). -static inline INT32 R_DoorClosed(void) +static INT32 R_DoorClosed(void) { return @@ -365,6 +365,36 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, return sec; } +boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back) +{ + return ( +#ifdef POLYOBJECTS + !line->polyseg && +#endif + back->ceilingpic == front->ceilingpic + && back->floorpic == front->floorpic +#ifdef ESLOPE + && back->f_slope == front->f_slope + && back->c_slope == front->c_slope +#endif + && back->lightlevel == front->lightlevel + && !line->sidedef->midtexture + // Check offsets too! + && back->floor_xoffs == front->floor_xoffs + && back->floor_yoffs == front->floor_yoffs + && back->floorpic_angle == front->floorpic_angle + && back->ceiling_xoffs == front->ceiling_xoffs + && back->ceiling_yoffs == front->ceiling_yoffs + && back->ceilingpic_angle == front->ceilingpic_angle + // Consider altered lighting. + && back->floorlightsec == front->floorlightsec + && back->ceilinglightsec == front->ceilinglightsec + // Consider colormaps + && back->extra_colormap == front->extra_colormap + && ((!front->ffloors && !back->ffloors) + || front->tag == back->tag)); +} + // // R_AddLine // Clips the given segment and adds any visible pieces to the line list. @@ -526,36 +556,8 @@ static void R_AddLine(seg_t *line) // Identical floor and ceiling on both sides, identical light levels on both sides, // and no middle texture. - if ( -#ifdef POLYOBJECTS - !line->polyseg && -#endif - backsector->ceilingpic == frontsector->ceilingpic - && backsector->floorpic == frontsector->floorpic -#ifdef ESLOPE - && backsector->f_slope == frontsector->f_slope - && backsector->c_slope == frontsector->c_slope -#endif - && backsector->lightlevel == frontsector->lightlevel - && !curline->sidedef->midtexture - // Check offsets too! - && backsector->floor_xoffs == frontsector->floor_xoffs - && backsector->floor_yoffs == frontsector->floor_yoffs - && backsector->floorpic_angle == frontsector->floorpic_angle - && backsector->ceiling_xoffs == frontsector->ceiling_xoffs - && backsector->ceiling_yoffs == frontsector->ceiling_yoffs - && backsector->ceilingpic_angle == frontsector->ceilingpic_angle - // Consider altered lighting. - && backsector->floorlightsec == frontsector->floorlightsec - && backsector->ceilinglightsec == frontsector->ceilinglightsec - // Consider colormaps - && backsector->extra_colormap == frontsector->extra_colormap - && ((!frontsector->ffloors && !backsector->ffloors) - || frontsector->tag == backsector->tag)) - { + if (R_IsEmptyLine(line, frontsector, backsector)) return; - } - clippass: R_ClipPassWallSegment(x1, x2 - 1); diff --git a/src/r_bsp.h b/src/r_bsp.h index e871b5dde..80824831b 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -50,6 +50,7 @@ extern polyobj_t **po_ptrs; // temp ptr array to sort polyobject pointers sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, INT32 *ceilinglightlevel, boolean back); +boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back); INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside); void R_Prep3DFloors(sector_t *sector); From df534887e9dcc92ffd176dd5c49039b060169174 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 12 Jan 2017 21:43:37 +0000 Subject: [PATCH 025/223] Remove pointless drawtextured variable and redundant fake planes checks (R_FakeFlat would already have made gr_frontsector/backsector something else if they were) --- src/hardware/hw_main.c | 98 ++++++++---------------------------------- 1 file changed, 19 insertions(+), 79 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b920a5c59..a1d68bc1e 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -328,9 +328,6 @@ static angle_t gr_xtoviewangle[MAXVIDWIDTH+1]; // test change fov when looking up/down but bsp projection messup :( //#define NOCRAPPYMLOOK -/// \note crappy -#define drawtextured true - // base values set at SetViewSize static float gr_basecentery; @@ -1492,44 +1489,21 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) v2x = FLOAT_TO_FIXED(ve.x); v2y = FLOAT_TO_FIXED(ve.y); #endif - - if (gr_frontsector->heightsec != -1) - { #ifdef ESLOPE - worldtop = worldtopslope = sectors[gr_frontsector->heightsec].ceilingheight; - worldbottom = worldbottomslope = sectors[gr_frontsector->heightsec].floorheight; -#else - worldtop = sectors[gr_frontsector->heightsec].ceilingheight; - worldbottom = sectors[gr_frontsector->heightsec].floorheight; -#endif - } - else - { -#ifdef ESLOPE - if (gr_frontsector->c_slope) - { - worldtop = P_GetZAt(gr_frontsector->c_slope, v1x, v1y); - worldtopslope = P_GetZAt(gr_frontsector->c_slope, v2x, v2y); - } - else - { - worldtop = worldtopslope = gr_frontsector->ceilingheight; - } - if (gr_frontsector->f_slope) - { - worldbottom = P_GetZAt(gr_frontsector->f_slope, v1x, v1y); - worldbottomslope = P_GetZAt(gr_frontsector->f_slope, v2x, v2y); - } - else - { - worldbottom = worldbottomslope = gr_frontsector->floorheight; - } +#define SLOPEPARAMS(slope, end1, end2, normalheight) \ + if (slope) { \ + end1 = P_GetZAt(slope, v1x, v1y); \ + end2 = P_GetZAt(slope, v2x, v2y); \ + } else \ + end1 = end2 = normalheight; + + SLOPEPARAMS(gr_frontsector->c_slope, worldtop, worldtopslope, gr_frontsector->ceilingheight) + SLOPEPARAMS(gr_frontsector->f_slope, worldbottom, worldbottomslope, gr_frontsector->floorheight) #else - worldtop = gr_frontsector->ceilingheight; - worldbottom = gr_frontsector->floorheight; + worldtop = gr_frontsector->ceilingheight; + worldbottom = gr_frontsector->floorheight; #endif - } // remember vertices ordering // 3--2 @@ -1544,7 +1518,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[2].z = wallVerts[1].z = ve.y; wallVerts[0].w = wallVerts[1].w = wallVerts[2].w = wallVerts[3].w = 1.0f; - if (drawtextured) { // x offset the texture fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset; @@ -1577,43 +1550,15 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) { INT32 gr_toptexture, gr_bottomtexture; // two sided line - if (gr_backsector->heightsec != -1) - { -#ifdef ESLOPE - worldhigh = worldhighslope = sectors[gr_backsector->heightsec].ceilingheight; - worldlow = worldlowslope = sectors[gr_backsector->heightsec].floorheight; -#else - worldhigh = sectors[gr_backsector->heightsec].ceilingheight; - worldlow = sectors[gr_backsector->heightsec].floorheight; -#endif - } - else - { -#ifdef ESLOPE - if (gr_backsector->c_slope) - { - worldhigh = P_GetZAt(gr_backsector->c_slope, v1x, v1y); - worldhighslope = P_GetZAt(gr_backsector->c_slope, v2x, v2y); - } - else - { - worldhigh = worldhighslope = gr_backsector->ceilingheight; - } - if (gr_backsector->f_slope) - { - worldlow = P_GetZAt(gr_backsector->f_slope, v1x, v1y); - worldlowslope = P_GetZAt(gr_backsector->f_slope, v2x, v2y); - } - else - { - worldlow = worldlowslope = gr_backsector->floorheight; - } +#ifdef ESLOPE + SLOPEPARAMS(gr_backsector->c_slope, worldhigh, worldhighslope, gr_backsector->ceilingheight) + SLOPEPARAMS(gr_backsector->f_slope, worldlow, worldlowslope, gr_backsector->floorheight) +#undef SLOPEPARAMS #else - worldhigh = gr_backsector->ceilingheight; - worldlow = gr_backsector->floorheight; + worldhigh = gr_backsector->ceilingheight; + worldlow = gr_backsector->floorheight; #endif - } // hack to allow height changes in outdoor areas // This is what gets rid of the upper textures if there should be sky @@ -1637,7 +1582,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) worldhigh < worldtop ) && gr_toptexture) { - if (drawtextured) { fixed_t texturevpegtop; // top @@ -1718,7 +1662,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) #endif worldlow > worldbottom) && gr_bottomtexture) //only if VISIBLE!!! { - if (drawtextured) { fixed_t texturevpegbottom = 0; // bottom @@ -1910,7 +1853,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) h = min(highcut, polytop); l = max(polybottom, lowcut); - if (drawtextured) { // PEGGING #ifdef ESLOPE @@ -1966,7 +1908,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) h = min(highcut, polytop); l = max(polybottom, lowcut); - if (drawtextured) { // PEGGING if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) @@ -2158,7 +2099,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture); if (gr_midtexture) { - if (drawtextured) { fixed_t texturevpeg; // PEGGING @@ -2299,7 +2239,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[0].s = wallVerts[3].s = 0; wallVerts[2].s = wallVerts[1].s = 0; } - else if (drawtextured) + else { #ifdef ESLOPE // P.S. this is better-organized than the old version fixed_t offs = sides[(newline ? newline : rover->master)->sidenum[0]].rowoffset; @@ -2432,7 +2372,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[0].s = wallVerts[3].s = 0; wallVerts[2].s = wallVerts[1].s = 0; } - else if (drawtextured) + else { grTex = HWR_GetTexture(texnum); From a38c2cf38e46dcef3be36387e86500eb6349cbb2 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 12 Jan 2017 21:44:27 +0000 Subject: [PATCH 026/223] clipping code didn't seem so bad this time (at least compared to without), let's enable it now? --- src/doomdef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doomdef.h b/src/doomdef.h index 6b06a4cf1..263219a9d 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -548,6 +548,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// on the bright side it fixes some weird issues with translucent walls /// \note SRB2CB port. /// SRB2CB itself ported this from PrBoom+ -//#define NEWCLIP +#define NEWCLIP #endif // __DOOMDEF__ From 00549c122c05ad40e37f5c79376360d4754dfdd1 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 16 Jan 2017 15:48:07 +0000 Subject: [PATCH 027/223] Updated SRB2.cbp for hw_clip.c/h --- SRB2.cbp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/SRB2.cbp b/SRB2.cbp index 88dc400fe..2a1eb87b8 100644 --- a/SRB2.cbp +++ b/SRB2.cbp @@ -1174,6 +1174,39 @@ HW3SOUND for 3D hardware sound support