Make tele getters const

This commit is contained in:
ChillerDragon 2024-02-09 15:55:01 +08:00
parent 552d466197
commit 4da4ca5bdd
10 changed files with 38 additions and 62 deletions

View file

@ -135,12 +135,9 @@ void CCollision::Init(class CLayers *pLayers)
m_TeleIns.clear();
m_TeleOuts.clear();
m_TeleCheckOuts.clear();
if(m_pLayers->TeleLayer())
if(m_pTele)
{
int Width = m_pLayers->TeleLayer()->m_Width;
int Height = m_pLayers->TeleLayer()->m_Height;
for(int i = 0; i < Width * Height; i++)
for(int i = 0; i < m_Width * m_Height; i++)
{
int Number = TeleLayer()[i].m_Number;
int Type = TeleLayer()[i].m_Type;
@ -148,15 +145,15 @@ void CCollision::Init(class CLayers *pLayers)
{
if(Type == TILE_TELEIN)
{
m_TeleIns[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f);
m_TeleIns[Number - 1].emplace_back(i % m_Width * 32.0f + 16.0f, i / m_Width * 32.0f + 16.0f);
}
else if(Type == TILE_TELEOUT)
{
m_TeleOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f);
m_TeleOuts[Number - 1].emplace_back(i % m_Width * 32.0f + 16.0f, i / m_Width * 32.0f + 16.0f);
}
else if(Type == TILE_TELECHECKOUT)
{
m_TeleCheckOuts[Number - 1].emplace_back(i % Width * 32.0f + 16.0f, i / Width * 32.0f + 16.0f);
m_TeleCheckOuts[Number - 1].emplace_back(i % m_Width * 32.0f + 16.0f, i / m_Width * 32.0f + 16.0f);
}
}
}

View file

@ -117,9 +117,9 @@ public:
class CLayers *Layers() { return m_pLayers; }
int m_HighestSwitchNumber;
std::map<int, std::vector<vec2>> &TeleIns() { return m_TeleIns; }
std::map<int, std::vector<vec2>> &TeleOuts() { return m_TeleOuts; }
std::map<int, std::vector<vec2>> &TeleCheckOuts() { return m_TeleCheckOuts; }
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]; }
private:
std::map<int, std::vector<vec2>> m_TeleIns;

View file

@ -70,11 +70,10 @@ float VelocityRamp(float Value, float Start, float Range, float Curvature)
return 1.0f / std::pow(Curvature, (Value - Start) / Range);
}
void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams, std::map<int, std::vector<vec2>> *pTeleOuts)
void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams)
{
m_pWorld = pWorld;
m_pCollision = pCollision;
m_pTeleOuts = pTeleOuts;
m_pTeams = pTeams;
m_Id = -1;
@ -327,14 +326,14 @@ void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick)
m_HookState = HOOK_RETRACT_START;
}
if(GoingThroughTele && m_pWorld && m_pTeleOuts && !m_pTeleOuts->empty() && !(*m_pTeleOuts)[teleNr - 1].empty())
if(GoingThroughTele && m_pWorld && !m_pCollision->TeleOuts(teleNr - 1).empty())
{
m_TriggeredEvents = 0;
SetHookedPlayer(-1);
m_NewHook = true;
int RandomOut = m_pWorld->RandomOr0((*m_pTeleOuts)[teleNr - 1].size());
m_HookPos = (*m_pTeleOuts)[teleNr - 1][RandomOut] + TargetDirection * PhysicalSize() * 1.5f;
int RandomOut = m_pWorld->RandomOr0(m_pCollision->TeleOuts(teleNr - 1).size());
m_HookPos = m_pCollision->TeleOuts(teleNr - 1)[RandomOut] + TargetDirection * PhysicalSize() * 1.5f;
m_HookDir = TargetDirection;
m_HookTeleBase = m_HookPos;
}
@ -677,11 +676,6 @@ void CCharacterCore::SetTeamsCore(CTeamsCore *pTeams)
m_pTeams = pTeams;
}
void CCharacterCore::SetTeleOuts(std::map<int, std::vector<vec2>> *pTeleOuts)
{
m_pTeleOuts = pTeleOuts;
}
bool CCharacterCore::IsSwitchActiveCb(int Number, void *pUser)
{
CCharacterCore *pThis = (CCharacterCore *)pUser;

View file

@ -221,7 +221,6 @@ class CCharacterCore
{
CWorldCore *m_pWorld = nullptr;
CCollision *m_pCollision;
std::map<int, std::vector<vec2>> *m_pTeleOuts;
public:
static constexpr float PhysicalSize() { return 28.0f; };
@ -269,7 +268,7 @@ public:
int m_TriggeredEvents;
void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams = nullptr, std::map<int, std::vector<vec2>> *pTeleOuts = nullptr);
void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams = nullptr);
void SetCoreWorld(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams);
void Reset();
void TickDeferred();
@ -290,7 +289,6 @@ public:
// DDNet Character
void SetTeamsCore(CTeamsCore *pTeams);
void SetTeleOuts(std::map<int, std::vector<vec2>> *pTeleOuts);
void ReadDDNet(const CNetObj_DDNetCharacter *pObjDDNet);
bool m_Solo;
bool m_Jetpack;

