chore: General cleanup roundup (#1444)

* Moved unrelated changes out of the TryParse PR branch

* const correctness and cstdint type usage

* removing a few "== nullptr"

* amf constexpr, const-correctness, and attrib tagging

* update to account for feedback

* Fixing accidentally included header and hopefully fixing the MacOS issue too

* try reordering the amf3 specializations to fix the MacOS issue again

* Amf3 template class member func instantiation fix

* try including only on macos

* Using if constexpr rather than specialization

* Trying a different solution for the instantiation problem

* Remove #include "dPlatforms.h"
This commit is contained in:
jadebenn
2024-02-10 13:44:40 -06:00
committed by GitHub
parent 0c1ee0513d
commit 29666a1ff7
12 changed files with 218 additions and 228 deletions

View File

@@ -23,7 +23,7 @@
#include "CppScripts.h"
QuickBuildComponent::QuickBuildComponent(Entity* entity) : Component(entity) {
QuickBuildComponent::QuickBuildComponent(Entity* const entity) : Component{ entity } {
std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition");
if (!checkPreconditions.empty()) {
@@ -283,47 +283,47 @@ void QuickBuildComponent::DespawnActivator() {
}
}
Entity* QuickBuildComponent::GetActivator() {
Entity* QuickBuildComponent::GetActivator() const {
return Game::entityManager->GetEntity(m_ActivatorId);
}
NiPoint3 QuickBuildComponent::GetActivatorPosition() {
NiPoint3 QuickBuildComponent::GetActivatorPosition() const noexcept {
return m_ActivatorPosition;
}
float QuickBuildComponent::GetResetTime() {
float QuickBuildComponent::GetResetTime() const noexcept {
return m_ResetTime;
}
float QuickBuildComponent::GetCompleteTime() {
float QuickBuildComponent::GetCompleteTime() const noexcept {
return m_CompleteTime;
}
int QuickBuildComponent::GetTakeImagination() {
int32_t QuickBuildComponent::GetTakeImagination() const noexcept {
return m_TakeImagination;
}
bool QuickBuildComponent::GetInterruptible() {
bool QuickBuildComponent::GetInterruptible() const noexcept {
return m_Interruptible;
}
bool QuickBuildComponent::GetSelfActivator() {
bool QuickBuildComponent::GetSelfActivator() const noexcept {
return m_SelfActivator;
}
std::vector<int> QuickBuildComponent::GetCustomModules() {
std::vector<int32_t> QuickBuildComponent::GetCustomModules() const noexcept {
return m_CustomModules;
}
int QuickBuildComponent::GetActivityId() {
int32_t QuickBuildComponent::GetActivityId() const noexcept {
return m_ActivityId;
}
int QuickBuildComponent::GetPostImaginationCost() {
int32_t QuickBuildComponent::GetPostImaginationCost() const noexcept {
return m_PostImaginationCost;
}
float QuickBuildComponent::GetTimeBeforeSmash() {
float QuickBuildComponent::GetTimeBeforeSmash() const noexcept {
return m_TimeBeforeSmash;
}
@@ -332,24 +332,24 @@ eQuickBuildState QuickBuildComponent::GetState() const noexcept {
}
Entity* QuickBuildComponent::GetBuilder() const {
auto* builder = Game::entityManager->GetEntity(m_Builder);
auto* const builder = Game::entityManager->GetEntity(m_Builder);
return builder;
}
bool QuickBuildComponent::GetRepositionPlayer() const {
bool QuickBuildComponent::GetRepositionPlayer() const noexcept {
return m_RepositionPlayer;
}
void QuickBuildComponent::SetActivatorPosition(NiPoint3 value) {
void QuickBuildComponent::SetActivatorPosition(const NiPoint3& value) noexcept {
m_ActivatorPosition = value;
}
void QuickBuildComponent::SetResetTime(float value) {
void QuickBuildComponent::SetResetTime(const float value) noexcept {
m_ResetTime = value;
}
void QuickBuildComponent::SetCompleteTime(float value) {
void QuickBuildComponent::SetCompleteTime(const float value) noexcept {
if (value < 0) {
m_CompleteTime = 4.5f;
} else {
@@ -357,31 +357,31 @@ void QuickBuildComponent::SetCompleteTime(float value) {
}
}
void QuickBuildComponent::SetTakeImagination(int value) {
void QuickBuildComponent::SetTakeImagination(const int32_t value) noexcept {
m_TakeImagination = value;
}
void QuickBuildComponent::SetInterruptible(bool value) {
void QuickBuildComponent::SetInterruptible(const bool value) noexcept {
m_Interruptible = value;
}
void QuickBuildComponent::SetSelfActivator(bool value) {
void QuickBuildComponent::SetSelfActivator(const bool value) noexcept {
m_SelfActivator = value;
}
void QuickBuildComponent::SetCustomModules(std::vector<int> value) {
void QuickBuildComponent::SetCustomModules(const std::vector<int32_t>& value) noexcept {
m_CustomModules = value;
}
void QuickBuildComponent::SetActivityId(int value) {
void QuickBuildComponent::SetActivityId(const int32_t value) noexcept {
m_ActivityId = value;
}
void QuickBuildComponent::SetPostImaginationCost(int value) {
void QuickBuildComponent::SetPostImaginationCost(const int32_t value) noexcept {
m_PostImaginationCost = value;
}
void QuickBuildComponent::SetTimeBeforeSmash(float value) {
void QuickBuildComponent::SetTimeBeforeSmash(const float value) noexcept {
if (value < 0) {
m_TimeBeforeSmash = 10.0f;
} else {
@@ -389,11 +389,11 @@ void QuickBuildComponent::SetTimeBeforeSmash(float value) {
}
}
void QuickBuildComponent::SetRepositionPlayer(bool value) {
void QuickBuildComponent::SetRepositionPlayer(const bool value) noexcept {
m_RepositionPlayer = value;
}
void QuickBuildComponent::StartQuickBuild(Entity* user) {
void QuickBuildComponent::StartQuickBuild(Entity* const user) {
if (m_State == eQuickBuildState::OPEN || m_State == eQuickBuildState::COMPLETED || m_State == eQuickBuildState::INCOMPLETE) {
m_Builder = user->GetObjectID();
@@ -426,10 +426,8 @@ void QuickBuildComponent::StartQuickBuild(Entity* user) {
}
}
void QuickBuildComponent::CompleteQuickBuild(Entity* user) {
if (user == nullptr) {
return;
}
void QuickBuildComponent::CompleteQuickBuild(Entity* const user) {
if (!user) return;
auto* characterComponent = user->GetComponent<CharacterComponent>();
if (characterComponent != nullptr) {
@@ -518,7 +516,7 @@ void QuickBuildComponent::CompleteQuickBuild(Entity* user) {
RenderComponent::PlayAnimation(user, u"rebuild-celebrate", 1.09f);
}
void QuickBuildComponent::ResetQuickBuild(bool failed) {
void QuickBuildComponent::ResetQuickBuild(const bool failed) {
Entity* builder = GetBuilder();
if (m_State == eQuickBuildState::BUILDING && builder) {
@@ -553,7 +551,7 @@ void QuickBuildComponent::ResetQuickBuild(bool failed) {
}
}
void QuickBuildComponent::CancelQuickBuild(Entity* entity, eQuickBuildFailReason failReason, bool skipChecks) {
void QuickBuildComponent::CancelQuickBuild(Entity* const entity, const eQuickBuildFailReason failReason, const bool skipChecks) {
if (m_State != eQuickBuildState::COMPLETED || skipChecks) {
m_Builder = LWOOBJID_EMPTY;
@@ -581,9 +579,7 @@ void QuickBuildComponent::CancelQuickBuild(Entity* entity, eQuickBuildFailReason
Game::entityManager->SerializeEntity(m_Parent);
}
if (entity == nullptr) {
return;
}
if (!entity) return;
CharacterComponent* characterComponent = entity->GetComponent<CharacterComponent>();
if (characterComponent) {

View File

@@ -24,7 +24,7 @@ class QuickBuildComponent final : public Component {
public:
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::QUICK_BUILD;
QuickBuildComponent(Entity* entity);
QuickBuildComponent(Entity* const entity);
~QuickBuildComponent() override;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate) override;
@@ -50,124 +50,124 @@ public:
* Returns the entity that acts as the activator for this quickbuild
* @return the entity that acts as the activator for this quickbuild
*/
Entity* GetActivator();
[[nodiscard]] Entity* GetActivator() const;
/**
* Returns the spawn position of the activator for this quickbuild, if any
* @return the spawn position of the activator for this quickbuild, if any
*/
NiPoint3 GetActivatorPosition();
[[nodiscard]] NiPoint3 GetActivatorPosition() const noexcept;
/**
* Sets the spawn position for the activator of this quickbuild
* @param value the spawn position to set for the activator
*/
void SetActivatorPosition(NiPoint3 value);
void SetActivatorPosition(const NiPoint3& value) noexcept;
/**
* Returns the time it takes for the quickbuild to reset after being built
* @return the time it takes for the quickbuild to reset after being built
*/
float GetResetTime();
[[nodiscard]] float GetResetTime() const noexcept;
/**
* Sets the time it takes for the quickbuild to reset after being built
* @param value the reset time to set
*/
void SetResetTime(float value);
void SetResetTime(const float value) noexcept;
/**
* Returns the time it takes to complete the quickbuild
* @return the time it takes to complete the quickbuild
*/
float GetCompleteTime();
[[nodiscard]] float GetCompleteTime() const noexcept;
/**
* Sets the time it takes to complete the quickbuild
* @param value the completion time to set
*/
void SetCompleteTime(float value);
void SetCompleteTime(const float value) noexcept;
/**
* Returns the imagination that's taken when completing the quickbuild
* @return the imagination that's taken when completing the quickbuild
*/
int GetTakeImagination();
[[nodiscard]] int32_t GetTakeImagination() const noexcept;
/**
* Sets the imagination that's taken when completing the quickbuild
* @param value the imagination deduction to set
*/
void SetTakeImagination(int value);
void SetTakeImagination(const int32_t value) noexcept;
/**
* Returns if the quickbuild can be interrupted, currently unused
* @return if the quickbuild can be interrupted
*/
bool GetInterruptible();
[[nodiscard]] bool GetInterruptible() const noexcept;
/**
* Sets whether or not the quickbuild can be interrupted, currently unused
* @param value true if the quickbuild may be interrupted, false otherwise
*/
void SetInterruptible(bool value);
void SetInterruptible(const bool value) noexcept;
/**
* Returns whether or not this entity contains a built-in activator
* @return whether or not this entity contains a built-in activator
*/
bool GetSelfActivator();
[[nodiscard]] bool GetSelfActivator() const noexcept;
/**
* Sets whether or not this entity contains a built-in activator. If set to false this will spawn activators on
* each new quickbuild.
* @param value whether or not this entity contains a built-in activator
*/
void SetSelfActivator(bool value);
void SetSelfActivator(const bool value) noexcept;
/**
* Currently unused
*/
std::vector<int> GetCustomModules();
[[nodiscard]] std::vector<int32_t> GetCustomModules() const noexcept;
/**
* Currently unused
*/
void SetCustomModules(std::vector<int> value);
void SetCustomModules(const std::vector<int32_t>& value) noexcept;
/**
* Returns the activity ID for participating in this quickbuild
* @return the activity ID for participating in this quickbuild
*/
int GetActivityId();
[[nodiscard]] int32_t GetActivityId() const noexcept;
/**
* Sets the activity ID for participating in this quickbuild
* @param value the activity ID to set
*/
void SetActivityId(int value);
void SetActivityId(const int32_t value) noexcept;
/**
* Currently unused
*/
int GetPostImaginationCost();
[[nodiscard]] int32_t GetPostImaginationCost() const noexcept;
/**
* Currently unused
*/
void SetPostImaginationCost(int value);
void SetPostImaginationCost(const int32_t value) noexcept;
/**
* Returns the time it takes for an incomplete quickbuild to be smashed automatically
* @return the time it takes for an incomplete quickbuild to be smashed automatically
*/
float GetTimeBeforeSmash();
[[nodiscard]] float GetTimeBeforeSmash() const noexcept;
/**
* Sets the time it takes for an incomplete quickbuild to be smashed automatically
* @param value the time to set
*/
void SetTimeBeforeSmash(float value);
void SetTimeBeforeSmash(const float value) noexcept;
/**
* Returns the current quickbuild state
@@ -179,19 +179,19 @@ public:
* Returns the player that is currently building this quickbuild
* @return the player that is currently building this quickbuild
*/
Entity* GetBuilder() const;
[[nodiscard]] Entity* GetBuilder() const;
/**
* Returns whether or not the player is repositioned when initiating the quickbuild
* @return whether or not the player is repositioned when initiating the quickbuild
*/
bool GetRepositionPlayer() const;
[[nodiscard]] bool GetRepositionPlayer() const noexcept;
/**
* Sets whether or not the player is repositioned when initiating the quickbuild
* @param value whether or not the player is repositioned when initiating the quickbuild
*/
void SetRepositionPlayer(bool value);
void SetRepositionPlayer(const bool value) noexcept;
/**
* Adds a callback that is called when the quickbuild is completed
@@ -209,7 +209,7 @@ public:
* Resets the quickbuild
* @param failed whether or not the player failed to complete the quickbuild, triggers an extra animation
*/
void ResetQuickBuild(bool failed);
void ResetQuickBuild(const bool failed);
/**
* Cancels the quickbuild if it wasn't completed
@@ -217,7 +217,7 @@ public:
* @param failReason the reason the quickbuild was cancelled
* @param skipChecks whether or not to skip the check for the quickbuild not being completed
*/
void CancelQuickBuild(Entity* builder, eQuickBuildFailReason failReason, bool skipChecks = false);
void CancelQuickBuild(Entity* const builder, const eQuickBuildFailReason failReason, const bool skipChecks = false);
private:
/**
* Whether or not the quickbuild state has been changed since we last serialized it.
@@ -287,7 +287,7 @@ private:
/**
* The imagination that's deducted when completing the quickbuild
*/
int m_TakeImagination = 0;
int32_t m_TakeImagination = 0;
/**
* Currently unused
@@ -302,17 +302,17 @@ private:
/**
* Currently unused
*/
std::vector<int> m_CustomModules{};
std::vector<int32_t> m_CustomModules{};
/**
* The activity ID that players partake in when doing this quickbuild
*/
int m_ActivityId = 0;
int32_t m_ActivityId = 0;
/**
* Currently unused
*/
int m_PostImaginationCost = 0;
int32_t m_PostImaginationCost = 0;
/**
* The time it takes for the quickbuild to reset when it's not completed yet
@@ -327,7 +327,7 @@ private:
/**
* The amount of imagination that was drained when building this quickbuild
*/
int m_DrainedImagination = 0;
int32_t m_DrainedImagination = 0;
/**
* Whether to reposition the player or not when building
@@ -337,7 +337,7 @@ private:
/**
* Currently unused
*/
float m_SoftTimer = 0;
int32_t m_SoftTimer = 0;
/**
* The ID of the entity that's currently building the quickbuild
@@ -353,13 +353,13 @@ private:
* Starts the quickbuild for a certain entity
* @param user the entity to start the quickbuild
*/
void StartQuickBuild(Entity* user);
void StartQuickBuild(Entity* const user);
/**
* Completes the quickbuild for an entity, dropping loot and despawning the activator
* @param user the entity that completed the quickbuild
*/
void CompleteQuickBuild(Entity* user);
void CompleteQuickBuild(Entity* const user);
};
#endif // QUICKBUILDCOMPONENT_H

View File

@@ -2,7 +2,7 @@
#include "Action.h"
AddStripMessage::AddStripMessage(AMFArrayValue* arguments) : BehaviorMessageBase(arguments) {
AddStripMessage::AddStripMessage(AMFArrayValue* const arguments) : BehaviorMessageBase{ arguments } {
actionContext = ActionContext(arguments);
position = StripUiPosition(arguments);

View File

@@ -18,7 +18,7 @@ class AMFArrayValue;
*/
class AddStripMessage : public BehaviorMessageBase {
public:
AddStripMessage(AMFArrayValue* arguments);
AddStripMessage(AMFArrayValue* const arguments);
StripUiPosition GetPosition() const { return position; };
ActionContext GetActionContext() const { return actionContext; };
std::vector<Action> GetActionsToAdd() const;

View File

@@ -8,9 +8,9 @@ BehaviorMessageBase::BehaviorMessageBase(AMFArrayValue* arguments) {
this->behaviorId = GetBehaviorIdFromArgument(arguments);
}
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments) {
const auto* key = "BehaviorID";
auto* behaviorIDValue = arguments->Get<std::string>(key);
int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* const arguments) {
const char* const key = "BehaviorID";
const auto* const behaviorIDValue = arguments->Get<std::string>(key);
if (behaviorIDValue && behaviorIDValue->GetValueType() == eAmf::String) {
this->behaviorId =
@@ -22,11 +22,9 @@ int32_t BehaviorMessageBase::GetBehaviorIdFromArgument(AMFArrayValue* arguments)
return this->behaviorId;
}
int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName) {
auto* actionIndexAmf = arguments->Get<double>(keyName);
if (!actionIndexAmf) {
throw std::invalid_argument("Unable to find actionIndex");
}
int32_t BehaviorMessageBase::GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName) const {
const auto* const actionIndexAmf = arguments->Get<double>(keyName);
if (!actionIndexAmf) throw std::invalid_argument("Unable to find actionIndex");
return static_cast<int32_t>(actionIndexAmf->GetValue());
}

View File

@@ -15,13 +15,13 @@ enum class BehaviorState : uint32_t;
*/
class BehaviorMessageBase {
public:
static inline int32_t DefaultBehaviorId = -1;
const int32_t GetBehaviorId() const { return behaviorId; };
bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; };
BehaviorMessageBase(AMFArrayValue* arguments);
static constexpr int32_t DefaultBehaviorId = -1;
[[nodiscard]] int32_t GetBehaviorId() const { return behaviorId; };
[[nodiscard]] bool IsDefaultBehaviorId() { return behaviorId == DefaultBehaviorId; };
BehaviorMessageBase(AMFArrayValue* const arguments);
protected:
int32_t GetBehaviorIdFromArgument(AMFArrayValue* arguments);
int32_t GetActionIndexFromArgument(AMFArrayValue* arguments, const std::string& keyName = "actionIndex");
[[nodiscard]] int32_t GetBehaviorIdFromArgument(AMFArrayValue* const arguments);
[[nodiscard]] int32_t GetActionIndexFromArgument(AMFArrayValue* const arguments, const std::string& keyName = "actionIndex") const;
int32_t behaviorId = DefaultBehaviorId;
};