2016-03-01 15:47:10 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// Copyright 1993-1996 id Software
|
|
|
|
// Copyright 1994-1996 Raven Software
|
|
|
|
// Copyright 1999-2016 Randy Heit
|
|
|
|
// Copyright 2002-2016 Christoph Oelckers
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +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 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
2016-03-01 15:47:10 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-04-17 11:33:19 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 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, see http://www.gnu.org/licenses/
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
2017-04-17 11:33:19 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2016-03-01 15:47:10 +00:00
|
|
|
//
|
|
|
|
// DESCRIPTION:
|
|
|
|
// Sky rendering. The DOOM sky is a texture map like any
|
|
|
|
// wall, wrapping around. 1024 columns equal 360 degrees.
|
|
|
|
// The default sky map is 256 columns and repeats 4 times
|
|
|
|
// on a 320 screen.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
// Needed for FRACUNIT.
|
|
|
|
#include "m_fixed.h"
|
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "r_utility.h"
|
|
|
|
#include "v_text.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// sky mapping
|
|
|
|
//
|
|
|
|
FTextureID skyflatnum;
|
2016-10-20 07:56:45 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
// [RH] Stretch sky texture if not taller than 128 pixels?
|
2016-10-19 22:59:51 +00:00
|
|
|
// Also now controls capped skies. 0 = normal, 1 = stretched, 2 = capped
|
|
|
|
CUSTOM_CVAR (Int, r_skymode, 2, CVAR_ARCHIVE)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
R_InitSkyMap ();
|
|
|
|
}
|
|
|
|
|
2018-04-28 10:34:09 +00:00
|
|
|
CVAR(Float, skyoffset, 0, 0) // for testing
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// R_InitSkyMap
|
|
|
|
//
|
|
|
|
// Called whenever the view size changes.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2019-01-29 03:44:44 +00:00
|
|
|
void InitSkyMap(FLevelLocals *Level)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
int skyheight;
|
|
|
|
FTexture *skytex1, *skytex2;
|
|
|
|
|
2016-10-22 07:57:26 +00:00
|
|
|
// Do not allow the null texture which has no bitmap and will crash.
|
2019-01-29 03:44:44 +00:00
|
|
|
if (Level->skytexture1.isNull())
|
2016-10-22 07:57:26 +00:00
|
|
|
{
|
2019-01-29 03:44:44 +00:00
|
|
|
Level->skytexture1 = TexMan.CheckForTexture("-noflat-", ETextureType::Any);
|
2016-10-22 07:57:26 +00:00
|
|
|
}
|
2019-01-29 03:44:44 +00:00
|
|
|
if (Level->skytexture2.isNull())
|
2016-10-22 07:57:26 +00:00
|
|
|
{
|
2019-01-29 03:44:44 +00:00
|
|
|
Level->skytexture2 = TexMan.CheckForTexture("-noflat-", ETextureType::Any);
|
2016-10-22 07:57:26 +00:00
|
|
|
}
|
|
|
|
|
2019-01-29 03:44:44 +00:00
|
|
|
skytex1 = TexMan.GetTexture(Level->skytexture1, false);
|
|
|
|
skytex2 = TexMan.GetTexture(Level->skytexture2, false);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-10-22 07:57:26 +00:00
|
|
|
if (skytex1 == nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
return;
|
|
|
|
|
2019-01-29 03:44:44 +00:00
|
|
|
if ((Level->flags & LEVEL_DOUBLESKY) && skytex1->GetDisplayHeight() != skytex2->GetDisplayHeight())
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2018-12-06 19:52:03 +00:00
|
|
|
Printf(TEXTCOLOR_BOLD "Both sky textures must be the same height." TEXTCOLOR_NORMAL "\n");
|
2019-01-29 03:44:44 +00:00
|
|
|
Level->flags &= ~LEVEL_DOUBLESKY;
|
|
|
|
Level->skytexture1 = Level->skytexture2;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// There are various combinations for sky rendering depending on how tall the sky is:
|
|
|
|
// h < 128: Unstretched and tiled, centered on horizon
|
|
|
|
// 128 <= h < 200: Can possibly be stretched. When unstretched, the baseline is
|
|
|
|
// 28 rows below the horizon so that the top of the texture
|
|
|
|
// aligns with the top of the screen when looking straight ahead.
|
|
|
|
// When stretched, it is scaled to 228 pixels with the baseline
|
|
|
|
// in the same location as an unstretched 128-tall sky, so the top
|
|
|
|
// of the texture aligns with the top of the screen when looking
|
|
|
|
// fully up.
|
|
|
|
// h == 200: Unstretched, baseline is on horizon, and top is at the top of
|
|
|
|
// the screen when looking fully up.
|
|
|
|
// h > 200: Unstretched, but the baseline is shifted down so that the top
|
|
|
|
// of the texture is at the top of the screen when looking fully up.
|
2018-12-06 00:11:04 +00:00
|
|
|
skyheight = skytex1->GetDisplayHeight();
|
2018-12-06 19:52:03 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
if (skyheight >= 128 && skyheight < 200)
|
|
|
|
{
|
2019-01-29 03:44:44 +00:00
|
|
|
Level->skystretch = (r_skymode == 1
|
2018-12-06 19:52:03 +00:00
|
|
|
&& skyheight >= 128
|
2019-01-29 03:44:44 +00:00
|
|
|
&& Level->IsFreelookAllowed()
|
|
|
|
&& !(Level->flags & LEVEL_FORCETILEDSKY)) ? 1 : 0;
|
2018-12-06 00:11:04 +00:00
|
|
|
}
|
2019-01-29 03:44:44 +00:00
|
|
|
else Level->skystretch = false;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-29 03:44:44 +00:00
|
|
|
void R_InitSkyMap()
|
|
|
|
{
|
|
|
|
for(auto Level : AllLevels())
|
|
|
|
{
|
|
|
|
InitSkyMap(Level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// R_UpdateSky
|
|
|
|
//
|
|
|
|
// Performs sky scrolling
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2017-11-16 01:33:08 +00:00
|
|
|
void R_UpdateSky (uint64_t mstime)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
double ms = (double)mstime * FRACUNIT;
|
2019-01-29 03:44:44 +00:00
|
|
|
for(auto Level : AllLevels())
|
|
|
|
{
|
|
|
|
// Scroll the sky
|
2019-01-29 14:22:26 +00:00
|
|
|
Level->sky1pos = ms * Level->skyspeed1;
|
|
|
|
Level->sky2pos = ms * Level->skyspeed2;
|
2018-04-27 22:18:49 +00:00
|
|
|
|
2019-01-29 03:44:44 +00:00
|
|
|
// The hardware renderer uses a different value range and clamps it to a single rotation
|
2019-01-29 14:22:26 +00:00
|
|
|
Level->hw_sky1pos = (float)(fmod((double(mstime) * Level->skyspeed1), 1024.) * (90. / 256.));
|
|
|
|
Level->hw_sky2pos = (float)(fmod((double(mstime) * Level->skyspeed2), 1024.) * (90. / 256.));
|
2019-01-29 03:44:44 +00:00
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|