View file

@ -361,13 +361,13 @@ void CGameContext::ConToTeleporter(IConsole::IResult *pResult, void *pUserData)
CGameContext *pSelf = (CGameContext *)pUserData;
unsigned int TeleTo = pResult->GetInteger(0);
if(!pSelf->Collision()->TeleOuts()[TeleTo - 1].empty())
if(!pSelf->Collision()->TeleOuts(TeleTo - 1).empty())
{
CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientId);
if(pChr)
{
int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleOuts()[TeleTo - 1].size());
pSelf->Teleport(pChr, pSelf->Collision()->TeleOuts()[TeleTo - 1][TeleOut]);
int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleOuts(TeleTo - 1).size());
pSelf->Teleport(pChr, pSelf->Collision()->TeleOuts(TeleTo - 1)[TeleOut]);
}
}
}
@ -377,13 +377,13 @@ void CGameContext::ConToCheckTeleporter(IConsole::IResult *pResult, void *pUserD
CGameContext *pSelf = (CGameContext *)pUserData;
unsigned int TeleTo = pResult->GetInteger(0);
if(!pSelf->Collision()->TeleCheckOuts()[TeleTo - 1].empty())
if(!pSelf->Collision()->TeleCheckOuts(TeleTo - 1).empty())
{
CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientId);
if(pChr)
{
int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleCheckOuts()[TeleTo - 1].size());
pSelf->Teleport(pChr, pSelf->Collision()->TeleCheckOuts()[TeleTo - 1][TeleOut]);
int TeleOut = pSelf->m_World.m_Core.RandomOr0(pSelf->Collision()->TeleCheckOuts(TeleTo - 1).size());
pSelf->Teleport(pChr, pSelf->Collision()->TeleCheckOuts(TeleTo - 1)[TeleOut]);
pChr->m_TeleCheckpoint = TeleTo;
}
}

View file

