holy mother of const

Use const everywhere that makes sense
return const variables when it makes sense
const functions and variables again, where it makes sense
No raw access and modifications to protected members
Move template definitions to tcc file

idk how I feel about this one
This commit is contained in:
EmosewaMC
2023-06-09 01:04:42 -07:00
parent d11e2db887
commit ec00f5fd9d
28 changed files with 334 additions and 336 deletions

View File

@@ -190,7 +190,7 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
}
if (m_MovementAI == nullptr) {
m_MovementAI = m_OwningEntity->GetComponent<MovementAIComponent>();
m_MovementAI = m_OwningEntity->GetSharedComponent<MovementAIComponent>();
if (m_MovementAI == nullptr) {
return;
}

View File

@@ -91,7 +91,7 @@ void BuffComponent::ApplyBuff(const int32_t id, const float duration, const LWOO
return;
}
GameMessages::SendAddBuff(const_cast<LWOOBJID&>(m_OwningEntity->GetObjectID()), source, (uint32_t)id,
GameMessages::SendAddBuff(m_OwningEntity->GetObjectID(), source, (uint32_t)id,
(uint32_t)duration * 1000, addImmunity, cancelOnDamaged, cancelOnDeath,
cancelOnLogout, cancelOnRemoveBuff, cancelOnUi, cancelOnUnequip, cancelOnZone);

View File

@@ -22,7 +22,7 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) :
m_BaseCombatAI = nullptr;
m_BaseCombatAI = m_OwningEntity->GetComponent<BaseCombatAIComponent>();
m_BaseCombatAI = m_OwningEntity->GetSharedComponent<BaseCombatAIComponent>();
//Try and fix the insane values:
if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius = m_Info.wanderRadius * 0.5f;

View File

@@ -363,7 +363,7 @@ void PetComponent::Update(float deltaTime) {
}
if (m_MovementAI == nullptr) {
m_MovementAI = m_OwningEntity->GetComponent<MovementAIComponent>();
m_MovementAI = m_OwningEntity->GetSharedComponent<MovementAIComponent>();
if (!m_MovementAI) return;
}
@@ -792,7 +792,7 @@ void PetComponent::ClientFailTamingMinigame() {
}
void PetComponent::Wander() {
m_MovementAI = m_OwningEntity->GetComponent<MovementAIComponent>();
if (!m_MovementAI) m_MovementAI = m_OwningEntity->GetSharedComponent<MovementAIComponent>();
if (m_MovementAI == nullptr || !m_MovementAI->AtFinalWaypoint()) {
return;
@@ -1038,7 +1038,7 @@ void PetComponent::SetAbility(PetAbilityType value) {
m_Ability = value;
}
std::shared_ptr<PetComponent> PetComponent::GetTamingPet(LWOOBJID tamer) {
PetComponent* PetComponent::GetTamingPet(LWOOBJID tamer) {
const auto& pair = currentActivities.find(tamer);
if (pair == currentActivities.end()) {
@@ -1056,7 +1056,7 @@ std::shared_ptr<PetComponent> PetComponent::GetTamingPet(LWOOBJID tamer) {
return entity->GetComponent<PetComponent>();
}
std::shared_ptr<PetComponent> PetComponent::GetActivePet(LWOOBJID owner) {
PetComponent* PetComponent::GetActivePet(LWOOBJID owner) {
const auto& pair = activePets.find(owner);
if (pair == activePets.end()) {

View File

@@ -195,14 +195,14 @@ public:
* @param tamer the entity that's currently taming
* @return the pet component of the entity that's being tamed
*/
static std::shared_ptr<PetComponent> GetTamingPet(LWOOBJID tamer);
static PetComponent* GetTamingPet(LWOOBJID tamer);
/**
* Returns the pet that's currently spawned for some entity (if any)
* @param owner the owner of the pet that's spawned
* @return the pet component of the entity that was spawned by the owner
*/
static std::shared_ptr<PetComponent> GetActivePet(LWOOBJID owner);
static PetComponent* GetActivePet(LWOOBJID owner);
/**
* Adds the timer to the owner of this pet to drain imagination at the rate

View File

@@ -58,7 +58,7 @@ RebuildComponent::~RebuildComponent() {
}
void RebuildComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
if (m_OwningEntity->GetComponent(eReplicaComponentType::DESTROYABLE) == nullptr) {
if (!m_OwningEntity->GetComponent<DestroyableComponent>()) {
if (bIsInitialUpdate) {
outBitStream->Write(false);
}

View File

@@ -10,7 +10,7 @@ SwitchComponent::SwitchComponent(Entity* parent) : Component(parent) {
m_ResetTime = m_OwningEntity->GetVarAs<int32_t>(u"switch_reset_time");
m_Rebuild = m_OwningEntity->GetComponent<RebuildComponent>();
m_Rebuild = m_OwningEntity->GetSharedComponent<RebuildComponent>();
}
SwitchComponent::~SwitchComponent() {