ddnet/src/game/client/components/maplayers.h

165 lines
4.5 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef GAME_CLIENT_COMPONENTS_MAPLAYERS_H
#define GAME_CLIENT_COMPONENTS_MAPLAYERS_H
#include <game/client/component.h>
2021-07-12 09:29:59 +00:00
#include <base/color.h>
#include <cstdint>
#include <vector>
#define INDEX_BUFFER_GROUP_WIDTH 12
#define INDEX_BUFFER_GROUP_HEIGHT 9
#define INDEX_BORDER_BUFFER_GROUP_SIZE 20
typedef char *offset_ptr_size;
typedef uintptr_t offset_ptr;
typedef unsigned int offset_ptr32;
2021-07-12 09:29:59 +00:00
struct CMapItemGroup;
struct CMapItemLayerTilemap;
struct CMapItemLayerQuads;
2010-05-29 07:25:38 +00:00
class CMapLayers : public CComponent
{
2015-08-25 00:11:04 +00:00
friend class CBackground;
2020-09-18 16:45:42 +00:00
friend class CMenuBackground;
2017-02-21 16:10:08 +00:00
CLayers *m_pLayers;
class CMapImages *m_pImages;
2010-05-29 07:25:38 +00:00
int m_Type;
int m_CurrentLocalTick;
int m_LastLocalTick;
bool m_EnvelopeUpdate;
2010-05-29 07:25:38 +00:00
2020-09-18 16:45:42 +00:00
bool m_OnlineOnly;
2010-10-17 08:43:27 +00:00
void MapScreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup, float Zoom = 1.0f);
2019-04-26 22:11:15 +00:00
struct STileLayerVisuals
{
STileLayerVisuals() :
m_TilesOfLayer(NULL), m_BorderTop(NULL), m_BorderLeft(NULL), m_BorderRight(NULL), m_BorderBottom(NULL)
{
m_Width = 0;
m_Height = 0;
m_BufferContainerIndex = -1;
m_IsTextured = false;
2019-04-26 22:11:15 +00:00
}
bool Init(unsigned int Width, unsigned int Height);
2019-04-26 22:11:15 +00:00
~STileLayerVisuals();
struct STileVisual
{
STileVisual() :
m_IndexBufferByteOffset(0) {}
private:
offset_ptr32 m_IndexBufferByteOffset;
public:
2019-04-26 22:11:15 +00:00
bool DoDraw()
{
return (m_IndexBufferByteOffset & 0x00000001) != 0;
}
2019-04-26 22:11:15 +00:00
void Draw(bool SetDraw)
{
m_IndexBufferByteOffset = (SetDraw ? 0x00000001 : (offset_ptr32)0) | (m_IndexBufferByteOffset & 0xFFFFFFFE);
}
offset_ptr IndexBufferByteOffset()
{
return ((offset_ptr)(m_IndexBufferByteOffset & 0xFFFFFFFE));
}
void SetIndexBufferByteOffset(offset_ptr32 IndexBufferByteOff)
{
m_IndexBufferByteOffset = IndexBufferByteOff | (m_IndexBufferByteOffset & 0x00000001);
}
void AddIndexBufferByteOffset(offset_ptr32 IndexBufferByteOff)
{
m_IndexBufferByteOffset = ((m_IndexBufferByteOffset & 0xFFFFFFFE) + IndexBufferByteOff) | (m_IndexBufferByteOffset & 0x00000001);
}
};
STileVisual *m_TilesOfLayer;
2019-04-26 22:11:15 +00:00
STileVisual m_BorderTopLeft;
STileVisual m_BorderTopRight;
STileVisual m_BorderBottomRight;
STileVisual m_BorderBottomLeft;
2019-04-26 22:11:15 +00:00
STileVisual m_BorderKillTile; //end of map kill tile -- game layer only
2019-04-26 22:11:15 +00:00
STileVisual *m_BorderTop;
STileVisual *m_BorderLeft;
STileVisual *m_BorderRight;
STileVisual *m_BorderBottom;
2019-04-26 22:11:15 +00:00
unsigned int m_Width;
unsigned int m_Height;
int m_BufferContainerIndex;
bool m_IsTextured;
};
std::vector<STileLayerVisuals *> m_TileLayerVisuals;
struct SQuadLayerVisuals
{
SQuadLayerVisuals() :
m_QuadNum(0), m_QuadsOfLayer(NULL), m_BufferContainerIndex(-1), m_IsTextured(false) {}
struct SQuadVisual
{
SQuadVisual() :
m_IndexBufferByteOffset(0) {}
offset_ptr m_IndexBufferByteOffset;
};
int m_QuadNum;
SQuadVisual *m_QuadsOfLayer;
int m_BufferContainerIndex;
bool m_IsTextured;
};
std::vector<SQuadLayerVisuals *> m_QuadLayerVisuals;
2019-04-26 22:11:15 +00:00
2020-09-18 16:45:42 +00:00
virtual class CCamera *GetCurCamera();
void LayersOfGroupCount(CMapItemGroup *pGroup, int &TileLayerCount, int &QuadLayerCount, bool &PassedGameLayer);
2018-10-29 07:44:55 +00:00
2018-10-29 08:00:47 +00:00
void RenderTileBorderCornerTiles(int WidthOffsetToOrigin, int HeightOffsetToOrigin, int TileCountWidth, int TileCountHeight, int BufferContainerIndex, float *pColor, offset_ptr_size IndexBufferOffset, float *pOffset, float *pDir);
2010-05-29 07:25:38 +00:00
public:
enum
{
2020-09-18 16:45:42 +00:00
TYPE_BACKGROUND = 0,
TYPE_BACKGROUND_FORCE,
2010-05-29 07:25:38 +00:00
TYPE_FOREGROUND,
2020-09-18 16:45:42 +00:00
TYPE_FULL_DESIGN,
TYPE_ALL = -1,
2010-05-29 07:25:38 +00:00
};
2020-09-18 16:45:42 +00:00
CMapLayers(int Type, bool OnlineOnly = true);
2020-09-30 21:57:03 +00:00
virtual ~CMapLayers();
virtual int Sizeof() const override { return sizeof(*this); }
virtual void OnInit() override;
virtual void OnRender() override;
virtual void OnMapLoad() override;
2019-04-26 22:11:15 +00:00
void RenderTileLayer(int LayerIndex, ColorRGBA *pColor, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup);
void RenderTileBorder(int LayerIndex, ColorRGBA *pColor, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup, int BorderX0, int BorderY0, int BorderX1, int BorderY1, int ScreenWidthTileCount, int ScreenHeightTileCount);
void RenderKillTileBorder(int LayerIndex, ColorRGBA *pColor, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup);
void RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer, CMapItemGroup *pGroup, bool ForceRender = false);
void EnvelopeUpdate();
2014-10-12 14:12:13 +00:00
static void EnvelopeEval(int TimeOffsetMillis, int Env, float *pChannels, void *pUser);
2010-05-29 07:25:38 +00:00
};
#endif