2020-05-23 22:15:38 +00:00
|
|
|
#pragma once
|
|
|
|
#include "sc_man.h"
|
|
|
|
#include "palettecontainer.h"
|
|
|
|
#include "textureid.h"
|
|
|
|
#include "vectors.h"
|
|
|
|
#include "bitmap.h"
|
|
|
|
#include "image.h"
|
2020-05-25 21:59:07 +00:00
|
|
|
#include "textures.h"
|
2020-05-23 22:15:38 +00:00
|
|
|
|
|
|
|
class FImageTexture;
|
2020-05-25 21:59:07 +00:00
|
|
|
class FTextureManager;
|
|
|
|
|
2020-05-23 22:15:38 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// TexPart is the data that will get passed to the final texture.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
struct TexPart
|
|
|
|
{
|
|
|
|
FRemapTable *Translation = nullptr;
|
|
|
|
FImageSource *Image = nullptr;
|
|
|
|
PalEntry Blend = 0;
|
|
|
|
blend_t Alpha = FRACUNIT;
|
|
|
|
int16_t OriginX = 0;
|
|
|
|
int16_t OriginY = 0;
|
|
|
|
uint8_t Rotate = 0;
|
|
|
|
uint8_t op = OP_COPY;
|
|
|
|
};
|
|
|
|
|
2020-05-25 21:59:07 +00:00
|
|
|
struct TexPartBuild
|
|
|
|
{
|
|
|
|
FRemapTable* Translation = nullptr;
|
|
|
|
FImageTexture *TexImage = nullptr;
|
|
|
|
PalEntry Blend = 0;
|
|
|
|
blend_t Alpha = FRACUNIT;
|
|
|
|
int16_t OriginX = 0;
|
|
|
|
int16_t OriginY = 0;
|
|
|
|
uint8_t Rotate = 0;
|
|
|
|
uint8_t op = OP_COPY;
|
|
|
|
};
|
|
|
|
|
2020-05-23 22:15:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// A texture defined in a TEXTURE1 or TEXTURE2 lump
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
class FMultiPatchTexture : public FImageSource
|
|
|
|
{
|
|
|
|
friend class FTexture;
|
2020-05-25 21:59:07 +00:00
|
|
|
friend class FGameTexture;
|
2020-05-23 22:15:38 +00:00
|
|
|
public:
|
2020-05-25 21:59:07 +00:00
|
|
|
FMultiPatchTexture(int w, int h, const TArray<TexPartBuild> &parts, bool complex, bool textual);
|
|
|
|
int GetNumParts() const { return NumParts; }
|
|
|
|
// Query some needed info for texture hack support.
|
|
|
|
bool SupportRemap0() override;
|
|
|
|
bool IsRawCompatible() override
|
|
|
|
{
|
|
|
|
return NumParts != 1 || Parts[0].OriginY == 0 || bTextual;
|
|
|
|
}
|
|
|
|
FImageSource* GetImageForPart(int num)
|
|
|
|
{
|
|
|
|
if (num >= 0 && num < NumParts) return Parts[num].Image;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-05-23 22:15:38 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int NumParts;
|
|
|
|
bool bComplex;
|
|
|
|
bool bTextual;
|
|
|
|
TexPart *Parts;
|
|
|
|
|
|
|
|
// The getters must optionally redirect if it's a simple one-patch texture.
|
2023-08-23 18:36:19 +00:00
|
|
|
int CopyPixels(FBitmap *bmp, int conversion, int frame = 0) override;
|
|
|
|
PalettedPixels CreatePalettedPixels(int conversion, int frame = 0) override;
|
2020-05-23 22:15:38 +00:00
|
|
|
void CopyToBlock(uint8_t *dest, int dwidth, int dheight, FImageSource *source, int xpos, int ypos, int rotate, const uint8_t *translation, int style);
|
2020-07-23 14:35:54 +00:00
|
|
|
void CollectForPrecache(PrecacheInfo &info, bool requiretruecolor) override;
|
2020-05-23 22:15:38 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Additional data per patch which is needed for initialization
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
struct TexInit
|
|
|
|
{
|
|
|
|
FString TexName;
|
2020-05-24 14:32:52 +00:00
|
|
|
ETextureType UseType = ETextureType::Null;
|
2020-05-26 21:12:04 +00:00
|
|
|
FGameTexture *GameTexture = nullptr;
|
2020-05-23 22:15:38 +00:00
|
|
|
bool Silent = false;
|
|
|
|
bool HasLine = false;
|
|
|
|
bool UseOffsets = false;
|
|
|
|
FScriptPosition sc;
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// All build info only needed to construct the multipatch textures
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
struct FPatchLookup;
|
|
|
|
|
|
|
|
struct BuildInfo
|
|
|
|
{
|
|
|
|
FString Name;
|
2020-05-25 21:59:07 +00:00
|
|
|
TArray<TexPartBuild> Parts;
|
2020-05-23 22:15:38 +00:00
|
|
|
TArray<TexInit> Inits;
|
|
|
|
int Width = 0;
|
|
|
|
int Height = 0;
|
|
|
|
DVector2 Scale = { 1, 1 };
|
|
|
|
bool bWorldPanning = false; // This sucks!
|
|
|
|
int DefinitionLump = 0;
|
|
|
|
bool bComplex = false;
|
|
|
|
bool textual = false;
|
|
|
|
bool bNoDecals = false;
|
2021-12-29 09:29:22 +00:00
|
|
|
bool bNoTrim = false;
|
2020-05-23 22:15:38 +00:00
|
|
|
int LeftOffset[2] = {};
|
|
|
|
int TopOffset[2] = {};
|
2020-05-25 21:59:07 +00:00
|
|
|
FGameTexture *texture = nullptr;
|
2020-05-23 22:15:38 +00:00
|
|
|
|
|
|
|
void swap(BuildInfo &other)
|
|
|
|
{
|
|
|
|
Name.Swap(other.Name);
|
|
|
|
Parts.Swap(other.Parts);
|
|
|
|
Inits.Swap(other.Inits);
|
|
|
|
std::swap(Width, other.Width);
|
|
|
|
std::swap(Height, other.Height);
|
|
|
|
std::swap(Scale, other.Scale);
|
|
|
|
std::swap(bWorldPanning, other.bWorldPanning);
|
|
|
|
std::swap(DefinitionLump, other.DefinitionLump);
|
|
|
|
std::swap(bComplex, other.bComplex);
|
|
|
|
std::swap(textual, other.textual);
|
|
|
|
std::swap(bNoDecals, other.bNoDecals);
|
|
|
|
std::swap(LeftOffset[0], other.LeftOffset[0]);
|
|
|
|
std::swap(LeftOffset[1], other.LeftOffset[1]);
|
|
|
|
std::swap(TopOffset[0], other.TopOffset[0]);
|
|
|
|
std::swap(TopOffset[1], other.TopOffset[1]);
|
2020-05-25 21:59:07 +00:00
|
|
|
std::swap(texture, other.texture);
|
2020-05-23 22:15:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-05-24 19:19:33 +00:00
|
|
|
|
|
|
|
class FMultipatchTextureBuilder
|
|
|
|
{
|
|
|
|
FTextureManager &TexMan;
|
|
|
|
TArray<BuildInfo> BuiltTextures;
|
2020-05-25 21:59:07 +00:00
|
|
|
TMap<FGameTexture*, bool> complex;
|
2020-05-24 19:19:33 +00:00
|
|
|
void(*progressFunc)();
|
|
|
|
void(*checkForHacks)(BuildInfo&);
|
|
|
|
|
|
|
|
void MakeTexture(BuildInfo &buildinfo, ETextureType usetype);
|
2020-05-25 21:59:07 +00:00
|
|
|
void AddImageToTexture(FImageTexture* tex, BuildInfo& buildinfo);
|
2020-05-24 19:19:33 +00:00
|
|
|
|
|
|
|
void BuildTexture(const void *texdef, FPatchLookup *patchlookup, int maxpatchnum, bool strife, int deflumpnum, ETextureType usetyoe);
|
|
|
|
void AddTexturesLump(const void *lumpdata, int lumpsize, int deflumpnum, int patcheslump, int firstdup, bool texture1);
|
|
|
|
|
2020-05-25 21:59:07 +00:00
|
|
|
void ParsePatch(FScanner &sc, BuildInfo &info, TexPartBuild &part, TexInit &init);
|
2020-05-24 19:19:33 +00:00
|
|
|
void ResolvePatches(BuildInfo &buildinfo);
|
|
|
|
|
|
|
|
public:
|
|
|
|
FMultipatchTextureBuilder(FTextureManager &texMan, void(*progressFunc_)(), void(*checkForHacks_)(BuildInfo &)) : TexMan(texMan), progressFunc(progressFunc_), checkForHacks(checkForHacks_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddTexturesLumps(int lump1, int lump2, int patcheslump);
|
2020-06-11 07:15:44 +00:00
|
|
|
void ParseTexture(FScanner &sc, ETextureType usetype, int deflump);
|
2020-05-24 19:19:33 +00:00
|
|
|
void ResolveAllPatches();
|
|
|
|
};
|