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_TeleIns.clear();
m_TeleOuts.clear(); m_TeleOuts.clear();
m_TeleCheckOuts.clear(); m_TeleCheckOuts.clear();
if(m_pLayers->TeleLayer()) if(m_pTele)
{ {
int Width = m_pLayers->TeleLayer()->m_Width; for(int i = 0; i < m_Width * m_Height; i++)
int Height = m_pLayers->TeleLayer()->m_Height;
for(int i = 0; i < Width * Height; i++)
{ {
int Number = TeleLayer()[i].m_Number; int Number = TeleLayer()[i].m_Number;
int Type = TeleLayer()[i].m_Type; int Type = TeleLayer()[i].m_Type;
@ -148,15 +145,15 @@ void CCollision::Init(class CLayers *pLayers)
{ {
if(Type == TILE_TELEIN) 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) 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) 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; } class CLayers *Layers() { return m_pLayers; }
int m_HighestSwitchNumber; int m_HighestSwitchNumber;
std::map<int, std::vector<vec2>> &TeleIns() { return m_TeleIns; } const std::vector<vec2> &TeleIns(int Number) { return m_TeleIns[Number]; }
std::map<int, std::vector<vec2>> &TeleOuts() { return m_TeleOuts; } const std::vector<vec2> &TeleOuts(int Number) { return m_TeleOuts[Number]; }
std::map<int, std::vector<vec2>> &TeleCheckOuts() { return m_TeleCheckOuts; } const std::vector<vec2> &TeleCheckOuts(int Number) { return m_TeleCheckOuts[Number]; }
private: private:
std::map<int, std::vector<vec2>> m_TeleIns; 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); 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_pWorld = pWorld;
m_pCollision = pCollision; m_pCollision = pCollision;
m_pTeleOuts = pTeleOuts;
m_pTeams = pTeams; m_pTeams = pTeams;
m_Id = -1; m_Id = -1;
@ -327,14 +326,14 @@ void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick)
m_HookState = HOOK_RETRACT_START; 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; m_TriggeredEvents = 0;
SetHookedPlayer(-1); SetHookedPlayer(-1);
m_NewHook = true; m_NewHook = true;
int RandomOut = m_pWorld->RandomOr0((*m_pTeleOuts)[teleNr - 1].size()); int RandomOut = m_pWorld->RandomOr0(m_pCollision->TeleOuts(teleNr - 1).size());
m_HookPos = (*m_pTeleOuts)[teleNr - 1][RandomOut] + TargetDirection * PhysicalSize() * 1.5f; m_HookPos = m_pCollision->TeleOuts(teleNr - 1)[RandomOut] + TargetDirection * PhysicalSize() * 1.5f;
m_HookDir = TargetDirection; m_HookDir = TargetDirection;
m_HookTeleBase = m_HookPos; m_HookTeleBase = m_HookPos;
} }
@ -677,11 +676,6 @@ void CCharacterCore::SetTeamsCore(CTeamsCore *pTeams)
m_pTeams = pTeams; m_pTeams = pTeams;
} }
void CCharacterCore::SetTeleOuts(std::map<int, std::vector<vec2>> *pTeleOuts)
{
m_pTeleOuts = pTeleOuts;
}
bool CCharacterCore::IsSwitchActiveCb(int Number, void *pUser) bool CCharacterCore::IsSwitchActiveCb(int Number, void *pUser)
{ {
CCharacterCore *pThis = (CCharacterCore *)pUser; CCharacterCore *pThis = (CCharacterCore *)pUser;

View file

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

View file

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

View file

@ -794,7 +794,7 @@ void CCharacter::TickDeferred()
// advance the dummy // advance the dummy
{ {
CWorldCore TempWorld; 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.m_Id = m_pPlayer->GetCid();
m_ReckoningCore.Tick(false); m_ReckoningCore.Tick(false);
m_ReckoningCore.Move(); m_ReckoningCore.Move();
@ -1293,13 +1293,6 @@ int CCharacter::Team()
return Teams()->m_Core.Team(m_pPlayer->GetCid()); 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) void CCharacter::FillAntibot(CAntibotCharacterData *pData)
{ {
pData->m_Pos = m_Pos; pData->m_Pos = m_Pos;
@ -1834,12 +1827,12 @@ void CCharacter::HandleTiles(int Index)
} }
int z = Collision()->IsTeleport(MapIndex); 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) if(m_Core.m_Super)
return; return;
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleOuts)[z - 1].size()); int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleOuts(z - 1).size());
m_Core.m_Pos = (*m_pTeleOuts)[z - 1][TeleOut]; m_Core.m_Pos = Collision()->TeleOuts(z - 1)[TeleOut];
if(!g_Config.m_SvTeleportHoldHook) if(!g_Config.m_SvTeleportHoldHook)
{ {
ResetHook(); ResetHook();
@ -1849,12 +1842,12 @@ void CCharacter::HandleTiles(int Index)
return; return;
} }
int evilz = Collision()->IsEvilTeleport(MapIndex); int evilz = Collision()->IsEvilTeleport(MapIndex);
if(evilz && !(*m_pTeleOuts)[evilz - 1].empty()) if(evilz && !Collision()->TeleOuts(evilz - 1).empty())
{ {
if(m_Core.m_Super) if(m_Core.m_Super)
return; return;
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleOuts)[evilz - 1].size()); int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleOuts(evilz - 1).size());
m_Core.m_Pos = (*m_pTeleOuts)[evilz - 1][TeleOut]; m_Core.m_Pos = Collision()->TeleOuts(evilz - 1)[TeleOut];
if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons) if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons)
{ {
m_Core.m_Vel = vec2(0, 0); 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 // 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--) 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()); int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleCheckOuts(k).size());
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut]; m_Core.m_Pos = Collision()->TeleCheckOuts(k)[TeleOut];
m_Core.m_Vel = vec2(0, 0); m_Core.m_Vel = vec2(0, 0);
if(!g_Config.m_SvTeleportHoldHook) 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 // 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--) 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()); int TeleOut = GameWorld()->m_Core.RandomOr0(Collision()->TeleCheckOuts(k).size());
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut]; m_Core.m_Pos = Collision()->TeleCheckOuts(k)[TeleOut];
if(!g_Config.m_SvTeleportHoldHook) if(!g_Config.m_SvTeleportHoldHook)
{ {

View file

@ -147,9 +147,6 @@ private:
CCharacterCore m_Core; CCharacterCore m_Core;
CGameTeams *m_pTeams = nullptr; 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 // info for dead reckoning
int m_ReckoningTick; // tick that we are performing dead reckoning From int m_ReckoningTick; // tick that we are performing dead reckoning From
CCharacterCore m_SendCore; // core that we should send CCharacterCore m_SendCore; // core that we should send
@ -179,7 +176,6 @@ private:
public: public:
CGameTeams *Teams() { return m_pTeams; } CGameTeams *Teams() { return m_pTeams; }
void SetTeams(CGameTeams *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 FillAntibot(CAntibotCharacterData *pData);
void Pause(bool Pause); void Pause(bool Pause);

View file

@ -164,10 +164,10 @@ void CLaser::DoBounce()
} }
m_ZeroEnergyBounceInLastTick = Distance == 0.0f; 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()); int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts(z - 1).size());
m_TelePos = GameServer()->Collision()->TeleOuts()[z - 1][TeleOut]; m_TelePos = GameServer()->Collision()->TeleOuts(z - 1)[TeleOut];
m_WasTele = true; m_WasTele = true;
} }
else else

View file

@ -276,10 +276,10 @@ void CProjectile::Tick()
z = GameServer()->Collision()->IsTeleport(x); z = GameServer()->Collision()->IsTeleport(x);
else else
z = GameServer()->Collision()->IsTeleportWeapon(x); 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()); int TeleOut = GameServer()->m_World.m_Core.RandomOr0(GameServer()->Collision()->TeleOuts(z - 1).size());
m_Pos = GameServer()->Collision()->TeleOuts()[z - 1][TeleOut]; m_Pos = GameServer()->Collision()->TeleOuts(z - 1)[TeleOut];
m_StartTick = Server()->Tick(); m_StartTick = Server()->Tick();
} }
} }

View file

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