Revert "fix: optimization: Various PVS-Studio warnings"

This commit is contained in:
MihailRis 2024-08-02 14:51:44 +03:00 committed by GitHub
parent a7ef7bb365
commit ba046a52c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
90 changed files with 259 additions and 274 deletions

View File

@ -1,6 +1,7 @@
#include "Assets.hpp" #include "Assets.hpp"
Assets::~Assets() = default; Assets::~Assets() {
}
const std::vector<TextureAnimation>& Assets::getAnimations() { const std::vector<TextureAnimation>& Assets::getAnimations() {
return animations; return animations;

View File

@ -68,7 +68,7 @@ class Assets {
std::unordered_map<std::type_index, assets_map> assets; std::unordered_map<std::type_index, assets_map> assets;
std::vector<assetload::setupfunc> setupFuncs; std::vector<assetload::setupfunc> setupFuncs;
public: public:
Assets() = default; Assets() {}
Assets(const Assets&) = delete; Assets(const Assets&) = delete;
~Assets(); ~Assets();

View File

@ -40,8 +40,7 @@ namespace AL {
/// @param field enum value /// @param field enum value
/// @param def default value will be returned in case of error /// @param def default value will be returned in case of error
/// @return field value or default /// @return field value or default
inline glm::vec3 getSource3f(uint source, ALenum field, const glm::vec3& def= {} inline glm::vec3 getSource3f(uint source, ALenum field, glm::vec3 def={}) {
) {
glm::vec3 value = def; glm::vec3 value = def;
if (source == 0) if (source == 0)
return def; return def;

View File

@ -210,10 +210,10 @@ std::unique_ptr<Stream> audio::open_stream(std::shared_ptr<PCMStream> stream, bo
void audio::set_listener( void audio::set_listener(
const glm::vec3& position, glm::vec3 position,
const glm::vec3& velocity, glm::vec3 velocity,
const glm::vec3& lookAt, glm::vec3 lookAt,
const glm::vec3& up glm::vec3 up
) { ) {
backend->setListener(position, velocity, lookAt, up); backend->setListener(position, velocity, lookAt, up);
} }
@ -253,7 +253,7 @@ speakerid_t audio::play(
if (!sound->variants.empty()) { if (!sound->variants.empty()) {
size_t index = rand() % (sound->variants.size() + 1); size_t index = rand() % (sound->variants.size() + 1);
if (index < sound->variants.size()) { if (index < sound->variants.size()) {
sound = sound->variants[index].get(); sound = sound->variants.at(index).get();
} }
} }
auto speaker_ptr = sound->newInstance(priority, channel); auto speaker_ptr = sound->newInstance(priority, channel);
@ -266,7 +266,7 @@ speakerid_t audio::play(
} }
auto speaker = speaker_ptr.get(); auto speaker = speaker_ptr.get();
speakerid_t id = nextId++; speakerid_t id = nextId++;
speakers.try_emplace(id, std::move(speaker_ptr)); speakers.emplace(id, std::move(speaker_ptr));
speaker->setPosition(position); speaker->setPosition(position);
speaker->setVolume(volume); speaker->setVolume(volume);
speaker->setPitch(pitch); speaker->setPitch(pitch);
@ -295,8 +295,8 @@ speakerid_t audio::play(
} }
auto speaker = speaker_ptr.get(); auto speaker = speaker_ptr.get();
speakerid_t id = nextId++; speakerid_t id = nextId++;
streams.try_emplace(id, stream); streams.emplace(id, stream);
speakers.try_emplace(id, std::move(speaker_ptr)); speakers.emplace(id, std::move(speaker_ptr));
stream->bindSpeaker(id); stream->bindSpeaker(id);
speaker->setPosition(position); speaker->setPosition(position);
@ -310,7 +310,7 @@ speakerid_t audio::play(
speakerid_t audio::play_stream( speakerid_t audio::play_stream(
const fs::path& file, const fs::path& file,
const glm::vec3& position, glm::vec3 position,
bool relative, bool relative,
float volume, float volume,
float pitch, float pitch,

View File

@ -399,10 +399,10 @@ namespace audio {
/// @param lookAt point the listener look at /// @param lookAt point the listener look at
/// @param up camera up vector /// @param up camera up vector
void set_listener( void set_listener(
const glm::vec3& position, glm::vec3 position,
const glm::vec3& velocity, glm::vec3 velocity,
const glm::vec3& lookAt, glm::vec3 lookAt,
const glm::vec3& up glm::vec3 up
); );
/// @brief Play 3D sound in the world /// @brief Play 3D sound in the world
@ -457,7 +457,7 @@ namespace audio {
/// @return speaker id or 0 /// @return speaker id or 0
speakerid_t play_stream( speakerid_t play_stream(
const fs::path& file, const fs::path& file,
const glm::vec3& position, glm::vec3 position,
bool relative, bool relative,
float volume, float volume,
float pitch, float pitch,

View File

@ -23,7 +23,7 @@ namespace xml {
std::string name; std::string name;
std::string text; std::string text;
public: public:
Attribute() = default; Attribute() {};
Attribute(std::string name, std::string text); Attribute(std::string name, std::string text);
const std::string& getName() const; const std::string& getName() const;

View File

@ -46,7 +46,8 @@ Content::Content(
} }
} }
Content::~Content() = default; Content::~Content() {
}
const rigging::SkeletonConfig* Content::getSkeleton(const std::string& id) const { const rigging::SkeletonConfig* Content::getSkeleton(const std::string& id) const {
auto found = skeletons.find(id); auto found = skeletons.find(id);

View File

@ -119,7 +119,7 @@ public:
static constexpr size_t MISSING = SIZE_MAX; static constexpr size_t MISSING = SIZE_MAX;
void add(const std::string& name, dynamic::Map_sptr map) { void add(std::string name, dynamic::Map_sptr map) {
indices[name] = names.size(); indices[name] = names.size();
names.push_back(name); names.push_back(name);
savedData->push_back(map); savedData->push_back(map);

View File

@ -2,7 +2,7 @@
#include "../objects/rigging.hpp" #include "../objects/rigging.hpp"
ContentBuilder::~ContentBuilder() = default; ContentBuilder::~ContentBuilder() {}
void ContentBuilder::add(std::unique_ptr<ContentPackRuntime> pack) { void ContentBuilder::add(std::unique_ptr<ContentPackRuntime> pack) {
packs[pack->getId()] = std::move(pack); packs[pack->getId()] = std::move(pack);

View File

@ -85,7 +85,7 @@ bool ContentLoader::fixPackIndices(
indexed.push_back(name); indexed.push_back(name);
} }
} }
for (const auto &name : detected) { for (auto name : detected) {
if (!util::contains(indexed, name)) { if (!util::contains(indexed, name)) {
arr->put(name); arr->put(name);
modified = true; modified = true;
@ -176,10 +176,9 @@ void ContentLoader::loadBlock(Block& def, const std::string& name, const fs::pat
def.hitboxes.resize(boxarr->size()); def.hitboxes.resize(boxarr->size());
for (uint i = 0; i < boxarr->size(); i++) { for (uint i = 0; i < boxarr->size(); i++) {
auto box = boxarr->list(i); auto box = boxarr->list(i);
auto& hitboxesIndex = def.hitboxes[i]; def.hitboxes[i].a = glm::vec3(box->num(0), box->num(1), box->num(2));
hitboxesIndex.a = glm::vec3(box->num(0), box->num(1), box->num(2)); def.hitboxes[i].b = glm::vec3(box->num(3), box->num(4), box->num(5));
hitboxesIndex.b = glm::vec3(box->num(3), box->num(4), box->num(5)); def.hitboxes[i].b += def.hitboxes[i].a;
hitboxesIndex.b += hitboxesIndex.a;
} }
} else if ((boxarr = root->list("hitbox"))){ } else if ((boxarr = root->list("hitbox"))){
AABB aabb; AABB aabb;
@ -252,11 +251,11 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
if (boxarr->size() == 7) if (boxarr->size() == 7)
for (uint j = 6; j < 12; j++) { for (uint j = 6; j < 12; j++) {
def.modelTextures.emplace_back(boxarr->str(6)); def.modelTextures.push_back(boxarr->str(6));
} }
else if (boxarr->size() == 12) else if (boxarr->size() == 12)
for (uint j = 6; j < 12; j++) { for (uint j = 6; j < 12; j++) {
def.modelTextures.emplace_back(boxarr->str(j)); def.modelTextures.push_back(boxarr->str(j));
} }
else else
for (uint j = 6; j < 12; j++) { for (uint j = 6; j < 12; j++) {
@ -277,7 +276,7 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
def.modelExtraPoints.push_back(p1+xw+yh); def.modelExtraPoints.push_back(p1+xw+yh);
def.modelExtraPoints.push_back(p1+yh); def.modelExtraPoints.push_back(p1+yh);
def.modelTextures.emplace_back(tgonobj->str(9)); def.modelTextures.push_back(tgonobj->str(9));
} }
} }
} }
@ -314,7 +313,7 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
auto root = files::read_json(file); auto root = files::read_json(file);
if (auto componentsarr = root->list("components")) { if (auto componentsarr = root->list("components")) {
for (size_t i = 0; i < componentsarr->size(); i++) { for (size_t i = 0; i < componentsarr->size(); i++) {
def.components.emplace_back(componentsarr->str(i)); def.components.push_back(componentsarr->str(i));
} }
} }
if (auto boxarr = root->list("hitbox")) { if (auto boxarr = root->list("hitbox")) {
@ -325,12 +324,12 @@ void ContentLoader::loadEntity(EntityDef& def, const std::string& name, const fs
if (auto sensorarr = sensorsarr->list(i)) { if (auto sensorarr = sensorsarr->list(i)) {
auto sensorType = sensorarr->str(0); auto sensorType = sensorarr->str(0);
if (sensorType == "aabb") { if (sensorType == "aabb") {
def.boxSensors.emplace_back(i, AABB{ def.boxSensors.push_back({i, {
{sensorarr->num(1), sensorarr->num(2), sensorarr->num(3)}, {sensorarr->num(1), sensorarr->num(2), sensorarr->num(3)},
{sensorarr->num(4), sensorarr->num(5), sensorarr->num(6)} {sensorarr->num(4), sensorarr->num(5), sensorarr->num(6)}
}); }});
} else if (sensorType == "radius") { } else if (sensorType == "radius") {
def.radialSensors.emplace_back(i, sensorarr->num(1)); def.radialSensors.push_back({i, sensorarr->num(1)});
} else { } else {
logger.error() << name << ": sensor #" << i << " - unknown type " logger.error() << name << ": sensor #" << i << " - unknown type "
<< util::quote(sensorType); << util::quote(sensorType);

View File

@ -142,4 +142,5 @@ ContentPackRuntime::ContentPackRuntime(
{ {
} }
ContentPackRuntime::~ContentPackRuntime() = default; ContentPackRuntime::~ContentPackRuntime() {
}

View File

@ -5,10 +5,11 @@
#include <queue> #include <queue>
#include <sstream> #include <sstream>
PacksManager::PacksManager() = default; PacksManager::PacksManager() {
}
void PacksManager::setSources(std::vector<fs::path> sources) { void PacksManager::setSources(std::vector<fs::path> sources) {
this->sources = std::move(sources); this->sources = sources;
} }
void PacksManager::scan() { void PacksManager::scan() {
@ -18,7 +19,7 @@ void PacksManager::scan() {
for (auto& folder : sources) { for (auto& folder : sources) {
ContentPack::scanFolder(folder, packsList); ContentPack::scanFolder(folder, packsList);
for (auto& pack : packsList) { for (auto& pack : packsList) {
packs.try_emplace(pack.id, pack); packs.emplace(pack.id, pack);
} }
} }
} }

View File

@ -41,7 +41,7 @@ namespace dynamic {
public: public:
std::vector<Value> values; std::vector<Value> values;
List() = default; List() {}
List(std::vector<Value> values) : values(std::move(values)) {} List(std::vector<Value> values) : values(std::move(values)) {}
std::string str(size_t index) const; std::string str(size_t index) const;
@ -79,7 +79,7 @@ namespace dynamic {
public: public:
std::unordered_map<std::string, Value> values; std::unordered_map<std::string, Value> values;
Map() = default; Map() {}
Map(std::unordered_map<std::string, Value> values) Map(std::unordered_map<std::string, Value> values)
: values(std::move(values)) {}; : values(std::move(values)) {};
@ -118,34 +118,34 @@ namespace dynamic {
List_sptr list(const std::string& key) const; List_sptr list(const std::string& key) const;
void flag(const std::string& key, bool& dst) const; void flag(const std::string& key, bool& dst) const;
Map& put(const std::string& key, std::unique_ptr<Map> value) { Map& put(std::string key, std::unique_ptr<Map> value) {
return put(key, Map_sptr(value.release())); return put(key, Map_sptr(value.release()));
} }
Map& put(const std::string& key, std::unique_ptr<List> value) { Map& put(std::string key, std::unique_ptr<List> value) {
return put(key, List_sptr(value.release())); return put(key, List_sptr(value.release()));
} }
Map& put(const std::string& key, int value) { Map& put(std::string key, int value) {
return put(key, Value(static_cast<integer_t>(value))); return put(key, Value(static_cast<integer_t>(value)));
} }
Map& put(const std::string& key, unsigned int value) { Map& put(std::string key, unsigned int value) {
return put(key, Value(static_cast<integer_t>(value))); return put(key, Value(static_cast<integer_t>(value)));
} }
Map& put(const std::string& key, int64_t value) { Map& put(std::string key, int64_t value) {
return put(key, Value(static_cast<integer_t>(value))); return put(key, Value(static_cast<integer_t>(value)));
} }
Map& put(const std::string& key, uint64_t value) { Map& put(std::string key, uint64_t value) {
return put(key, Value(static_cast<integer_t>(value))); return put(key, Value(static_cast<integer_t>(value)));
} }
Map& put(const std::string& key, float value) { Map& put(std::string key, float value) {
return put(key, Value(static_cast<number_t>(value))); return put(key, Value(static_cast<number_t>(value)));
} }
Map& put(const std::string& key, double value) { Map& put(std::string key, double value) {
return put(key, Value(static_cast<number_t>(value))); return put(key, Value(static_cast<number_t>(value)));
} }
Map& put(const std::string& key, bool value) { Map& put(std::string key, bool value) {
return put(key, Value(static_cast<bool>(value))); return put(key, Value(static_cast<bool>(value)));
} }
Map& put(const std::string& key, const char* value) { Map& put(std::string key, const char* value) {
return put(key, Value(value)); return put(key, Value(value));
} }
Map& put(const std::string& key, const Value& value); Map& put(const std::string& key, const Value& value);

View File

@ -55,7 +55,7 @@ static void add_world_generators() {
WorldGenerators::addGenerator<FlatWorldGenerator>("core:flat"); WorldGenerators::addGenerator<FlatWorldGenerator>("core:flat");
} }
static void create_channel(Engine* engine, const std::string& name, NumberSetting& setting) { static void create_channel(Engine* engine, std::string name, NumberSetting& setting) {
if (name != "master") { if (name != "master") {
audio::create_channel(name); audio::create_channel(name);
} }

View File

@ -73,12 +73,11 @@ std::shared_ptr<Task> WorldConverter::startTask(
[=](){return std::make_shared<ConverterWorker>(converter);}, [=](){return std::make_shared<ConverterWorker>(converter);},
[=](int&) {} [=](int&) {}
); );
auto& converterTasks = converter->tasks; while (!converter->tasks.empty()) {
while (!converterTasks.empty()) { const convert_task& task = converter->tasks.front();
const convert_task& task = converterTasks.front();
auto ptr = std::make_shared<convert_task>(task); auto ptr = std::make_shared<convert_task>(task);
pool->enqueueJob(ptr); pool->enqueueJob(ptr);
converterTasks.pop(); converter->tasks.pop();
} }
pool->setOnComplete([=]() { pool->setOnComplete([=]() {
converter->write(); converter->write();

View File

@ -47,7 +47,8 @@ WorldFiles::WorldFiles(const fs::path& directory, const DebugSettings& settings)
regions.doWriteLights = doWriteLights; regions.doWriteLights = doWriteLights;
} }
WorldFiles::~WorldFiles() = default; WorldFiles::~WorldFiles() {
}
void WorldFiles::createDirectories() { void WorldFiles::createDirectories() {
fs::create_directories(directory / fs::path("data")); fs::create_directories(directory / fs::path("data"));

View File

@ -56,7 +56,8 @@ WorldRegion::WorldRegion()
sizes(std::make_unique<uint32_t[]>(REGION_CHUNKS_COUNT)) sizes(std::make_unique<uint32_t[]>(REGION_CHUNKS_COUNT))
{} {}
WorldRegion::~WorldRegion() = default; WorldRegion::~WorldRegion() {
}
void WorldRegion::setUnsaved(bool unsaved) { void WorldRegion::setUnsaved(bool unsaved) {
this->unsaved = unsaved; this->unsaved = unsaved;
@ -97,7 +98,8 @@ WorldRegions::WorldRegions(const fs::path& directory) : directory(directory) {
layers[REGION_LAYER_ENTITIES].folder = directory/fs::path("entities"); layers[REGION_LAYER_ENTITIES].folder = directory/fs::path("entities");
} }
WorldRegions::~WorldRegions() = default; WorldRegions::~WorldRegions() {
}
WorldRegion* WorldRegions::getRegion(int x, int z, int layer) { WorldRegion* WorldRegions::getRegion(int x, int z, int layer) {
RegionsLayer& regions = layers[layer]; RegionsLayer& regions = layers[layer];
@ -196,7 +198,7 @@ ubyte* WorldRegions::getData(int x, int z, int layer, uint32_t& size) {
return nullptr; return nullptr;
} }
regfile_ptr WorldRegions::useRegFile(const glm::ivec3& coord) { regfile_ptr WorldRegions::useRegFile(glm::ivec3 coord) {
auto* file = openRegFiles[coord].get(); auto* file = openRegFiles[coord].get();
file->inUse = true; file->inUse = true;
return regfile_ptr(file, &regFilesCv); return regfile_ptr(file, &regFilesCv);
@ -208,7 +210,7 @@ void WorldRegions::closeRegFile(glm::ivec3 coord) {
} }
// Marks regfile as used and unmarks when shared_ptr dies // Marks regfile as used and unmarks when shared_ptr dies
regfile_ptr WorldRegions::getRegFile(const glm::ivec3& coord, bool create) { regfile_ptr WorldRegions::getRegFile(glm::ivec3 coord, bool create) {
{ {
std::lock_guard lock(regFilesMutex); std::lock_guard lock(regFilesMutex);
const auto found = openRegFiles.find(coord); const auto found = openRegFiles.find(coord);
@ -225,7 +227,7 @@ regfile_ptr WorldRegions::getRegFile(const glm::ivec3& coord, bool create) {
return nullptr; return nullptr;
} }
regfile_ptr WorldRegions::createRegFile(const glm::ivec3& coord) { regfile_ptr WorldRegions::createRegFile(glm::ivec3 coord) {
fs::path file = layers[coord[2]].folder/getRegionFilename(coord[0], coord[1]); fs::path file = layers[coord[2]].folder/getRegionFilename(coord[0], coord[1]);
if (!fs::exists(file)) { if (!fs::exists(file)) {
return nullptr; return nullptr;
@ -352,7 +354,7 @@ static std::unique_ptr<ubyte[]> write_inventories(Chunk* chunk, uint& datasize)
} }
/// @brief Store chunk data (voxels and lights) in region (existing or new) /// @brief Store chunk data (voxels and lights) in region (existing or new)
void WorldRegions::put(Chunk* chunk, const std::vector<ubyte>& entitiesData){ void WorldRegions::put(Chunk* chunk, std::vector<ubyte> entitiesData){
assert(chunk != nullptr); assert(chunk != nullptr);
if (!chunk->flags.lighted) { if (!chunk->flags.lighted) {
return; return;

View File

@ -149,10 +149,10 @@ class WorldRegions {
ubyte* getData(int x, int z, int layer, uint32_t& size); ubyte* getData(int x, int z, int layer, uint32_t& size);
regfile_ptr getRegFile(const glm::ivec3& coord, bool create=true); regfile_ptr getRegFile(glm::ivec3 coord, bool create=true);
void closeRegFile(glm::ivec3 coord); void closeRegFile(glm::ivec3 coord);
regfile_ptr useRegFile(const glm::ivec3& coord); regfile_ptr useRegFile(glm::ivec3 coord);
regfile_ptr createRegFile(const glm::ivec3& coord); regfile_ptr createRegFile(glm::ivec3 coord);
fs::path getRegionFilename(int x, int y) const; fs::path getRegionFilename(int x, int y) const;
@ -172,7 +172,7 @@ public:
~WorldRegions(); ~WorldRegions();
/// @brief Put all chunk data to regions /// @brief Put all chunk data to regions
void put(Chunk* chunk, const std::vector<ubyte>& entitiesData); void put(Chunk* chunk, std::vector<ubyte> entitiesData);
/// @brief Store data in specified region /// @brief Store data in specified region
/// @param x chunk.x /// @param x chunk.x

View File

@ -214,7 +214,7 @@ std::vector<std::string> ResPaths::listdirRaw(const std::string& folderName) con
continue; continue;
for (const auto& entry : fs::directory_iterator(folder)) { for (const auto& entry : fs::directory_iterator(folder)) {
auto name = entry.path().filename().u8string(); auto name = entry.path().filename().u8string();
entries.emplace_back(root.name+":"+folderName+"/"+name); entries.push_back(root.name+":"+folderName+"/"+name);
} }
} }
{ {
@ -223,7 +223,7 @@ std::vector<std::string> ResPaths::listdirRaw(const std::string& folderName) con
return entries; return entries;
for (const auto& entry : fs::directory_iterator(folder)) { for (const auto& entry : fs::directory_iterator(folder)) {
auto name = entry.path().filename().u8string(); auto name = entry.path().filename().u8string();
entries.emplace_back("core:"+folderName+"/"+name); entries.push_back("core:"+folderName+"/"+name);
} }
} }
return entries; return entries;

View File

@ -103,7 +103,7 @@ std::string files::read_string(const fs::path& filename) {
return std::string((const char*)bytes.get(), size); return std::string((const char*)bytes.get(), size);
} }
bool files::write_string(const fs::path& filename, const std::string& content) { bool files::write_string(const fs::path& filename, const std::string content) {
std::ofstream file(filename); std::ofstream file(filename);
if (!file) { if (!file) {
return false; return false;

View File

@ -40,7 +40,7 @@ namespace files {
uint append_bytes(const fs::path& file, const ubyte* data, size_t size); uint append_bytes(const fs::path& file, const ubyte* data, size_t size);
/// @brief Write string to the file /// @brief Write string to the file
bool write_string(const fs::path& filename, const std::string& content); bool write_string(const fs::path& filename, const std::string content);
/// @brief Write dynamic data to the JSON file /// @brief Write dynamic data to the JSON file
/// @param nice if true, human readable format will be used, otherwise minimal /// @param nice if true, human readable format will be used, otherwise minimal

View File

@ -38,7 +38,8 @@ ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets) : conte
} }
} }
ContentGfxCache::~ContentGfxCache() = default; ContentGfxCache::~ContentGfxCache() {
}
const Content* ContentGfxCache::getContent() const { const Content* ContentGfxCache::getContent() const {
return content; return content;

View File

@ -81,7 +81,8 @@ LevelFrontend::LevelFrontend(
); );
} }
LevelFrontend::~LevelFrontend() = default; LevelFrontend::~LevelFrontend() {
}
Level* LevelFrontend::getLevel() const { Level* LevelFrontend::getLevel() const {
return level; return level;

View File

@ -314,7 +314,7 @@ void Hud::openInventory() {
} }
void Hud::openInventory( void Hud::openInventory(
const glm::ivec3& block, glm::ivec3 block,
UiDocument* doc, UiDocument* doc,
std::shared_ptr<Inventory> blockinv, std::shared_ptr<Inventory> blockinv,
bool playerInventory bool playerInventory
@ -406,9 +406,9 @@ void Hud::add(const HudElement& element) {
using namespace dynamic; using namespace dynamic;
gui->add(element.getNode()); gui->add(element.getNode());
auto invview = std::dynamic_pointer_cast<InventoryView>(element.getNode());
auto document = element.getDocument(); auto document = element.getDocument();
if (document) { if (document) {
auto invview = std::dynamic_pointer_cast<InventoryView>(element.getNode());
auto inventory = invview ? invview->getInventory() : nullptr; auto inventory = invview ? invview->getInventory() : nullptr;
std::vector<Value> args; std::vector<Value> args;
args.emplace_back(inventory ? inventory.get()->getId() : 0); args.emplace_back(inventory ? inventory.get()->getId() : 0);

View File

@ -140,12 +140,12 @@ public:
/// @brief Show block inventory in inventory-mode /// @brief Show block inventory in inventory-mode
/// @param block block position /// @param block block position
/// @param doc block ui layout /// @param doc block ui layout
/// @param blockinv block inventory /// @param blockInv block inventory
/// @param playerInventory show player inventory too /// @param playerInventory show player inventory too
void openInventory( void openInventory(
const glm::ivec3& block, glm::ivec3 block,
UiDocument* doc, UiDocument* doc,
std::shared_ptr<Inventory> blockinv, std::shared_ptr<Inventory> blockInv,
bool playerInventory bool playerInventory
); );

View File

@ -146,7 +146,7 @@ void langs::load(const fs::path& resdir,
if (locale != fallback) { if (locale != fallback) {
load(resdir, locale, packs, *lang.get()); load(resdir, locale, packs, *lang.get());
} }
current = std::move(lang); current.reset(lang.release());
} }
void langs::setup(const fs::path& resdir, void langs::setup(const fs::path& resdir,

View File

@ -19,7 +19,8 @@ Atlas::Atlas(
} }
} }
Atlas::~Atlas() = default; Atlas::~Atlas() {
}
void Atlas::prepare() { void Atlas::prepare() {
texture = Texture::from(image.get()); texture = Texture::from(image.get());

View File

@ -47,7 +47,7 @@ class AtlasBuilder {
std::vector<atlasentry> entries; std::vector<atlasentry> entries;
std::set<std::string> names; std::set<std::string> names;
public: public:
AtlasBuilder() = default; AtlasBuilder() {}
void add(const std::string& name, std::unique_ptr<ImageData> image); void add(const std::string& name, std::unique_ptr<ImageData> image);
bool has(const std::string& name) const; bool has(const std::string& name) const;
const std::set<std::string>& getNames() { return names; }; const std::set<std::string>& getNames() { return names; };

View File

@ -59,8 +59,8 @@ void Batch2D::vertex(
buffer[index++] = a; buffer[index++] = a;
} }
void Batch2D::vertex( void Batch2D::vertex(
const glm::vec2& point, glm::vec2 point,
const glm::vec2& uvpoint, glm::vec2 uvpoint,
float r, float g, float b, float a float r, float g, float b, float a
) { ) {
buffer[index++] = point.x; buffer[index++] = point.x;
@ -138,7 +138,7 @@ void Batch2D::rect(
UVRegion region, UVRegion region,
bool flippedX, bool flippedX,
bool flippedY, bool flippedY,
const glm::vec4& tint glm::vec4 tint
) { ) {
if (index + 6*B2D_VERTEX_SIZE >= capacity) { if (index + 6*B2D_VERTEX_SIZE >= capacity) {
flush(); flush();
@ -322,13 +322,11 @@ void Batch2D::rect(
vertex(v1, glm::vec2(0, 0), r2,g2,b2,1.0f); vertex(v1, glm::vec2(0, 0), r2,g2,b2,1.0f);
} }
void Batch2D::sprite(float x, float y, float w, float h, const UVRegion& region, void Batch2D::sprite(float x, float y, float w, float h, const UVRegion& region, glm::vec4 tint){
const glm::vec4& tint){
rect(x, y, w, h, region.u1, region.v1, region.u2-region.u1, region.v2-region.v1, tint.r, tint.g, tint.b, tint.a); rect(x, y, w, h, region.u1, region.v1, region.u2-region.u1, region.v2-region.v1, tint.r, tint.g, tint.b, tint.a);
} }
void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index, void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index, glm::vec4 tint){
const glm::vec4& tint){
float scale = 1.0f / (float)atlasRes; float scale = 1.0f / (float)atlasRes;
float u = (index % atlasRes) * scale; float u = (index % atlasRes) * scale;
float v = 1.0f - ((index / atlasRes) * scale) - scale; float v = 1.0f - ((index / atlasRes) * scale) - scale;

View File

@ -31,8 +31,8 @@ class Batch2D : public Flushable {
); );
void vertex( void vertex(
const glm::vec2& point, glm::vec2 point,
const glm::vec2& uvpoint, glm::vec2 uvpoint,
float r, float g, float b, float a float r, float g, float b, float a
); );
@ -44,13 +44,11 @@ public:
void texture(Texture* texture); void texture(Texture* texture);
void untexture(); void untexture();
void setRegion(UVRegion region); void setRegion(UVRegion region);
void sprite(float x, float y, float w, float h, const UVRegion& region, void sprite(float x, float y, float w, float h, const UVRegion& region, glm::vec4 tint);
const glm::vec4& tint); void sprite(float x, float y, float w, float h, int atlasRes, int index, glm::vec4 tint);
void sprite(float x, float y, float w, float h, int atlasRes, int index,
const glm::vec4& tint);
void point(float x, float y, float r, float g, float b, float a); void point(float x, float y, float r, float g, float b, float a);
inline void setColor(const glm::vec4& color) { inline void setColor(glm::vec4 color) {
this->color = color; this->color = color;
} }
inline glm::vec4 getColor() const { inline glm::vec4 getColor() const {
@ -71,7 +69,7 @@ public:
float ox, float oy, float ox, float oy,
float angle, UVRegion region, float angle, UVRegion region,
bool flippedX, bool flippedY, bool flippedX, bool flippedY,
const glm::vec4& tint glm::vec4 tint
); );
void rect(float x, float y, float w, float h); void rect(float x, float y, float w, float h);

View File

@ -51,7 +51,7 @@ void Batch3D::vertex(
buffer[index++] = a; buffer[index++] = a;
} }
void Batch3D::vertex( void Batch3D::vertex(
const glm::vec3& coord, float u, float v, glm::vec3 coord, float u, float v,
float r, float g, float b, float a float r, float g, float b, float a
) { ) {
buffer[index++] = coord.x; buffer[index++] = coord.x;
@ -65,8 +65,8 @@ void Batch3D::vertex(
buffer[index++] = a; buffer[index++] = a;
} }
void Batch3D::vertex( void Batch3D::vertex(
const glm::vec3& point, glm::vec3 point,
const glm::vec2& uvpoint, glm::vec2 uvpoint,
float r, float g, float b, float a float r, float g, float b, float a
) { ) {
buffer[index++] = point.x; buffer[index++] = point.x;
@ -118,12 +118,12 @@ void Batch3D::texture(Texture* new_texture){
} }
void Batch3D::sprite( void Batch3D::sprite(
const glm::vec3& pos, glm::vec3 pos,
const glm::vec3& up, glm::vec3 up,
const glm::vec3& right, glm::vec3 right,
float w, float h, float w, float h,
const UVRegion& uv, const UVRegion& uv,
const glm::vec4& color glm::vec4 color
){ ){
const float r = color.r; const float r = color.r;
const float g = color.g; const float g = color.g;
@ -245,11 +245,11 @@ void Batch3D::blockCube(
cube((1.0f - size) * -0.5f, size, texfaces, tint, shading); cube((1.0f - size) * -0.5f, size, texfaces, tint, shading);
} }
void Batch3D::point(const glm::vec3& coord, const glm::vec2& uv, const glm::vec4& tint) { void Batch3D::point(glm::vec3 coord, glm::vec2 uv, glm::vec4 tint) {
vertex(coord, uv, tint.r, tint.g, tint.b, tint.a); vertex(coord, uv, tint.r, tint.g, tint.b, tint.a);
} }
void Batch3D::point(const glm::vec3& coord, const glm::vec4& tint) { void Batch3D::point(glm::vec3 coord, glm::vec4 tint) {
point(coord, glm::vec2(), tint); point(coord, glm::vec2(), tint);
} }

View File

@ -27,13 +27,12 @@ class Batch3D : public Flushable {
float r, float g, float b, float a float r, float g, float b, float a
); );
void vertex( void vertex(
const glm::vec3& coord, glm::vec3 coord,
float u, float v, float u, float v,
float r, float g, float b, float a float r, float g, float b, float a
); );
void vertex( void vertex(
const glm::vec3& point, glm::vec3 point, glm::vec2 uvpoint,
const glm::vec2& uvpoint,
float r, float g, float b, float a float r, float g, float b, float a
); );
void face( void face(
@ -50,18 +49,12 @@ public:
void begin(); void begin();
void texture(Texture* texture); void texture(Texture* texture);
void sprite( void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h, const UVRegion& uv, glm::vec4 tint);
const glm::vec3& pos,
const glm::vec3& up,
const glm::vec3& right, float w, float h, const UVRegion& uv,
const glm::vec4& color
);
void xSprite(float w, float h, const UVRegion& uv, const glm::vec4 tint, bool shading=true); void xSprite(float w, float h, const UVRegion& uv, const glm::vec4 tint, bool shading=true);
void cube(const glm::vec3 coords, const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true); void cube(const glm::vec3 coords, const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true);
void blockCube(const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true); void blockCube(const glm::vec3 size, const UVRegion(&texfaces)[6], const glm::vec4 tint, bool shading=true);
void point( void point(glm::vec3 pos, glm::vec2 uv, glm::vec4 tint);
const glm::vec3& coord, const glm::vec2& uv, const glm::vec4& tint); void point(glm::vec3 pos, glm::vec4 tint);
void point(const glm::vec3& coord, const glm::vec4& tint);
void flush() override; void flush() override;
void flushPoints(); void flushPoints();
}; };

View File

@ -148,7 +148,7 @@ void DrawContext::setBlendMode(BlendMode mode) {
set_blend_mode(mode); set_blend_mode(mode);
} }
void DrawContext::setScissors(const glm::vec4& area) { void DrawContext::setScissors(glm::vec4 area) {
Window::pushScissor(area); Window::pushScissor(area);
scissorsCount++; scissorsCount++;
} }

View File

@ -35,7 +35,7 @@ public:
void setDepthTest(bool flag); void setDepthTest(bool flag);
void setCullFace(bool flag); void setCullFace(bool flag);
void setBlendMode(BlendMode mode); void setBlendMode(BlendMode mode);
void setScissors(const glm::vec4& area); void setScissors(glm::vec4 area);
void setLineWidth(float width); void setLineWidth(float width);
}; };

View File

@ -12,7 +12,8 @@ Font::Font(std::vector<std::unique_ptr<Texture>> pages, int lineHeight, int yoff
: lineHeight(lineHeight), yoffset(yoffset), pages(std::move(pages)) { : lineHeight(lineHeight), yoffset(yoffset), pages(std::move(pages)) {
} }
Font::~Font() = default; Font::~Font(){
}
int Font::getYOffset() const { int Font::getYOffset() const {
return yoffset; return yoffset;

View File

@ -41,7 +41,8 @@ ImageData::ImageData(ImageFormat format, uint width, uint height, const ubyte* d
std::memcpy(this->data.get(), data, width * height * pixsize); std::memcpy(this->data.get(), data, width * height * pixsize);
} }
ImageData::~ImageData() = default; ImageData::~ImageData() {
}
void ImageData::flipX() { void ImageData::flipX() {
switch (format) { switch (format) {

View File

@ -18,7 +18,7 @@ public:
LineBatch(size_t capacity=4096); LineBatch(size_t capacity=4096);
~LineBatch(); ~LineBatch();
inline void line(const glm::vec3 &a, const glm::vec3 &b, const glm::vec4 &color) { inline void line(const glm::vec3 a, const glm::vec3 b, const glm::vec4 color) {
line(a.x, a.y, a.z, b.x, b.y, b.z, color.r, color.g, color.b, color.a); line(a.x, a.y, a.z, b.x, b.y, b.z, color.r, color.g, color.b, color.a);
} }
void line(float x1, float y1, float z1, float x2, float y2, float z2, void line(float x1, float y1, float z1, float x2, float y2, float z2,
@ -26,7 +26,7 @@ public:
void box(float x, float y, float z, float w, float h, float d, void box(float x, float y, float z, float w, float h, float d,
float r, float g, float b, float a); float r, float g, float b, float a);
inline void box(const glm::vec3 &xyz, const glm::vec3 &whd, const glm::vec4 &rgba) { inline void box(glm::vec3 xyz, glm::vec3 whd, glm::vec4 rgba) {
box(xyz.x, xyz.y, xyz.z, whd.x, whd.y, whd.z, box(xyz.x, xyz.y, xyz.z, whd.x, whd.y, whd.z,
rgba.r, rgba.g, rgba.b, rgba.a); rgba.r, rgba.g, rgba.b, rgba.a);
} }

View File

@ -8,11 +8,7 @@ inline constexpr glm::vec3 X(1, 0, 0);
inline constexpr glm::vec3 Y(0, 1, 0); inline constexpr glm::vec3 Y(0, 1, 0);
inline constexpr glm::vec3 Z(0, 0, 1); inline constexpr glm::vec3 Z(0, 0, 1);
void Mesh::addPlane( void Mesh::addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm) {
const glm::vec3 &pos,
const glm::vec3 &right,
const glm::vec3 &up,
const glm::vec3 &norm) {
vertices.push_back({pos-right-up, {0,0}, norm}); vertices.push_back({pos-right-up, {0,0}, norm});
vertices.push_back({pos+right-up, {1,0}, norm}); vertices.push_back({pos+right-up, {1,0}, norm});
vertices.push_back({pos+right+up, {1,1}, norm}); vertices.push_back({pos+right+up, {1,1}, norm});
@ -22,7 +18,7 @@ void Mesh::addPlane(
vertices.push_back({pos-right+up, {0,1}, norm}); vertices.push_back({pos-right+up, {0,1}, norm});
} }
void Mesh::addBox(const glm::vec3 &pos, const glm::vec3 &size) { void Mesh::addBox(glm::vec3 pos, glm::vec3 size) {
addPlane(pos+Z*size, X*size, Y*size, Z); addPlane(pos+Z*size, X*size, Y*size, Z);
addPlane(pos-Z*size, -X*size, Y*size, -Z); addPlane(pos-Z*size, -X*size, Y*size, -Z);

View File

@ -16,12 +16,8 @@ namespace model {
std::string texture; std::string texture;
std::vector<Vertex> vertices; std::vector<Vertex> vertices;
void addPlane( void addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm);
const glm::vec3& pos, void addBox(glm::vec3 pos, glm::vec3 size);
const glm::vec3& right,
const glm::vec3& up,
const glm::vec3& norm);
void addBox(const glm::vec3& pos, const glm::vec3& size);
}; };
struct Model { struct Model {

View File

@ -18,7 +18,8 @@ PostProcessing::PostProcessing() {
quadMesh = std::make_unique<Mesh>(vertices, 6, attrs); quadMesh = std::make_unique<Mesh>(vertices, 6, attrs);
} }
PostProcessing::~PostProcessing() = default; PostProcessing::~PostProcessing() {
}
void PostProcessing::use(DrawContext& context) { void PostProcessing::use(DrawContext& context) {
const auto& vp = context.getViewport(); const auto& vp = context.getViewport();

View File

@ -32,7 +32,7 @@ uint Shader::getUniformLocation(const std::string& name) {
auto found = uniformLocations.find(name); auto found = uniformLocations.find(name);
if (found == uniformLocations.end()) { if (found == uniformLocations.end()) {
uint location = glGetUniformLocation(id, name.c_str()); uint location = glGetUniformLocation(id, name.c_str());
uniformLocations.try_emplace(name, location); uniformLocations.emplace(name, location);
return location; return location;
} }
return found->second; return found->second;
@ -54,11 +54,11 @@ void Shader::uniform2f(const std::string& name, float x, float y){
glUniform2f(getUniformLocation(name), x, y); glUniform2f(getUniformLocation(name), x, y);
} }
void Shader::uniform2f(const std::string& name, const glm::vec2& xy){ void Shader::uniform2f(const std::string& name, glm::vec2 xy){
glUniform2f(getUniformLocation(name), xy.x, xy.y); glUniform2f(getUniformLocation(name), xy.x, xy.y);
} }
void Shader::uniform2i(const std::string& name, const glm::ivec2& xy){ void Shader::uniform2i(const std::string& name, glm::ivec2 xy){
glUniform2i(getUniformLocation(name), xy.x, xy.y); glUniform2i(getUniformLocation(name), xy.x, xy.y);
} }
@ -66,7 +66,7 @@ void Shader::uniform3f(const std::string& name, float x, float y, float z){
glUniform3f(getUniformLocation(name), x,y,z); glUniform3f(getUniformLocation(name), x,y,z);
} }
void Shader::uniform3f(const std::string& name, const glm::vec3& xyz){ void Shader::uniform3f(const std::string& name, glm::vec3 xyz){
glUniform3f(getUniformLocation(name), xyz.x, xyz.y, xyz.z); glUniform3f(getUniformLocation(name), xyz.x, xyz.y, xyz.z);
} }

View File

@ -26,10 +26,10 @@ public:
void uniform1i(const std::string& name, int x); void uniform1i(const std::string& name, int x);
void uniform1f(const std::string& name, float x); void uniform1f(const std::string& name, float x);
void uniform2f(const std::string& name, float x, float y); void uniform2f(const std::string& name, float x, float y);
void uniform2f(const std::string& name, const glm::vec2& xy); void uniform2f(const std::string& name, glm::vec2 xy);
void uniform2i(const std::string& name, const glm::ivec2& xy); void uniform2i(const std::string& name, glm::ivec2 xy);
void uniform3f(const std::string& name, float x, float y, float z); void uniform3f(const std::string& name, float x, float y, float z);
void uniform3f(const std::string& name, const glm::vec3& xyz); void uniform3f(const std::string& name, glm::vec3 xyz);
/// @brief Create shader program using vertex and fragment shaders source. /// @brief Create shader program using vertex and fragment shaders source.
/// @param vertexFile vertex shader file name /// @param vertexFile vertex shader file name

View File

@ -22,7 +22,7 @@ struct Frame {
class TextureAnimation { class TextureAnimation {
public: public:
TextureAnimation(Texture* srcTex, Texture* dstTex) : srcTexture(srcTex), dstTexture(dstTex) {}; TextureAnimation(Texture* srcTex, Texture* dstTex) : srcTexture(srcTex), dstTexture(dstTex) {};
~TextureAnimation() = default; ~TextureAnimation() {};
void addFrame(const Frame& frame) { frames.emplace_back(frame); }; void addFrame(const Frame& frame) { frames.emplace_back(frame); };

View File

@ -50,10 +50,9 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
} }
offset = glm::vec3(1, 1, 0.0f); offset = glm::vec3(1, 1, 0.0f);
shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset)); shader->uniformMatrix("u_apply", glm::translate(glm::mat4(1.0f), offset));
glm::vec3 scaledSize = glm::vec3(size * 0.63f);
batch->cube( batch->cube(
-hitbox * scaledSize * 0.5f * glm::vec3(1,1,-1), -hitbox * glm::vec3(size * 0.63f)*0.5f * glm::vec3(1,1,-1),
hitbox * scaledSize, hitbox * glm::vec3(size * 0.63f),
texfaces, glm::vec4(1.0f), texfaces, glm::vec4(1.0f),
!def->rt.emissive !def->rt.emissive
); );

View File

@ -35,7 +35,7 @@ struct DecomposedMat4 {
glm::vec4 perspective; glm::vec4 perspective;
}; };
static glm::mat4 extract_rotation(const glm::mat4& matrix) { static glm::mat4 extract_rotation(glm::mat4 matrix) {
DecomposedMat4 decomposed = {}; DecomposedMat4 decomposed = {};
glm::quat rotation; glm::quat rotation;
glm::decompose( glm::decompose(
@ -64,12 +64,11 @@ ModelBatch::ModelBatch(size_t capacity, Assets* assets, Chunks* chunks)
blank = Texture::from(&image); blank = Texture::from(&image);
} }
ModelBatch::~ModelBatch() = default; ModelBatch::~ModelBatch() {
}
void ModelBatch::draw(const model::Mesh& mesh, void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
const glm::mat4& matrix, const glm::mat3& rotation, glm::vec3 tint,
const glm::mat3& rotation,
const glm::vec3& tint,
const texture_names_map* varTextures) { const texture_names_map* varTextures) {
glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); glm::vec3 gpos = matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
light_t light = chunks->getLight(floor(gpos.x), floor(gpos.y), floor(gpos.z)); light_t light = chunks->getLight(floor(gpos.x), floor(gpos.y), floor(gpos.z));
@ -96,9 +95,8 @@ void ModelBatch::draw(const model::Mesh& mesh,
} }
} }
void ModelBatch::draw( void ModelBatch::draw(glm::mat4 matrix,
const glm::mat4& matrix, glm::vec3 tint,
const glm::vec3& tint,
const model::Model* model, const model::Model* model,
const texture_names_map* varTextures) { const texture_names_map* varTextures) {
for (const auto& mesh : model->meshes) { for (const auto& mesh : model->meshes) {

View File

@ -37,10 +37,7 @@ class ModelBatch {
static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f}; static inline glm::vec3 SUN_VECTOR {0.411934f, 0.863868f, -0.279161f};
inline void vertex( inline void vertex(
const glm::vec3& pos, glm::vec3 pos, glm::vec2 uv, glm::vec4 light, glm::vec3 tint
const glm::vec2& uv,
const glm::vec4& light,
const glm::vec3& tint
) { ) {
float* buffer = this->buffer.get(); float* buffer = this->buffer.get();
buffer[index++] = pos.x; buffer[index++] = pos.x;
@ -67,8 +64,8 @@ class ModelBatch {
void draw(const model::Mesh& mesh, void draw(const model::Mesh& mesh,
const glm::mat4& matrix, const glm::mat4& matrix,
const glm::mat3& rotation, const glm::mat3& rotation,
const glm::vec3& tint, glm::vec3 tint,
const texture_names_map* varTextures); const texture_names_map* varTextures);
void setTexture(const std::string& name, void setTexture(const std::string& name,
const texture_names_map* varTextures); const texture_names_map* varTextures);
@ -87,9 +84,8 @@ public:
ModelBatch(size_t capacity, Assets* assets, Chunks* chunks); ModelBatch(size_t capacity, Assets* assets, Chunks* chunks);
~ModelBatch(); ~ModelBatch();
void draw( void draw(glm::mat4 matrix,
const glm::mat4& matrix, glm::vec3 tint,
const glm::vec3& tint,
const model::Model* model, const model::Model* model,
const texture_names_map* varTextures); const texture_names_map* varTextures);
void render(); void render();

View File

@ -55,7 +55,8 @@ Skybox::Skybox(uint size, Shader* shader)
}); });
} }
Skybox::~Skybox() = default; Skybox::~Skybox() {
}
void Skybox::drawBackground(Camera* camera, Assets* assets, int width, int height) { void Skybox::drawBackground(Camera* camera, Assets* assets, int width, int height) {
auto backShader = assets->get<Shader>("background"); auto backShader = assets->get<Shader>("background");

View File

@ -75,7 +75,8 @@ WorldRenderer::WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* pl
); );
} }
WorldRenderer::~WorldRenderer() = default; WorldRenderer::~WorldRenderer() {
}
bool WorldRenderer::drawChunk( bool WorldRenderer::drawChunk(
size_t index, size_t index,
@ -230,29 +231,26 @@ void WorldRenderer::renderBlockSelection() {
: block->hitboxes; : block->hitboxes;
lineBatch->lineWidth(2.0f); lineBatch->lineWidth(2.0f);
constexpr auto boxOffset = glm::vec3(0.02);
constexpr auto boxColor = glm::vec4(0.f, 0.f, 0.f, 0.5f);
for (auto& hitbox: hitboxes) { for (auto& hitbox: hitboxes) {
const glm::vec3 center = glm::vec3(pos) + hitbox.center(); const glm::vec3 center = glm::vec3(pos) + hitbox.center();
const glm::vec3 size = hitbox.size(); const glm::vec3 size = hitbox.size();
lineBatch->box(center, size + boxOffset, boxColor); lineBatch->box(center, size + glm::vec3(0.02), glm::vec4(0.f, 0.f, 0.f, 0.5f));
if (player->debug) { if (player->debug) {
lineBatch->line(point, point+norm*0.5f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f)); lineBatch->line(point, point+norm*0.5f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f));
} }
} }
lineBatch->flush();
} }
void WorldRenderer::renderLines( void WorldRenderer::renderLines(
Camera* camera, Shader* linesShader, const DrawContext& pctx Camera* camera, Shader* linesShader, const DrawContext& pctx
) { ) {
auto ctx = pctx.sub(lineBatch.get());
linesShader->use(); linesShader->use();
linesShader->uniformMatrix("u_projview", camera->getProjView()); linesShader->uniformMatrix("u_projview", camera->getProjView());
if (player->selection.vox.id != BLOCK_VOID) { if (player->selection.vox.id != BLOCK_VOID) {
renderBlockSelection(); renderBlockSelection();
} }
if (player->debug && showEntitiesDebug) { if (player->debug && showEntitiesDebug) {
auto ctx = pctx.sub(lineBatch.get());
level->entities->renderDebug(*lineBatch, *frustumCulling, ctx); level->entities->renderDebug(*lineBatch, *frustumCulling, ctx);
} }
} }
@ -343,12 +341,12 @@ void WorldRenderer::draw(
ctx.setDepthTest(true); ctx.setDepthTest(true);
ctx.setCullFace(true); ctx.setCullFace(true);
renderLevel(ctx, camera, settings, delta, pause); renderLevel(ctx, camera, settings, delta, pause);
// Debug lines
if (hudVisible){ if (hudVisible){
renderLines(camera, linesShader, ctx); renderLines(camera, linesShader, ctx);
} }
} }
// Debug lines
if (hudVisible && player->debug) { if (hudVisible && player->debug) {
renderDebugLines(wctx, camera, linesShader); renderDebugLines(wctx, camera, linesShader);
} }

View File

@ -44,7 +44,8 @@ GUI::GUI() {
container->add(tooltip); container->add(tooltip);
} }
GUI::~GUI() = default; GUI::~GUI() {
}
std::shared_ptr<Menu> GUI::getMenu() { std::shared_ptr<Menu> GUI::getMenu() {
return menu; return menu;

View File

@ -52,7 +52,7 @@ InventoryBuilder::InventoryBuilder() {
void InventoryBuilder::addGrid( void InventoryBuilder::addGrid(
int cols, int count, int cols, int count,
const glm::vec2 &pos, glm::vec2 pos,
int padding, int padding,
bool addpanel, bool addpanel,
const SlotLayout& slotLayout const SlotLayout& slotLayout
@ -126,7 +126,7 @@ void SlotView::draw(const DrawContext* pctx, Assets* assets) {
langs::get(util::str2wstr_utf8(def->caption)) langs::get(util::str2wstr_utf8(def->caption))
); );
} else { } else {
tooltip.clear(); tooltip = L"";
} }
} }
prevItem = itemid; prevItem = itemid;
@ -381,7 +381,7 @@ void InventoryView::setPos(glm::vec2 pos) {
Container::setPos(pos - origin); Container::setPos(pos - origin);
} }
void InventoryView::setOrigin(const glm::vec2 &origin) { void InventoryView::setOrigin(glm::vec2 origin) {
this->origin = origin; this->origin = origin;
} }

View File

@ -93,7 +93,7 @@ namespace gui {
virtual void setPos(glm::vec2 pos) override; virtual void setPos(glm::vec2 pos) override;
void setOrigin(const glm::vec2 &origin); void setOrigin(glm::vec2 origin);
glm::vec2 getOrigin() const; glm::vec2 getOrigin() const;
void setSelected(int index); void setSelected(int index);
@ -130,7 +130,7 @@ namespace gui {
/// @param slotLayout slot settings (index and position are ignored) /// @param slotLayout slot settings (index and position are ignored)
void addGrid( void addGrid(
int cols, int count, int cols, int count,
const glm::vec2 &pos, glm::vec2 pos,
int padding, int padding,
bool addpanel, bool addpanel,
const SlotLayout& slotLayout const SlotLayout& slotLayout

View File

@ -145,7 +145,7 @@ uint Label::getLineByYOffset(int offset) const {
uint Label::getLineByTextIndex(size_t index) const { uint Label::getLineByTextIndex(size_t index) const {
for (size_t i = 0; i < cache.lines.size(); i++) { for (size_t i = 0; i < cache.lines.size(); i++) {
if (cache.lines[i].offset > index) { if (cache.lines.at(i).offset > index) {
return i-1; return i-1;
} }
} }
@ -195,7 +195,7 @@ void Label::draw(const DrawContext* pctx, Assets* assets) {
if (multiline) { if (multiline) {
for (size_t i = 0; i < cache.lines.size(); i++) { for (size_t i = 0; i < cache.lines.size(); i++) {
auto& line = cache.lines[i]; auto& line = cache.lines.at(i);
size_t offset = line.offset; size_t offset = line.offset;
std::wstring_view view(text.c_str()+offset, text.length()-offset); std::wstring_view view(text.c_str()+offset, text.length()-offset);
if (i < cache.lines.size()-1) { if (i < cache.lines.size()-1) {

View File

@ -203,7 +203,7 @@ static void _readPanel(UiXmlReader& reader, const xml::xmlelement& element, Pane
panel.setMaxLength(element->attr("max-length").asInt()); panel.setMaxLength(element->attr("max-length").asInt());
} }
if (element->has("orientation")) { if (element->has("orientation")) {
const auto &oname = element->attr("orientation").getText(); auto oname = element->attr("orientation").getText();
if (oname == "horizontal") { if (oname == "horizontal") {
panel.setOrientation(Orientation::horizontal); panel.setOrientation(Orientation::horizontal);
} }
@ -286,7 +286,7 @@ static std::shared_ptr<UINode> readButton(UiXmlReader& reader, const xml::xmlele
std::shared_ptr<Button> button; std::shared_ptr<Button> button;
auto& elements = element->getElements(); auto& elements = element->getElements();
if (!elements.empty() && elements[0]->getTag() != "#") { if (!elements.empty() && elements.at(0)->getTag() != "#") {
auto inner = reader.readUINode(element->getElements().at(0)); auto inner = reader.readUINode(element->getElements().at(0));
if (inner != nullptr) { if (inner != nullptr) {
button = std::make_shared<Button>(inner, padding); button = std::make_shared<Button>(inner, padding);

View File

@ -8,7 +8,8 @@
Inventories::Inventories(Level& level) : level(level) { Inventories::Inventories(Level& level) : level(level) {
} }
Inventories::~Inventories() = default; Inventories::~Inventories() {
}
std::shared_ptr<Inventory> Inventories::create(size_t size) { std::shared_ptr<Inventory> Inventories::create(size_t size) {
int64_t id = level.getWorld()->getNextInventoryId(); int64_t id = level.getWorld()->getNextInventoryId();

View File

@ -38,8 +38,8 @@ struct ItemDef {
struct { struct {
itemid_t id; itemid_t id;
blockid_t placingBlock;
item_funcs_set funcsset {}; item_funcs_set funcsset {};
blockid_t placingBlock;
bool emissive = false; bool emissive = false;
} rt {}; } rt {};

View File

@ -20,7 +20,8 @@ Lighting::Lighting(const Content* content, Chunks* chunks)
solverS = std::make_unique<LightSolver>(indices, chunks, 3); solverS = std::make_unique<LightSolver>(indices, chunks, 3);
} }
Lighting::~Lighting() = default; Lighting::~Lighting(){
}
void Lighting::clear(){ void Lighting::clear(){
for (size_t index = 0; index < chunks->volume; index++){ for (size_t index = 0; index < chunks->volume; index++){

View File

@ -30,7 +30,8 @@ ChunksController::ChunksController(Level* level, uint padding)
generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) { generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) {
} }
ChunksController::~ChunksController() = default; ChunksController::~ChunksController(){
}
void ChunksController::update(int64_t maxDuration) { void ChunksController::update(int64_t maxDuration) {
int64_t mcstotal = 0; int64_t mcstotal = 0;
@ -112,22 +113,21 @@ bool ChunksController::buildLights(const std::shared_ptr<Chunk>& chunk) {
void ChunksController::createChunk(int x, int z) { void ChunksController::createChunk(int x, int z) {
auto chunk = level->chunksStorage->create(x, z); auto chunk = level->chunksStorage->create(x, z);
chunks->putChunk(chunk); chunks->putChunk(chunk);
auto& chunkFlags = chunk->flags;
if (!chunkFlags.loaded) { if (!chunk->flags.loaded) {
generator->generate( generator->generate(
chunk->voxels, x, z, chunk->voxels, x, z,
level->getWorld()->getSeed() level->getWorld()->getSeed()
); );
chunkFlags.unsaved = true; chunk->flags.unsaved = true;
} }
chunk->updateHeights(); chunk->updateHeights();
if (!chunkFlags.loadedLights) { if (!chunk->flags.loadedLights) {
Lighting::prebuildSkyLight( Lighting::prebuildSkyLight(
chunk.get(), level->content->getIndices() chunk.get(), level->content->getIndices()
); );
} }
chunkFlags.loaded = true; chunk->flags.loaded = true;
chunkFlags.ready = true; chunk->flags.ready = true;
} }

View File

@ -255,8 +255,8 @@ public:
} }
dynamic::Value applyRelative( dynamic::Value applyRelative(
Argument* arg, Argument* arg,
const dynamic::Value& value, dynamic::Value value,
const dynamic::Value& origin const dynamic::Value& origin
) { ) {
if (origin.index() == 0) { if (origin.index() == 0) {

View File

@ -55,7 +55,7 @@ namespace cmd {
std::string description; std::string description;
executor_func executor; executor_func executor;
public: public:
Command() = default; Command() {}
Command( Command(
std::string name, std::string name,

View File

@ -47,12 +47,11 @@ void LevelController::update(float delta, bool input, bool pause) {
player->postUpdate(delta, input, pause); player->postUpdate(delta, input, pause);
// erease null pointers // erease null pointers
auto& objects = level->objects; level->objects.erase(
objects.erase(
std::remove_if( std::remove_if(
objects.begin(), objects.end(), level->objects.begin(), level->objects.end(),
[](auto obj) { return obj == nullptr; }), [](auto obj) { return obj == nullptr; }),
objects.end() level->objects.end()
); );
} }

View File

@ -105,7 +105,7 @@ glm::vec3 CameraControl::updateCameraShaking(const Hitbox& hitbox, float delta)
} }
void CameraControl::updateFovEffects(const Hitbox& hitbox, void CameraControl::updateFovEffects(const Hitbox& hitbox,
PlayerInput input, float delta) { const PlayerInput& input, float delta) {
bool crouch = input.shift && hitbox.grounded && !input.sprint; bool crouch = input.shift && hitbox.grounded && !input.sprint;
float dt = fmin(1.0f, delta * ZOOM_SPEED); float dt = fmin(1.0f, delta * ZOOM_SPEED);
@ -146,7 +146,7 @@ void CameraControl::switchCamera() {
} }
} }
void CameraControl::update(PlayerInput input, float delta, Chunks* chunks) { void CameraControl::update(const PlayerInput& input, float delta, Chunks* chunks) {
offset = glm::vec3(0.0f, 0.0f, 0.0f); offset = glm::vec3(0.0f, 0.0f, 0.0f);
if (auto hitbox = player->getHitbox()) { if (auto hitbox = player->getHitbox()) {
@ -455,7 +455,7 @@ void PlayerController::updateEntityInteraction(entityid_t eid, bool lclick, bool
if (!entityOpt.has_value()) { if (!entityOpt.has_value()) {
return; return;
} }
auto entity = *entityOpt; auto entity = entityOpt.value();
if (lclick) { if (lclick) {
scripting::on_attacked(entity, player.get(), player->getEntity()); scripting::on_attacked(entity, player.get(), player->getEntity());
} }

View File

@ -32,7 +32,7 @@ class CameraControl {
/// @brief Update field-of-view effects /// @brief Update field-of-view effects
/// @param input player inputs /// @param input player inputs
/// @param delta delta time /// @param delta delta time
void updateFovEffects(const Hitbox& hitbox, PlayerInput input, void updateFovEffects(const Hitbox& hitbox, const PlayerInput& input,
float delta); float delta);
/// @brief Switch active player camera /// @brief Switch active player camera
@ -41,7 +41,7 @@ public:
CameraControl(const std::shared_ptr<Player>& player, CameraControl(const std::shared_ptr<Player>& player,
const CameraSettings& settings); const CameraSettings& settings);
void updateMouse(PlayerInput& input); void updateMouse(PlayerInput& input);
void update(PlayerInput input, float delta, Chunks* chunks); void update(const PlayerInput& input, float delta, Chunks* chunks);
void refresh(); void refresh();
}; };

View File

@ -75,7 +75,7 @@ static int l_get_command_info(lua::State* L) {
lua::createtable(L, args.size(), 0); lua::createtable(L, args.size(), 0);
for (size_t i = 0; i < args.size(); i++) { for (size_t i = 0; i < args.size(); i++) {
auto& arg = args[i]; auto& arg = args.at(i);
lua::createtable(L, 0, 2); lua::createtable(L, 0, 2);
lua::pushstring(L, arg.name); lua::pushstring(L, arg.name);

View File

@ -324,6 +324,8 @@ static int l_gui_getattr(lua::State* L) {
auto docname = lua::require_string(L, 1); auto docname = lua::require_string(L, 1);
auto element = lua::require_string(L, 2); auto element = lua::require_string(L, 2);
auto attr = lua::require_string(L, 3); auto attr = lua::require_string(L, 3);
auto docnode = getDocumentNode(L, docname, element);
auto node = docnode.node;
static const std::unordered_map<std::string_view, std::function<int(UINode*,lua::State*)>> getters { static const std::unordered_map<std::string_view, std::function<int(UINode*,lua::State*)>> getters {
{"color", p_get_color}, {"color", p_get_color},
@ -365,8 +367,6 @@ static int l_gui_getattr(lua::State* L) {
}; };
auto func = getters.find(attr); auto func = getters.find(attr);
if (func != getters.end()) { if (func != getters.end()) {
auto docnode = getDocumentNode(L, docname, element);
auto node = docnode.node;
return func->second(node.get(), L); return func->second(node.get(), L);
} }
return 0; return 0;

View File

@ -95,7 +95,7 @@ static int l_pack_get_info(lua::State* L, const ContentPack& pack, const Content
if (!pack.dependencies.empty()) { if (!pack.dependencies.empty()) {
lua::createtable(L, pack.dependencies.size(), 0); lua::createtable(L, pack.dependencies.size(), 0);
for (size_t i = 0; i < pack.dependencies.size(); i++) { for (size_t i = 0; i < pack.dependencies.size(); i++) {
auto& dpack = pack.dependencies[i]; auto& dpack = pack.dependencies.at(i);
std::string prefix; std::string prefix;
switch (dpack.level) { switch (dpack.level) {
case DependencyLevel::required: prefix = "!"; break; case DependencyLevel::required: prefix = "!"; break;
@ -142,7 +142,7 @@ static int l_pack_get_info(lua::State* L) {
manager.scan(); manager.scan();
auto vec = manager.getAll({packid}); auto vec = manager.getAll({packid});
if (!vec.empty()) { if (!vec.empty()) {
return l_pack_get_info(L, vec[0], content); return l_pack_get_info(L, vec.at(0), content);
} }
return 0; return 0;
} }

View File

@ -151,20 +151,20 @@ namespace lua {
return 3; return 3;
} }
inline int pushivec3_stack(lua::State* L, const glm::ivec3 &vec) { inline int pushivec3_stack(lua::State* L, glm::ivec3 vec) {
pushinteger(L, vec.x); pushinteger(L, vec.x);
pushinteger(L, vec.y); pushinteger(L, vec.y);
pushinteger(L, vec.z); pushinteger(L, vec.z);
return 3; return 3;
} }
inline int pushvec3_stack(lua::State* L, const glm::vec3 &vec) { inline int pushvec3_stack(lua::State* L, glm::vec3 vec) {
pushnumber(L, vec.x); pushnumber(L, vec.x);
pushnumber(L, vec.y); pushnumber(L, vec.y);
pushnumber(L, vec.z); pushnumber(L, vec.z);
return 3; return 3;
} }
inline int pushvec4_stack(lua::State* L, const glm::vec4 &vec) { inline int pushvec4_stack(lua::State* L, glm::vec4 vec) {
pushnumber(L, vec.x); pushnumber(L, vec.x);
pushnumber(L, vec.y); pushnumber(L, vec.y);
pushnumber(L, vec.z); pushnumber(L, vec.z);
@ -179,15 +179,15 @@ namespace lua {
lua_pushvalue(L, idx); lua_pushvalue(L, idx);
return 1; return 1;
} }
inline int pushvec2(lua::State* L, const glm::vec2 &vec) { inline int pushvec2(lua::State* L, glm::vec2 vec) {
return pushvec(L, vec); return pushvec(L, vec);
} }
inline int pushvec3(lua::State* L, const glm::vec3 &vec) { inline int pushvec3(lua::State* L, glm::vec3 vec) {
return pushvec(L, vec); return pushvec(L, vec);
} }
inline int pushvec4(lua::State* L, const glm::vec4 &vec) { inline int pushvec4(lua::State* L, glm::vec4 vec) {
return pushvec(L, vec); return pushvec(L, vec);
} }
inline int pushcolor(lua::State* L, glm::vec4 vec) { inline int pushcolor(lua::State* L, glm::vec4 vec) {
@ -210,7 +210,7 @@ namespace lua {
} }
return 1; return 1;
} }
inline int pushmat4(lua::State* L, const glm::mat4 &matrix) { inline int pushmat4(lua::State* L, glm::mat4 matrix) {
createtable(L, 16, 0); createtable(L, 16, 0);
for (uint y = 0; y < 4; y++) { for (uint y = 0; y < 4; y++) {
for (uint x = 0; x < 4; x++) { for (uint x = 0; x < 4; x++) {
@ -222,7 +222,7 @@ namespace lua {
return 1; return 1;
} }
/// @brief pushes matrix table to the stack and updates it with glm matrix /// @brief pushes matrix table to the stack and updates it with glm matrix
inline int setmat4(lua::State* L, int idx, const glm::mat4 &matrix) { inline int setmat4(lua::State* L, int idx, glm::mat4 matrix) {
pushvalue(L, idx); pushvalue(L, idx);
for (uint y = 0; y < 4; y++) { for (uint y = 0; y < 4; y++) {
for (uint x = 0; x < 4; x++) { for (uint x = 0; x < 4; x++) {

View File

@ -240,8 +240,8 @@ void scripting::on_block_placed(Player* player, const Block* block, int x, int y
} }
void scripting::on_block_broken(Player* player, const Block* block, int x, int y, int z) { void scripting::on_block_broken(Player* player, const Block* block, int x, int y, int z) {
std::string name = block->name + ".broken";
if (block->rt.funcsset.onbroken) { if (block->rt.funcsset.onbroken) {
std::string name = block->name + ".broken";
lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (auto L) { lua::emit_event(lua::get_main_thread(), name, [x, y, z, player] (auto L) {
lua::pushivec3_stack(L, x, y, z); lua::pushivec3_stack(L, x, y, z);
lua::pushinteger(L, player ? player->getId() : -1); lua::pushinteger(L, player ? player->getId() : -1);

View File

@ -66,7 +66,7 @@ wstringsupplier scripting::create_wstring_supplier(
auto str = lua::require_wstring(L, -1); lua::pop(L); auto str = lua::require_wstring(L, -1); lua::pop(L);
return str; return str;
} }
return std::wstring(); return std::wstring(L"");
}; };
} }

View File

@ -5,7 +5,7 @@
class Frustum { class Frustum {
public: public:
Frustum() = default; Frustum() {};
void update(glm::mat4 projview); void update(glm::mat4 projview);
bool isBoxVisible(const glm::vec3& minp, const glm::vec3& maxp) const; bool isBoxVisible(const glm::vec3& minp, const glm::vec3& maxp) const;

View File

@ -70,7 +70,7 @@ struct AABB {
b = end; b = end;
} }
inline void addPoint(const glm::vec3& p) { inline void addPoint(glm::vec3 p) {
a = glm::min(a, p); a = glm::min(a, p);
b = glm::max(b, p); b = glm::max(b, p);
} }

View File

@ -21,7 +21,7 @@ class AABBFaces {
public: public:
std::array<std::pair<rayvec3, rayvec2>, AABBFACES_COUNT> faces; // every face is min-point and opposite corner point std::array<std::pair<rayvec3, rayvec2>, AABBFACES_COUNT> faces; // every face is min-point and opposite corner point
AABBFaces() = default; AABBFaces(){};
AABBFaces(const rayvec3& parentBoxPos, const AABB& parentBox); AABBFaces(const rayvec3& parentBoxPos, const AABB& parentBox);
}; };

View File

@ -186,7 +186,7 @@ void Entities::loadEntity(const dynamic::Map_sptr& map) {
spawn(def, {}, nullptr, map, uid); spawn(def, {}, nullptr, map, uid);
} }
void Entities::loadEntity(const dynamic::Map_sptr& map, const Entity &entity) { void Entities::loadEntity(const dynamic::Map_sptr& map, Entity entity) {
auto& transform = entity.getTransform(); auto& transform = entity.getTransform();
auto& body = entity.getRigidbody(); auto& body = entity.getRigidbody();
auto& skeleton = entity.getSkeleton(); auto& skeleton = entity.getSkeleton();
@ -228,7 +228,7 @@ void Entities::loadEntity(const dynamic::Map_sptr& map, const Entity &entity) {
} }
std::optional<Entities::RaycastResult> Entities::rayCast( std::optional<Entities::RaycastResult> Entities::rayCast(
const glm::vec3 &start, const glm::vec3 &dir, float maxDistance, entityid_t ignore glm::vec3 start, glm::vec3 dir, float maxDistance, entityid_t ignore
) { ) {
Ray ray(start, dir); Ray ray(start, dir);
auto view = registry.view<EntityId, Transform, Rigidbody>(); auto view = registry.view<EntityId, Transform, Rigidbody>();
@ -547,7 +547,7 @@ bool Entities::hasBlockingInside(AABB aabb) {
return false; return false;
} }
std::vector<Entity> Entities::getAllInside(const AABB &aabb) { std::vector<Entity> Entities::getAllInside(AABB aabb) {
std::vector<Entity> collected; std::vector<Entity> collected;
auto view = registry.view<Transform>(); auto view = registry.view<Transform>();
for (auto [entity, transform] : view.each()) { for (auto [entity, transform] : view.each()) {
@ -564,7 +564,7 @@ std::vector<Entity> Entities::getAllInside(const AABB &aabb) {
return collected; return collected;
} }
std::vector<Entity> Entities::getAllInRadius(const glm::vec3 &center, float radius) { std::vector<Entity> Entities::getAllInRadius(glm::vec3 center, float radius) {
std::vector<Entity> collected; std::vector<Entity> collected;
auto view = registry.view<Transform>(); auto view = registry.view<Transform>();
for (auto [entity, transform] : view.each()) { for (auto [entity, transform] : view.each()) {

View File

@ -49,19 +49,19 @@ struct Transform {
void refresh(); void refresh();
inline void setRot(const glm::mat3 &m) { inline void setRot(glm::mat3 m) {
rot = m; rot = m;
dirty = true; dirty = true;
} }
inline void setSize(const glm::vec3 &v) { inline void setSize(glm::vec3 v) {
if (glm::distance2(displaySize, v) >= 0.00001f) { if (glm::distance2(displaySize, v) >= 0.00001f) {
dirty = true; dirty = true;
} }
size = v; size = v;
} }
inline void setPos(const glm::vec3 &v) { inline void setPos(glm::vec3 v) {
if (glm::distance2(displayPos, v) >= 0.0001f) { if (glm::distance2(displayPos, v) >= 0.0001f) {
dirty = true; dirty = true;
} }
@ -212,15 +212,15 @@ public:
/// @param ignore Ignored entity ID /// @param ignore Ignored entity ID
/// @return An optional structure containing entity, normal and distance /// @return An optional structure containing entity, normal and distance
std::optional<RaycastResult> rayCast( std::optional<RaycastResult> rayCast(
const glm::vec3 &start, const glm::vec3 &dir, float maxDistance, entityid_t ignore=-1); glm::vec3 start, glm::vec3 dir, float maxDistance, entityid_t ignore=-1);
void loadEntities(dynamic::Map_sptr map); void loadEntities(dynamic::Map_sptr map);
void loadEntity(const dynamic::Map_sptr& map); void loadEntity(const dynamic::Map_sptr& map);
void loadEntity(const dynamic::Map_sptr& map, const Entity &entity); void loadEntity(const dynamic::Map_sptr& map, Entity entity);
void onSave(const Entity& entity); void onSave(const Entity& entity);
bool hasBlockingInside(AABB aabb); bool hasBlockingInside(AABB aabb);
std::vector<Entity> getAllInside(const AABB &aabb); std::vector<Entity> getAllInside(AABB aabb);
std::vector<Entity> getAllInRadius(const glm::vec3 &center, float radius); std::vector<Entity> getAllInRadius(glm::vec3 center, float radius);
void despawn(entityid_t id); void despawn(entityid_t id);
dynamic::Value serialize(const Entity& entity); dynamic::Value serialize(const Entity& entity);

View File

@ -169,7 +169,7 @@ void Player::postUpdate() {
glm::mat4(1.0f), glm::radians(cam.y), glm::vec3(1, 0, 0)); glm::mat4(1.0f), glm::radians(cam.y), glm::vec3(1, 0, 0));
} }
void Player::teleport(const glm::vec3 &position) { void Player::teleport(glm::vec3 position) {
this->position = position; this->position = position;
if (auto hitbox = getHitbox()) { if (auto hitbox = getHitbox()) {
hitbox->position = position; hitbox->position = position;
@ -239,7 +239,7 @@ std::shared_ptr<Inventory> Player::getInventory() const {
return inventory; return inventory;
} }
void Player::setSpawnPoint(const glm::vec3 &spawnpoint) { void Player::setSpawnPoint(glm::vec3 spawnpoint) {
this->spawnpoint = spawnpoint; this->spawnpoint = spawnpoint;
} }

View File

@ -64,7 +64,7 @@ public:
std::shared_ptr<Inventory> inv, entityid_t eid); std::shared_ptr<Inventory> inv, entityid_t eid);
~Player(); ~Player();
void teleport(const glm::vec3 &position); void teleport(glm::vec3 position);
void updateEntity(); void updateEntity();
void updateInput(PlayerInput& input, float delta); void updateInput(PlayerInput& input, float delta);
void updateSelectedEntity(); void updateSelectedEntity();
@ -96,7 +96,7 @@ public:
Hitbox* getHitbox(); Hitbox* getHitbox();
void setSpawnPoint(const glm::vec3 &spawnpoint); void setSpawnPoint(glm::vec3 point);
glm::vec3 getSpawnPoint() const; glm::vec3 getSpawnPoint() const;
std::unique_ptr<dynamic::Map> serialize() const override; std::unique_ptr<dynamic::Map> serialize() const override;

View File

@ -68,8 +68,8 @@ SkeletonConfig::SkeletonConfig(const std::string& name, std::unique_ptr<Bone> ro
size_t SkeletonConfig::update( size_t SkeletonConfig::update(
size_t index, size_t index,
Skeleton& skeleton, Skeleton& skeleton,
Bone* node, Bone* node,
const glm::mat4& matrix) const glm::mat4 matrix) const
{ {
auto boneMatrix = skeleton.pose.matrices[index]; auto boneMatrix = skeleton.pose.matrices[index];
auto boneOffset = node->getOffset(); auto boneOffset = node->getOffset();
@ -85,7 +85,7 @@ size_t SkeletonConfig::update(
return count; return count;
} }
void SkeletonConfig::update(Skeleton& skeleton, const glm::mat4& matrix) const { void SkeletonConfig::update(Skeleton& skeleton, glm::mat4 matrix) const {
update(0, skeleton, root.get(), matrix); update(0, skeleton, root.get(), matrix);
} }

View File

@ -103,12 +103,12 @@ namespace rigging {
size_t index, size_t index,
Skeleton& skeleton, Skeleton& skeleton,
Bone* node, Bone* node,
const glm::mat4& matrix) const; glm::mat4 matrix) const;
public: public:
SkeletonConfig(const std::string& name, std::unique_ptr<Bone> root, SkeletonConfig(const std::string& name, std::unique_ptr<Bone> root,
size_t nodesCount); size_t nodesCount);
void update(Skeleton& skeleton, const glm::mat4& matrix) const; void update(Skeleton& skeleton, glm::mat4 matrix) const;
void render( void render(
Assets* assets, Assets* assets,
ModelBatch& batch, ModelBatch& batch,

View File

@ -28,8 +28,8 @@ struct ThreadPoolResult {
template<class T, class R> template<class T, class R>
class Worker { class Worker {
public: public:
Worker() = default; Worker() {}
virtual ~Worker() = default; virtual ~Worker() {}
virtual R operator()(const std::shared_ptr<T>&) = 0; virtual R operator()(const std::shared_ptr<T>&) = 0;
}; };

View File

@ -11,12 +11,12 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
class ArgsReader { class ArgsReader {
const char* last = "";
char** argv;
int argc; int argc;
char** argv;
int pos = 0; int pos = 0;
const char* last = "";
public: public:
ArgsReader(int argc, char** argv) : argv(argv), argc(argc) {} ArgsReader(int argc, char** argv) : argc(argc), argv(argv) {}
void skip() { void skip() {
pos++; pos++;

View File

@ -7,7 +7,7 @@ std::string util::to_string(const std::vector<std::string>& vec) {
std::stringstream ss; std::stringstream ss;
ss << "["; ss << "[";
for (size_t i = 0; i < vec.size(); i++) { for (size_t i = 0; i < vec.size(); i++) {
ss << util::quote(vec[1]); ss << util::quote(vec.at(i));
if (i < vec.size()-1) { if (i < vec.size()-1) {
ss << ", "; ss << ", ";
} }

View File

@ -37,7 +37,7 @@ std::string util::quote(const std::string& s) {
return escape(s); return escape(s);
} }
std::wstring util::lfill(const std::wstring& s, uint length, wchar_t c) { std::wstring util::lfill(std::wstring s, uint length, wchar_t c) {
if (s.length() >= length) { if (s.length() >= length) {
return s; return s;
} }
@ -49,7 +49,7 @@ std::wstring util::lfill(const std::wstring& s, uint length, wchar_t c) {
return ss.str(); return ss.str();
} }
std::wstring util::rfill(const std::wstring& s, uint length, wchar_t c) { std::wstring util::rfill(std::wstring s, uint length, wchar_t c) {
if (s.length() >= length) { if (s.length() >= length) {
return s; return s;
} }

View File

@ -13,8 +13,8 @@ namespace util {
/// @brief Function used for error messages /// @brief Function used for error messages
std::string quote(const std::string& s); std::string quote(const std::string& s);
std::wstring lfill(const std::wstring& s, uint length, wchar_t c); std::wstring lfill(std::wstring s, uint length, wchar_t c);
std::wstring rfill(const std::wstring& s, uint length, wchar_t c); std::wstring rfill(std::wstring s, uint length, wchar_t c);
uint encode_utf8(uint32_t c, ubyte* bytes); uint encode_utf8(uint32_t c, ubyte* bytes);
uint32_t decode_utf8(uint& size, const char* bytes); uint32_t decode_utf8(uint& size, const char* bytes);

View File

@ -48,7 +48,7 @@ struct CoordSystem {
void transform(AABB& aabb) const; void transform(AABB& aabb) const;
inline bool isVectorHasNegatives(const glm::ivec3& vec) { inline bool isVectorHasNegatives(glm::ivec3 vec) {
return (vec.x < 0 || vec.y < 0 || vec.z < 0); return (vec.x < 0 || vec.y < 0 || vec.z < 0);
} }
}; };

View File

@ -232,13 +232,13 @@ void Chunks::repairSegments(const Block* def, blockstate state, int x, int y, in
} }
} }
bool Chunks::checkReplaceability(const Block* def, blockstate state, const glm::ivec3 &coord, blockid_t ignore) { bool Chunks::checkReplaceability(const Block* def, blockstate state, glm::ivec3 origin, blockid_t ignore) {
const auto& rotation = def->rotations.variants[state.rotation]; const auto& rotation = def->rotations.variants[state.rotation];
const auto size = def->size; const auto size = def->size;
for (int sy = 0; sy < size.y; sy++) { for (int sy = 0; sy < size.y; sy++) {
for (int sz = 0; sz < size.z; sz++) { for (int sz = 0; sz < size.z; sz++) {
for (int sx = 0; sx < size.x; sx++) { for (int sx = 0; sx < size.x; sx++) {
auto pos = coord; auto pos = origin;
pos += rotation.axisX * sx; pos += rotation.axisX * sx;
pos += rotation.axisY * sy; pos += rotation.axisY * sy;
pos += rotation.axisZ * sz; pos += rotation.axisZ * sz;
@ -257,7 +257,7 @@ bool Chunks::checkReplaceability(const Block* def, blockstate state, const glm::
} }
void Chunks::setRotationExtended( void Chunks::setRotationExtended(
Block* def, blockstate state, const glm::ivec3 &origin, uint8_t index Block* def, blockstate state, glm::ivec3 origin, uint8_t index
) { ) {
auto newstate = state; auto newstate = state;
newstate.rotation = index; newstate.rotation = index;
@ -387,8 +387,8 @@ void Chunks::set(int32_t x, int32_t y, int32_t z, uint32_t id, blockstate state)
} }
voxel* Chunks::rayCast( voxel* Chunks::rayCast(
const glm::vec3 &start, glm::vec3 start,
const glm::vec3 &dir, glm::vec3 dir,
float maxDist, float maxDist,
glm::vec3& end, glm::vec3& end,
glm::ivec3& norm, glm::ivec3& norm,
@ -520,7 +520,7 @@ voxel* Chunks::rayCast(
return nullptr; return nullptr;
} }
glm::vec3 Chunks::rayCastToObstacle(const glm::vec3 &start, const glm::vec3 &dir, float maxDist) { glm::vec3 Chunks::rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist) {
const float px = start.x; const float px = start.x;
const float py = start.y; const float py = start.y;
const float pz = start.z; const float pz = start.z;

View File

@ -27,7 +27,7 @@ class Chunks {
void eraseSegments(const Block* def, blockstate state, int x, int y, int z); void eraseSegments(const Block* def, blockstate state, int x, int y, int z);
void repairSegments(const Block* def, blockstate state, int x, int y, int z); void repairSegments(const Block* def, blockstate state, int x, int y, int z);
void setRotationExtended(Block* def, blockstate state, const glm::ivec3 &origin, uint8_t rotation); void setRotationExtended(Block* def, blockstate state, glm::ivec3 origin, uint8_t rotation);
public: public:
std::vector<std::shared_ptr<Chunk>> chunks; std::vector<std::shared_ptr<Chunk>> chunks;
std::vector<std::shared_ptr<Chunk>> chunksSecond; std::vector<std::shared_ptr<Chunk>> chunksSecond;
@ -48,7 +48,7 @@ public:
Chunk* getChunkByVoxel(int32_t x, int32_t y, int32_t z); Chunk* getChunkByVoxel(int32_t x, int32_t y, int32_t z);
voxel* get(int32_t x, int32_t y, int32_t z) const; voxel* get(int32_t x, int32_t y, int32_t z) const;
inline voxel* get(const glm::ivec3 &pos) { inline voxel* get(glm::ivec3 pos) {
return get(pos.x, pos.y, pos.z); return get(pos.x, pos.y, pos.z);
} }
@ -68,20 +68,20 @@ public:
/// @param state the block state /// @param state the block state
/// @param coord position of the zone start /// @param coord position of the zone start
/// @param ignore ignored block id (will be counted as replaceable) /// @param ignore ignored block id (will be counted as replaceable)
bool checkReplaceability(const Block* def, blockstate state, const glm::ivec3 &coord, blockid_t ignore=0); bool checkReplaceability(const Block* def, blockstate state, glm::ivec3 coord, blockid_t ignore=0);
void setRotation(int32_t x, int32_t y, int32_t z, uint8_t rotation); void setRotation(int32_t x, int32_t y, int32_t z, uint8_t rotation);
voxel* rayCast( voxel* rayCast(
const glm::vec3 &start, glm::vec3 start,
const glm::vec3 &dir, glm::vec3 dir,
float maxLength, float maxLength,
glm::vec3& end, glm::vec3& end,
glm::ivec3& norm, glm::ivec3& norm,
glm::ivec3& iend glm::ivec3& iend
); );
glm::vec3 rayCastToObstacle(const glm::vec3 &start, const glm::vec3 &dir, float maxDist); glm::vec3 rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist);
const AABB* isObstacleAt(float x, float y, float z); const AABB* isObstacleAt(float x, float y, float z);
bool isSolidBlock(int32_t x, int32_t y, int32_t z); bool isSolidBlock(int32_t x, int32_t y, int32_t z);

View File

@ -115,7 +115,7 @@ void Events::bind(const std::string& name, inputtype type, mousecode code) {
} }
void Events::bind(const std::string& name, inputtype type, int code) { void Events::bind(const std::string& name, inputtype type, int code) {
bindings.try_emplace(name, Binding(type, code)); bindings.emplace(name, Binding(type, code));
} }
void Events::rebind(const std::string& name, inputtype type, int code) { void Events::rebind(const std::string& name, inputtype type, int code) {

View File

@ -205,11 +205,11 @@ void Window::clearDepth() {
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
} }
void Window::setBgColor(const glm::vec3 &color) { void Window::setBgColor(glm::vec3 color) {
glClearColor(color.r, color.g, color.b, 1.0f); glClearColor(color.r, color.g, color.b, 1.0f);
} }
void Window::setBgColor(const glm::vec4 &color) { void Window::setBgColor(glm::vec4 color) {
glClearColor(color.r, color.g, color.b, color.a); glClearColor(color.r, color.g, color.b, color.a);
} }

View File

@ -49,8 +49,8 @@ public:
static void clear(); static void clear();
static void clearDepth(); static void clearDepth();
static void setBgColor(const glm::vec3 &color); static void setBgColor(glm::vec3 color);
static void setBgColor(const glm::vec4 &color); static void setBgColor(glm::vec4 color);
static double time(); static double time();
static const char* getClipboardText(); static const char* getClipboardText();
static void setClipboardText(const char* text); static void setClipboardText(const char* text);

View File

@ -142,7 +142,7 @@ struct Binding {
bool state = false; bool state = false;
bool justChange = false; bool justChange = false;
Binding() = default; Binding(){}
Binding(inputtype type, int code) : type(type), code(code) {} Binding(inputtype type, int code) : type(type), code(code) {}
bool active() const { bool active() const {

View File

@ -201,7 +201,7 @@ void World::deserialize(dynamic::Map* root) {
generator = root->get("generator", generator); generator = root->get("generator", generator);
seed = root->get("seed", seed); seed = root->get("seed", seed);
if (generator.empty()) { if (generator == "") {
generator = WorldGenerators::getDefaultGeneratorID(); generator = WorldGenerators::getDefaultGeneratorID();
} }
if (auto verobj = root->map("version")) { if (auto verobj = root->map("version")) {