Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include "version.h"
  2.  
  3. #ifdef USE_FLOORCEILINGTEX
  4.  
  5. #include "wl_def.h"
  6. #include "wl_shade.h"
  7.  
  8. // Textured Floor and Ceiling by DarkOne
  9. // With multi-textured floors and ceilings stored in lower and upper bytes of
  10. // according tile in third mapplane, respectively.
  11. void DrawFloorAndCeiling(byte *vbuf, unsigned vbufPitch, int min_wallheight)
  12. {
  13.     fixed dist;                                // distance to row projection
  14.     fixed tex_step;                            // global step per one screen pixel
  15.     fixed gu, gv, du, dv;                      // global texture coordinates
  16.     int u, v;                                  // local texture coordinates
  17.     byte *toptex, *bottex;
  18.     unsigned lasttoptex = 0xffffffff, lastbottex = 0xffffffff;
  19.  
  20.     int halfheight = viewheight >> 1;
  21.     int y0 = min_wallheight >> 3;              // starting y value
  22.     if(y0 > halfheight)
  23.         return;                                // view obscured by walls
  24.     if(!y0) y0 = 1;                            // don't let division by zero
  25.     unsigned bot_offset0 = vbufPitch * (halfheight + y0);
  26.     unsigned top_offset0 = vbufPitch * (halfheight - y0 - 1);
  27.  
  28.     // draw horizontal lines
  29.     for(int y = y0, bot_offset = bot_offset0, top_offset = top_offset0;
  30.         y < halfheight; y++, bot_offset += vbufPitch, top_offset -= vbufPitch)
  31.     {
  32.         dist = (heightnumerator / (y + 1)) << 5;
  33.         gu =  viewx + FixedMul(dist, viewcos);
  34.         gv = -viewy + FixedMul(dist, viewsin);
  35.         tex_step = (dist << 8) / viewwidth / 175;
  36.         du =  FixedMul(tex_step, viewsin);
  37.         dv = -FixedMul(tex_step, viewcos);
  38.         gu -= (viewwidth >> 1) * du;
  39.         gv -= (viewwidth >> 1) * dv; // starting point (leftmost)
  40. #ifdef USE_SHADING
  41.         byte *curshades = shadetable[GetShade(y << 3)];
  42. #endif
  43.         for(int x = 0, bot_add = bot_offset, top_add = top_offset;
  44.             x < viewwidth; x++, bot_add++, top_add++)
  45.         {
  46.             if(wallheight[x] >> 3 <= y)
  47.             {
  48.                 int curx = (gu >> TILESHIFT) & (MAPSIZE - 1);
  49.                 int cury = (-(gv >> TILESHIFT) - 1) & (MAPSIZE - 1);
  50.                 unsigned curtex = MAPSPOT(curx, cury, 2);
  51.                 if(curtex)
  52.                 {
  53.                     unsigned curtoptex = curtex >> 8;
  54.                     if (curtoptex != lasttoptex)
  55.                     {
  56.                         lasttoptex = curtoptex;
  57.                         toptex = PM_GetTexture(curtoptex);
  58.                     }
  59.                     unsigned curbottex = curtex & 0xff;
  60.                     if (curbottex != lastbottex)
  61.                     {
  62.                         lastbottex = curbottex;
  63.                         bottex = PM_GetTexture(curbottex);
  64.                     }
  65.                     u = (gu >> (TILESHIFT - TEXTURESHIFT)) & (TEXTURESIZE - 1);
  66.                     v = (gv >> (TILESHIFT - TEXTURESHIFT)) & (TEXTURESIZE - 1);
  67.                     unsigned texoffs = (u << TEXTURESHIFT) + (TEXTURESIZE - 1) - v;
  68. #ifdef USE_SHADING
  69.                     if(curtoptex)
  70.                         vbuf[top_add] = curshades[toptex[texoffs]];
  71.                     if(curbottex)
  72.                         vbuf[bot_add] = curshades[bottex[texoffs]];
  73. #else
  74.                     if(curtoptex)
  75.                         vbuf[top_add] = toptex[texoffs];
  76.                     if(curbottex)
  77.                         vbuf[bot_add] = bottex[texoffs];
  78. #endif
  79.                 }
  80.             }
  81.             gu += du;
  82.             gv += dv;
  83.         }
  84.     }
  85. }
  86.  
  87. #endif
  88.