From dfdcce090bf452213d0e689cf63e3fb8ac5d58ec Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 6 Jul 2012 15:36:50 +0000 Subject: [PATCH] Polymer: factor out wall y panning coefficient calculation. Non-pow2 wall/mask drawing in classic introduced cases where walls are drawn "incorrectly" because they were constructed with the old behavior in mind. Polymer appears to "correct" for it partially, but doesn't cover all cases. Specifically, now we have: - E1L1 first inside secret room (5000, 50000): Polymer draws like Duke 1.5, classic now draws with an offset. - E3L2 near the vault (-20000, 25000): both classic and Polymer draw with offsets compared to Duke 1.5, but they're different! This means that more research is needed into what makes these two cases diverge, even though both have the same root cause. !!! Also, mappers should abstain from using non-power-of two textures on walls until this issue is resolved in a satisfactory fashion !!! git-svn-id: https://svn.eduke32.com/eduke32@2811 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/polymer.c | 53 ++++++++++------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index ee1d0e03e..a3aef3955 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -2721,6 +2721,20 @@ static int32_t polymer_initwall(int16_t wallnum) return (1); } +static float calc_ypancoef(char curypanning, int16_t curpicnum) +{ + float ypancoef = (float)(pow2long[picsiz[curpicnum] >> 4]); + + if (ypancoef < tilesizy[curpicnum]) + ypancoef *= 2; + if (curypanning > 256 - (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef)) + curypanning -= (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef); + + ypancoef *= (float)curypanning / (256.0f * (float)tilesizy[curpicnum]); + + return ypancoef; +} + static void polymer_updatewall(int16_t wallnum) { int16_t nwallnum, nnwallnum, curpicnum, wallpicnum, walloverpicnum, nwallpicnum; @@ -2861,15 +2875,7 @@ static void polymer_updatewall(int16_t wallnum) } if (wal->ypanning) - { - ypancoef = (float)(pow2long[picsiz[curpicnum] >> 4]); - if (ypancoef < tilesizy[curpicnum]) - ypancoef *= 2; - curypanning = wal->ypanning; - if (curypanning > 256 - (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef)) - curypanning -= (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef); - ypancoef *= (float)(curypanning) / (256.0f * (float)(tilesizy[curpicnum])); - } + ypancoef = calc_ypancoef(wal->ypanning, curpicnum); else ypancoef = 0; @@ -2934,14 +2940,7 @@ static void polymer_updatewall(int16_t wallnum) yref = nsec->floorz; if (curypanning) - { - ypancoef = (float)(pow2long[picsiz[curpicnum] >> 4]); - if (ypancoef < tilesizy[curpicnum]) - ypancoef *= 2; - if (curypanning > 256 - (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef)) - curypanning -= (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef); - ypancoef *= (float)(curypanning) / (256.0f * (float)(tilesizy[curpicnum])); - } + ypancoef = calc_ypancoef(curypanning, curpicnum); else ypancoef = 0; @@ -3021,15 +3020,7 @@ static void polymer_updatewall(int16_t wallnum) yref = nsec->ceilingz; if (wal->ypanning) - { - ypancoef = (float)(pow2long[picsiz[curpicnum] >> 4]); - if (ypancoef < tilesizy[curpicnum]) - ypancoef *= 2; - curypanning = wal->ypanning; - if (curypanning > 256 - (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef)) - curypanning -= (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef); - ypancoef *= (float)(curypanning) / (256.0f * (float)(tilesizy[curpicnum])); - } + ypancoef = calc_ypancoef(wal->ypanning, curpicnum); else ypancoef = 0; @@ -3074,15 +3065,7 @@ static void polymer_updatewall(int16_t wallnum) curpicnum = walloverpicnum; if (wal->ypanning) - { - ypancoef = (float)(pow2long[picsiz[curpicnum] >> 4]); - if (ypancoef < tilesizy[curpicnum]) - ypancoef *= 2; - curypanning = wal->ypanning; - if (curypanning > 256 - (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef)) - curypanning -= (ypancoef - tilesizy[curpicnum]) * (256.0f / ypancoef); - ypancoef *= (float)(curypanning) / (256.0f * (float)(tilesizy[curpicnum])); - } + ypancoef = calc_ypancoef(wal->ypanning, curpicnum); else ypancoef = 0;