From 257a0bacc8c49b19afb194506b706b1362bbf2eb Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Thu, 9 May 2024 11:19:02 +0800 Subject: [PATCH] Store all tele types in vectors --- src/game/client/components/camera.cpp | 6 ++- src/game/collision.cpp | 50 ++++++++++++++++++++ src/game/collision.h | 68 +++++++++------------------ 3 files changed, 76 insertions(+), 48 deletions(-) diff --git a/src/game/client/components/camera.cpp b/src/game/client/components/camera.cpp index 69dba64ed..b95d3dd30 100644 --- a/src/game/client/components/camera.cpp +++ b/src/game/client/components/camera.cpp @@ -323,7 +323,8 @@ void CCamera::GotoTele(int Number, int Offset) { if((size_t)Offset >= NumTeles || Offset < 0) Offset = 0; - MatchPos = ivec2(Collision()->TeleAllGet(Number, Offset).x / 32, Collision()->TeleAllGet(Number, Offset).y / 32); + vec2 Tele = Collision()->TeleAllGet(Number, Offset); + MatchPos = ivec2(Tele.x / 32, Tele.y / 32); m_GotoTeleOffset = Offset; } else @@ -331,7 +332,8 @@ void CCamera::GotoTele(int Number, int Offset) bool FullRound = false; do { - MatchPos = ivec2(Collision()->TeleAllGet(Number, m_GotoTeleOffset).x / 32, Collision()->TeleAllGet(Number, m_GotoTeleOffset).y / 32); + vec2 Tele = Collision()->TeleAllGet(Number, m_GotoTeleOffset); + MatchPos = ivec2(Tele.x / 32, Tele.y / 32); m_GotoTeleOffset++; if((size_t)m_GotoTeleOffset >= NumTeles) { diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 0b796e8be..c0522515a 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -139,6 +139,10 @@ void CCollision::Init(class CLayers *pLayers) { m_TeleCheckOuts[Number - 1].emplace_back(i % m_Width * 32.0f + 16.0f, i / m_Width * 32.0f + 16.0f); } + else if(Type) + { + m_TeleOthers[Number - 1].emplace_back(i % m_Width * 32.0f + 16.0f, i / m_Width * 32.0f + 16.0f); + } } } } @@ -156,6 +160,7 @@ void CCollision::Unload() m_TeleIns.clear(); m_TeleOuts.clear(); m_TeleCheckOuts.clear(); + m_TeleOthers.clear(); m_pTele = nullptr; m_pSpeedup = nullptr; @@ -1260,3 +1265,48 @@ int CCollision::IsFTimeCheckpoint(int Index) const return z - TILE_TIME_CHECKPOINT_FIRST; return -1; } + +vec2 CCollision::TeleAllGet(int Number, size_t Offset) +{ + if(m_TeleIns.count(Number) > 0) + { + if(m_TeleIns[Number].size() > Offset) + return m_TeleIns[Number][Offset]; + else + Offset -= m_TeleIns[Number].size(); + } + if(m_TeleOuts.count(Number) > 0) + { + if(m_TeleOuts[Number].size() > Offset) + return m_TeleOuts[Number][Offset]; + else + Offset -= m_TeleOuts[Number].size(); + } + if(m_TeleCheckOuts.count(Number) > 0) + { + if(m_TeleCheckOuts[Number].size() > Offset) + return m_TeleCheckOuts[Number][Offset]; + else + Offset -= m_TeleCheckOuts[Number].size(); + } + if(m_TeleOthers.count(Number) > 0) + { + if(m_TeleOthers[Number].size() > Offset) + return m_TeleOthers[Number][Offset]; + } + return vec2(-1, -1); +} + +size_t CCollision::TeleAllSize(int Number) +{ + size_t Total = 0; + if(m_TeleIns.count(Number) > 0) + Total += m_TeleIns[Number].size(); + if(m_TeleOuts.count(Number) > 0) + Total += m_TeleOuts[Number].size(); + if(m_TeleCheckOuts.count(Number) > 0) + Total += m_TeleCheckOuts[Number].size(); + if(m_TeleOthers.count(Number) > 0) + Total += m_TeleOthers[Number].size(); + return Total; +} diff --git a/src/game/collision.h b/src/game/collision.h index 0bc94b88f..91f0f0eed 100644 --- a/src/game/collision.h +++ b/src/game/collision.h @@ -113,57 +113,28 @@ public: class CLayers *Layers() { return m_pLayers; } int m_HighestSwitchNumber; - // Index all teleporter types (in, out and checkpoints) - // as one consecutive list - // - // @param Number is the teleporter number (one less than what is shown in game) - // @param Offset picks the n'th occurence of that teleporter in the map - // - // @return The coordinates of the teleporter in the map - // or (-1, -1) if not found - vec2 TeleAllGet(int Number, size_t Offset) - { - if(m_TeleIns.count(Number) > 0) - { - if(m_TeleIns[Number].size() > Offset) - return m_TeleIns[Number][Offset]; - else - Offset -= m_TeleIns[Number].size(); - } - if(m_TeleOuts.count(Number) > 0) - { - if(m_TeleOuts[Number].size() > Offset) - return m_TeleOuts[Number][Offset]; - else - Offset -= m_TeleOuts[Number].size(); - } - if(m_TeleCheckOuts.count(Number) > 0) - { - if(m_TeleCheckOuts[Number].size() > Offset) - return m_TeleCheckOuts[Number][Offset]; - else - Offset -= m_TeleCheckOuts[Number].size(); - } - return vec2(-1, -1); - } + /** + * Index all teleporter types (in, out and checkpoints) + * as one consecutive list. + * + * @param Number is the teleporter number (one less than what is shown in game) + * @param Offset picks the n'th occurence of that teleporter in the map + * + * @return The coordinates of the teleporter in the map + * or (-1, -1) if not found + */ + vec2 TeleAllGet(int Number, size_t Offset); - // @param Number is the teleporter number (one less than what is shown in game) - // @return The amount of occurences of that teleporter across all types (in, out, checkpoint) - size_t TeleAllSize(int Number) - { - size_t Total = 0; - if(m_TeleIns.count(Number) > 0) - Total += m_TeleIns[Number].size(); - if(m_TeleOuts.count(Number) > 0) - Total += m_TeleOuts[Number].size(); - if(m_TeleCheckOuts.count(Number) > 0) - Total += m_TeleCheckOuts[Number].size(); - return Total; - } + /** + * @param Number is the teleporter number (one less than what is shown in game) + * @return The amount of occurences of that teleporter across all types (in, out, checkpoint) + */ + size_t TeleAllSize(int Number); const std::vector &TeleIns(int Number) { return m_TeleIns[Number]; } const std::vector &TeleOuts(int Number) { return m_TeleOuts[Number]; } const std::vector &TeleCheckOuts(int Number) { return m_TeleCheckOuts[Number]; } + const std::vector &TeleOthers(int Number) { return m_TeleOthers[Number]; } private: class CTile *m_pTiles; @@ -171,9 +142,14 @@ private: int m_Height; class CLayers *m_pLayers; + // TILE_TELEIN std::map> m_TeleIns; + // TILE_TELEOUT std::map> m_TeleOuts; + // TILE_TELECHECKOUT std::map> m_TeleCheckOuts; + // TILE_TELEINEVIL, TILE_TELECHECK, TILE_TELECHECKIN, TILE_TELECHECKINEVIL + std::map> m_TeleOthers; class CTeleTile *m_pTele; class CSpeedupTile *m_pSpeedup;