diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index c3e3b38d3..ee9e682e6 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -792,6 +792,21 @@ static int cliptestsector(int const dasect, int const nextsect, int32_t const fl auto const sec2 = (usectorptr_t)§or[nextsect]; + if (blooddemohack) + { + int32_t daz = getflorzofslope(dasect, pos.x, pos.y); + int32_t daz2 = getflorzofslope(nextsect, pos.x, pos.y); + + if (daz2 < daz-(1<<8) && (sec2->floorstat&1) == 0) + if (posz >= daz2-(flordist-1)) return 1; + daz = getceilzofslope(dasect, pos.x, pos.y); + daz2 = getceilzofslope(nextsect, pos.x, pos.y); + if (daz2 > daz+(1<<8) && (sec2->ceilingstat&1) == 0) + if (posz <= daz2+(ceildist-1)) return 1; + + return 0; + } + int32_t daz2 = sec2->floorz; int32_t dacz2 = sec2->ceilingz; @@ -947,6 +962,12 @@ static int get_floorspr_clipyou(vec2_t const v1, vec2_t const v2, vec2_t const v static void clipupdatesector(vec2_t const pos, int16_t * const sectnum, int const walldist) { + if (blooddemohack) + { + updatesector(pos.x, pos.y, sectnum); + return; + } + if (inside_p(pos.x, pos.y, *sectnum)) return; @@ -1168,7 +1189,7 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int } // We're not interested in any sector reached by portal traversal that we're "inside" of. - if (!curspr && dasect != initialsectnum && inside(pos->x, pos->y, dasect) == 1) + if (!blooddemohack && !curspr && dasect != initialsectnum && inside(pos->x, pos->y, dasect) == 1) { int k; for (k=startwall; k 0) v.x = -v.x; v.y = walldist; if (d.x < 0) v.y = -v.y; - if (d.x * (pos->y-p1.y-v.y) < (pos->x-p1.x-v.x) * d.y) + if (!blooddemohack && d.x * (pos->y-p1.y-v.y) < (pos->x-p1.x-v.x) * d.y) v.x >>= 1, v.y >>= 1; addclipline(p1.x+v.x, p1.y+v.y, p2.x+v.x, p2.y+v.y, objtype, false); @@ -1351,6 +1372,7 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int do { + if (!blooddemohack) for (native_t i=clipnum-1;i>=0;--i) { if (!bitmap_test(clipignore, i) && clipinsideboxline(pos->x, pos->y, clipit[i].x1, clipit[i].y1, clipit[i].x2, clipit[i].y2, walldist)) @@ -1368,6 +1390,20 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int if ((hitwall = cliptrace(pos->vec2, &vec)) >= 0) { vec2_t const clipr = { clipit[hitwall].x2 - clipit[hitwall].x1, clipit[hitwall].y2 - clipit[hitwall].y1 }; + if (blooddemohack) + { + int32_t const templl = clipr.x * clipr.x + clipr.y * clipr.y; + + if (templl > 0) + { + int32_t const templl2 = (goal.x-vec.x)*clipr.x + (goal.y-vec.y)*clipr.y; + int32_t const i = ((klabs(templl2)>>11) < templl) ? divscale20(templl2, templl) : 0; + + goal = { mulscale20(clipr.x, i)+vec.x, mulscale20(clipr.y, i)+vec.y }; + } + } + else + { int64_t const templl = (int64_t)clipr.x * clipr.x + (int64_t)clipr.y * clipr.y; if (templl > 0) @@ -1377,6 +1413,7 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int goal = { mulscale20(clipr.x, i)+vec.x, mulscale20(clipr.y, i)+vec.y }; } + } int32_t const tempint = dmulscale6(clipr.x, move.x, clipr.y, move.y); @@ -1385,8 +1422,12 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int j = hitwalls[i]; if ((tempint ^ dmulscale6(clipit[j].x2-clipit[j].x1, move.x, clipit[j].y2-clipit[j].y1, move.y)) < 0) + { + if (blooddemohack == 1) + updatesector(pos->x, pos->y, sectnum); return clipReturn; } + } keepaway(&goal.x, &goal.y, hitwall); xvect = (goal.x-vec.x)<<14; @@ -1397,6 +1438,7 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int hitwalls[cnt] = hitwall; } + if (!blooddemohack) clipupdatesector(vec, sectnum, rad); pos->x = vec.x; @@ -1404,6 +1446,52 @@ int32_t clipmove(vec3_t * const pos, int16_t * const sectnum, int32_t xvect, int cnt--; } while ((xvect|yvect) != 0 && hitwall >= 0 && cnt > 0); + if (blooddemohack) + { + for (native_t j=0; jx, pos->y, clipsectorlist[j]) == 1) + { + *sectnum = clipsectorlist[j]; + return clipReturn; + } + + int32_t tempint2, tempint1 = INT32_MAX; + *sectnum = -1; + for (native_t j=numsectors-1; j>=0; j--) + if (inside(pos->x, pos->y, j) == 1) + { + if (sector[j].ceilingstat&2) + tempint2 = getceilzofslope(j, pos->x, pos->y) - pos->z; + else + tempint2 = sector[j].ceilingz - pos->z; + + if (tempint2 > 0) + { + if (tempint2 < tempint1) + { + *sectnum = j; tempint1 = tempint2; + } + } + else + { + if (sector[j].floorstat&2) + tempint2 = pos->z - getflorzofslope(j, pos->x, pos->y); + else + tempint2 = pos->z - sector[j].floorz; + + if (tempint2 <= 0) + { + *sectnum = j; + return clipReturn; + } + if (tempint2 < tempint1) + { + *sectnum = j; tempint1 = tempint2; + } + } + } + } + return clipReturn; } @@ -1630,11 +1718,13 @@ restart_grand: int32_t daz, daz2; closest = { pos->x, pos->y }; + if (!blooddemohack) getsectordist(closest, k, &closest); getzsofslope(k,closest.x,closest.y,&daz,&daz2); int32_t fz, cz; closest = { pos->x, pos->y }; + if (!blooddemohack) getsectordist(closest, sectq[clipinfo[curidx].qend], &closest); getzsofslope(sectq[clipinfo[curidx].qend],closest.x,closest.y,&cz,&fz); @@ -1720,6 +1810,7 @@ restart_grand: //It actually got here, through all the continue's!!! int32_t daz, daz2; closest = { pos->x, pos->y }; + if (!blooddemohack) getsectordist(closest, k, &closest); getzsofslope(k, closest.x,closest.y, &daz,&daz2); @@ -1729,6 +1820,7 @@ restart_grand: int32_t fz,cz, hitwhat=(curspr-(uspritetype *)sprite)+49152; closest = { pos->x, pos->y }; + if (!blooddemohack) getsectordist(closest, sectq[clipinfo[curidx].qend], &closest); getzsofslope(sectq[clipinfo[curidx].qend],closest.x,closest.y,&cz,&fz); diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 3e3968060..b62dcab9c 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -7955,6 +7955,39 @@ int32_t lintersect(const int32_t originX, const int32_t originY, const int32_t o // rintersect (internal) // // returns: -1 if didn't intersect, coefficient (x3--x4 fraction)<<16 else +int32_t rintersect_old(int32_t x1, int32_t y1, int32_t z1, + int32_t vx, int32_t vy, int32_t vz, + int32_t x3, int32_t y3, int32_t x4, int32_t y4, + int32_t *intx, int32_t *inty, int32_t *intz) +{ + //p1 towards p2 is a ray + + int32_t const x34=x3-x4, y34=y3-y4; + int32_t const x31=x3-x1, y31=y3-y1; + + int32_t const bot = vx*y34 - vy*x34; + int32_t const topt = x31*y34 - y31*x34; + + if (bot == 0) + return -1; + + int32_t const topu = vx*y31 - vy*x31; + + if (bot > 0 && (topt < 0 || topu < 0 || topu >= bot)) + return -1; + else if (bot < 0 && (topt > 0 || topu > 0 || topu <= bot)) + return -1; + + int32_t t = divscale16(topt, bot); + *intx = x1 + mulscale16(vx, t); + *inty = y1 + mulscale16(vy, t); + *intz = z1 + mulscale16(vz, t); + + t = divscale16(topu, bot); + + return t; +} + int32_t rintersect(int32_t x1, int32_t y1, int32_t z1, int32_t vx, int32_t vy, int32_t vz, int32_t x3, int32_t y3, int32_t x4, int32_t y4, @@ -7962,6 +7995,9 @@ int32_t rintersect(int32_t x1, int32_t y1, int32_t z1, { //p1 towards p2 is a ray + if (blooddemohack) + return rintersect_old(x1,y1,z1,vx,vy,vz,x3,y3,x4,y4,intx,inty,intz); + int64_t const x34=x3-x4, y34=y3-y4; int64_t const x31=x3-x1, y31=y3-y1;