2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
29 float skyspeed
, skyspeed2
;
36 int r_skydirect
; // not used?
39 // TODO: clean up these routines
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
53 A sky texture is 256*128, with the right side being a masked overlay
56 void R_InitSky (texture_t
*mt
)
61 src
= (byte
*)mt
+ mt
->offsets
[0];
63 for (i
=0 ; i
<128 ; i
++)
65 for (j
=0 ; j
<128 ; j
++)
67 newsky
[(i
*256) + j
+ 128] = src
[i
*256 + j
+ 128];
71 for (i
=0 ; i
<128 ; i
++)
73 for (j
=0 ; j
<131 ; j
++)
75 if (src
[i
*256 + (j
& 0x7F)])
77 bottomsky
[(i
*131) + j
] = src
[i
*256 + (j
& 0x7F)];
78 bottommask
[(i
*131) + j
] = 0;
82 bottomsky
[(i
*131) + j
] = 0;
83 bottommask
[(i
*131) + j
] = 0xff;
103 static int xlast
= -1, ylast
= -1;
105 xshift
= skytime
*skyspeed
;
106 yshift
= skytime
*skyspeed
;
108 if ((xshift
== xlast
) && (yshift
== ylast
))
114 pnewsky
= (unsigned *)&newsky
[0];
116 for (y
=0 ; y
<SKYSIZE
; y
++)
118 baseofs
= ((y
+yshift
) & SKYMASK
) * 131;
120 // FIXME: clean this up
123 for (x
=0 ; x
<SKYSIZE
; x
+= 4)
125 ofs
= baseofs
+ ((x
+xshift
) & SKYMASK
);
127 // PORT: unaligned dword access to bottommask and bottomsky
129 *pnewsky
= (*(pnewsky
+ (128 / sizeof (unsigned))) &
130 *(unsigned *)&bottommask
[ofs
]) |
131 *(unsigned *)&bottomsky
[ofs
];
137 for (x
=0 ; x
<SKYSIZE
; x
++)
139 ofs
= baseofs
+ ((x
+xshift
) & SKYMASK
);
141 *(byte
*)pnewsky
= (*((byte
*)pnewsky
+ 128) &
142 *(byte
*)&bottommask
[ofs
]) |
143 *(byte
*)&bottomsky
[ofs
];
144 pnewsky
= (unsigned *)((byte
*)pnewsky
+ 1);
149 pnewsky
+= 128 / sizeof (unsigned);
161 void R_GenSkyTile (void *pdest
)
169 xshift
= skytime
*skyspeed
;
170 yshift
= skytime
*skyspeed
;
172 pnewsky
= (unsigned *)&newsky
[0];
173 pd
= (unsigned *)pdest
;
175 for (y
=0 ; y
<SKYSIZE
; y
++)
177 baseofs
= ((y
+yshift
) & SKYMASK
) * 131;
179 // FIXME: clean this up
182 for (x
=0 ; x
<SKYSIZE
; x
+= 4)
184 ofs
= baseofs
+ ((x
+xshift
) & SKYMASK
);
186 // PORT: unaligned dword access to bottommask and bottomsky
188 *pd
= (*(pnewsky
+ (128 / sizeof (unsigned))) &
189 *(unsigned *)&bottommask
[ofs
]) |
190 *(unsigned *)&bottomsky
[ofs
];
197 for (x
=0 ; x
<SKYSIZE
; x
++)
199 ofs
= baseofs
+ ((x
+xshift
) & SKYMASK
);
201 *(byte
*)pd
= (*((byte
*)pnewsky
+ 128) &
202 *(byte
*)&bottommask
[ofs
]) |
203 *(byte
*)&bottomsky
[ofs
];
204 pnewsky
= (unsigned *)((byte
*)pnewsky
+ 1);
205 pd
= (unsigned *)((byte
*)pd
+ 1);
210 pnewsky
+= 128 / sizeof (unsigned);
220 void R_GenSkyTile16 (void *pdest
)
228 xshift
= skytime
* skyspeed
;
229 yshift
= skytime
* skyspeed
;
231 pnewsky
= (byte
*)&newsky
[0];
232 pd
= (unsigned short *)pdest
;
234 for (y
=0 ; y
<SKYSIZE
; y
++)
236 baseofs
= ((y
+yshift
) & SKYMASK
) * 131;
238 // FIXME: clean this up
239 // FIXME: do faster unaligned version?
240 for (x
=0 ; x
<SKYSIZE
; x
++)
242 ofs
= baseofs
+ ((x
+xshift
) & SKYMASK
);
244 *pd
= d_8to16table
[(*(pnewsky
+ 128) &
245 *(byte
*)&bottommask
[ofs
]) |
246 *(byte
*)&bottomsky
[ofs
]];
251 pnewsky
+= TILE_SIZE
;
261 void R_SetSkyFrame (void)
266 skyspeed
= iskyspeed
;
267 skyspeed2
= iskyspeed2
;
269 g
= GreatestCommonDivisor (iskyspeed
, iskyspeed2
);
272 temp
= SKYSIZE
* s1
* s2
;
274 skytime
= cl
.time
- ((int)(cl
.time
/ temp
) * temp
);