Advertisement
Guest User

Untitled

a guest
Feb 10th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.07 KB | None | 0 0
  1. // ----------- R_StoreWallRange -----------
  2. // R_FixWiggle(frontsector);
  3. // sectorheight is 144
  4. max_rwscale = 2048<<16 = 134217728
  5.  
  6. ds_p->scale1 = rw_scale = R_ScaleFromGlobalAngle (viewangle + xtoviewangle[start]);
  7. // ds_p->scale1 = 114623
  8.  
  9. ds_p->scale2 = R_ScaleFromGlobalAngle (viewangle + xtoviewangle[stop]);
  10. // ds_p->scale2 = 120301273
  11.  
  12. ds_p->scalestep = rw_scalestep = (ds_p->scale2-rw_scale) / (stop-start);
  13. // stop-start = 1023-265 = 758
  14. // ds_p->scalestep = 158557
  15.  
  16. // ----------- R_RenderMaskedSegRange() -----------
  17. spryscale = ds->scale1 + (x1 - ds->x1)*rw_scalestep;
  18. // spryscale = 114623 + (265 - 265)*158557 = 114623
  19.  
  20. for (dcvars.x = x1 ; dcvars.x <= x2 ; dcvars.x++, spryscale += rw_scalestep)
  21.   // dcvars.x from 265 to 1023
  22.   // spryscale starts from 114623, max value is 114623 + (1023-265)*158557 = 120300829
  23.  
  24.   // sprtopscreen calculation within this loop
  25.   // killough 3/2/98:
  26.   //
  27.   // This calculation used to overflow and cause crashes in Doom:
  28.   //
  29.   // sprtopscreen = centeryfrac - FixedMul(dcvars.texturemid, spryscale);
  30.   //
  31.   // This code fixes it, by using double-precision intermediate
  32.   // arithmetic and by skipping the drawing of 2s normals whose
  33.   // mapping to screen coordinates is totally out of range:
  34.   int_64_t t = ((int_64_t) centeryfrac << FRACBITS) - (int_64_t) dcvars.texturemid * spryscale;
  35.   if (t + (int_64_t) textureheight[texnum] * spryscale < 0 || t > (int_64_t) SCREENHEIGHT << FRACBITS*2)
  36.     continue; // skip if the texture is out of screen's range
  37.   sprtopscreen = (long)(t >> FRACBITS);
  38.  
  39.   // centeryfrac = 22020096 (336<<16)
  40.   // dcvars.texturemid = 5701632 (87<<16)
  41.   // max value for spryscale is 120300829
  42.   // t = (22020096<<16)-5701632*120300829 = -684467947241472
  43.   // sprtopscreen = t >> FRACBITS = -684467947241472 >> 16 = -10444152027 < MIN_INT
  44.   //
  45.   // first time it overflows when dcvars.x == 422
  46.   // in this case spryscale = 114623 + (422-265)*158557 = 25008072
  47.   // t = (22020096<<16)-5701632*25008072 = -141143714562048
  48.   // sprtopscreen = -141143714562048 >> 16 = -2153682168 < MIN_INT (-2147483647)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement