/
multipatchtexture.h
114 lines (93 loc) · 3.12 KB
/
multipatchtexture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#pragma once
//==========================================================================
//
// 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;
};
//==========================================================================
//
// A texture defined in a TEXTURE1 or TEXTURE2 lump
//
//==========================================================================
class FMultiPatchTexture : public FImageSource
{
public:
FMultiPatchTexture(int w, int h, const TArray<TexPart> &parts, bool complex, bool textual);
protected:
int NumParts;
bool bComplex;
bool bTextual;
TexPart *Parts;
// The getters must optionally redirect if it's a simple one-patch texture.
int CopyPixels(FBitmap *bmp, int conversion) override;
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
void CopyToBlock(uint8_t *dest, int dwidth, int dheight, FImageSource *source, int xpos, int ypos, int rotate, const uint8_t *translation, int style);
void CollectForPrecache(PrecacheInfo &info, bool requiretruecolor);
};
//==========================================================================
//
// Additional data per patch which is needed for initialization
//
//==========================================================================
struct TexInit
{
FString TexName;
ETextureType UseType = ETextureType::Null;
FTexture *Texture = nullptr;
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;
TArray<TexPart> Parts;
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;
int LeftOffset[2] = {};
int TopOffset[2] = {};
FImageTexture *tex = nullptr;
};
class FMultipatchTextureBuilder
{
FTextureManager &TexMan;
TArray<BuildInfo> BuiltTextures;
void MakeTexture(BuildInfo &buildinfo, ETextureType usetype);
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);
void ParsePatch(FScanner &sc, BuildInfo &info, TexPart &part, TexInit &init);
void CheckForHacks(BuildInfo &buildinfo);
void ResolvePatches(BuildInfo &buildinfo);
public:
FMultipatchTextureBuilder(FTextureManager &texMan) : TexMan(texMan)
{
}
void AddTexturesLumps(int lump1, int lump2, int patcheslump);
void ParseTexture(FScanner &sc, ETextureType usetype);
void ResolveAllPatches();
};