diff --git a/rwengine/src/TextureArchive.cpp b/rwengine/src/TextureArchive.cpp index f68bad04..6e25cd68 100644 --- a/rwengine/src/TextureArchive.cpp +++ b/rwengine/src/TextureArchive.cpp @@ -46,7 +46,7 @@ std::unique_ptr TextureArchive::create( bufSize); } - textureArchive->textures.push_back(std::move(texture)); + textureArchive->textures.push_back(texture); section = section->next; // Extension } diff --git a/rwengine/src/core/Logger.hpp b/rwengine/src/core/Logger.hpp index c026458f..0c82e8ac 100644 --- a/rwengine/src/core/Logger.hpp +++ b/rwengine/src/core/Logger.hpp @@ -3,6 +3,7 @@ #include #include +#include #include /** @@ -22,9 +23,12 @@ public: /// Logged message std::string message; - LogMessage(const std::string& cc, MessageSeverity ss, - const std::string& mm) - : component(cc), severity(ss), message(mm) { + template + LogMessage(String1&& cc, MessageSeverity ss, + String2&& mm) + : component(std::forward(cc)) + , severity(ss) + , message(std::forward(mm)) { } }; diff --git a/rwengine/src/data/AnimGroup.hpp b/rwengine/src/data/AnimGroup.hpp index 6601c122..605bb006 100644 --- a/rwengine/src/data/AnimGroup.hpp +++ b/rwengine/src/data/AnimGroup.hpp @@ -202,8 +202,13 @@ struct AnimCycleInfo { /// The actual animation AnimationPtr anim = nullptr; - AnimCycleInfo(const std::string& name = "", uint32_t flags = 0) - : name(name), flags(flags) { + template + AnimCycleInfo(String&& _name, uint32_t _flags = 0) + : name(std::forward(_name)) + , flags(_flags) { + } + AnimCycleInfo(uint32_t _flags = 0) + : flags(_flags) { } }; @@ -226,9 +231,10 @@ struct AnimGroup { static uint32_t getAnimationFlags(const std::string& animation); - AnimGroup(const std::string& name, + template + AnimGroup(String&& name, const std::initializer_list& cycles = {}) - : name_(name) { + : name_(std::forward(name)) { std::copy(std::begin(cycles), std::end(cycles), std::begin(animations_)); } diff --git a/rwengine/src/data/InstanceData.hpp b/rwengine/src/data/InstanceData.hpp index 0084b23f..f7be3b09 100644 --- a/rwengine/src/data/InstanceData.hpp +++ b/rwengine/src/data/InstanceData.hpp @@ -28,9 +28,10 @@ struct InstanceData { /** * Constructor */ - InstanceData(int _id, std::string _model, glm::vec3 _pos, glm::vec3 _scale, glm::quat _rot) + template + InstanceData(int _id, String&& _model, glm::vec3 _pos, glm::vec3 _scale, glm::quat _rot) : id(_id) - , model(_model) + , model(std::forward(_model)) , pos(_pos) , scale(_scale) , rot(_rot){ diff --git a/rwengine/src/data/ModelData.hpp b/rwengine/src/data/ModelData.hpp index 0662e049..13fe973a 100644 --- a/rwengine/src/data/ModelData.hpp +++ b/rwengine/src/data/ModelData.hpp @@ -137,7 +137,7 @@ public: } /// @todo change with librw - void setAtomic(ClumpPtr model, int n, AtomicPtr atomic) { + void setAtomic(const ClumpPtr& model, int n, const AtomicPtr& atomic) { model_ = model; /// @todo disassociated the Atomic from Clump atomics_[n] = atomic; @@ -281,7 +281,7 @@ public: ClumpModelInfo(ModelDataType type) : BaseModelInfo(type) { } - void setModel(ClumpPtr model) { + void setModel(const ClumpPtr& model) { model_ = model; } diff --git a/rwengine/src/data/ZoneData.hpp b/rwengine/src/data/ZoneData.hpp index 2cded80a..0205ddeb 100644 --- a/rwengine/src/data/ZoneData.hpp +++ b/rwengine/src/data/ZoneData.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #define ZONE_GANG_COUNT 13 @@ -73,11 +74,12 @@ struct ZoneData { */ std::vector children_ = {}; - ZoneData(const std::string& _name, const int& _type, const glm::vec3& _min, + template + ZoneData(String&& _name, const int& _type, const glm::vec3& _min, const glm::vec3& _max, const int& _island, const unsigned int& _pedGroupDay, const unsigned int& _pedGroupNight) - : name(_name) + : name(std::forward(_name)) , type(_type) , min(_min) , max(_max) diff --git a/rwengine/src/engine/Animator.cpp b/rwengine/src/engine/Animator.cpp index e8c1ac5a..5749839c 100644 --- a/rwengine/src/engine/Animator.cpp +++ b/rwengine/src/engine/Animator.cpp @@ -11,7 +11,7 @@ #include #include -Animator::Animator(ClumpPtr model) : model(model) { +Animator::Animator(const ClumpPtr& _model) : model(_model) { } void Animator::tick(float dt) { diff --git a/rwengine/src/engine/Animator.hpp b/rwengine/src/engine/Animator.hpp index f41c1645..59842ec9 100644 --- a/rwengine/src/engine/Animator.hpp +++ b/rwengine/src/engine/Animator.hpp @@ -46,7 +46,7 @@ class Animator { std::vector animations; public: - Animator(ClumpPtr model); + Animator(const ClumpPtr& _model); AnimationPtr getAnimation(unsigned int slot) { if (slot < animations.size()) { @@ -55,7 +55,7 @@ public: return nullptr; } - void playAnimation(unsigned int slot, AnimationPtr anim, float speed, + void playAnimation(unsigned int slot, const AnimationPtr& anim, float speed, bool repeat) { if (slot >= animations.size()) { animations.resize(slot + 1); diff --git a/rwengine/src/engine/GameWorld.cpp b/rwengine/src/engine/GameWorld.cpp index 6a25ee12..8ea01f3b 100644 --- a/rwengine/src/engine/GameWorld.cpp +++ b/rwengine/src/engine/GameWorld.cpp @@ -79,9 +79,7 @@ GameWorld::~GameWorld() { } } -bool GameWorld::placeItems(const std::string& name) { - std::string path = name; - +bool GameWorld::placeItems(const std::string& path) { LoaderIPL ipll; if (ipll.load(path)) { diff --git a/rwengine/src/loaders/LoaderIDE.cpp b/rwengine/src/loaders/LoaderIDE.cpp index 47ff665b..26d0ee1f 100644 --- a/rwengine/src/loaders/LoaderIDE.cpp +++ b/rwengine/src/loaders/LoaderIDE.cpp @@ -237,7 +237,7 @@ bool LoaderIDE::load(const std::string &filename, const PedStatsList &stats) { getline(buffstream, buff, ','); node.other_thing2 = atoi(buff.c_str()); - path.nodes.push_back(std::move(node)); + path.nodes.push_back(node); } auto &object = objects[path.ID]; diff --git a/rwengine/src/objects/CharacterObject.cpp b/rwengine/src/objects/CharacterObject.cpp index b5994f65..19a11591 100644 --- a/rwengine/src/objects/CharacterObject.cpp +++ b/rwengine/src/objects/CharacterObject.cpp @@ -552,7 +552,7 @@ void CharacterObject::resetToAINode() { } } -void CharacterObject::playActivityAnimation(AnimationPtr animation, bool repeat, +void CharacterObject::playActivityAnimation(const AnimationPtr& animation, bool repeat, bool blocked) { RW_CHECK(animator != nullptr, "No Animator"); animator->playAnimation(AnimIndexAction, animation, 1.f, repeat); @@ -574,7 +574,7 @@ void CharacterObject::playCycle(AnimCycle cycle) { } void CharacterObject::playCycleAnimOverride(AnimCycle cycle, - AnimationPtr anim) { + const AnimationPtr& anim) { auto flags = animations->flags(cycle); cycle_ = cycle; diff --git a/rwengine/src/objects/CharacterObject.hpp b/rwengine/src/objects/CharacterObject.hpp index f2f15b88..f6cd88ea 100644 --- a/rwengine/src/objects/CharacterObject.hpp +++ b/rwengine/src/objects/CharacterObject.hpp @@ -198,7 +198,7 @@ public: * This allows controller activities to play their own animations and * controll blending with movement. */ - void playActivityAnimation(AnimationPtr animation, bool repeat, + void playActivityAnimation(const AnimationPtr& animation, bool repeat, bool blocking); /** * @brief activityFinished removes activity animation @@ -218,7 +218,7 @@ public: * This sets the same state as playCycle, but provides an alternate * animation to play. */ - void playCycleAnimOverride(AnimCycle cycle, AnimationPtr anim); + void playCycleAnimOverride(AnimCycle cycle, const AnimationPtr& anim); AnimCycle getCurrentCycle() const { return cycle_; diff --git a/rwengine/src/objects/GameObject.hpp b/rwengine/src/objects/GameObject.hpp index 86c53e5c..b4927c34 100644 --- a/rwengine/src/objects/GameObject.hpp +++ b/rwengine/src/objects/GameObject.hpp @@ -110,7 +110,7 @@ public: /** * Changes the current model, used for re-dressing chars */ - void setModel(ClumpPtr model) { + void setModel(const ClumpPtr& model) { model_ = model; } @@ -248,7 +248,7 @@ class ClumpObject { ClumpPtr clump_; protected: - void setClump(ClumpPtr ptr) { + void setClump(const ClumpPtr& ptr) { clump_ = ptr; } diff --git a/rwengine/src/objects/InstanceObject.cpp b/rwengine/src/objects/InstanceObject.cpp index 30acd42c..084869e0 100644 --- a/rwengine/src/objects/InstanceObject.cpp +++ b/rwengine/src/objects/InstanceObject.cpp @@ -16,7 +16,7 @@ InstanceObject::InstanceObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, const glm::vec3& scale, BaseModelInfo* modelinfo, - std::shared_ptr dyn) + const std::shared_ptr& dyn) : GameObject(engine, pos, rot, modelinfo) , health(100.f) , scale(scale) diff --git a/rwengine/src/objects/InstanceObject.hpp b/rwengine/src/objects/InstanceObject.hpp index d2ecbdf0..7c845d52 100644 --- a/rwengine/src/objects/InstanceObject.hpp +++ b/rwengine/src/objects/InstanceObject.hpp @@ -36,7 +36,7 @@ public: InstanceObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, const glm::vec3& scale, BaseModelInfo* modelinfo, - std::shared_ptr dyn); + const std::shared_ptr& dyn); ~InstanceObject() override; Type type() const override { diff --git a/rwengine/src/render/GameRenderer.hpp b/rwengine/src/render/GameRenderer.hpp index dc7a5be9..590ce37f 100644 --- a/rwengine/src/render/GameRenderer.hpp +++ b/rwengine/src/render/GameRenderer.hpp @@ -171,7 +171,7 @@ public: * * GameRenderer will take ownership of the Model* pointer */ - void setSpecialModel(SpecialModel usage, ClumpPtr model) { + void setSpecialModel(SpecialModel usage, const ClumpPtr& model) { specialmodels_[usage] = model; } diff --git a/rwengine/src/script/ScriptMachine.hpp b/rwengine/src/script/ScriptMachine.hpp index 84b56a24..fdb1423c 100644 --- a/rwengine/src/script/ScriptMachine.hpp +++ b/rwengine/src/script/ScriptMachine.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -38,9 +39,10 @@ struct IllegalInstruction : SCMException { unsigned int offset; std::string thread; - IllegalInstruction(SCMOpcode opcode, unsigned int offset, - const std::string& thread) - : opcode(opcode), offset(offset), thread(thread) { + template + IllegalInstruction(SCMOpcode _opcode, unsigned int _offset, + String&& _thread) + : opcode(_opcode), offset(_offset), thread(std::forward(_thread)) { } std::string what() const override { @@ -58,8 +60,9 @@ struct UnknownType : SCMException { unsigned int offset; std::string thread; - UnknownType(SCMByte type, unsigned int offset, const std::string& thread) - : type(type), offset(offset), thread(thread) { + template + UnknownType(SCMByte _type, unsigned int _offset, String&& _thread) + : type(_type), offset(_offset), thread(std::forward(_thread)) { } std::string what() const override { diff --git a/rwengine/src/script/ScriptModule.hpp b/rwengine/src/script/ScriptModule.hpp index 44f2152c..5c905881 100644 --- a/rwengine/src/script/ScriptModule.hpp +++ b/rwengine/src/script/ScriptModule.hpp @@ -153,7 +153,9 @@ void do_unpacked_call(Tret (*const& func)(Targs...), */ class ScriptModule { public: - ScriptModule(const std::string& name) : name(name) { + template + ScriptModule(String&& _name) + : name(std::forward(_name)) { } const std::string& getName() const { diff --git a/rwgame/MenuSystem.hpp b/rwgame/MenuSystem.hpp index 530c4537..df717dd0 100644 --- a/rwgame/MenuSystem.hpp +++ b/rwgame/MenuSystem.hpp @@ -39,10 +39,10 @@ public: std::function callback; public: - MenuEntry(const std::string& n, std::function cb) + MenuEntry(const std::string& n, const std::function& cb) : text(GameStringUtil::fromString(n)), callback(cb) { } - MenuEntry(const GameString& n, std::function cb) + MenuEntry(const GameString& n, const std::function& cb) : text(n), callback(cb) { } diff --git a/rwgame/states/LoadingState.cpp b/rwgame/states/LoadingState.cpp index bf0e9a2b..58f9dc06 100644 --- a/rwgame/states/LoadingState.cpp +++ b/rwgame/states/LoadingState.cpp @@ -1,7 +1,7 @@ #include "LoadingState.hpp" #include "RWGame.hpp" -LoadingState::LoadingState(RWGame* game, std::function callback) +LoadingState::LoadingState(RWGame* game, const std::function& callback) : State(game), complete(callback) { } diff --git a/rwgame/states/LoadingState.hpp b/rwgame/states/LoadingState.hpp index fc8446c4..559362a3 100644 --- a/rwgame/states/LoadingState.hpp +++ b/rwgame/states/LoadingState.hpp @@ -8,7 +8,7 @@ class LoadingState : public State { std::function complete; public: - LoadingState(RWGame* game, std::function callback); + LoadingState(RWGame* game, const std::function& callback); void enter() override; diff --git a/rwlib/source/data/Clump.hpp b/rwlib/source/data/Clump.hpp index a4c6e9dc..e21d98f9 100644 --- a/rwlib/source/data/Clump.hpp +++ b/rwlib/source/data/Clump.hpp @@ -203,7 +203,7 @@ public: ATOMIC_RENDER = 0x04 }; - void setFrame(ModelFramePtr frame) { + void setFrame(const ModelFramePtr& frame) { frame_ = frame; } @@ -211,7 +211,7 @@ public: return frame_; } - void setGeometry(GeometryPtr geom) { + void setGeometry(const GeometryPtr& geom) { geometry_ = geom; } diff --git a/rwlib/source/loaders/LoaderDFF.hpp b/rwlib/source/loaders/LoaderDFF.hpp index c1ae7312..29d46cab 100644 --- a/rwlib/source/loaders/LoaderDFF.hpp +++ b/rwlib/source/loaders/LoaderDFF.hpp @@ -15,7 +15,8 @@ class DFFLoaderException { std::string _message; public: - DFFLoaderException(const std::string& message) : _message(message) { + template + DFFLoaderException(String&& message) : _message(message) { } const std::string& which() { @@ -32,7 +33,7 @@ public: ClumpPtr loadFromMemory(FileHandle file); - void setTextureLookupCallback(TextureLookupCallback tlc) { + void setTextureLookupCallback(const TextureLookupCallback& tlc) { texturelookup = tlc; } diff --git a/rwlib/source/loaders/LoaderSDT.cpp b/rwlib/source/loaders/LoaderSDT.cpp index 1af5f143..ee82b6fd 100644 --- a/rwlib/source/loaders/LoaderSDT.cpp +++ b/rwlib/source/loaders/LoaderSDT.cpp @@ -29,10 +29,9 @@ typedef struct { } data; } WaveHeader; -bool LoaderSDT::load(const std::string& filename) { - auto baseName = filename; - auto sdtName = baseName + ".SDT"; - auto rawName = baseName + ".RAW"; +bool LoaderSDT::load(const std::string& baseName) { + const auto sdtName = baseName + ".SDT"; + const auto rawName = baseName + ".RAW"; FILE* fp = fopen(sdtName.c_str(), "rb"); if (fp) {