2021-04-11 07:59:55 +00:00
|
|
|
/*
|
|
|
|
** precache.cpp
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2019-2021 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
2021-04-11 11:19:48 +00:00
|
|
|
#include "ns.h"
|
2021-04-11 07:59:55 +00:00
|
|
|
#include "build.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "hw_material.h"
|
2021-04-11 11:19:48 +00:00
|
|
|
#include "gamestruct.h"
|
|
|
|
#include "gamecontrol.h"
|
2021-05-02 11:12:24 +00:00
|
|
|
#include "texturemanager.h"
|
2021-04-11 11:56:10 +00:00
|
|
|
#include "hw_models.h"
|
|
|
|
#include "hw_voxels.h"
|
2021-05-02 11:12:24 +00:00
|
|
|
#include "mapinfo.h"
|
2022-09-30 14:25:21 +00:00
|
|
|
#include "models/modeldata.h"
|
2022-09-30 17:06:44 +00:00
|
|
|
#include "gamefuncs.h"
|
2022-12-07 16:10:27 +00:00
|
|
|
#include "texinfo.h"
|
|
|
|
|
|
|
|
#include "buildtiles.h"
|
2021-04-11 07:59:55 +00:00
|
|
|
|
|
|
|
static void PrecacheTex(FGameTexture* tex, int palid)
|
|
|
|
{
|
|
|
|
if (!tex || !tex->isValid()) return;
|
|
|
|
int scaleflags = 0;
|
|
|
|
if (shouldUpscale(tex, UF_Texture)) scaleflags |= CTF_Upscale;
|
|
|
|
|
|
|
|
auto mat = FMaterial::ValidateTexture(tex, scaleflags);
|
|
|
|
screen->PrecacheMaterial(mat, palid);
|
|
|
|
}
|
|
|
|
|
2022-12-08 19:53:14 +00:00
|
|
|
static void doprecache(FTextureID texid, int palette)
|
2021-04-11 07:59:55 +00:00
|
|
|
{
|
2021-04-11 11:19:48 +00:00
|
|
|
if ((palette < (MAXPALOOKUPS - RESERVEDPALS)) && (!lookups.checkTable(palette))) return;
|
2021-04-11 07:59:55 +00:00
|
|
|
|
2021-04-11 11:19:48 +00:00
|
|
|
int palid = TRANSLATION(Translation_Remap + curbasepal, palette);
|
2022-12-08 19:53:14 +00:00
|
|
|
auto tex = TexMan.GetGameTexture(texid);
|
2021-04-11 07:59:55 +00:00
|
|
|
PrecacheTex(tex, palid);
|
|
|
|
|
2022-12-08 17:26:09 +00:00
|
|
|
int const mid = -1;// hw_models ? modelManager.CheckModel(picnum, palette) : -1;
|
2021-04-11 07:59:55 +00:00
|
|
|
|
2022-09-30 14:25:21 +00:00
|
|
|
if (mid < 0)
|
2021-04-11 07:59:55 +00:00
|
|
|
{
|
2021-04-11 11:19:48 +00:00
|
|
|
if (r_voxels)
|
2021-04-11 07:59:55 +00:00
|
|
|
{
|
2022-12-08 19:53:14 +00:00
|
|
|
int vox = GetExtInfo(texid).tiletovox;
|
2021-04-11 11:38:23 +00:00
|
|
|
if (vox >= 0 && vox < MAXVOXELS && voxmodels[vox] && voxmodels[vox]->model)
|
2021-04-11 11:19:48 +00:00
|
|
|
{
|
|
|
|
FHWModelRenderer mr(*screen->RenderState(), 0);
|
|
|
|
voxmodels[vox]->model->BuildVertexBuffer(&mr);
|
|
|
|
}
|
2021-04-11 07:59:55 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-30 14:25:21 +00:00
|
|
|
#if 0
|
2021-04-11 07:59:55 +00:00
|
|
|
int const surfaces = (models[mid]->mdnum == 3) ? ((md3model_t *)models[mid])->head.numsurfs : 0;
|
|
|
|
|
|
|
|
for (int i = 0; i <= surfaces; i++)
|
|
|
|
{
|
2021-12-24 08:56:02 +00:00
|
|
|
auto skintex = mdloadskin((md2model_t *)models[mid], 0, palette, i, nullptr);
|
|
|
|
int paletteid = TRANSLATION(Translation_Remap + curbasepal, palette);
|
|
|
|
if (skintex) PrecacheTex(skintex, paletteid);
|
2021-04-11 07:59:55 +00:00
|
|
|
}
|
2022-09-30 14:25:21 +00:00
|
|
|
#endif
|
2021-04-11 07:59:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TMap<int64_t, bool> cachemap;
|
|
|
|
|
2022-12-08 19:53:14 +00:00
|
|
|
void markTextureForPrecache(FTextureID nTex, int palnum)
|
2021-04-11 07:59:55 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
2022-12-08 18:56:55 +00:00
|
|
|
auto& picanm = GetExtInfo(nTex).picanm;
|
|
|
|
if (picanm.type() == PICANM_ANIMTYPE_BACK)
|
2021-04-11 07:59:55 +00:00
|
|
|
{
|
2022-12-08 19:53:14 +00:00
|
|
|
i = nTex.GetIndex() - picanm.num;
|
|
|
|
j = nTex.GetIndex();
|
2021-04-11 07:59:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-08 19:53:14 +00:00
|
|
|
i = nTex.GetIndex();
|
|
|
|
j = nTex.GetIndex() + picanm.num * ((picanm.type() == PICANM_ANIMTYPE_OSC) ? 2 : 1);
|
2021-04-11 07:59:55 +00:00
|
|
|
}
|
|
|
|
|
2022-12-08 19:53:14 +00:00
|
|
|
for (; i <= j; i = i + 1)
|
2021-04-11 07:59:55 +00:00
|
|
|
{
|
|
|
|
int64_t val = i + (int64_t(palnum) << 32);
|
|
|
|
cachemap.Insert(val, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-08 19:53:14 +00:00
|
|
|
void markTextureForPrecache(const char* texname, int palnum)
|
|
|
|
{
|
|
|
|
auto texid = TexMan.CheckForTexture(texname, ETextureType::Any);
|
|
|
|
if (texid.isValid()) markTextureForPrecache(texid, palnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-11 07:59:55 +00:00
|
|
|
void precacheMarkedTiles()
|
|
|
|
{
|
2021-04-11 08:50:04 +00:00
|
|
|
screen->StartPrecaching();
|
2021-04-11 07:59:55 +00:00
|
|
|
decltype(cachemap)::Iterator it(cachemap);
|
|
|
|
decltype(cachemap)::Pair* pair;
|
|
|
|
while (it.NextPair(pair))
|
|
|
|
{
|
2022-12-08 19:53:14 +00:00
|
|
|
int texid = pair->Key & 0x7fffffff;
|
|
|
|
int palnum = pair->Key >> 32;
|
|
|
|
doprecache(FSetTextureID(texid), palnum);
|
2021-04-11 07:59:55 +00:00
|
|
|
}
|
2021-05-02 11:12:24 +00:00
|
|
|
|
|
|
|
// Cache everything the map explicitly declares.
|
|
|
|
TMap<FString, bool> cachetexmap;
|
|
|
|
for (auto& tex : currentLevel->PrecacheTextures) cachetexmap.Insert(tex, true);
|
|
|
|
|
|
|
|
decltype(cachetexmap)::Iterator it2(cachetexmap);
|
|
|
|
decltype(cachetexmap)::Pair* pair2;
|
|
|
|
while (it2.NextPair(pair2))
|
|
|
|
{
|
|
|
|
auto tex = TexMan.FindGameTexture(pair2->Key, ETextureType::Any);
|
|
|
|
if (tex) PrecacheTex(tex, 0);
|
|
|
|
}
|
|
|
|
|
2021-04-11 11:38:23 +00:00
|
|
|
cachemap.Clear();
|
2021-04-11 07:59:55 +00:00
|
|
|
}
|
|
|
|
|
2022-12-08 19:53:14 +00:00
|
|
|
void precacheMap()
|
|
|
|
{
|
|
|
|
for (auto& sect : sector)
|
|
|
|
{
|
2022-12-09 09:48:47 +00:00
|
|
|
markTextureForPrecache(sect.ceilingtexture, sect.ceilingpal);
|
|
|
|
markTextureForPrecache(sect.floortexture, sect.floorpal);
|
2022-12-08 19:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& wal : wall)
|
|
|
|
{
|
2022-12-10 18:03:17 +00:00
|
|
|
markTextureForPrecache(wal.walltexture, wal.pal);
|
2022-12-08 19:53:14 +00:00
|
|
|
|
|
|
|
if (wal.twoSided())
|
|
|
|
{
|
2022-12-10 18:03:17 +00:00
|
|
|
markTextureForPrecache(wal.overtexture, wal.pal);
|
2022-12-08 19:53:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|