OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Texture.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Textures used by the landscape */
19 
20 #ifndef INC_C4Texture
21 #define INC_C4Texture
22 
24 #include "graphics/C4Surface.h"
25 #include "graphics/C4Draw.h"
26 #include "config/C4Constants.h"
27 #include "landscape/C4Material.h"
28 
29 class C4Texture
30 {
31  friend class C4TextureMap;
32 public:
33  C4Texture();
34  ~C4Texture();
36 
37  void SetAverageColor(uint32_t Color) { AvgColor = Color; }
38  uint32_t GetAverageColor() const { return AvgColor; }
39  void SetMaterialShape(class C4TextureShape *s) { material_shape.reset(s); }
40  class C4TextureShape *GetMaterialShape() const { return material_shape.get(); }
41 protected:
43  uint32_t AvgColor;
44  std::unique_ptr<class C4TextureShape> material_shape;
46 };
47 
49 {
50  friend class C4TextureMap;
51 public:
52  C4TexMapEntry();
53 private:
54  StdCopyStrBuf Material, Texture;
55  int32_t iMaterialIndex;
56  C4Material *pMaterial;
57  C4Pattern MatPattern;
58 public:
59  bool isNull() const { return Material.isNull(); }
60  const char *GetMaterialName() const { return Material.getData(); }
61  const char *GetTextureName() const { return Texture.getData(); }
62  int32_t GetMaterialIndex() const { return iMaterialIndex; }
63  C4Material *GetMaterial() const { return pMaterial; }
64  const C4Pattern &GetPattern() const { return MatPattern; }
65  void Clear();
66  bool Create(const char *szMaterial, const char *szTexture);
67  bool Init();
68 };
69 
71 {
72 public:
73  C4TextureMap();
74  ~C4TextureMap();
75 protected:
77  std::vector<int32_t> Order; // drawing order in map2landscape. Reflects order in MatMap.txt file.
81  bool fInitialized; // Set after Init() - newly added entries initialized automatically
82 public:
84 public:
85  const C4TexMapEntry *GetEntry(int32_t iIndex) const { return Inside<int32_t>(iIndex, 0, C4M_MaxTexIndex-1) ? &Entry[iIndex] : nullptr; }
86  void RemoveEntry(int32_t iIndex);
87  void Clear();
88  void StoreMapPalette(CStdPalette *, C4MaterialMap &rMaterials);
89  static bool LoadFlags(C4Group &hGroup, const char *szEntryName, bool *pOverloadMaterials, bool *pOverloadTextures);
90  int32_t LoadMap(C4Group &hGroup, const char *szEntryName, bool *pOverloadMaterials, bool *pOverloadTextures);
91  int32_t Init();
92  bool SaveMap(C4Group &hGroup, const char *szEntryName);
93  int32_t LoadTextures(C4Group &hGroup, C4Group* OverloadFile=0);
94  bool HasTextures(C4Group &hGroup);
95  const char *GetTexture(int32_t iIndex);
96  void MoveIndex(BYTE byOldIndex, BYTE byNewIndex); // change index of texture
97  int32_t GetIndex(const char *szMaterial, const char *szTexture, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr);
98  int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture = nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr);
99  C4Texture * GetTexture(const char *szTexture);
100  bool CheckTexture(const char *szTexture); // return whether texture exists
101  bool AddEntry(BYTE byIndex, const char *szMaterial, const char *szTexture);
102  bool AddTexture(const char *szTexture, C4Surface * sfcSurface);
103  int32_t GetTextureIndex(const char *pTexName);
104  BYTE DefaultBkgMatTex(BYTE fg) const;
105 protected:
106  friend class C4Landscape;
107 };
108 
109 extern C4TextureMap TextureMap;
110 
111 #endif
const char * getData() const
Definition: StdBuf.h:450
C4TextureMap TextureMap
Definition: C4Texture.cpp:585
uint32_t AvgColor
Definition: C4Texture.h:43
int32_t GetMaterialIndex() const
Definition: C4Texture.h:62
C4Material * GetMaterial() const
Definition: C4Texture.h:63
BYTE DefaultBkgMatTex(BYTE fg) const
Definition: C4Texture.cpp:513
bool AddEntry(BYTE byIndex, const char *szMaterial, const char *szTexture)
Definition: C4Texture.cpp:111
void Clear()
Definition: C4Texture.cpp:176
int32_t GetTextureIndex(const char *pTexName)
Definition: C4Texture.cpp:484
bool Create(const char *szMaterial, const char *szTexture)
Definition: C4Texture.cpp:62
C4Surface * Surface32
Definition: C4Texture.h:35
uint32_t GetAverageColor() const
Definition: C4Texture.h:38
uint8_t BYTE
static bool LoadFlags(C4Group &hGroup, const char *szEntryName, bool *pOverloadMaterials, bool *pOverloadTextures)
Definition: C4Texture.cpp:195
int32_t LoadMap(C4Group &hGroup, const char *szEntryName, bool *pOverloadMaterials, bool *pOverloadTextures)
Definition: C4Texture.cpp:219
class C4TextureShape * GetMaterialShape() const
Definition: C4Texture.h:40
const C4TexMapEntry * GetEntry(int32_t iIndex) const
Definition: C4Texture.h:85
Definition: C4Texture.h:48
bool SaveMap(C4Group &hGroup, const char *szEntryName)
Definition: C4Texture.cpp:317
int32_t GetIndex(const char *szMaterial, const char *szTexture, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:423
void SetMaterialShape(class C4TextureShape *s)
Definition: C4Texture.h:39
void SetAverageColor(uint32_t Color)
Definition: C4Texture.h:37
const C4Pattern & GetPattern() const
Definition: C4Texture.h:64
void RemoveEntry(int32_t iIndex)
Definition: C4Texture.cpp:534
bool CheckTexture(const char *szTexture)
Definition: C4Texture.cpp:494
const char * GetMaterialName() const
Definition: C4Texture.h:60
const char * GetTextureName() const
Definition: C4Texture.h:61
bool AddTexture(const char *szTexture, C4Surface *sfcSurface)
Definition: C4Texture.cpp:134
const int C4M_MaxTexIndex
Definition: C4Constants.h:51
C4TexMapEntry Entry[C4M_MaxTexIndex]
Definition: C4Texture.h:76
void MoveIndex(BYTE byOldIndex, BYTE byNewIndex)
Definition: C4Texture.cpp:412
bool fOverloadMaterials
Definition: C4Texture.h:79
std::vector< int32_t > Order
Definition: C4Texture.h:77
bool isNull() const
Definition: C4Texture.h:59
std::unique_ptr< class C4TextureShape > material_shape
Definition: C4Texture.h:44
void StoreMapPalette(CStdPalette *, C4MaterialMap &rMaterials)
Definition: C4Texture.cpp:546
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:503
int32_t LoadTextures(C4Group &hGroup, C4Group *OverloadFile=0)
Definition: C4Texture.cpp:349
StdStrBuf Name
Definition: C4Texture.h:42
int32_t Init()
Definition: C4Texture.cpp:300
C4Texture * Next
Definition: C4Texture.h:45
bool fInitialized
Definition: C4Texture.h:81
bool isNull() const
Definition: StdBuf.h:449
bool fOverloadTextures
Definition: C4Texture.h:80
bool Init()
Definition: C4Texture.cpp:71
C4Texture * FirstTexture
Definition: C4Texture.h:78
int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture=nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:450
bool fEntriesAdded
Definition: C4Texture.h:83
#define s
bool HasTextures(C4Group &hGroup)
Definition: C4Texture.cpp:407
void Clear()
Definition: C4Texture.cpp:54
C4TexMapEntry()
Definition: C4Texture.cpp:49