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

Merge pull request #447 from ShFil119/small_impr

[Ready] Perfect forwarding and some forgotten stuff
This commit is contained in:
darkf 2018-05-21 17:07:01 -05:00 committed by GitHub
commit 17077627fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 90 additions and 74 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

@ -1,6 +1,6 @@
#ifndef _RWENGINE_PATHDATA_HPP_
#define _RWENGINE_PATHDATA_HPP_
#include <stdint.h>
#include <cstdint>
#include <glm/glm.hpp>
#include <string>
#include <vector>

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,23 +79,21 @@ GameWorld::~GameWorld() {
}
bool GameWorld::placeItems(const std::string& name) {
std::string path = name;
LoaderIPL ipll;
if (ipll.load(path)) {
if (ipll.load(name)) {
// Find the object.
for (const auto& inst : ipll.m_instances) {
if (!createInstance(inst->id, inst->pos, inst->rot)) {
logger->error("World", "No object data for instance " +
std::to_string(inst->id) + " in " +
path);
name);
}
}
return true;
} else {
logger->error("Data", "Failed to load IPL " + path);
logger->error("Data", "Failed to load IPL " + name);
return false;
}

View File

@ -12,7 +12,7 @@
#include "data/CutsceneData.hpp"
#include "platform/FileHandle.hpp"
void LoaderCutsceneDAT::load(CutsceneTracks &tracks, FileHandle file) {
void LoaderCutsceneDAT::load(CutsceneTracks &tracks, const FileHandle& file) {
std::string dataStr(file->data, file->length);
std::stringstream ss(dataStr);

View File

@ -7,7 +7,7 @@ struct CutsceneTracks;
class LoaderCutsceneDAT {
public:
void load(CutsceneTracks& tracks, FileHandle file);
void load(CutsceneTracks& tracks, const FileHandle& file);
};
#endif

View File

@ -9,7 +9,7 @@
#include "data/GameTexts.hpp"
void LoaderGXT::load(GameTexts &texts, FileHandle &file) {
void LoaderGXT::load(GameTexts &texts, const FileHandle &file) {
auto data = file->data;
data += 4; // TKEY

View File

@ -6,7 +6,7 @@ class GameTexts;
class LoaderGXT {
public:
void load(GameTexts& texts, FileHandle& file);
void load(GameTexts& texts, const FileHandle& file);
};
#endif

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

@ -578,7 +578,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);
@ -600,7 +600,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

@ -207,7 +207,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
@ -227,7 +227,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

@ -6,7 +6,7 @@
#include "engine/Animator.hpp"
CutsceneObject::CutsceneObject(GameWorld *engine, const glm::vec3 &pos,
const glm::quat &rot, ClumpPtr model,
const glm::quat &rot, const ClumpPtr& model,
BaseModelInfo *modelinfo)
: GameObject(engine, pos, rot, modelinfo)
, _parent(nullptr)

View File

@ -19,7 +19,7 @@ class CutsceneObject : public GameObject, public ClumpObject {
public:
CutsceneObject(GameWorld* engine, const glm::vec3& pos,
const glm::quat& rot, ClumpPtr model,
const glm::quat& rot, const ClumpPtr& model,
BaseModelInfo* modelinfo);
~CutsceneObject() override;

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

@ -261,7 +261,7 @@ public:
OpenGLShaderProgram(GLuint p) : program(p) {
}
~OpenGLShaderProgram() {
~OpenGLShaderProgram() override {
glDeleteProgram(program);
}
@ -284,7 +284,7 @@ public:
OpenGLRenderer();
~OpenGLRenderer() = default;
~OpenGLRenderer() override = default;
std::string getIDString() const override;

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

@ -42,7 +42,7 @@ void ModelFrame::updateHierarchyTransform() {
}
}
void ModelFrame::addChild(ModelFramePtr child) {
void ModelFrame::addChild(const ModelFramePtr& child) {
// Make sure the child is an orphan
if (child->getParent()) {
auto& other_children = child->getParent()->children_;

View File

@ -87,7 +87,7 @@ public:
return parent_;
}
void addChild(ModelFramePtr child);
void addChild(const ModelFramePtr& child);
const std::vector<ModelFramePtr>& getChildren() const {
return children_;
@ -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;
}
@ -259,7 +259,7 @@ public:
return boundingRadius;
}
void addAtomic(AtomicPtr& atomic) {
void addAtomic(const AtomicPtr& atomic) {
atomics_.push_back(atomic);
}
@ -267,7 +267,7 @@ public:
return atomics_;
}
void setFrame(ModelFramePtr& root) {
void setFrame(const ModelFramePtr& root) {
rootframe_ = root;
}

View File

@ -270,7 +270,7 @@ GeometryPtr LoaderDFF::readGeometry(const RWBStream &stream) {
return geom;
}
void LoaderDFF::readMaterialList(GeometryPtr &geom, const RWBStream &stream) {
void LoaderDFF::readMaterialList(const GeometryPtr &geom, const RWBStream &stream) {
auto listStream = stream.getInnerStream();
auto listStructID = listStream.getNextChunk();
@ -294,7 +294,7 @@ void LoaderDFF::readMaterialList(GeometryPtr &geom, const RWBStream &stream) {
}
}
void LoaderDFF::readMaterial(GeometryPtr &geom, const RWBStream &stream) {
void LoaderDFF::readMaterial(const GeometryPtr &geom, const RWBStream &stream) {
auto materialStream = stream.getInnerStream();
auto matStructID = materialStream.getNextChunk();
@ -367,7 +367,7 @@ void LoaderDFF::readTexture(Geometry::Material &material,
material.textures.emplace_back(std::move(name), std::move(alpha), textureinst);
}
void LoaderDFF::readGeometryExtension(GeometryPtr &geom,
void LoaderDFF::readGeometryExtension(const GeometryPtr &geom,
const RWBStream &stream) {
auto extStream = stream.getInnerStream();
@ -383,7 +383,7 @@ void LoaderDFF::readGeometryExtension(GeometryPtr &geom,
}
}
void LoaderDFF::readBinMeshPLG(GeometryPtr &geom, const RWBStream &stream) {
void LoaderDFF::readBinMeshPLG(const GeometryPtr &geom, const RWBStream &stream) {
auto data = stream.getCursor();
geom->facetype = static_cast<Geometry::FaceType>(bit_cast<std::uint32_t>(*data));
@ -454,7 +454,7 @@ AtomicPtr LoaderDFF::readAtomic(FrameList &framelist,
return atomic;
}
ClumpPtr LoaderDFF::loadFromMemory(FileHandle file) {
ClumpPtr LoaderDFF::loadFromMemory(const FileHandle& file) {
auto model = std::make_shared<Clump>();
RWBStream rootStream(file->data, file->length);

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() {
@ -30,9 +31,9 @@ public:
using GeometryList = std::vector<GeometryPtr>;
using FrameList = std::vector<ModelFramePtr>;
ClumpPtr loadFromMemory(FileHandle file);
ClumpPtr loadFromMemory(const FileHandle& file);
void setTextureLookupCallback(TextureLookupCallback tlc) {
void setTextureLookupCallback(const TextureLookupCallback& tlc) {
texturelookup = tlc;
}
@ -45,15 +46,15 @@ private:
GeometryPtr readGeometry(const RWBStream& stream);
void readMaterialList(GeometryPtr& geom, const RWBStream& stream);
void readMaterialList(const GeometryPtr& geom, const RWBStream& stream);
void readMaterial(GeometryPtr& geom, const RWBStream& stream);
void readMaterial(const GeometryPtr& geom, const RWBStream& stream);
void readTexture(Geometry::Material& material, const RWBStream& stream);
void readGeometryExtension(GeometryPtr& geom, const RWBStream& stream);
void readGeometryExtension(const GeometryPtr& geom, const RWBStream& stream);
void readBinMeshPLG(GeometryPtr& geom, const RWBStream& stream);
void readBinMeshPLG(const GeometryPtr& geom, const RWBStream& stream);
AtomicPtr readAtomic(FrameList& framelist, GeometryList& geometrylist,
const RWBStream& stream);

View File

@ -30,9 +30,8 @@ typedef struct {
} WaveHeader;
bool LoaderSDT::load(const std::string& filename) {
auto baseName = filename;
auto sdtName = baseName + ".SDT";
auto rawName = baseName + ".RAW";
const auto sdtName = filename + ".SDT";
const auto rawName = filename + ".RAW";
FILE* fp = fopen(sdtName.c_str(), "rb");
if (fp) {

View File

@ -172,7 +172,7 @@ TextureData::Handle createTexture(RW::BSTextureNative& texNative,
transparent);
}
bool TextureLoader::loadFromMemory(FileHandle file,
bool TextureLoader::loadFromMemory(const FileHandle& file,
TextureArchive& inTextures) {
auto data = file->data;
RW::BinaryStreamSection root(data);

View File

@ -6,7 +6,7 @@
class TextureLoader {
public:
bool loadFromMemory(FileHandle file, TextureArchive& inTextures);
bool loadFromMemory(const FileHandle& file, TextureArchive& inTextures);
};
#endif