Mark CCollision functions const, add const tile getters

Mark remaining `CCollision` functions as `const` when possible.

Add remaining getter functions for all tile data and mark all tile getter functions as `const`.
This commit is contained in:
Robert Müller 2024-08-04 14:03:54 +02:00
parent 6dba8851a5
commit 5ac3bb506c
2 changed files with 32 additions and 19 deletions

View file

@ -123,8 +123,8 @@ void CCollision::Init(class CLayers *pLayers)
{
for(int i = 0; i < m_Width * m_Height; i++)
{
int Number = TeleLayer()[i].m_Number;
int Type = TeleLayer()[i].m_Type;
int Number = m_pTele[i].m_Number;
int Type = m_pTele[i].m_Type;
if(Number > 0)
{
if(Type == TILE_TELEIN)
@ -171,7 +171,7 @@ void CCollision::Unload()
m_pDoor = nullptr;
}
void CCollision::FillAntibot(CAntibotMapData *pMapData)
void CCollision::FillAntibot(CAntibotMapData *pMapData) const
{
pMapData->m_Width = m_Width;
pMapData->m_Height = m_Height;

View file

@ -9,6 +9,14 @@
#include <map>
#include <vector>
class CTile;
class CLayers;
class CTeleTile;
class CSpeedupTile;
class CSwitchTile;
class CTuneTile;
class CDoorTile;
enum
{
CANTMOVE_LEFT = 1 << 0,
@ -28,9 +36,9 @@ public:
CCollision();
~CCollision();
void Init(class CLayers *pLayers);
void Init(CLayers *pLayers);
void Unload();
void FillAntibot(CAntibotMapData *pMapData);
void FillAntibot(CAntibotMapData *pMapData) const;
bool CheckPoint(float x, float y) const { return IsSolid(round_to_int(x), round_to_int(y)); }
bool CheckPoint(vec2 Pos) const { return CheckPoint(Pos.x, Pos.y); }
@ -60,7 +68,7 @@ public:
int GetFIndex(int x, int y) const;
int GetMoveRestrictions(CALLBACK_SWITCHACTIVE pfnSwitchActive, void *pUser, vec2 Pos, float Distance = 18.0f, int OverrideCenterTileIndex = -1) const;
int GetMoveRestrictions(vec2 Pos, float Distance = 18.0f)
int GetMoveRestrictions(vec2 Pos, float Distance = 18.0f) const
{
return GetMoveRestrictions(nullptr, nullptr, Pos, Distance);
}
@ -107,10 +115,14 @@ public:
vec2 CpSpeed(int index, int Flags = 0) const;
class CTeleTile *TeleLayer() { return m_pTele; }
class CSwitchTile *SwitchLayer() { return m_pSwitch; }
class CTuneTile *TuneLayer() { return m_pTune; }
class CLayers *Layers() { return m_pLayers; }
const CLayers *Layers() const { return m_pLayers; }
const CTile *GameLayer() const { return m_pTiles; }
const CTeleTile *TeleLayer() const { return m_pTele; }
const CSpeedupTile *SpeedupLayer() const { return m_pSpeedup; }
const CTile *FrontLayer() const { return m_pFront; }
const CSwitchTile *SwitchLayer() const { return m_pSwitch; }
const CTuneTile *TuneLayer() const { return m_pTune; }
int m_HighestSwitchNumber;
/**
@ -137,10 +149,18 @@ public:
const std::vector<vec2> &TeleOthers(int Number) { return m_TeleOthers[Number]; }
private:
class CTile *m_pTiles;
CLayers *m_pLayers;
int m_Width;
int m_Height;
class CLayers *m_pLayers;
CTile *m_pTiles;
CTeleTile *m_pTele;
CSpeedupTile *m_pSpeedup;
CTile *m_pFront;
CSwitchTile *m_pSwitch;
CTuneTile *m_pTune;
CDoorTile *m_pDoor;
// TILE_TELEIN
std::map<int, std::vector<vec2>> m_TeleIns;
@ -150,13 +170,6 @@ private:
std::map<int, std::vector<vec2>> m_TeleCheckOuts;
// TILE_TELEINEVIL, TILE_TELECHECK, TILE_TELECHECKIN, TILE_TELECHECKINEVIL
std::map<int, std::vector<vec2>> m_TeleOthers;
class CTeleTile *m_pTele;
class CSpeedupTile *m_pSpeedup;
class CTile *m_pFront;
class CSwitchTile *m_pSwitch;
class CTuneTile *m_pTune;
class CDoorTile *m_pDoor;
};
void ThroughOffset(vec2 Pos0, vec2 Pos1, int *pOffsetX, int *pOffsetY);