2020-05-24 14:11:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "tarray.h"
|
|
|
|
#include "textureid.h"
|
2020-06-14 16:57:55 +00:00
|
|
|
#include "textures.h"
|
2020-05-24 14:11:10 +00:00
|
|
|
#include "basics.h"
|
|
|
|
#include "texmanip.h"
|
|
|
|
#include "name.h"
|
|
|
|
|
|
|
|
class FxAddSub;
|
|
|
|
struct BuildInfo;
|
2020-05-25 21:59:07 +00:00
|
|
|
class FMultipatchTextureBuilder;
|
2020-05-26 21:12:04 +00:00
|
|
|
class FScanner;
|
2020-05-24 14:11:10 +00:00
|
|
|
|
|
|
|
// Texture manager
|
|
|
|
class FTextureManager
|
|
|
|
{
|
|
|
|
void (*progressFunc)();
|
|
|
|
friend class FxAddSub; // needs access to do a bounds check on the texture ID.
|
|
|
|
public:
|
|
|
|
FTextureManager ();
|
|
|
|
~FTextureManager ();
|
2021-12-30 09:30:21 +00:00
|
|
|
|
2020-05-24 14:11:10 +00:00
|
|
|
private:
|
|
|
|
int ResolveLocalizedTexture(int texnum);
|
|
|
|
|
2022-12-06 19:35:53 +00:00
|
|
|
int ResolveTextureIndex(int texnum, bool animate) const
|
2020-05-24 14:11:10 +00:00
|
|
|
{
|
2020-05-25 21:59:07 +00:00
|
|
|
if ((unsigned)texnum >= Textures.Size()) return -1;
|
2020-05-24 14:11:10 +00:00
|
|
|
if (animate) texnum = Translation[texnum];
|
2022-12-06 19:35:53 +00:00
|
|
|
//if (localize && Textures[texnum].Flags & TEXFLAG_HASLOCALIZATION) texnum = ResolveLocalizedTexture(texnum);
|
2020-05-25 21:59:07 +00:00
|
|
|
return texnum;
|
|
|
|
}
|
|
|
|
|
2022-12-06 19:35:53 +00:00
|
|
|
FGameTexture *InternalGetTexture(int texnum, bool animate) const
|
2020-05-25 21:59:07 +00:00
|
|
|
{
|
2022-12-06 19:35:53 +00:00
|
|
|
texnum = ResolveTextureIndex(texnum, animate);
|
2020-05-25 21:59:07 +00:00
|
|
|
if (texnum == -1) return nullptr;
|
2020-05-24 14:11:10 +00:00
|
|
|
return Textures[texnum].Texture;
|
|
|
|
}
|
2020-05-25 21:59:07 +00:00
|
|
|
|
2022-12-06 19:35:53 +00:00
|
|
|
FTextureID ResolveTextureIndex(FTextureID texid, bool animate) const
|
2020-05-25 21:59:07 +00:00
|
|
|
{
|
2022-12-06 19:35:53 +00:00
|
|
|
return FSetTextureID(ResolveTextureIndex(texid.GetIndex(), animate));
|
2020-05-25 21:59:07 +00:00
|
|
|
}
|
|
|
|
|
2022-12-06 19:35:53 +00:00
|
|
|
public:
|
2020-05-24 14:11:10 +00:00
|
|
|
// This only gets used in UI code so we do not need PALVERS handling.
|
2020-06-28 12:41:44 +00:00
|
|
|
FGameTexture* GetGameTextureByName(const char *name, bool animate = false, int flags = 0)
|
2020-05-24 14:11:10 +00:00
|
|
|
{
|
2020-06-28 12:41:44 +00:00
|
|
|
FTextureID texnum = GetTextureID(name, ETextureType::MiscPatch, flags);
|
2022-12-06 19:35:53 +00:00
|
|
|
return InternalGetTexture(texnum.GetIndex(), animate);
|
2020-05-24 14:11:10 +00:00
|
|
|
}
|
2020-05-25 21:59:07 +00:00
|
|
|
|
2022-12-06 19:35:53 +00:00
|
|
|
FGameTexture* GetGameTexture(FTextureID texnum, bool animate = false) const
|
2020-05-24 14:11:10 +00:00
|
|
|
{
|
2022-12-06 19:35:53 +00:00
|
|
|
return InternalGetTexture(texnum.GetIndex(), animate);
|
2020-05-24 14:11:10 +00:00
|
|
|
}
|
2021-12-30 09:30:21 +00:00
|
|
|
|
2022-12-06 19:35:53 +00:00
|
|
|
FGameTexture* GetPalettedTexture(FTextureID texnum, bool animate = false, bool allowsubstitute = true) const
|
2020-05-24 14:11:10 +00:00
|
|
|
{
|
2022-12-06 19:35:53 +00:00
|
|
|
auto texid = ResolveTextureIndex(texnum.GetIndex(), animate);
|
2020-05-25 21:59:07 +00:00
|
|
|
if (texid == -1) return nullptr;
|
|
|
|
if (allowsubstitute && Textures[texid].Paletted > 0) texid = Textures[texid].Paletted;
|
|
|
|
return Textures[texid].Texture;
|
2020-05-24 14:11:10 +00:00
|
|
|
}
|
2020-05-25 21:59:07 +00:00
|
|
|
|
2022-12-06 19:35:53 +00:00
|
|
|
FGameTexture* GameByIndex(int i, bool animate = false) const
|
2020-05-24 14:11:10 +00:00
|
|
|
{
|
2022-12-06 19:35:53 +00:00
|
|
|
return InternalGetTexture(i, animate);
|
2020-05-24 14:11:10 +00:00
|
|
|
}
|
2020-05-25 21:59:07 +00:00
|
|
|
|
|
|
|
FGameTexture* FindGameTexture(const char* texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny);
|
|
|
|
|
2020-05-24 14:11:10 +00:00
|
|
|
bool OkForLocalization(FTextureID texnum, const char *substitute, int locnum);
|
|
|
|
|
|
|
|
void FlushAll();
|
2022-12-08 10:35:21 +00:00
|
|
|
void Listaliases();
|
2020-05-25 21:59:07 +00:00
|
|
|
FTextureID GetFrontSkyLayer(FTextureID);
|
2022-11-25 11:33:52 +00:00
|
|
|
FTextureID GetRawTexture(FTextureID tex, bool dontlookup = false);
|
|
|
|
void SetRawTexture(FTextureID texid)
|
|
|
|
{
|
|
|
|
int texidx = texid.GetIndex();
|
|
|
|
if ((unsigned)texidx < Textures.Size())
|
|
|
|
{
|
|
|
|
Textures[texidx].RawTexture = texidx;
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 14:11:10 +00:00
|
|
|
|
2023-08-19 14:57:37 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// link a texture with a given lump
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
TMap<int, FGameTexture*> linkedMap;
|
|
|
|
void SetLinkedTexture(int lump, FGameTexture* tex);
|
|
|
|
FGameTexture* GetLinkedTexture(int lump);
|
2020-05-24 14:11:10 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TEXMAN_TryAny = 1,
|
|
|
|
TEXMAN_Overridable = 2,
|
|
|
|
TEXMAN_ReturnFirst = 4,
|
|
|
|
TEXMAN_AllowSkins = 8,
|
|
|
|
TEXMAN_ShortNameOnly = 16,
|
|
|
|
TEXMAN_DontCreate = 32,
|
2020-06-28 12:41:44 +00:00
|
|
|
TEXMAN_Localize = 64,
|
2020-10-06 17:26:22 +00:00
|
|
|
TEXMAN_ForceLookup = 128,
|
|
|
|
TEXMAN_NoAlias = 256,
|
2022-12-07 16:10:27 +00:00
|
|
|
TEXMAN_ReturnAll = 512,
|
2020-05-24 14:11:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
HIT_Wall = 1,
|
|
|
|
HIT_Flat = 2,
|
|
|
|
HIT_Sky = 4,
|
|
|
|
HIT_Sprite = 8,
|
|
|
|
|
|
|
|
HIT_Columnmode = HIT_Wall|HIT_Sky|HIT_Sprite
|
|
|
|
};
|
|
|
|
|
|
|
|
FTextureID CheckForTexture (const char *name, ETextureType usetype, BITFIELD flags=TEXMAN_TryAny);
|
|
|
|
FTextureID GetTextureID (const char *name, ETextureType usetype, BITFIELD flags=0);
|
|
|
|
int ListTextures (const char *name, TArray<FTextureID> &list, bool listall = false);
|
|
|
|
|
|
|
|
void AddGroup(int wadnum, int ns, ETextureType usetype);
|
|
|
|
void AddPatches (int lumpnum);
|
|
|
|
void AddHiresTextures (int wadnum);
|
|
|
|
void LoadTextureDefs(int wadnum, const char *lumpname, FMultipatchTextureBuilder &build);
|
|
|
|
void ParseColorization(FScanner& sc);
|
|
|
|
void ParseTextureDef(int remapLump, FMultipatchTextureBuilder &build);
|
|
|
|
void SortTexturesByType(int start, int end);
|
|
|
|
bool AreTexturesCompatible (FTextureID picnum1, FTextureID picnum2);
|
|
|
|
void AddLocalizedVariants();
|
|
|
|
|
|
|
|
FTextureID CreateTexture (int lumpnum, ETextureType usetype=ETextureType::Any); // Also calls AddTexture
|
2020-05-25 21:59:07 +00:00
|
|
|
FTextureID AddGameTexture(FGameTexture* texture, bool addtohash = true);
|
2020-05-24 14:11:10 +00:00
|
|
|
FTextureID GetDefaultTexture() const { return DefaultTexture; }
|
|
|
|
|
|
|
|
void LoadTextureX(int wadnum, FMultipatchTextureBuilder &build);
|
|
|
|
void AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &build);
|
2022-06-06 09:45:02 +00:00
|
|
|
void Init();
|
2022-10-02 18:33:18 +00:00
|
|
|
void AddTextures(void (*progressFunc_)(), void (*checkForHacks)(BuildInfo&), void (*customtexturehandler)() = nullptr);
|
2020-05-24 14:11:10 +00:00
|
|
|
void DeleteAll();
|
|
|
|
|
2023-05-20 10:40:34 +00:00
|
|
|
void ReplaceTexture (FTextureID texid, FGameTexture *newtexture, bool free);
|
2020-05-24 14:11:10 +00:00
|
|
|
|
|
|
|
int NumTextures () const { return (int)Textures.Size(); }
|
|
|
|
|
|
|
|
int GuesstimateNumTextures ();
|
|
|
|
|
|
|
|
TextureManipulation* GetTextureManipulation(FName name)
|
|
|
|
{
|
|
|
|
return tmanips.CheckKey(name);
|
|
|
|
}
|
|
|
|
void InsertTextureManipulation(FName cname, TextureManipulation tm)
|
|
|
|
{
|
|
|
|
tmanips.Insert(cname, tm);
|
|
|
|
}
|
|
|
|
void RemoveTextureManipulation(FName cname)
|
|
|
|
{
|
|
|
|
tmanips.Remove(cname);
|
|
|
|
}
|
|
|
|
|
2022-12-07 16:10:27 +00:00
|
|
|
void AddAlias(const char* name, int texindex);
|
|
|
|
void AddAlias(const char* name, FTextureID texindex)
|
|
|
|
{
|
|
|
|
AddAlias(name, texindex.GetIndex());
|
|
|
|
}
|
2020-10-06 17:26:22 +00:00
|
|
|
|
2020-05-24 14:11:10 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
// texture counting
|
|
|
|
int CountTexturesX ();
|
|
|
|
int CountLumpTextures (int lumpnum);
|
|
|
|
void AdjustSpriteOffsets();
|
|
|
|
|
|
|
|
// Build tiles
|
|
|
|
//int CountBuildTiles ();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
TArray<uint8_t>& GetNewBuildTileData()
|
|
|
|
{
|
|
|
|
BuildTileData.Reserve(1);
|
|
|
|
return BuildTileData.Last();
|
|
|
|
}
|
2022-12-08 11:44:06 +00:00
|
|
|
TArray<TArray<uint8_t>>& GetBuildTileDataStore()
|
|
|
|
{
|
|
|
|
return BuildTileData;
|
|
|
|
}
|
2020-05-24 14:11:10 +00:00
|
|
|
|
2020-05-25 21:59:07 +00:00
|
|
|
FGameTexture* GameTexture(FTextureID id) { return Textures[id.GetIndex()].Texture; }
|
2020-05-24 14:11:10 +00:00
|
|
|
void SetTranslation(FTextureID fromtexnum, FTextureID totexnum);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void InitPalettedVersions();
|
2021-12-30 09:30:21 +00:00
|
|
|
|
2020-05-24 14:11:10 +00:00
|
|
|
// Switches
|
|
|
|
|
2022-11-25 09:03:04 +00:00
|
|
|
struct TextureDescriptor
|
2020-05-24 14:11:10 +00:00
|
|
|
{
|
2020-05-25 21:59:07 +00:00
|
|
|
FGameTexture* Texture;
|
|
|
|
int Paletted; // redirection to paletted variant
|
|
|
|
int FrontSkyLayer; // and front sky layer,
|
|
|
|
int RawTexture;
|
2020-05-24 14:11:10 +00:00
|
|
|
int HashNext;
|
2022-11-25 09:03:04 +00:00
|
|
|
uint64_t Flags;
|
|
|
|
};
|
2022-11-25 12:45:18 +00:00
|
|
|
|
2022-11-25 09:03:04 +00:00
|
|
|
enum : uint64_t
|
|
|
|
{
|
|
|
|
TEXFLAG_HASLOCALIZATION = 1,
|
2020-05-24 14:11:10 +00:00
|
|
|
};
|
2022-11-25 12:45:18 +00:00
|
|
|
public:
|
|
|
|
constexpr static int TEXFLAG_FIRSTUSER = 65536; // this leaves 16 flags to the texture manager and 48 flags to the user
|
|
|
|
private:
|
|
|
|
|
2020-05-24 14:11:10 +00:00
|
|
|
enum { HASH_END = -1, HASH_SIZE = 1027 };
|
2022-11-25 09:03:04 +00:00
|
|
|
TArray<TextureDescriptor> Textures;
|
2020-05-24 14:11:10 +00:00
|
|
|
TMap<uint64_t, int> LocalizedTextures;
|
|
|
|
int HashFirst[HASH_SIZE];
|
|
|
|
FTextureID DefaultTexture;
|
|
|
|
TArray<int> FirstTextureForFile;
|
|
|
|
TArray<TArray<uint8_t> > BuildTileData;
|
|
|
|
TArray<int> Translation;
|
|
|
|
|
|
|
|
TMap<FName, TextureManipulation> tmanips;
|
2020-10-06 17:26:22 +00:00
|
|
|
TMap<FName, int> aliases;
|
2020-05-24 14:11:10 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
short sintable[2048]; // for texture warping
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SINMASK = 2047
|
|
|
|
};
|
|
|
|
|
|
|
|
FTextureID glPart2;
|
|
|
|
FTextureID glPart;
|
|
|
|
FTextureID mirrorTexture;
|
2021-07-05 20:39:24 +00:00
|
|
|
bool usefullnames;
|
2020-05-24 14:11:10 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
extern FTextureManager TexMan;
|
2020-05-25 21:59:07 +00:00
|
|
|
|