1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design)
5 * Copyright (c) 2017-2021, The LegacyClonk Team and contributors
6 *
7 * Distributed under the terms of the ISC license; see accompanying file
8 * "COPYING" for details.
9 *
10 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11 * See accompanying file "TRADEMARK" for details.
12 *
13 * To redistribute this file separately, substitute the full license texts
14 * for the above references.
15 */
16
17/* Textures used by the landscape */
18
19#pragma once
20
21#include "C4Constants.h"
22#include "C4ForwardDeclarations.h"
23#include <C4Surface.h>
24#include "StdDDraw2.h"
25
26class C4Texture
27{
28 friend class C4TextureMap;
29
30public:
31 C4Texture();
32 ~C4Texture();
33 C4Surface *Surface32;
34 CSurface8 *Surface8;
35
36protected:
37 char Name[C4M_MaxName + 1];
38 C4Texture *Next;
39};
40
41class C4TexMapEntry
42{
43 friend class C4TextureMap;
44
45public:
46 C4TexMapEntry();
47
48private:
49 StdStrBuf Material, Texture;
50 int32_t iMaterialIndex;
51 C4Material *pMaterial;
52 CPattern MatPattern;
53
54public:
55 bool isNull() const { return Material.isNull(); }
56 const char *GetMaterialName() const { return Material.getData(); }
57 const char *GetTextureName() const { return Texture.getData(); }
58 int32_t GetMaterialIndex() const { return iMaterialIndex; }
59 C4Material *GetMaterial() const { return pMaterial; }
60 const CPattern &getPattern() const { return MatPattern; }
61 void Clear();
62 bool Create(const char *szMaterial, const char *szTexture);
63 bool Init();
64};
65
66class C4TextureMap
67{
68public:
69 C4TextureMap();
70 ~C4TextureMap();
71
72protected:
73 C4TexMapEntry Entry[C4M_MaxTexIndex];
74 C4Texture *FirstTexture;
75 bool fOverloadMaterials;
76 bool fOverloadTextures;
77 bool fInitialized; // Set after Init() - newly added entries initialized automatically
78
79public:
80 bool fEntriesAdded;
81
82public:
83 const C4TexMapEntry *GetEntry(int32_t iIndex) const { return Inside<int32_t>(ival: iIndex, lbound: 0, rbound: C4M_MaxTexIndex - 1) ? &Entry[iIndex] : nullptr; }
84 void RemoveEntry(int32_t iIndex) { if (Inside<int32_t>(ival: iIndex, lbound: 1, rbound: C4M_MaxTexIndex - 1)) Entry[iIndex].Clear(); }
85 void Default();
86 void Clear();
87 void StoreMapPalette(uint8_t *bypPalette, C4MaterialMap &rMaterials);
88 static bool LoadFlags(C4Group &hGroup, const char *szEntryName, bool *pOverloadMaterials, bool *pOverloadTextures);
89 int32_t LoadMap(C4Group &hGroup, const char *szEntryName, bool *pOverloadMaterials, bool *pOverloadTextures);
90 int32_t Init();
91 bool SaveMap(C4Group &hGroup, const char *szEntryName);
92 int32_t LoadTextures(C4Group &hGroup, C4Group *OverloadFile = nullptr);
93 const char *GetTexture(size_t iIndex);
94 void MoveIndex(uint8_t byOldIndex, uint8_t byNewIndex); // change index of texture
95 int32_t GetIndex(const char *szMaterial, const char *szTexture, bool fAddIfNotExist = true, const char *szErrorIfFailed = nullptr);
96 int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture = nullptr, bool fAddIfNotExist = true, const char *szErrorIfFailed = nullptr);
97 C4Texture *GetTexture(const char *szTexture);
98 bool CheckTexture(const char *szTexture); // return whether texture exists
99 bool AddEntry(uint8_t byIndex, const char *szMaterial, const char *szTexture);
100
101protected:
102 bool AddTexture(const char *szTexture, C4Surface *sfcSurface);
103 bool AddTexture(const char *szTexture, CSurface8 *sfcSurface);
104};
105