1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 10:22:52 +01:00

Rearrange passing args to functions/ctors

Kill extra shared_ptr by passing them using const reference.
Use perfect forwarding for strings.
Remove redundant std::move.
This commit is contained in:
Filip Gawin 2018-05-08 16:10:29 +02:00
parent 0c4e38a95b
commit 4e1948c23c
24 changed files with 64 additions and 48 deletions

View File

@ -46,7 +46,7 @@ std::unique_ptr<TextureArchive> TextureArchive::create(
bufSize);
}
textureArchive->textures.push_back(std::move(texture));
textureArchive->textures.push_back(texture);
section = section->next; // Extension
}

View File

@ -3,6 +3,7 @@
#include <initializer_list>
#include <string>
#include <utility>
#include <vector>
/**
@ -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 <class String1, class String2>
LogMessage(String1&& cc, MessageSeverity ss,
String2&& mm)
: component(std::forward<String1>(cc))
, severity(ss)
, message(std::forward<String2>(mm)) {
}
};

View File

@ -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 <class String>
AnimCycleInfo(String&& _name, uint32_t _flags = 0)
: name(std::forward<String>(_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 <class String>
AnimGroup(String&& name,
const std::initializer_list<AnimCycleInfo>& cycles = {})
: name_(name) {
: name_(std::forward<String>(name)) {
std::copy(std::begin(cycles), std::end(cycles),
std::begin(animations_));
}

View File

@ -28,9 +28,10 @@ struct InstanceData {
/**
* Constructor
*/
InstanceData(int _id, std::string _model, glm::vec3 _pos, glm::vec3 _scale, glm::quat _rot)
template <class String>
InstanceData(int _id, String&& _model, glm::vec3 _pos, glm::vec3 _scale, glm::quat _rot)
: id(_id)
, model(_model)
, model(std::forward<String>(_model))
, pos(_pos)
, scale(_scale)
, rot(_rot){

View File

@ -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;
}

View File

@ -5,6 +5,7 @@
#include <glm/glm.hpp>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#define ZONE_GANG_COUNT 13
@ -73,11 +74,12 @@ struct ZoneData {
*/
std::vector<ZoneData*> children_ = {};
ZoneData(const std::string& _name, const int& _type, const glm::vec3& _min,
template <class String>
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<String>(_name))
, type(_type)
, min(_min)
, max(_max)

View File

@ -11,7 +11,7 @@
#include <algorithm>
#include <cmath>
Animator::Animator(ClumpPtr model) : model(model) {
Animator::Animator(const ClumpPtr& _model) : model(_model) {
}
void Animator::tick(float dt) {

View File

@ -46,7 +46,7 @@ class Animator {
std::vector<AnimationState> 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);

View File

@ -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)) {

View File

@ -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];

View File

@ -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;

View File

@ -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_;

View File

@ -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;
}

View File

@ -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<DynamicObjectData> dyn)
const std::shared_ptr<DynamicObjectData>& dyn)
: GameObject(engine, pos, rot, modelinfo)
, health(100.f)
, scale(scale)

View File

@ -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<DynamicObjectData> dyn);
const std::shared_ptr<DynamicObjectData>& dyn);
~InstanceObject() override;
Type type() const override {

View File

@ -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;
}

View File

@ -7,6 +7,7 @@
#include <list>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <random>
#include <type_traits>
@ -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 <class String>
IllegalInstruction(SCMOpcode _opcode, unsigned int _offset,
String&& _thread)
: opcode(_opcode), offset(_offset), thread(std::forward<String>(_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 <class String>
UnknownType(SCMByte _type, unsigned int _offset, String&& _thread)
: type(_type), offset(_offset), thread(std::forward<String>(_thread)) {
}
std::string what() const override {

View File

@ -153,7 +153,9 @@ void do_unpacked_call(Tret (*const& func)(Targs...),
*/
class ScriptModule {
public:
ScriptModule(const std::string& name) : name(name) {
template <class String>
ScriptModule(String&& _name)
: name(std::forward<String>(_name)) {
}
const std::string& getName() const {

View File

@ -39,10 +39,10 @@ public:
std::function<void(void)> callback;
public:
MenuEntry(const std::string& n, std::function<void(void)> cb)
MenuEntry(const std::string& n, const std::function<void(void)>& cb)
: text(GameStringUtil::fromString(n)), callback(cb) {
}
MenuEntry(const GameString& n, std::function<void(void)> cb)
MenuEntry(const GameString& n, const std::function<void(void)>& cb)
: text(n), callback(cb) {
}

View File

@ -1,7 +1,7 @@
#include "LoadingState.hpp"
#include "RWGame.hpp"
LoadingState::LoadingState(RWGame* game, std::function<void(void)> callback)
LoadingState::LoadingState(RWGame* game, const std::function<void(void)>& callback)
: State(game), complete(callback) {
}

View File

@ -8,7 +8,7 @@ class LoadingState : public State {
std::function<void(void)> complete;
public:
LoadingState(RWGame* game, std::function<void(void)> callback);
LoadingState(RWGame* game, const std::function<void(void)>& callback);
void enter() override;

View File

@ -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;
}

View File

@ -15,7 +15,8 @@ class DFFLoaderException {
std::string _message;
public:
DFFLoaderException(const std::string& message) : _message(message) {
template <class String>
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;
}

View File

@ -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) {