home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quake_src / r_sky.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-17  |  5.4 KB  |  283 lines

  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // r_sky.c
  21.  
  22. #include "quakedef.h"
  23. #include "r_local.h"
  24. #include "d_local.h"
  25.  
  26.  
  27. int   iskyspeed = 8;
  28. int   iskyspeed2 = 2;
  29. float skyspeed, skyspeed2;
  30.  
  31. float   skytime;
  32.  
  33. byte    *r_skysource;
  34.  
  35. int r_skymade;
  36. int r_skydirect;    // not used?
  37.  
  38.  
  39. // TODO: clean up these routines
  40.  
  41. byte  bottomsky[128*131];
  42. byte  bottommask[128*131];
  43. byte  newsky[128*256];  // newsky and topsky both pack in here, 128 bytes
  44.               //  of newsky on the left of each scan, 128 bytes
  45.               //  of topsky on the right, because the low-level
  46.               //  drawers need 256-byte scan widths
  47.  
  48.  
  49. /*
  50. =============
  51. R_InitSky
  52.  
  53. A sky texture is 256*128, with the right side being a masked overlay
  54. ==============
  55. */
  56. void R_InitSky (texture_t *mt)
  57. {
  58.   int     i, j;
  59.   byte    *src;
  60.  
  61.   src = (byte *)mt + mt->offsets[0];
  62.  
  63.   for (i=0 ; i<128 ; i++)
  64.   {
  65.     for (j=0 ; j<128 ; j++)
  66.     {
  67.       newsky[(i*256) + j + 128] = src[i*256 + j + 128];
  68.     }
  69.   }
  70.  
  71.   for (i=0 ; i<128 ; i++)
  72.   {
  73.     for (j=0 ; j<131 ; j++)
  74.     {
  75.       if (src[i*256 + (j & 0x7F)])
  76.       {
  77.         bottomsky[(i*131) + j] = src[i*256 + (j & 0x7F)];
  78.         bottommask[(i*131) + j] = 0;
  79.       }
  80.       else
  81.       {
  82.         bottomsky[(i*131) + j] = 0;
  83.         bottommask[(i*131) + j] = 0xff;
  84.       }
  85.     }
  86.   }
  87.   
  88.   r_skysource = newsky;
  89. }
  90.  
  91.  
  92. #ifndef M68KASM
  93. /*
  94. =================
  95. R_MakeSky
  96. =================
  97. */
  98. void R_MakeSky (void)
  99. {
  100.   int     x, y;
  101.   int     ofs, baseofs;
  102.   int     xshift, yshift;
  103.   unsigned  *pnewsky;
  104.   static int  xlast = -1, ylast = -1;
  105.  
  106.   xshift = skytime*skyspeed;
  107.   yshift = skytime*skyspeed;
  108.  
  109.   if ((xshift == xlast) && (yshift == ylast))
  110.     return;
  111.  
  112.   xlast = xshift;
  113.   ylast = yshift;
  114.   
  115.   pnewsky = (unsigned *)&newsky[0];
  116.  
  117.   for (y=0 ; y<SKYSIZE ; y++)
  118.   {
  119.     baseofs = ((y+yshift) & SKYMASK) * 131;
  120.  
  121. // FIXME: clean this up
  122. #if UNALIGNED_OK
  123.  
  124.     for (x=0 ; x<SKYSIZE ; x += 4)
  125.     {
  126.       ofs = baseofs + ((x+xshift) & SKYMASK);
  127.  
  128.     // PORT: unaligned dword access to bottommask and bottomsky
  129.  
  130.       *pnewsky = (*(pnewsky + (128 / sizeof (unsigned))) &
  131.             *(unsigned *)&bottommask[ofs]) |
  132.             *(unsigned *)&bottomsky[ofs];
  133.       pnewsky++;
  134.     }
  135.  
  136. #else
  137.  
  138.     for (x=0 ; x<SKYSIZE ; x++)
  139.     {
  140.       ofs = baseofs + ((x+xshift) & SKYMASK);
  141.  
  142.       *(byte *)pnewsky = (*((byte *)pnewsky + 128) &
  143.             *(byte *)&bottommask[ofs]) |
  144.             *(byte *)&bottomsky[ofs];
  145.       pnewsky = (unsigned *)((byte *)pnewsky + 1);
  146.     }
  147.  
  148. #endif
  149.  
  150.     pnewsky += 128 / sizeof (unsigned);
  151.   }
  152.  
  153.   r_skymade = 1;
  154. }
  155. #endif
  156.  
  157.  
  158. /*
  159. =================
  160. R_GenSkyTile
  161. =================
  162. */
  163. void R_GenSkyTile (void *pdest)
  164. {
  165.   int     x, y;
  166.   int     ofs, baseofs;
  167.   int     xshift, yshift;
  168.   unsigned  *pnewsky;
  169.   unsigned  *pd;
  170.  
  171.   xshift = skytime*skyspeed;
  172.   yshift = skytime*skyspeed;
  173.  
  174.   pnewsky = (unsigned *)&newsky[0];
  175.   pd = (unsigned *)pdest;
  176.  
  177.   for (y=0 ; y<SKYSIZE ; y++)
  178.   {
  179.     baseofs = ((y+yshift) & SKYMASK) * 131;
  180.  
  181. // FIXME: clean this up
  182. #if UNALIGNED_OK
  183.  
  184.     for (x=0 ; x<SKYSIZE ; x += 4)
  185.     {
  186.       ofs = baseofs + ((x+xshift) & SKYMASK);
  187.  
  188.     // PORT: unaligned dword access to bottommask and bottomsky
  189.  
  190.       *pd = (*(pnewsky + (128 / sizeof (unsigned))) &
  191.            *(unsigned *)&bottommask[ofs]) |
  192.            *(unsigned *)&bottomsky[ofs];
  193.       pnewsky++;
  194.       pd++;
  195.     }
  196.  
  197. #else
  198.  
  199.     for (x=0 ; x<SKYSIZE ; x++)
  200.     {
  201.       ofs = baseofs + ((x+xshift) & SKYMASK);
  202.  
  203.       *(byte *)pd = (*((byte *)pnewsky + 128) &
  204.             *(byte *)&bottommask[ofs]) |
  205.             *(byte *)&bottomsky[ofs];
  206.       pnewsky = (unsigned *)((byte *)pnewsky + 1);
  207.       pd = (unsigned *)((byte *)pd + 1);
  208.     }
  209.  
  210. #endif
  211.  
  212.     pnewsky += 128 / sizeof (unsigned);
  213.   }
  214. }
  215.  
  216.  
  217. /*
  218. =================
  219. R_GenSkyTile16
  220. =================
  221. */
  222. void R_GenSkyTile16 (void *pdest)
  223. {
  224.   int       x, y;
  225.   int       ofs, baseofs;
  226.   int       xshift, yshift;
  227.   byte      *pnewsky;
  228.   unsigned short  *pd;
  229.  
  230.   xshift = skytime * skyspeed;
  231.   yshift = skytime * skyspeed;
  232.  
  233.   pnewsky = (byte *)&newsky[0];
  234.   pd = (unsigned short *)pdest;
  235.  
  236.   for (y=0 ; y<SKYSIZE ; y++)
  237.   {
  238.     baseofs = ((y+yshift) & SKYMASK) * 131;
  239.  
  240. // FIXME: clean this up
  241. // FIXME: do faster unaligned version?
  242.     for (x=0 ; x<SKYSIZE ; x++)
  243.     {
  244.       ofs = baseofs + ((x+xshift) & SKYMASK);
  245.  
  246.       *pd = d_8to16table[(*(pnewsky + 128) &
  247.           *(byte *)&bottommask[ofs]) |
  248.           *(byte *)&bottomsky[ofs]];
  249.       pnewsky++;
  250.       pd++;
  251.     }
  252.  
  253.     pnewsky += TILE_SIZE;
  254.   }
  255. }
  256.  
  257.  
  258. /*
  259. =============
  260. R_SetSkyFrame
  261. ==============
  262. */
  263. void R_SetSkyFrame (void)
  264. {
  265.   int   g, s1, s2;
  266.   float temp;
  267.  
  268.   skyspeed = iskyspeed;
  269.   skyspeed2 = iskyspeed2;
  270.  
  271.   g = GreatestCommonDivisor (iskyspeed, iskyspeed2);
  272.   s1 = iskyspeed / g;
  273.   s2 = iskyspeed2 / g;
  274.   temp = SKYSIZE * s1 * s2;
  275.  
  276.   skytime = cl.time - ((int)(cl.time / temp) * temp);
  277.   
  278.  
  279.   r_skymade = 0;
  280. }
  281.  
  282.  
  283.