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>
|
|
|
|
|
2020-02-13 14:27:39 +00:00
|
|
|
#include <cstdint>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <vector>
|
2017-09-12 18:22:18 +00:00
|
|
|
|
|
|
|
#define INDEX_BUFFER_GROUP_WIDTH 12
|
|
|
|
#define INDEX_BUFFER_GROUP_HEIGHT 9
|
|
|
|
#define INDEX_BORDER_BUFFER_GROUP_SIZE 20
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
typedef char *offset_ptr_size;
|
2018-01-16 09:18:14 +00:00
|
|
|
typedef uintptr_t offset_ptr;
|
|
|
|
typedef unsigned int offset_ptr32;
|
2018-01-16 08:35:28 +00:00
|
|
|
|
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
|
2011-04-13 18:37:12 +00:00
|
|
|
{
|
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
|
|
|
|
2017-09-12 18:22:18 +00:00
|
|
|
CLayers *m_pLayers;
|
|
|
|
class CMapImages *m_pImages;
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_Type;
|
2011-12-04 13:04:12 +00:00
|
|
|
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
|
|
|
|
2017-09-27 10:20:23 +00:00
|
|
|
struct STileLayerVisuals
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
STileLayerVisuals() :
|
2022-03-24 18:30:26 +00:00
|
|
|
m_pTilesOfLayer(NULL), m_pBorderTop(NULL), m_pBorderLeft(NULL), m_pBorderRight(NULL), m_pBorderBottom(NULL)
|
2017-09-27 10:20:23 +00:00
|
|
|
{
|
|
|
|
m_Width = 0;
|
|
|
|
m_Height = 0;
|
2018-03-13 20:57:46 +00:00
|
|
|
m_BufferContainerIndex = -1;
|
2017-09-27 10:20:23 +00:00
|
|
|
m_IsTextured = false;
|
2019-04-26 22:11:15 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 10:20:23 +00:00
|
|
|
bool Init(unsigned int Width, unsigned int Height);
|
2019-04-26 22:11:15 +00:00
|
|
|
|
|
|
|
~STileLayerVisuals();
|
|
|
|
|
2017-09-27 10:20:23 +00:00
|
|
|
struct STileVisual
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
STileVisual() :
|
|
|
|
m_IndexBufferByteOffset(0) {}
|
|
|
|
|
2018-01-16 08:35:28 +00:00
|
|
|
private:
|
2018-01-16 09:18:14 +00:00
|
|
|
offset_ptr32 m_IndexBufferByteOffset;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2018-01-16 08:35:28 +00:00
|
|
|
public:
|
2019-04-26 22:11:15 +00:00
|
|
|
bool DoDraw()
|
2018-01-16 08:35:28 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
return (m_IndexBufferByteOffset & 0x00000001) != 0;
|
2018-01-16 08:35:28 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 22:11:15 +00:00
|
|
|
void Draw(bool SetDraw)
|
2018-01-16 08:35:28 +00:00
|
|
|
{
|
2018-03-13 20:57:46 +00:00
|
|
|
m_IndexBufferByteOffset = (SetDraw ? 0x00000001 : (offset_ptr32)0) | (m_IndexBufferByteOffset & 0xFFFFFFFE);
|
2018-01-16 08:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
offset_ptr IndexBufferByteOffset()
|
|
|
|
{
|
2018-03-13 20:57:46 +00:00
|
|
|
return ((offset_ptr)(m_IndexBufferByteOffset & 0xFFFFFFFE));
|
2018-01-16 08:35:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 09:18:14 +00:00
|
|
|
void SetIndexBufferByteOffset(offset_ptr32 IndexBufferByteOff)
|
2018-01-16 08:35:28 +00:00
|
|
|
{
|
2018-03-13 20:57:46 +00:00
|
|
|
m_IndexBufferByteOffset = IndexBufferByteOff | (m_IndexBufferByteOffset & 0x00000001);
|
2018-01-16 08:35:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 09:18:14 +00:00
|
|
|
void AddIndexBufferByteOffset(offset_ptr32 IndexBufferByteOff)
|
2018-01-16 08:35:28 +00:00
|
|
|
{
|
2019-04-11 10:21:42 +00:00
|
|
|
m_IndexBufferByteOffset = ((m_IndexBufferByteOffset & 0xFFFFFFFE) + IndexBufferByteOff) | (m_IndexBufferByteOffset & 0x00000001);
|
2018-01-16 08:35:28 +00:00
|
|
|
}
|
2017-09-12 18:22:18 +00:00
|
|
|
};
|
2022-03-24 18:30:26 +00:00
|
|
|
STileVisual *m_pTilesOfLayer;
|
2019-04-26 22:11:15 +00:00
|
|
|
|
2017-09-27 10:20:23 +00:00
|
|
|
STileVisual m_BorderTopLeft;
|
|
|
|
STileVisual m_BorderTopRight;
|
|
|
|
STileVisual m_BorderBottomRight;
|
|
|
|
STileVisual m_BorderBottomLeft;
|
2019-04-26 22:11:15 +00:00
|
|
|
|
2017-09-27 10:20:23 +00:00
|
|
|
STileVisual m_BorderKillTile; //end of map kill tile -- game layer only
|
2019-04-26 22:11:15 +00:00
|
|
|
|
2022-03-24 18:30:26 +00:00
|
|
|
STileVisual *m_pBorderTop;
|
|
|
|
STileVisual *m_pBorderLeft;
|
|
|
|
STileVisual *m_pBorderRight;
|
|
|
|
STileVisual *m_pBorderBottom;
|
2019-04-26 22:11:15 +00:00
|
|
|
|
2017-09-27 10:20:23 +00:00
|
|
|
unsigned int m_Width;
|
|
|
|
unsigned int m_Height;
|
2018-03-13 20:57:46 +00:00
|
|
|
int m_BufferContainerIndex;
|
2017-09-27 10:20:23 +00:00
|
|
|
bool m_IsTextured;
|
2017-09-12 18:22:18 +00:00
|
|
|
};
|
2020-09-26 19:41:58 +00:00
|
|
|
std::vector<STileLayerVisuals *> m_TileLayerVisuals;
|
2018-03-13 20:57:46 +00:00
|
|
|
|
|
|
|
struct SQuadLayerVisuals
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
SQuadLayerVisuals() :
|
2022-03-24 18:30:26 +00:00
|
|
|
m_QuadNum(0), m_pQuadsOfLayer(NULL), m_BufferContainerIndex(-1), m_IsTextured(false) {}
|
2018-03-13 20:57:46 +00:00
|
|
|
|
|
|
|
struct SQuadVisual
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
SQuadVisual() :
|
|
|
|
m_IndexBufferByteOffset(0) {}
|
2018-03-13 20:57:46 +00:00
|
|
|
|
|
|
|
offset_ptr m_IndexBufferByteOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
int m_QuadNum;
|
2022-03-24 18:30:26 +00:00
|
|
|
SQuadVisual *m_pQuadsOfLayer;
|
2018-03-13 20:57:46 +00:00
|
|
|
|
|
|
|
int m_BufferContainerIndex;
|
|
|
|
bool m_IsTextured;
|
|
|
|
};
|
2020-09-26 19:41:58 +00:00
|
|
|
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);
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
2020-09-18 16:45:42 +00:00
|
|
|
TYPE_BACKGROUND = 0,
|
2017-09-12 18:22:18 +00:00
|
|
|
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();
|
2022-01-31 02:11:47 +00:00
|
|
|
virtual int Sizeof() const override { return sizeof(*this); }
|
2022-01-30 23:43:56 +00:00
|
|
|
virtual void OnInit() override;
|
|
|
|
virtual void OnRender() override;
|
|
|
|
virtual void OnMapLoad() override;
|
2019-04-26 22:11:15 +00:00
|
|
|
|
2020-09-26 19:41:58 +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);
|
2018-03-13 20:57:46 +00:00
|
|
|
|
2011-12-04 13:04:12 +00:00
|
|
|
void EnvelopeUpdate();
|
2014-10-12 14:12:13 +00:00
|
|
|
|
2020-10-04 00:30:36 +00:00
|
|
|
static void EnvelopeEval(int TimeOffsetMillis, int Env, float *pChannels, void *pUser);
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|