Store all tele types in vectors

This commit is contained in:
ChillerDragon 2024-05-09 11:19:02 +08:00
parent 6f75087d9f
commit 257a0bacc8
3 changed files with 76 additions and 48 deletions

View file

@ -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)
{

View file

@ -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;
}

View file

@ -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<vec2> &TeleIns(int Number) { return m_TeleIns[Number]; }
const std::vector<vec2> &TeleOuts(int Number) { return m_TeleOuts[Number]; }
const std::vector<vec2> &TeleCheckOuts(int Number) { return m_TeleCheckOuts[Number]; }
const std::vector<vec2> &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<int, std::vector<vec2>> m_TeleIns;
// TILE_TELEOUT
std::map<int, std::vector<vec2>> m_TeleOuts;
// TILE_TELECHECKOUT
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;