@ -794,7 +794,7 @@ void CCharacter::TickDeferred()
// advance the dummy
{
CWorldCore TempWorld;
m_ReckoningCore.Init(&TempWorld, Collision(), &Teams()->m_Core, m_pTeleOuts);
m_ReckoningCore.Init(&TempWorld, Collision(), &Teams()->m_Core);
m_ReckoningCore.m_Id = m_pPlayer->GetCid();
m_ReckoningCore.Tick(false);
m_ReckoningCore.Move();
@ -1293,13 +1293,6 @@ int CCharacter::Team()
return Teams()->m_Core.Team(m_pPlayer->GetCid());
}
void CCharacter::SetTeleports(std::map<int, std::vector<vec2>> *pTeleOuts, std::map<int, std::vector<vec2>> *pTeleCheckOuts)
{
m_pTeleOuts = pTeleOuts;
m_pTeleCheckOuts = pTeleCheckOuts;
m_Core.SetTeleOuts(pTeleOuts);
}
void CCharacter::FillAntibot(CAntibotCharacterData *pData)
{
pData->m_Pos = m_Pos;
@ -1834,12 +1827,12 @@ void CCharacter::HandleTiles(int Index)
}
int z = Collision()->IsTeleport(MapIndex);
if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons && z && !(*m_pTeleOuts)[z - 1].empty())
if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons && z && !Collision()->TeleOuts(z - 1).empty())
{
if(m_Core.m_Super)
return;
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleOuts)[z - 1].size());
m_Core.m_Pos = (*m_pTeleOuts)[z - 1][TeleOut];
int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleOuts(z - 1).size());
m_Core.m_Pos = Collision()->TeleOuts(z - 1)[TeleOut];
if(!g_Config.m_SvTeleportHoldHook)
{
ResetHook();
@ -1849,12 +1842,12 @@ void CCharacter::HandleTiles(int Index)
return;
}
int evilz = Collision()->IsEvilTeleport(MapIndex);
if(evilz && !(*m_pTeleOuts)[evilz - 1].empty())
if(evilz && !Collision()->TeleOuts(evilz - 1).empty())
{
if(m_Core.m_Super)
return;
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleOuts)[evilz - 1].size());
m_Core.m_Pos = (*m_pTeleOuts)[evilz - 1][TeleOut];
int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleOuts(evilz - 1).size());
m_Core.m_Pos = Collision()->TeleOuts(evilz - 1)[TeleOut];
if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons)
{
m_Core.m_Vel = vec2(0, 0);
@ -1878,10 +1871,10 @@ void CCharacter::HandleTiles(int Index)
// first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints
for(int k = m_TeleCheckpoint - 1; k >= 0; k--)
{
if(!(*m_pTeleCheckOuts)[k].empty())
if(!Collision()->TeleCheckOuts(k).empty())
{
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleCheckOuts)[k].size());
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut];
int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleCheckOuts(k).size());
m_Core.m_Pos = Collision()->TeleCheckOuts(k)[TeleOut];
m_Core.m_Vel = vec2(0, 0);
if(!g_Config.m_SvTeleportHoldHook)
@ -1915,10 +1908,10 @@ void CCharacter::HandleTiles(int Index)
// first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints
for(int k = m_TeleCheckpoint - 1; k >= 0; k--)
{
if(!(*m_pTeleCheckOuts)[k].empty())
if(!Collision()->TeleCheckOuts(k).empty())
{
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleCheckOuts)[k].size());
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut];
int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleCheckOuts(k).size());
m_Core.m_Pos = Collision()->TeleCheckOuts(k)[TeleOut];
if(!g_Config.m_SvTeleportHoldHook)
{

View file

@ -147,9 +147,6 @@ private:
CCharacterCore m_Core;
CGameTeams *m_pTeams = nullptr;
std::map<int, std::vector<vec2>> *m_pTeleOuts = nullptr;
std::map<int, std::vector<vec2>> *m_pTeleCheckOuts = nullptr;
// info for dead reckoning
int m_ReckoningTick; // tick that we are performing dead reckoning From
CCharacterCore m_SendCore; // core that we should send
@ -179,7 +176,6 @@ private:
public:
CGameTeams *Teams() { return m_pTeams; }
void SetTeams(CGameTeams *pTeams);
void SetTeleports(std::map<int, std::vector<vec2>> *pTeleOuts, std::map<int, std::vector<vec2>> *pTeleCheckOuts);
void FillAntibot(CAntibotCharacterData *pData);
void Pause(bool Pause);

View file

@ -164,10 +164,10 @@ void CLaser::DoBounce()
}
m_ZeroEnergyBounceInLastTick = Distance == 0.0f;
if(Res == TILE_TELEINWEAPON && !GameServer()->Collision()->TeleOuts()[z - 1].empty())
if(Res == TILE_TELEINWEAPON && !GameServer()->Collision()->TeleOuts(z - 1).empty())
{
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts()[z - 1].size());
m_TelePos = GameServer()->Collision()->TeleOuts()[z - 1][TeleOut];
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts(z - 1).size());
m_TelePos = GameServer()->Collision()->TeleOuts(z - 1)[TeleOut];
m_WasTele = true;
}
else

View file

@ -276,10 +276,10 @@ void CProjectile::Tick()
z = GameServer()->Collision()->IsTeleport(x);
else
z = GameServer()->Collision()->IsTeleportWeapon(x);
if(z && !GameServer()->Collision()->TeleOuts()[z - 1].empty())
if(z && !GameServer()->Collision()->TeleOuts(z - 1).empty())
{
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts()[z - 1].size());
m_Pos = GameServer()->Collision()->TeleOuts()[z - 1][TeleOut];
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts(z - 1).size());
m_Pos = GameServer()->Collision()->TeleOuts(z - 1)[TeleOut];
m_StartTick = Server()->Tick();
}
}

View file

@ -482,8 +482,6 @@ void IGameController::OnCharacterSpawn(class CCharacter *pChr)
// give default weapons
pChr->GiveWeapon(WEAPON_HAMMER);
pChr->GiveWeapon(WEAPON_GUN);
pChr->SetTeleports(&GameServer()->Collision()->TeleOuts(), &GameServer()->Collision()->TeleCheckOuts());
}
void IGameController::HandleCharacterTiles(CCharacter *pChr, int MapIndex)