Optimize parameter passing to avoid unnecessary copying

This commit is contained in:
Pugemon
2024-06-07 04:00:38 +03:00
parent 46ca1bb04a
commit f25a425cb9
123 changed files with 578 additions and 522 deletions
+11 -10
View File
@@ -16,23 +16,24 @@
#include <memory>
#include <glm/glm.hpp>
#include <utility>
static debug::Logger logger("world");
world_load_error::world_load_error(std::string message)
world_load_error::world_load_error(const std::string& message)
: std::runtime_error(message) {
}
World::World(
std::string name,
std::string generator,
fs::path directory,
const fs::path& directory,
uint64_t seed,
EngineSettings& settings,
const Content* content,
const std::vector<ContentPack> packs
) : name(name),
generator(generator),
const std::vector<ContentPack>& packs
) : name(std::move(name)),
generator(std::move(generator)),
seed(seed),
settings(settings),
content(content),
@@ -70,7 +71,7 @@ void World::write(Level* level) {
auto playerFile = dynamic::Map();
auto& players = playerFile.putList("players");
for (auto object : level->objects) {
for (const auto& object : level->objects) {
if (auto player = std::dynamic_pointer_cast<Player>(object)) {
players.put(player->serialize());
}
@@ -79,9 +80,9 @@ void World::write(Level* level) {
}
std::unique_ptr<Level> World::create(
std::string name,
std::string generator,
fs::path directory,
const std::string& name,
const std::string& generator,
const fs::path& directory,
uint64_t seed,
EngineSettings& settings,
const Content* content,
@@ -94,7 +95,7 @@ std::unique_ptr<Level> World::create(
}
std::unique_ptr<Level> World::load(
fs::path directory,
const fs::path& directory,
EngineSettings& settings,
const Content* content,
const std::vector<ContentPack>& packs