From 2164854e8721e88a41d1f8d49d4bc3c3923d96bd Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 26 Mar 2020 00:28:31 -0400 Subject: [PATCH] CVisorFlare: Pass flares by value and use std::move Same behavior, but allows calling code to move into the parameter and avoid copies entirely. --- Runtime/World/CScriptVisorFlare.cpp | 5 ++--- Runtime/World/CScriptVisorFlare.hpp | 6 +++--- Runtime/World/CVisorFlare.cpp | 4 ++-- Runtime/World/CVisorFlare.hpp | 2 +- Runtime/World/ScriptLoader.cpp | 31 +++++++++++++++++------------ 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Runtime/World/CScriptVisorFlare.cpp b/Runtime/World/CScriptVisorFlare.cpp index a71b6df82..895d6afcc 100644 --- a/Runtime/World/CScriptVisorFlare.cpp +++ b/Runtime/World/CScriptVisorFlare.cpp @@ -11,11 +11,10 @@ namespace urde { CScriptVisorFlare::CScriptVisorFlare(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, const zeus::CVector3f& pos, CVisorFlare::EBlendMode blendMode, bool b1, float f1, - float f2, float f3, u32 w1, u32 w2, - const std::vector& flares) + float f2, float f3, u32 w1, u32 w2, std::vector flares) : CActor(uid, active, name, info, zeus::CTransform::Translate(pos), CModelData::CModelDataNull(), CMaterialList(EMaterialTypes::NoStepLogic), CActorParameters::None(), kInvalidUniqueId) -, xe8_flare(blendMode, b1, f1, f2, f3, w1, w2, flares) { +, xe8_flare(blendMode, b1, f1, f2, f3, w1, w2, std::move(flares)) { xe6_27_thermalVisorFlags = 2; } diff --git a/Runtime/World/CScriptVisorFlare.hpp b/Runtime/World/CScriptVisorFlare.hpp index 718ccb7d4..f5a6883b1 100644 --- a/Runtime/World/CScriptVisorFlare.hpp +++ b/Runtime/World/CScriptVisorFlare.hpp @@ -12,9 +12,9 @@ class CScriptVisorFlare : public CActor { bool x11c_notInRenderLast = true; public: - CScriptVisorFlare(TUniqueId, std::string_view name, const CEntityInfo& info, bool, const zeus::CVector3f&, - CVisorFlare::EBlendMode blendMode, bool, float, float, float, u32, u32, - const std::vector& flares); + CScriptVisorFlare(TUniqueId uid, std::string_view name, const CEntityInfo& info, bool active, + const zeus::CVector3f& pos, CVisorFlare::EBlendMode blendMode, bool, float, float, float, u32, u32, + std::vector flares); void Accept(IVisitor& visitor) override; void Think(float, CStateManager& stateMgr) override; diff --git a/Runtime/World/CVisorFlare.cpp b/Runtime/World/CVisorFlare.cpp index 06c7bd13e..1be3c4a63 100644 --- a/Runtime/World/CVisorFlare.cpp +++ b/Runtime/World/CVisorFlare.cpp @@ -27,9 +27,9 @@ std::optional CVisorFlare::LoadFlareDef(CInputStream& in } CVisorFlare::CVisorFlare(EBlendMode blendMode, bool b1, float f1, float f2, float f3, u32 w1, u32 w2, - const std::vector& flares) + std::vector flares) : x0_blendMode(blendMode) -, x4_flareDefs(flares) +, x4_flareDefs(std::move(flares)) , x14_b1(b1) , x18_f1(std::max(f1, FLT_EPSILON)) , x1c_f2(f2) diff --git a/Runtime/World/CVisorFlare.hpp b/Runtime/World/CVisorFlare.hpp index ff70aff6e..b1c084de2 100644 --- a/Runtime/World/CVisorFlare.hpp +++ b/Runtime/World/CVisorFlare.hpp @@ -49,7 +49,7 @@ private: u32 x30_w2; public: - CVisorFlare(EBlendMode blendMode, bool, float, float, float, u32, u32, const std::vector& flares); + CVisorFlare(EBlendMode blendMode, bool, float, float, float, u32, u32, std::vector flares); void Update(float dt, const zeus::CVector3f& pos, const CActor* act, CStateManager& mgr); void Render(const zeus::CVector3f& pos, const CStateManager& mgr) const; static std::optional LoadFlareDef(CInputStream& in); diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index 060122f19..c7670a387 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -2339,25 +2339,30 @@ CEntity* ScriptLoader::LoadFishCloudModifier(CStateManager& mgr, CInputStream& i } CEntity* ScriptLoader::LoadVisorFlare(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { - if (!EnsurePropertyCount(propCount, 14, "VisorFlare")) + if (!EnsurePropertyCount(propCount, 14, "VisorFlare")) { return nullptr; + } + + const std::string name = mgr.HashInstanceName(in); + const zeus::CVector3f pos = zeus::CVector3f::ReadBig(in); + const bool b1 = in.readBool(); + const auto w1 = CVisorFlare::EBlendMode(in.readUint32Big()); + const bool b2 = in.readBool(); + const float f1 = in.readFloatBig(); + const float f2 = in.readFloatBig(); + const float f3 = in.readFloatBig(); + const u32 w2 = in.readUint32Big(); - std::string name = mgr.HashInstanceName(in); - zeus::CVector3f pos = zeus::CVector3f::ReadBig(in); - bool b1 = in.readBool(); - CVisorFlare::EBlendMode w1 = CVisorFlare::EBlendMode(in.readUint32Big()); - bool b2 = in.readBool(); - float f1 = in.readFloatBig(); - float f2 = in.readFloatBig(); - float f3 = in.readFloatBig(); - u32 w2 = in.readUint32Big(); std::vector flares; flares.reserve(5); - for (int i = 0; i < 5; ++i) - if (auto flare = CVisorFlare::LoadFlareDef(in)) + for (size_t i = 0; i < flares.capacity(); ++i) { + if (auto flare = CVisorFlare::LoadFlareDef(in)) { flares.push_back(*flare); + } + } - return new CScriptVisorFlare(mgr.AllocateUniqueId(), name, info, b1, pos, w1, b2, f1, f2, f3, 2, w2, flares); + return new CScriptVisorFlare(mgr.AllocateUniqueId(), name, info, b1, pos, w1, b2, f1, f2, f3, 2, w2, + std::move(flares)); } CEntity* ScriptLoader::LoadWorldTeleporter(CStateManager& mgr, CInputStream& in, int propCount,