From 5ac3bb506c4383ec177eccb7131eb93129c6b89f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 4 Aug 2024 14:03:54 +0200 Subject: [PATCH] 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`. --- src/game/collision.cpp | 6 +++--- src/game/collision.h | 45 +++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 28ca23aaf..b640e04c3 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -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; diff --git a/src/game/collision.h b/src/game/collision.h index 91f0f0eed..e6fc4dcb5 100644 --- a/src/game/collision.h +++ b/src/game/collision.h @@ -9,6 +9,14 @@ #include #include +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 &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> m_TeleIns; @@ -150,13 +170,6 @@ private: std::map> m_TeleCheckOuts; // TILE_TELEINEVIL, TILE_TELECHECK, TILE_TELECHECKIN, TILE_TELECHECKINEVIL std::map> 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);