Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ----------- R_StoreWallRange -----------
- // R_FixWiggle(frontsector);
- // sectorheight is 144
- max_rwscale = 2048<<16 = 134217728
- ds_p->scale1 = rw_scale = R_ScaleFromGlobalAngle (viewangle + xtoviewangle[start]);
- // ds_p->scale1 = 114623
- ds_p->scale2 = R_ScaleFromGlobalAngle (viewangle + xtoviewangle[stop]);
- // ds_p->scale2 = 120301273
- ds_p->scalestep = rw_scalestep = (ds_p->scale2-rw_scale) / (stop-start);
- // stop-start = 1023-265 = 758
- // ds_p->scalestep = 158557
- // ----------- R_RenderMaskedSegRange() -----------
- spryscale = ds->scale1 + (x1 - ds->x1)*rw_scalestep;
- // spryscale = 114623 + (265 - 265)*158557 = 114623
- for (dcvars.x = x1 ; dcvars.x <= x2 ; dcvars.x++, spryscale += rw_scalestep)
- // dcvars.x from 265 to 1023
- // spryscale starts from 114623, max value is 114623 + (1023-265)*158557 = 120300829
- // sprtopscreen calculation within this loop
- // killough 3/2/98:
- //
- // This calculation used to overflow and cause crashes in Doom:
- //
- // sprtopscreen = centeryfrac - FixedMul(dcvars.texturemid, spryscale);
- //
- // This code fixes it, by using double-precision intermediate
- // arithmetic and by skipping the drawing of 2s normals whose
- // mapping to screen coordinates is totally out of range:
- int_64_t t = ((int_64_t) centeryfrac << FRACBITS) - (int_64_t) dcvars.texturemid * spryscale;
- if (t + (int_64_t) textureheight[texnum] * spryscale < 0 || t > (int_64_t) SCREENHEIGHT << FRACBITS*2)
- continue; // skip if the texture is out of screen's range
- sprtopscreen = (long)(t >> FRACBITS);
- // centeryfrac = 22020096 (336<<16)
- // dcvars.texturemid = 5701632 (87<<16)
- // max value for spryscale is 120300829
- // t = (22020096<<16)-5701632*120300829 = -684467947241472
- // sprtopscreen = t >> FRACBITS = -684467947241472 >> 16 = -10444152027 < MIN_INT
- //
- // first time it overflows when dcvars.x == 422
- // in this case spryscale = 114623 + (422-265)*158557 = 25008072
- // t = (22020096<<16)-5701632*25008072 = -141143714562048
- // sprtopscreen = -141143714562048 >> 16 = -2153682168 < MIN_INT (-2147483647)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement