2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Copyright (c) 1998-2000, Matthes Bender
|
|
|
|
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
|
2016-04-03 18:18:29 +00:00
|
|
|
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* Distributed under the terms of the ISC license; see accompanying file
|
|
|
|
* "COPYING" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
|
|
|
|
* See accompanying file "TRADEMARK" for details.
|
2009-05-08 13:28:41 +00:00
|
|
|
*
|
2013-12-17 20:01:09 +00:00
|
|
|
* To redistribute this file separately, substitute the full license texts
|
|
|
|
* for the above references.
|
2009-05-08 13:28:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Textures used by the landscape */
|
|
|
|
|
|
|
|
#ifndef INC_C4Texture
|
|
|
|
#define INC_C4Texture
|
|
|
|
|
2016-04-03 18:07:56 +00:00
|
|
|
#include "config/C4Constants.h"
|
|
|
|
#include "landscape/C4Material.h"
|
2017-04-30 08:49:09 +00:00
|
|
|
#include "landscape/C4TextureShape.h"
|
|
|
|
#include "graphics/C4Draw.h"
|
|
|
|
#include "graphics/C4Surface.h"
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
class C4Texture
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
friend class C4TextureMap;
|
2010-03-28 17:58:21 +00:00
|
|
|
public:
|
|
|
|
C4Texture();
|
|
|
|
~C4Texture();
|
2011-10-03 14:06:41 +00:00
|
|
|
C4Surface * Surface32;
|
2010-04-10 12:24:38 +00:00
|
|
|
|
2013-01-07 23:24:41 +00:00
|
|
|
void SetAverageColor(uint32_t Color) { AvgColor = Color; }
|
2010-04-10 12:24:38 +00:00
|
|
|
uint32_t GetAverageColor() const { return AvgColor; }
|
2015-10-09 04:11:53 +00:00
|
|
|
void SetMaterialShape(class C4TextureShape *s) { material_shape.reset(s); }
|
|
|
|
class C4TextureShape *GetMaterialShape() const { return material_shape.get(); }
|
2010-03-28 17:58:21 +00:00
|
|
|
protected:
|
2012-09-05 20:51:25 +00:00
|
|
|
StdStrBuf Name;
|
2010-04-10 12:24:38 +00:00
|
|
|
uint32_t AvgColor;
|
2015-10-09 04:11:53 +00:00
|
|
|
std::unique_ptr<class C4TextureShape> material_shape;
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Texture *Next;
|
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
class C4TexMapEntry
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
2010-03-27 16:05:02 +00:00
|
|
|
friend class C4TextureMap;
|
2010-03-28 17:58:21 +00:00
|
|
|
public:
|
|
|
|
C4TexMapEntry();
|
|
|
|
private:
|
|
|
|
StdCopyStrBuf Material, Texture;
|
|
|
|
int32_t iMaterialIndex;
|
|
|
|
C4Material *pMaterial;
|
2011-09-30 20:15:51 +00:00
|
|
|
C4Pattern MatPattern;
|
2010-03-28 17:58:21 +00:00
|
|
|
public:
|
|
|
|
bool isNull() const { return Material.isNull(); }
|
|
|
|
const char *GetMaterialName() const { return Material.getData(); }
|
|
|
|
const char *GetTextureName() const { return Texture.getData(); }
|
|
|
|
int32_t GetMaterialIndex() const { return iMaterialIndex; }
|
|
|
|
C4Material *GetMaterial() const { return pMaterial; }
|
2011-09-30 20:15:51 +00:00
|
|
|
const C4Pattern &GetPattern() const { return MatPattern; }
|
2010-03-28 17:58:21 +00:00
|
|
|
void Clear();
|
|
|
|
bool Create(const char *szMaterial, const char *szTexture);
|
|
|
|
bool Init();
|
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
class C4TextureMap
|
2010-03-28 17:58:21 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
C4TextureMap();
|
|
|
|
~C4TextureMap();
|
|
|
|
protected:
|
|
|
|
C4TexMapEntry Entry[C4M_MaxTexIndex];
|
2015-08-10 04:34:43 +00:00
|
|
|
std::vector<int32_t> Order; // drawing order in map2landscape. Reflects order in MatMap.txt file.
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Texture *FirstTexture;
|
|
|
|
bool fOverloadMaterials;
|
|
|
|
bool fOverloadTextures;
|
|
|
|
bool fInitialized; // Set after Init() - newly added entries initialized automatically
|
|
|
|
public:
|
|
|
|
bool fEntriesAdded;
|
|
|
|
public:
|
2016-11-02 23:58:02 +00:00
|
|
|
const C4TexMapEntry *GetEntry(int32_t iIndex) const { return Inside<int32_t>(iIndex, 0, C4M_MaxTexIndex-1) ? &Entry[iIndex] : nullptr; }
|
2015-08-10 04:34:43 +00:00
|
|
|
void RemoveEntry(int32_t iIndex);
|
2010-03-28 17:58:21 +00:00
|
|
|
void Clear();
|
2012-08-15 22:45:27 +00:00
|
|
|
void StoreMapPalette(CStdPalette *, C4MaterialMap &rMaterials);
|
2010-03-28 17:58:21 +00:00
|
|
|
static bool LoadFlags(C4Group &hGroup, const char *szEntryName, bool *pOverloadMaterials, bool *pOverloadTextures);
|
|
|
|
int32_t LoadMap(C4Group &hGroup, const char *szEntryName, bool *pOverloadMaterials, bool *pOverloadTextures);
|
|
|
|
int32_t Init();
|
|
|
|
bool SaveMap(C4Group &hGroup, const char *szEntryName);
|
|
|
|
int32_t LoadTextures(C4Group &hGroup, C4Group* OverloadFile=0);
|
|
|
|
bool HasTextures(C4Group &hGroup);
|
|
|
|
const char *GetTexture(int32_t iIndex);
|
|
|
|
void MoveIndex(BYTE byOldIndex, BYTE byNewIndex); // change index of texture
|
2016-11-02 23:58:02 +00:00
|
|
|
int32_t GetIndex(const char *szMaterial, const char *szTexture, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr);
|
|
|
|
int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture = nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr);
|
2010-03-28 17:58:21 +00:00
|
|
|
C4Texture * GetTexture(const char *szTexture);
|
|
|
|
bool CheckTexture(const char *szTexture); // return whether texture exists
|
|
|
|
bool AddEntry(BYTE byIndex, const char *szMaterial, const char *szTexture);
|
2012-02-12 18:41:48 +00:00
|
|
|
bool AddTexture(const char *szTexture, C4Surface * sfcSurface);
|
2011-05-23 23:12:19 +00:00
|
|
|
int32_t GetTextureIndex(const char *pTexName);
|
2015-07-08 01:17:40 +00:00
|
|
|
BYTE DefaultBkgMatTex(BYTE fg) const;
|
2010-03-28 17:58:21 +00:00
|
|
|
protected:
|
2015-08-10 04:34:43 +00:00
|
|
|
friend class C4Landscape;
|
2010-03-28 17:58:21 +00:00
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
2009-06-05 15:09:54 +00:00
|
|
|
extern C4TextureMap TextureMap;
|
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
#endif
|