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 ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int ResolveLocalizedTexture(int texnum);
|
|
|
|
|
2020-05-25 21:59:07 +00:00
|
|
|
int ResolveTextureIndex(int texnum, bool animate, bool localize)
|
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];
|
|
|
|
if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(texnum);
|
2020-05-25 21:59:07 +00:00
|
|
|
return texnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
FGameTexture *InternalGetTexture(int texnum, bool animate, bool localize)
|
|
|
|
{
|
|
|
|
texnum = ResolveTextureIndex(texnum, animate, localize);
|
|
|
|
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
|
|
|
|
2020-05-24 14:11:10 +00:00
|
|
|
public:
|
2020-05-25 21:59:07 +00:00
|
|
|
FTextureID ResolveTextureIndex(FTextureID texid, bool animate, bool localize)
|
|
|
|
{
|
|
|
|
return FSetTextureID(ResolveTextureIndex(texid.GetIndex(), animate, localize));
|
|
|
|
}
|
|
|
|
|
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);
|
2020-05-25 21:59:07 +00:00
|
|
|
return InternalGetTexture(texnum.GetIndex(), animate, true);
|
2020-05-24 14:11:10 +00:00
|
|
|
}
|
2020-05-25 21:59:07 +00:00
|
|
|
|
|
|
|
FGameTexture* GetGameTexture(FTextureID texnum, bool animate = false)
|
2020-05-24 14:11:10 +00:00
|
|
|
{
|
2020-05-25 21:59:07 +00:00
|
|
|
return InternalGetTexture(texnum.GetIndex(), animate, true);
|
2020-05-24 14:11:10 +00:00
|
|
|
}
|
|
|
|
|
2020-05-25 21:59:07 +00:00
|
|
|
FGameTexture* GetPalettedTexture(FTextureID texnum, bool animate = false, bool allowsubstitute = true)
|
2020-05-24 14:11:10 +00:00
|
|
|
{
|
2020-05-25 21:59:07 +00:00
|
|
|
auto texid = ResolveTextureIndex(texnum.GetIndex(), animate, true);
|
|
|
|
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
|
|
|
|
|
|
|
FGameTexture* GameByIndex(int i, bool animate = false)
|
2020-05-24 14:11:10 +00:00
|
|
|
{
|
2020-05-25 21:59:07 +00:00
|
|
|
return InternalGetTexture(i, animate, true);
|
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();
|
2020-05-25 21:59:07 +00:00
|
|
|
FTextureID GetFrontSkyLayer(FTextureID);
|
|
|
|
FTextureID GetRawTexture(FTextureID);
|
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,
|
|
|
|
TEXMAN_ForceLookup = 128
|
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);
|
|
|
|
void Init(void (*progressFunc_)(), void (*checkForHacks)(BuildInfo &));
|
|
|
|
void DeleteAll();
|
|
|
|
|
2020-05-25 21:59:07 +00:00
|
|
|
void ReplaceTexture (FTextureID picnum, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Switches
|
|
|
|
|
|
|
|
struct TextureHash
|
|
|
|
{
|
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;
|
|
|
|
bool HasLocalization;
|
|
|
|
};
|
|
|
|
enum { HASH_END = -1, HASH_SIZE = 1027 };
|
|
|
|
TArray<TextureHash> Textures;
|
|
|
|
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;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
short sintable[2048]; // for texture warping
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SINMASK = 2047
|
|
|
|
};
|
|
|
|
|
|
|
|
FTextureID glPart2;
|
|
|
|
FTextureID glPart;
|
|
|
|
FTextureID mirrorTexture;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
extern FTextureManager TexMan;
|
2020-05-25 21:59:07 +00:00
|
|
|
|