2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-11 16:03:29 +00:00
|
|
|
r_sky.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
(description)
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-05-17 10:03:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-05-17 10:03:19 +00:00
|
|
|
#endif
|
2000-12-30 02:16:36 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
#include "r_local.h"
|
|
|
|
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int iskyspeed = 8;
|
|
|
|
int iskyspeed2 = 2;
|
|
|
|
float skyspeed, skyspeed2;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
float skytime;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
byte *r_skysource;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int r_skymade;
|
|
|
|
int r_skydirect; // not used?
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
// TODO: clean up these routines
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
byte bottomsky[128 * 131];
|
|
|
|
byte bottommask[128 * 131];
|
|
|
|
byte newsky[128 * 256]; // newsky and topsky both pack in
|
|
|
|
|
|
|
|
// here, 128 bytes
|
|
|
|
// of newsky on the left of each scan, 128 bytes
|
|
|
|
// of topsky on the right, because the low-level
|
|
|
|
// drawers need 256-byte scan widths
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
R_InitSky
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2001-02-09 02:53:09 +00:00
|
|
|
A sky texture is 256*128, with the right side being a masked overlay
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_InitSky (texture_t *mt)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int i, j;
|
|
|
|
byte *src;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
src = (byte *) mt + mt->offsets[0];
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 128; i++) {
|
|
|
|
for (j = 0; j < 128; j++) {
|
|
|
|
newsky[(i * 256) + j + 128] = src[i * 256 + j + 128];
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (i = 0; i < 128; i++) {
|
|
|
|
for (j = 0; j < 131; j++) {
|
|
|
|
if (src[i * 256 + (j & 0x7F)]) {
|
|
|
|
bottomsky[(i * 131) + j] = src[i * 256 + (j & 0x7F)];
|
|
|
|
bottommask[(i * 131) + j] = 0;
|
|
|
|
} else {
|
|
|
|
bottomsky[(i * 131) + j] = 0;
|
|
|
|
bottommask[(i * 131) + j] = 0xff;
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-12-08 06:51:37 +00:00
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
r_skysource = newsky;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
R_MakeSky
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_MakeSky (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int x, y;
|
|
|
|
int ofs, baseofs;
|
|
|
|
int xshift, yshift;
|
|
|
|
unsigned int *pnewsky;
|
|
|
|
static int xlast = -1, ylast = -1;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
xshift = skytime * skyspeed;
|
|
|
|
yshift = skytime * skyspeed;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
if ((xshift == xlast) && (yshift == ylast))
|
|
|
|
return;
|
|
|
|
|
|
|
|
xlast = xshift;
|
|
|
|
ylast = yshift;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
pnewsky = (unsigned int *) &newsky[0];
|
|
|
|
|
|
|
|
for (y = 0; y < SKYSIZE; y++) {
|
|
|
|
baseofs = ((y + yshift) & SKYMASK) * 131;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// FIXME: clean this up
|
|
|
|
#if UNALIGNED_OK
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (x = 0; x < SKYSIZE; x += 4) {
|
|
|
|
ofs = baseofs + ((x + xshift) & SKYMASK);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// PORT: unaligned dword access to bottommask and bottomsky
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-09-22 09:08:08 +00:00
|
|
|
*pnewsky = (*(pnewsky + (128 / sizeof (unsigned int))) &
|
2000-12-08 06:51:37 +00:00
|
|
|
*(unsigned int *) &bottommask[ofs]) |
|
|
|
|
*(unsigned int *) &bottomsky[ofs];
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
pnewsky++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (x = 0; x < SKYSIZE; x++) {
|
|
|
|
ofs = baseofs + ((x + xshift) & SKYMASK);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
*(byte *) pnewsky = (*((byte *) pnewsky + 128) &
|
|
|
|
*(byte *) & bottommask[ofs]) |
|
|
|
|
*(byte *) & bottomsky[ofs];
|
|
|
|
pnewsky = (unsigned int *) ((byte *) pnewsky + 1);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2000-09-22 09:08:08 +00:00
|
|
|
pnewsky += 128 / sizeof (unsigned int);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r_skymade = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
R_GenSkyTile
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_GenSkyTile (void *pdest)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int x, y;
|
|
|
|
int ofs, baseofs;
|
|
|
|
int xshift, yshift;
|
|
|
|
unsigned int *pnewsky;
|
|
|
|
unsigned int *pd;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
xshift = skytime * skyspeed;
|
|
|
|
yshift = skytime * skyspeed;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
pnewsky = (unsigned int *) &newsky[0];
|
|
|
|
pd = (unsigned int *) pdest;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (y = 0; y < SKYSIZE; y++) {
|
|
|
|
baseofs = ((y + yshift) & SKYMASK) * 131;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// FIXME: clean this up
|
|
|
|
#if UNALIGNED_OK
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (x = 0; x < SKYSIZE; x += 4) {
|
|
|
|
ofs = baseofs + ((x + xshift) & SKYMASK);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// PORT: unaligned dword access to bottommask and bottomsky
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-09-22 09:08:08 +00:00
|
|
|
*pd = (*(pnewsky + (128 / sizeof (unsigned int))) &
|
2000-12-08 06:51:37 +00:00
|
|
|
*(unsigned int *) &bottommask[ofs]) |
|
|
|
|
*(unsigned int *) &bottomsky[ofs];
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
pnewsky++;
|
|
|
|
pd++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (x = 0; x < SKYSIZE; x++) {
|
|
|
|
ofs = baseofs + ((x + xshift) & SKYMASK);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
*(byte *) pd = (*((byte *) pnewsky + 128) &
|
|
|
|
*(byte *) & bottommask[ofs]) |
|
|
|
|
*(byte *) & bottomsky[ofs];
|
|
|
|
pnewsky = (unsigned int *) ((byte *) pnewsky + 1);
|
|
|
|
pd = (unsigned int *) ((byte *) pd + 1);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2000-09-22 09:08:08 +00:00
|
|
|
pnewsky += 128 / sizeof (unsigned int);
|
2000-05-10 11:29:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
R_GenSkyTile16
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_GenSkyTile16 (void *pdest)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int x, y;
|
|
|
|
int ofs, baseofs;
|
|
|
|
int xshift, yshift;
|
|
|
|
byte *pnewsky;
|
|
|
|
unsigned short *pd;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
xshift = skytime * skyspeed;
|
|
|
|
yshift = skytime * skyspeed;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
pnewsky = (byte *) & newsky[0];
|
|
|
|
pd = (unsigned short *) pdest;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
for (y = 0; y < SKYSIZE; y++) {
|
|
|
|
baseofs = ((y + yshift) & SKYMASK) * 131;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
// FIXME: clean this up
|
|
|
|
// FIXME: do faster unaligned version?
|
2000-12-08 06:51:37 +00:00
|
|
|
for (x = 0; x < SKYSIZE; x++) {
|
|
|
|
ofs = baseofs + ((x + xshift) & SKYMASK);
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
*pd = d_8to16table[(*(pnewsky + 128) &
|
2000-12-08 06:51:37 +00:00
|
|
|
*(byte *) & bottommask[ofs]) |
|
|
|
|
*(byte *) & bottomsky[ofs]];
|
2000-05-10 11:29:38 +00:00
|
|
|
pnewsky++;
|
|
|
|
pd++;
|
|
|
|
}
|
|
|
|
|
|
|
|
pnewsky += TILE_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
R_SetSkyFrame
|
2000-05-10 11:29:38 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
R_SetSkyFrame (void)
|
2000-05-10 11:29:38 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
int g, s1, s2;
|
|
|
|
float temp;
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
skyspeed = iskyspeed;
|
|
|
|
skyspeed2 = iskyspeed2;
|
|
|
|
|
|
|
|
g = GreatestCommonDivisor (iskyspeed, iskyspeed2);
|
|
|
|
s1 = iskyspeed / g;
|
|
|
|
s2 = iskyspeed2 / g;
|
|
|
|
temp = SKYSIZE * s1 * s2;
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
skytime = cl.time - ((int) (cl.time / temp) * temp);
|
|
|
|
|
2000-05-10 11:29:38 +00:00
|
|
|
|
|
|
|
r_skymade = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-18 20:32:11 +00:00
|
|
|
/*
|
|
|
|
R_LoadSkys
|
|
|
|
|
|
|
|
Stub function for loading a skybox. Currently we only have support for
|
|
|
|
skyboxes in GL targets, so we just do nothing here. --KB
|
|
|
|
*/
|
|
|
|
void
|
2000-12-08 06:51:37 +00:00
|
|
|
R_LoadSkys (char *name)
|
2000-05-18 20:32:11 +00:00
|
|
|
{
|
|
|
|
}
|