Optimize parameter passing to avoid unnecessary copying
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "Block.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../core_defs.hpp"
|
||||
#include "../util/stringutil.hpp"
|
||||
|
||||
@@ -38,7 +40,7 @@ const BlockRotProfile BlockRotProfile::PANE {"pane", {
|
||||
{ { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }}, // West
|
||||
}};
|
||||
|
||||
Block::Block(std::string name)
|
||||
Block::Block(const std::string& name)
|
||||
: name(name),
|
||||
caption(util::id_to_caption(name)),
|
||||
textureFaces {TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,
|
||||
@@ -46,7 +48,7 @@ Block::Block(std::string name)
|
||||
rotations(BlockRotProfile::PIPE)
|
||||
{}
|
||||
|
||||
Block::Block(std::string name, std::string texture) : name(name),
|
||||
Block::Block(std::string name, const std::string& texture) : name(std::move(name)),
|
||||
textureFaces{texture,texture,texture,texture,texture,texture},
|
||||
rotations(BlockRotProfile::PIPE)
|
||||
{}
|
||||
|
||||
@@ -186,8 +186,8 @@ public:
|
||||
itemid_t pickingItem = 0;
|
||||
} rt;
|
||||
|
||||
Block(std::string name);
|
||||
Block(std::string name, std::string texture);
|
||||
Block(const std::string& name);
|
||||
Block(std::string name, const std::string& texture);
|
||||
Block(const Block&) = delete;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "Chunk.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "voxel.hpp"
|
||||
|
||||
#include "../items/Inventory.hpp"
|
||||
@@ -41,7 +43,7 @@ void Chunk::updateHeights() {
|
||||
|
||||
void Chunk::addBlockInventory(std::shared_ptr<Inventory> inventory,
|
||||
uint x, uint y, uint z) {
|
||||
inventories[vox_index(x, y, z)] = inventory;
|
||||
inventories[vox_index(x, y, z)] = std::move(inventory);
|
||||
flags.unsaved = true;
|
||||
}
|
||||
|
||||
@@ -52,7 +54,7 @@ void Chunk::removeBlockInventory(uint x, uint y, uint z) {
|
||||
}
|
||||
|
||||
void Chunk::setBlockInventories(chunk_inventories_map map) {
|
||||
inventories = map;
|
||||
inventories = std::move(map);
|
||||
}
|
||||
|
||||
std::shared_ptr<Inventory> Chunk::getBlockInventory(uint x, uint y, uint z) const {
|
||||
|
||||
@@ -480,7 +480,7 @@ void Chunks::_setOffset(int32_t x, int32_t z) {
|
||||
oz = z;
|
||||
}
|
||||
|
||||
bool Chunks::putChunk(std::shared_ptr<Chunk> chunk) {
|
||||
bool Chunks::putChunk(const std::shared_ptr<Chunk>& chunk) {
|
||||
int x = chunk->x;
|
||||
int z = chunk->z;
|
||||
x -= ox;
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
WorldFiles* worldFiles, LevelEvents* events, const Content* content);
|
||||
~Chunks() = default;
|
||||
|
||||
bool putChunk(std::shared_ptr<Chunk> chunk);
|
||||
bool putChunk(const std::shared_ptr<Chunk>& chunk);
|
||||
|
||||
Chunk* getChunk(int32_t x, int32_t z);
|
||||
Chunk* getChunkByVoxel(int32_t x, int32_t y, int32_t z);
|
||||
|
||||
@@ -18,7 +18,7 @@ static debug::Logger logger("chunks-storage");
|
||||
ChunksStorage::ChunksStorage(Level* level) : level(level) {
|
||||
}
|
||||
|
||||
void ChunksStorage::store(std::shared_ptr<Chunk> chunk) {
|
||||
void ChunksStorage::store(const std::shared_ptr<Chunk>& chunk) {
|
||||
chunksMap[glm::ivec2(chunk->x, chunk->z)] = chunk;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
~ChunksStorage() = default;
|
||||
|
||||
std::shared_ptr<Chunk> get(int x, int z) const;
|
||||
void store(std::shared_ptr<Chunk> chunk);
|
||||
void store(const std::shared_ptr<Chunk>& chunk);
|
||||
void remove(int x, int y);
|
||||
void getVoxels(VoxelsVolume* volume, bool backlight=false) const;
|
||||
std::shared_ptr<Chunk> create(int x, int z);
|
||||
|
||||
Reference in New Issue
Block a user