diff --git a/Runtime/World/CAi.cpp b/Runtime/World/CAi.cpp index 8b051bbe3..56e77bd79 100644 --- a/Runtime/World/CAi.cpp +++ b/Runtime/World/CAi.cpp @@ -78,9 +78,9 @@ void CAi::FluidFXThink(EFluidState state, CScriptWater& water, urde::CStateManag water.GetFluidPlane().AddRipple(GetMass(), GetUniqueId(), center, GetVelocity(), water, mgr, pos); } -CAiStateFunc CAi::GetStateFunc(const char* func) { return m_FuncMap->GetStateFunc(func); } +CAiStateFunc CAi::GetStateFunc(std::string_view func) { return m_FuncMap->GetStateFunc(func); } -CAiTriggerFunc CAi::GetTrigerFunc(const char* func) { return m_FuncMap->GetTriggerFunc(func); } +CAiTriggerFunc CAi::GetTriggerFunc(std::string_view func) { return m_FuncMap->GetTriggerFunc(func); } const CStateMachine* CAi::GetStateMachine() const { return x2c8_stateMachine.GetObj(); } void CAi::CreateFuncLookup(CAiFuncMap* funcMap) { m_FuncMap = funcMap; } diff --git a/Runtime/World/CAi.hpp b/Runtime/World/CAi.hpp index 6ba2be1ca..de4dd8569 100644 --- a/Runtime/World/CAi.hpp +++ b/Runtime/World/CAi.hpp @@ -36,8 +36,8 @@ public: const CMaterialList& list, CAssetId fsm, const CActorParameters&, float f1, float f2); static void CreateFuncLookup(CAiFuncMap* funcMap); - static CAiStateFunc GetStateFunc(const char* func); - static CAiTriggerFunc GetTrigerFunc(const char* func); + static CAiStateFunc GetStateFunc(std::string_view func); + static CAiTriggerFunc GetTriggerFunc(std::string_view func); const CStateMachine* GetStateMachine() const; diff --git a/Runtime/World/CAiFuncMap.cpp b/Runtime/World/CAiFuncMap.cpp index d03b0ceeb..9518d5d10 100644 --- a/Runtime/World/CAiFuncMap.cpp +++ b/Runtime/World/CAiFuncMap.cpp @@ -137,7 +137,7 @@ CAiFuncMap::CAiFuncMap() { CAi::CreateFuncLookup(this); } -CAiStateFunc CAiFuncMap::GetStateFunc(const char* func) const { +CAiStateFunc CAiFuncMap::GetStateFunc(std::string_view func) const { const auto iter = x0_stateFuncs.find(func); if (iter == x0_stateFuncs.cend()) { @@ -147,7 +147,7 @@ CAiStateFunc CAiFuncMap::GetStateFunc(const char* func) const { return iter->second; } -CAiTriggerFunc CAiFuncMap::GetTriggerFunc(const char* func) const { +CAiTriggerFunc CAiFuncMap::GetTriggerFunc(std::string_view func) const { const auto iter = x10_triggerFuncs.find(func); if (iter == x10_triggerFuncs.cend()) { diff --git a/Runtime/World/CAiFuncMap.hpp b/Runtime/World/CAiFuncMap.hpp index 06d81a624..5c77d53eb 100644 --- a/Runtime/World/CAiFuncMap.hpp +++ b/Runtime/World/CAiFuncMap.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include namespace urde { @@ -13,12 +13,12 @@ using CAiStateFunc = void (CAi::*)(CStateManager&, EStateMsg, float); using CAiTriggerFunc = bool (CAi::*)(CStateManager&, float); class CAiFuncMap { - std::unordered_map x0_stateFuncs; - std::unordered_map x10_triggerFuncs; + std::unordered_map x0_stateFuncs; + std::unordered_map x10_triggerFuncs; public: CAiFuncMap(); - CAiStateFunc GetStateFunc(const char*) const; - CAiTriggerFunc GetTriggerFunc(const char*) const; + CAiStateFunc GetStateFunc(std::string_view func) const; + CAiTriggerFunc GetTriggerFunc(std::string_view func) const; }; } // namespace urde diff --git a/Runtime/World/CStateMachine.cpp b/Runtime/World/CStateMachine.cpp index 1208afb7b..1e4a4c034 100644 --- a/Runtime/World/CStateMachine.cpp +++ b/Runtime/World/CStateMachine.cpp @@ -14,7 +14,7 @@ CStateMachine::CStateMachine(CInputStream& in) { for (u32 i = 0; i < stateCount; ++i) { std::string name = in.readString(31, false); - CAiStateFunc func = CAi::GetStateFunc(name.c_str()); + CAiStateFunc func = CAi::GetStateFunc(name); x0_states.emplace_back(func, name.c_str()); } @@ -28,14 +28,14 @@ CStateMachine::CStateMachine(CInputStream& in) { x0_states[i].SetTriggers(firstTrig); x10_triggers.resize(x10_triggers.size() + x0_states[i].GetNumTriggers()); - for (u32 j = 0; j < x0_states[i].GetNumTriggers(); ++j) { - u32 triggerCount = in.readUint32Big(); - u32 lastTriggerIdx = triggerCount - 1; + for (s32 j = 0; j < x0_states[i].GetNumTriggers(); ++j) { + const u32 triggerCount = in.readUint32Big(); + const u32 lastTriggerIdx = triggerCount - 1; for (u32 k = 0; k < triggerCount; ++k) { std::string name = in.readString(31, false); - bool isNot = name.front() == '!'; - CAiTriggerFunc func = CAi::GetTrigerFunc(isNot ? name.c_str() + 1 : name.c_str()); - float arg = in.readFloatBig(); + const bool isNot = name.front() == '!'; + const CAiTriggerFunc func = CAi::GetTriggerFunc(isNot ? name.c_str() + 1 : name.c_str()); + const float arg = in.readFloatBig(); CAiTrigger* newTrig; if (k < lastTriggerIdx) { newTrig = &x10_triggers.emplace_back();