Merge pull request #277 from Pugemon/pvs-fix
fix: optimization: Various PVS-Studio warnings
This commit is contained in:
commit
a7ef7bb365
@ -1,7 +1,6 @@
|
|||||||
#include "Assets.hpp"
|
#include "Assets.hpp"
|
||||||
|
|
||||||
Assets::~Assets() {
|
Assets::~Assets() = default;
|
||||||
}
|
|
||||||
|
|
||||||
const std::vector<TextureAnimation>& Assets::getAnimations() {
|
const std::vector<TextureAnimation>& Assets::getAnimations() {
|
||||||
return animations;
|
return animations;
|
||||||
|
|||||||
@ -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() {}
|
Assets() = default;
|
||||||
Assets(const Assets&) = delete;
|
Assets(const Assets&) = delete;
|
||||||
~Assets();
|
~Assets();
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,8 @@ 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, glm::vec3 def={}) {
|
inline glm::vec3 getSource3f(uint source, ALenum field, const glm::vec3& def= {}
|
||||||
|
) {
|
||||||
glm::vec3 value = def;
|
glm::vec3 value = def;
|
||||||
if (source == 0)
|
if (source == 0)
|
||||||
return def;
|
return def;
|
||||||
|
|||||||
@ -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(
|
||||||
glm::vec3 position,
|
const glm::vec3& position,
|
||||||
glm::vec3 velocity,
|
const glm::vec3& velocity,
|
||||||
glm::vec3 lookAt,
|
const glm::vec3& lookAt,
|
||||||
glm::vec3 up
|
const 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.at(index).get();
|
sound = sound->variants[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.emplace(id, std::move(speaker_ptr));
|
speakers.try_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.emplace(id, stream);
|
streams.try_emplace(id, stream);
|
||||||
speakers.emplace(id, std::move(speaker_ptr));
|
speakers.try_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,
|
||||||
glm::vec3 position,
|
const glm::vec3& position,
|
||||||
bool relative,
|
bool relative,
|
||||||
float volume,
|
float volume,
|
||||||
float pitch,
|
float pitch,
|
||||||
|
|||||||
@ -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(
|
||||||
glm::vec3 position,
|
const glm::vec3& position,
|
||||||
glm::vec3 velocity,
|
const glm::vec3& velocity,
|
||||||
glm::vec3 lookAt,
|
const glm::vec3& lookAt,
|
||||||
glm::vec3 up
|
const 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,
|
||||||
glm::vec3 position,
|
const glm::vec3& position,
|
||||||
bool relative,
|
bool relative,
|
||||||
float volume,
|
float volume,
|
||||||
float pitch,
|
float pitch,
|
||||||
|
|||||||
@ -23,7 +23,7 @@ namespace xml {
|
|||||||
std::string name;
|
std::string name;
|
||||||
std::string text;
|
std::string text;
|
||||||
public:
|
public:
|
||||||
Attribute() {};
|
Attribute() = default;
|
||||||
Attribute(std::string name, std::string text);
|
Attribute(std::string name, std::string text);
|
||||||
|
|
||||||
const std::string& getName() const;
|
const std::string& getName() const;
|
||||||
|
|||||||
@ -46,8 +46,7 @@ Content::Content(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Content::~Content() {
|
Content::~Content() = default;
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@ -119,7 +119,7 @@ public:
|
|||||||
|
|
||||||
static constexpr size_t MISSING = SIZE_MAX;
|
static constexpr size_t MISSING = SIZE_MAX;
|
||||||
|
|
||||||
void add(std::string name, dynamic::Map_sptr map) {
|
void add(const 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);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "../objects/rigging.hpp"
|
#include "../objects/rigging.hpp"
|
||||||
|
|
||||||
ContentBuilder::~ContentBuilder() {}
|
ContentBuilder::~ContentBuilder() = default;
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@ -85,7 +85,7 @@ bool ContentLoader::fixPackIndices(
|
|||||||
indexed.push_back(name);
|
indexed.push_back(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto name : detected) {
|
for (const auto &name : detected) {
|
||||||
if (!util::contains(indexed, name)) {
|
if (!util::contains(indexed, name)) {
|
||||||
arr->put(name);
|
arr->put(name);
|
||||||
modified = true;
|
modified = true;
|
||||||
@ -176,9 +176,10 @@ 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);
|
||||||
def.hitboxes[i].a = glm::vec3(box->num(0), box->num(1), box->num(2));
|
auto& hitboxesIndex = def.hitboxes[i];
|
||||||
def.hitboxes[i].b = glm::vec3(box->num(3), box->num(4), box->num(5));
|
hitboxesIndex.a = glm::vec3(box->num(0), box->num(1), box->num(2));
|
||||||
def.hitboxes[i].b += def.hitboxes[i].a;
|
hitboxesIndex.b = glm::vec3(box->num(3), box->num(4), box->num(5));
|
||||||
|
hitboxesIndex.b += hitboxesIndex.a;
|
||||||
}
|
}
|
||||||
} else if ((boxarr = root->list("hitbox"))){
|
} else if ((boxarr = root->list("hitbox"))){
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
@ -251,11 +252,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.push_back(boxarr->str(6));
|
def.modelTextures.emplace_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.push_back(boxarr->str(j));
|
def.modelTextures.emplace_back(boxarr->str(j));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
for (uint j = 6; j < 12; j++) {
|
for (uint j = 6; j < 12; j++) {
|
||||||
@ -276,7 +277,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.push_back(tgonobj->str(9));
|
def.modelTextures.emplace_back(tgonobj->str(9));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,7 +314,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.push_back(componentsarr->str(i));
|
def.components.emplace_back(componentsarr->str(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (auto boxarr = root->list("hitbox")) {
|
if (auto boxarr = root->list("hitbox")) {
|
||||||
@ -324,12 +325,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.push_back({i, {
|
def.boxSensors.emplace_back(i, AABB{
|
||||||
{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.push_back({i, sensorarr->num(1)});
|
def.radialSensors.emplace_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);
|
||||||
|
|||||||
@ -142,5 +142,4 @@ ContentPackRuntime::ContentPackRuntime(
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentPackRuntime::~ContentPackRuntime() {
|
ContentPackRuntime::~ContentPackRuntime() = default;
|
||||||
}
|
|
||||||
|
|||||||
@ -5,11 +5,10 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
PacksManager::PacksManager() {
|
PacksManager::PacksManager() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void PacksManager::setSources(std::vector<fs::path> sources) {
|
void PacksManager::setSources(std::vector<fs::path> sources) {
|
||||||
this->sources = sources;
|
this->sources = std::move(sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacksManager::scan() {
|
void PacksManager::scan() {
|
||||||
@ -19,7 +18,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.emplace(pack.id, pack);
|
packs.try_emplace(pack.id, pack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ namespace dynamic {
|
|||||||
public:
|
public:
|
||||||
std::vector<Value> values;
|
std::vector<Value> values;
|
||||||
|
|
||||||
List() {}
|
List() = default;
|
||||||
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() {}
|
Map() = default;
|
||||||
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(std::string key, std::unique_ptr<Map> value) {
|
Map& put(const std::string& key, std::unique_ptr<Map> value) {
|
||||||
return put(key, Map_sptr(value.release()));
|
return put(key, Map_sptr(value.release()));
|
||||||
}
|
}
|
||||||
Map& put(std::string key, std::unique_ptr<List> value) {
|
Map& put(const std::string& key, std::unique_ptr<List> value) {
|
||||||
return put(key, List_sptr(value.release()));
|
return put(key, List_sptr(value.release()));
|
||||||
}
|
}
|
||||||
Map& put(std::string key, int value) {
|
Map& put(const 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(std::string key, unsigned int value) {
|
Map& put(const 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(std::string key, int64_t value) {
|
Map& put(const 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(std::string key, uint64_t value) {
|
Map& put(const 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(std::string key, float value) {
|
Map& put(const 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(std::string key, double value) {
|
Map& put(const 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(std::string key, bool value) {
|
Map& put(const std::string& key, bool value) {
|
||||||
return put(key, Value(static_cast<bool>(value)));
|
return put(key, Value(static_cast<bool>(value)));
|
||||||
}
|
}
|
||||||
Map& put(std::string key, const char* value) {
|
Map& put(const 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);
|
||||||
|
|||||||
@ -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, std::string name, NumberSetting& setting) {
|
static void create_channel(Engine* engine, const std::string& name, NumberSetting& setting) {
|
||||||
if (name != "master") {
|
if (name != "master") {
|
||||||
audio::create_channel(name);
|
audio::create_channel(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -73,11 +73,12 @@ std::shared_ptr<Task> WorldConverter::startTask(
|
|||||||
[=](){return std::make_shared<ConverterWorker>(converter);},
|
[=](){return std::make_shared<ConverterWorker>(converter);},
|
||||||
[=](int&) {}
|
[=](int&) {}
|
||||||
);
|
);
|
||||||
while (!converter->tasks.empty()) {
|
auto& converterTasks = converter->tasks;
|
||||||
const convert_task& task = converter->tasks.front();
|
while (!converterTasks.empty()) {
|
||||||
|
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);
|
||||||
converter->tasks.pop();
|
converterTasks.pop();
|
||||||
}
|
}
|
||||||
pool->setOnComplete([=]() {
|
pool->setOnComplete([=]() {
|
||||||
converter->write();
|
converter->write();
|
||||||
|
|||||||
@ -47,8 +47,7 @@ WorldFiles::WorldFiles(const fs::path& directory, const DebugSettings& settings)
|
|||||||
regions.doWriteLights = doWriteLights;
|
regions.doWriteLights = doWriteLights;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldFiles::~WorldFiles() {
|
WorldFiles::~WorldFiles() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void WorldFiles::createDirectories() {
|
void WorldFiles::createDirectories() {
|
||||||
fs::create_directories(directory / fs::path("data"));
|
fs::create_directories(directory / fs::path("data"));
|
||||||
|
|||||||
@ -56,8 +56,7 @@ WorldRegion::WorldRegion()
|
|||||||
sizes(std::make_unique<uint32_t[]>(REGION_CHUNKS_COUNT))
|
sizes(std::make_unique<uint32_t[]>(REGION_CHUNKS_COUNT))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
WorldRegion::~WorldRegion() {
|
WorldRegion::~WorldRegion() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void WorldRegion::setUnsaved(bool unsaved) {
|
void WorldRegion::setUnsaved(bool unsaved) {
|
||||||
this->unsaved = unsaved;
|
this->unsaved = unsaved;
|
||||||
@ -98,8 +97,7 @@ 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() {
|
WorldRegions::~WorldRegions() = default;
|
||||||
}
|
|
||||||
|
|
||||||
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];
|
||||||
@ -198,7 +196,7 @@ ubyte* WorldRegions::getData(int x, int z, int layer, uint32_t& size) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
regfile_ptr WorldRegions::useRegFile(glm::ivec3 coord) {
|
regfile_ptr WorldRegions::useRegFile(const glm::ivec3& coord) {
|
||||||
auto* file = openRegFiles[coord].get();
|
auto* file = openRegFiles[coord].get();
|
||||||
file->inUse = true;
|
file->inUse = true;
|
||||||
return regfile_ptr(file, ®FilesCv);
|
return regfile_ptr(file, ®FilesCv);
|
||||||
@ -210,7 +208,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(glm::ivec3 coord, bool create) {
|
regfile_ptr WorldRegions::getRegFile(const 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);
|
||||||
@ -227,7 +225,7 @@ regfile_ptr WorldRegions::getRegFile(glm::ivec3 coord, bool create) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
regfile_ptr WorldRegions::createRegFile(glm::ivec3 coord) {
|
regfile_ptr WorldRegions::createRegFile(const 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;
|
||||||
@ -354,7 +352,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, std::vector<ubyte> entitiesData){
|
void WorldRegions::put(Chunk* chunk, const std::vector<ubyte>& entitiesData){
|
||||||
assert(chunk != nullptr);
|
assert(chunk != nullptr);
|
||||||
if (!chunk->flags.lighted) {
|
if (!chunk->flags.lighted) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -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(glm::ivec3 coord, bool create=true);
|
regfile_ptr getRegFile(const glm::ivec3& coord, bool create=true);
|
||||||
void closeRegFile(glm::ivec3 coord);
|
void closeRegFile(glm::ivec3 coord);
|
||||||
regfile_ptr useRegFile(glm::ivec3 coord);
|
regfile_ptr useRegFile(const glm::ivec3& coord);
|
||||||
regfile_ptr createRegFile(glm::ivec3 coord);
|
regfile_ptr createRegFile(const 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, std::vector<ubyte> entitiesData);
|
void put(Chunk* chunk, const std::vector<ubyte>& entitiesData);
|
||||||
|
|
||||||
/// @brief Store data in specified region
|
/// @brief Store data in specified region
|
||||||
/// @param x chunk.x
|
/// @param x chunk.x
|
||||||
|
|||||||
@ -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.push_back(root.name+":"+folderName+"/"+name);
|
entries.emplace_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.push_back("core:"+folderName+"/"+name);
|
entries.emplace_back("core:"+folderName+"/"+name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return entries;
|
return entries;
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -38,8 +38,7 @@ ContentGfxCache::ContentGfxCache(const Content* content, Assets* assets) : conte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentGfxCache::~ContentGfxCache() {
|
ContentGfxCache::~ContentGfxCache() = default;
|
||||||
}
|
|
||||||
|
|
||||||
const Content* ContentGfxCache::getContent() const {
|
const Content* ContentGfxCache::getContent() const {
|
||||||
return content;
|
return content;
|
||||||
|
|||||||
@ -81,8 +81,7 @@ LevelFrontend::LevelFrontend(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
LevelFrontend::~LevelFrontend() {
|
LevelFrontend::~LevelFrontend() = default;
|
||||||
}
|
|
||||||
|
|
||||||
Level* LevelFrontend::getLevel() const {
|
Level* LevelFrontend::getLevel() const {
|
||||||
return level;
|
return level;
|
||||||
|
|||||||
@ -314,7 +314,7 @@ void Hud::openInventory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Hud::openInventory(
|
void Hud::openInventory(
|
||||||
glm::ivec3 block,
|
const 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);
|
||||||
|
|||||||
@ -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(
|
||||||
glm::ivec3 block,
|
const glm::ivec3& block,
|
||||||
UiDocument* doc,
|
UiDocument* doc,
|
||||||
std::shared_ptr<Inventory> blockInv,
|
std::shared_ptr<Inventory> blockinv,
|
||||||
bool playerInventory
|
bool playerInventory
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -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.reset(lang.release());
|
current = std::move(lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
void langs::setup(const fs::path& resdir,
|
void langs::setup(const fs::path& resdir,
|
||||||
|
|||||||
@ -19,8 +19,7 @@ Atlas::Atlas(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas::~Atlas() {
|
Atlas::~Atlas() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void Atlas::prepare() {
|
void Atlas::prepare() {
|
||||||
texture = Texture::from(image.get());
|
texture = Texture::from(image.get());
|
||||||
|
|||||||
@ -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() {}
|
AtlasBuilder() = default;
|
||||||
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; };
|
||||||
|
|||||||
@ -59,8 +59,8 @@ void Batch2D::vertex(
|
|||||||
buffer[index++] = a;
|
buffer[index++] = a;
|
||||||
}
|
}
|
||||||
void Batch2D::vertex(
|
void Batch2D::vertex(
|
||||||
glm::vec2 point,
|
const glm::vec2& point,
|
||||||
glm::vec2 uvpoint,
|
const 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,
|
||||||
glm::vec4 tint
|
const glm::vec4& tint
|
||||||
) {
|
) {
|
||||||
if (index + 6*B2D_VERTEX_SIZE >= capacity) {
|
if (index + 6*B2D_VERTEX_SIZE >= capacity) {
|
||||||
flush();
|
flush();
|
||||||
@ -322,11 +322,13 @@ 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, glm::vec4 tint){
|
void Batch2D::sprite(float x, float y, float w, float h, const UVRegion& region,
|
||||||
|
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, glm::vec4 tint){
|
void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index,
|
||||||
|
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;
|
||||||
|
|||||||
@ -31,8 +31,8 @@ class Batch2D : public Flushable {
|
|||||||
);
|
);
|
||||||
|
|
||||||
void vertex(
|
void vertex(
|
||||||
glm::vec2 point,
|
const glm::vec2& point,
|
||||||
glm::vec2 uvpoint,
|
const glm::vec2& uvpoint,
|
||||||
float r, float g, float b, float a
|
float r, float g, float b, float a
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -44,11 +44,13 @@ 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, glm::vec4 tint);
|
void sprite(float x, float y, float w, float h, const UVRegion& region,
|
||||||
void sprite(float x, float y, float w, float h, int atlasRes, int index, glm::vec4 tint);
|
const 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(glm::vec4 color) {
|
inline void setColor(const glm::vec4& color) {
|
||||||
this->color = color;
|
this->color = color;
|
||||||
}
|
}
|
||||||
inline glm::vec4 getColor() const {
|
inline glm::vec4 getColor() const {
|
||||||
@ -69,7 +71,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,
|
||||||
glm::vec4 tint
|
const glm::vec4& tint
|
||||||
);
|
);
|
||||||
|
|
||||||
void rect(float x, float y, float w, float h);
|
void rect(float x, float y, float w, float h);
|
||||||
|
|||||||
@ -51,7 +51,7 @@ void Batch3D::vertex(
|
|||||||
buffer[index++] = a;
|
buffer[index++] = a;
|
||||||
}
|
}
|
||||||
void Batch3D::vertex(
|
void Batch3D::vertex(
|
||||||
glm::vec3 coord, float u, float v,
|
const 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(
|
||||||
glm::vec3 point,
|
const 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
|
||||||
) {
|
) {
|
||||||
buffer[index++] = point.x;
|
buffer[index++] = point.x;
|
||||||
@ -118,12 +118,12 @@ void Batch3D::texture(Texture* new_texture){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Batch3D::sprite(
|
void Batch3D::sprite(
|
||||||
glm::vec3 pos,
|
const glm::vec3& pos,
|
||||||
glm::vec3 up,
|
const glm::vec3& up,
|
||||||
glm::vec3 right,
|
const glm::vec3& right,
|
||||||
float w, float h,
|
float w, float h,
|
||||||
const UVRegion& uv,
|
const UVRegion& uv,
|
||||||
glm::vec4 color
|
const 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(glm::vec3 coord, glm::vec2 uv, glm::vec4 tint) {
|
void Batch3D::point(const glm::vec3& coord, const glm::vec2& uv, const 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(glm::vec3 coord, glm::vec4 tint) {
|
void Batch3D::point(const glm::vec3& coord, const glm::vec4& tint) {
|
||||||
point(coord, glm::vec2(), tint);
|
point(coord, glm::vec2(), tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,12 +27,13 @@ class Batch3D : public Flushable {
|
|||||||
float r, float g, float b, float a
|
float r, float g, float b, float a
|
||||||
);
|
);
|
||||||
void vertex(
|
void vertex(
|
||||||
glm::vec3 coord,
|
const 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(
|
||||||
glm::vec3 point, glm::vec2 uvpoint,
|
const glm::vec3& point,
|
||||||
|
const glm::vec2& uvpoint,
|
||||||
float r, float g, float b, float a
|
float r, float g, float b, float a
|
||||||
);
|
);
|
||||||
void face(
|
void face(
|
||||||
@ -49,12 +50,18 @@ public:
|
|||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
void texture(Texture* texture);
|
void texture(Texture* texture);
|
||||||
void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h, const UVRegion& uv, glm::vec4 tint);
|
void sprite(
|
||||||
|
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(glm::vec3 pos, glm::vec2 uv, glm::vec4 tint);
|
void point(
|
||||||
void point(glm::vec3 pos, glm::vec4 tint);
|
const glm::vec3& coord, const glm::vec2& uv, const glm::vec4& tint);
|
||||||
|
void point(const glm::vec3& coord, const glm::vec4& tint);
|
||||||
void flush() override;
|
void flush() override;
|
||||||
void flushPoints();
|
void flushPoints();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -148,7 +148,7 @@ void DrawContext::setBlendMode(BlendMode mode) {
|
|||||||
set_blend_mode(mode);
|
set_blend_mode(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawContext::setScissors(glm::vec4 area) {
|
void DrawContext::setScissors(const glm::vec4& area) {
|
||||||
Window::pushScissor(area);
|
Window::pushScissor(area);
|
||||||
scissorsCount++;
|
scissorsCount++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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(glm::vec4 area);
|
void setScissors(const glm::vec4& area);
|
||||||
void setLineWidth(float width);
|
void setLineWidth(float width);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -12,8 +12,7 @@ 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(){
|
Font::~Font() = default;
|
||||||
}
|
|
||||||
|
|
||||||
int Font::getYOffset() const {
|
int Font::getYOffset() const {
|
||||||
return yoffset;
|
return yoffset;
|
||||||
|
|||||||
@ -41,8 +41,7 @@ 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() {
|
ImageData::~ImageData() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void ImageData::flipX() {
|
void ImageData::flipX() {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
|
|||||||
@ -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(glm::vec3 xyz, glm::vec3 whd, glm::vec4 rgba) {
|
inline void box(const glm::vec3 &xyz, const glm::vec3 &whd, const 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,11 @@ 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(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm) {
|
void Mesh::addPlane(
|
||||||
|
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});
|
||||||
@ -18,7 +22,7 @@ void Mesh::addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm
|
|||||||
vertices.push_back({pos-right+up, {0,1}, norm});
|
vertices.push_back({pos-right+up, {0,1}, norm});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::addBox(glm::vec3 pos, glm::vec3 size) {
|
void Mesh::addBox(const glm::vec3 &pos, const 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);
|
||||||
|
|
||||||
|
|||||||
@ -16,8 +16,12 @@ namespace model {
|
|||||||
std::string texture;
|
std::string texture;
|
||||||
std::vector<Vertex> vertices;
|
std::vector<Vertex> vertices;
|
||||||
|
|
||||||
void addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm);
|
void addPlane(
|
||||||
void addBox(glm::vec3 pos, glm::vec3 size);
|
const glm::vec3& pos,
|
||||||
|
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 {
|
||||||
|
|||||||
@ -18,8 +18,7 @@ PostProcessing::PostProcessing() {
|
|||||||
quadMesh = std::make_unique<Mesh>(vertices, 6, attrs);
|
quadMesh = std::make_unique<Mesh>(vertices, 6, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
PostProcessing::~PostProcessing() {
|
PostProcessing::~PostProcessing() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void PostProcessing::use(DrawContext& context) {
|
void PostProcessing::use(DrawContext& context) {
|
||||||
const auto& vp = context.getViewport();
|
const auto& vp = context.getViewport();
|
||||||
|
|||||||
@ -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.emplace(name, location);
|
uniformLocations.try_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, glm::vec2 xy){
|
void Shader::uniform2f(const std::string& name, const glm::vec2& xy){
|
||||||
glUniform2f(getUniformLocation(name), xy.x, xy.y);
|
glUniform2f(getUniformLocation(name), xy.x, xy.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::uniform2i(const std::string& name, glm::ivec2 xy){
|
void Shader::uniform2i(const std::string& name, const 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, glm::vec3 xyz){
|
void Shader::uniform3f(const std::string& name, const glm::vec3& xyz){
|
||||||
glUniform3f(getUniformLocation(name), xyz.x, xyz.y, xyz.z);
|
glUniform3f(getUniformLocation(name), xyz.x, xyz.y, xyz.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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, glm::vec2 xy);
|
void uniform2f(const std::string& name, const glm::vec2& xy);
|
||||||
void uniform2i(const std::string& name, glm::ivec2 xy);
|
void uniform2i(const std::string& name, const 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, glm::vec3 xyz);
|
void uniform3f(const std::string& name, const 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
|
||||||
|
|||||||
@ -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() {};
|
~TextureAnimation() = default;
|
||||||
|
|
||||||
void addFrame(const Frame& frame) { frames.emplace_back(frame); };
|
void addFrame(const Frame& frame) { frames.emplace_back(frame); };
|
||||||
|
|
||||||
|
|||||||
@ -50,9 +50,10 @@ 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 * glm::vec3(size * 0.63f)*0.5f * glm::vec3(1,1,-1),
|
-hitbox * scaledSize * 0.5f * glm::vec3(1,1,-1),
|
||||||
hitbox * glm::vec3(size * 0.63f),
|
hitbox * scaledSize,
|
||||||
texfaces, glm::vec4(1.0f),
|
texfaces, glm::vec4(1.0f),
|
||||||
!def->rt.emissive
|
!def->rt.emissive
|
||||||
);
|
);
|
||||||
|
|||||||
@ -35,7 +35,7 @@ struct DecomposedMat4 {
|
|||||||
glm::vec4 perspective;
|
glm::vec4 perspective;
|
||||||
};
|
};
|
||||||
|
|
||||||
static glm::mat4 extract_rotation(glm::mat4 matrix) {
|
static glm::mat4 extract_rotation(const glm::mat4& matrix) {
|
||||||
DecomposedMat4 decomposed = {};
|
DecomposedMat4 decomposed = {};
|
||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
glm::decompose(
|
glm::decompose(
|
||||||
@ -64,11 +64,12 @@ ModelBatch::ModelBatch(size_t capacity, Assets* assets, Chunks* chunks)
|
|||||||
blank = Texture::from(&image);
|
blank = Texture::from(&image);
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelBatch::~ModelBatch() {
|
ModelBatch::~ModelBatch() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
|
void ModelBatch::draw(const model::Mesh& mesh,
|
||||||
const glm::mat3& rotation, glm::vec3 tint,
|
const glm::mat4& matrix,
|
||||||
|
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));
|
||||||
@ -95,8 +96,9 @@ void ModelBatch::draw(const model::Mesh& mesh, const glm::mat4& matrix,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelBatch::draw(glm::mat4 matrix,
|
void ModelBatch::draw(
|
||||||
glm::vec3 tint,
|
const glm::mat4& matrix,
|
||||||
|
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) {
|
||||||
|
|||||||
@ -37,7 +37,10 @@ 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(
|
||||||
glm::vec3 pos, glm::vec2 uv, glm::vec4 light, glm::vec3 tint
|
const glm::vec3& pos,
|
||||||
|
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;
|
||||||
@ -64,8 +67,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,
|
||||||
glm::vec3 tint,
|
const 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);
|
||||||
@ -84,8 +87,9 @@ public:
|
|||||||
ModelBatch(size_t capacity, Assets* assets, Chunks* chunks);
|
ModelBatch(size_t capacity, Assets* assets, Chunks* chunks);
|
||||||
~ModelBatch();
|
~ModelBatch();
|
||||||
|
|
||||||
void draw(glm::mat4 matrix,
|
void draw(
|
||||||
glm::vec3 tint,
|
const glm::mat4& matrix,
|
||||||
|
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();
|
||||||
|
|||||||
@ -55,8 +55,7 @@ Skybox::Skybox(uint size, Shader* shader)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Skybox::~Skybox() {
|
Skybox::~Skybox() = default;
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
||||||
|
|||||||
@ -75,8 +75,7 @@ WorldRenderer::WorldRenderer(Engine* engine, LevelFrontend* frontend, Player* pl
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldRenderer::~WorldRenderer() {
|
WorldRenderer::~WorldRenderer() = default;
|
||||||
}
|
|
||||||
|
|
||||||
bool WorldRenderer::drawChunk(
|
bool WorldRenderer::drawChunk(
|
||||||
size_t index,
|
size_t index,
|
||||||
@ -231,26 +230,29 @@ 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 + glm::vec3(0.02), glm::vec4(0.f, 0.f, 0.f, 0.5f));
|
lineBatch->box(center, size + boxOffset, boxColor);
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -341,12 +343,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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,8 +44,7 @@ GUI::GUI() {
|
|||||||
container->add(tooltip);
|
container->add(tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI::~GUI() {
|
GUI::~GUI() = default;
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Menu> GUI::getMenu() {
|
std::shared_ptr<Menu> GUI::getMenu() {
|
||||||
return menu;
|
return menu;
|
||||||
|
|||||||
@ -52,7 +52,7 @@ InventoryBuilder::InventoryBuilder() {
|
|||||||
|
|
||||||
void InventoryBuilder::addGrid(
|
void InventoryBuilder::addGrid(
|
||||||
int cols, int count,
|
int cols, int count,
|
||||||
glm::vec2 pos,
|
const 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 = L"";
|
tooltip.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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(glm::vec2 origin) {
|
void InventoryView::setOrigin(const glm::vec2 &origin) {
|
||||||
this->origin = origin;
|
this->origin = origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -93,7 +93,7 @@ namespace gui {
|
|||||||
|
|
||||||
virtual void setPos(glm::vec2 pos) override;
|
virtual void setPos(glm::vec2 pos) override;
|
||||||
|
|
||||||
void setOrigin(glm::vec2 origin);
|
void setOrigin(const 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,
|
||||||
glm::vec2 pos,
|
const glm::vec2 &pos,
|
||||||
int padding,
|
int padding,
|
||||||
bool addpanel,
|
bool addpanel,
|
||||||
const SlotLayout& slotLayout
|
const SlotLayout& slotLayout
|
||||||
|
|||||||
@ -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.at(i).offset > index) {
|
if (cache.lines[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.at(i);
|
auto& line = cache.lines[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) {
|
||||||
|
|||||||
@ -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")) {
|
||||||
auto oname = element->attr("orientation").getText();
|
const 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.at(0)->getTag() != "#") {
|
if (!elements.empty() && elements[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);
|
||||||
|
|||||||
@ -8,8 +8,7 @@
|
|||||||
Inventories::Inventories(Level& level) : level(level) {
|
Inventories::Inventories(Level& level) : level(level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Inventories::~Inventories() {
|
Inventories::~Inventories() = default;
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
||||||
|
|||||||
@ -38,8 +38,8 @@ struct ItemDef {
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
itemid_t id;
|
itemid_t id;
|
||||||
item_funcs_set funcsset {};
|
|
||||||
blockid_t placingBlock;
|
blockid_t placingBlock;
|
||||||
|
item_funcs_set funcsset {};
|
||||||
bool emissive = false;
|
bool emissive = false;
|
||||||
} rt {};
|
} rt {};
|
||||||
|
|
||||||
|
|||||||
@ -20,8 +20,7 @@ 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(){
|
Lighting::~Lighting() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void Lighting::clear(){
|
void Lighting::clear(){
|
||||||
for (size_t index = 0; index < chunks->volume; index++){
|
for (size_t index = 0; index < chunks->volume; index++){
|
||||||
|
|||||||
@ -30,8 +30,7 @@ ChunksController::ChunksController(Level* level, uint padding)
|
|||||||
generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) {
|
generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ChunksController::~ChunksController(){
|
ChunksController::~ChunksController() = default;
|
||||||
}
|
|
||||||
|
|
||||||
void ChunksController::update(int64_t maxDuration) {
|
void ChunksController::update(int64_t maxDuration) {
|
||||||
int64_t mcstotal = 0;
|
int64_t mcstotal = 0;
|
||||||
@ -113,21 +112,22 @@ 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 (!chunk->flags.loaded) {
|
if (!chunkFlags.loaded) {
|
||||||
generator->generate(
|
generator->generate(
|
||||||
chunk->voxels, x, z,
|
chunk->voxels, x, z,
|
||||||
level->getWorld()->getSeed()
|
level->getWorld()->getSeed()
|
||||||
);
|
);
|
||||||
chunk->flags.unsaved = true;
|
chunkFlags.unsaved = true;
|
||||||
}
|
}
|
||||||
chunk->updateHeights();
|
chunk->updateHeights();
|
||||||
|
|
||||||
if (!chunk->flags.loadedLights) {
|
if (!chunkFlags.loadedLights) {
|
||||||
Lighting::prebuildSkyLight(
|
Lighting::prebuildSkyLight(
|
||||||
chunk.get(), level->content->getIndices()
|
chunk.get(), level->content->getIndices()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
chunk->flags.loaded = true;
|
chunkFlags.loaded = true;
|
||||||
chunk->flags.ready = true;
|
chunkFlags.ready = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -255,8 +255,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
dynamic::Value applyRelative(
|
dynamic::Value applyRelative(
|
||||||
Argument* arg,
|
Argument* arg,
|
||||||
dynamic::Value value,
|
const dynamic::Value& value,
|
||||||
const dynamic::Value& origin
|
const dynamic::Value& origin
|
||||||
) {
|
) {
|
||||||
if (origin.index() == 0) {
|
if (origin.index() == 0) {
|
||||||
|
|||||||
@ -55,7 +55,7 @@ namespace cmd {
|
|||||||
std::string description;
|
std::string description;
|
||||||
executor_func executor;
|
executor_func executor;
|
||||||
public:
|
public:
|
||||||
Command() {}
|
Command() = default;
|
||||||
|
|
||||||
Command(
|
Command(
|
||||||
std::string name,
|
std::string name,
|
||||||
|
|||||||
@ -47,11 +47,12 @@ 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
|
||||||
level->objects.erase(
|
auto& objects = level->objects;
|
||||||
|
objects.erase(
|
||||||
std::remove_if(
|
std::remove_if(
|
||||||
level->objects.begin(), level->objects.end(),
|
objects.begin(), objects.end(),
|
||||||
[](auto obj) { return obj == nullptr; }),
|
[](auto obj) { return obj == nullptr; }),
|
||||||
level->objects.end()
|
objects.end()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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,
|
||||||
const PlayerInput& input, float delta) {
|
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(const PlayerInput& input, float delta, Chunks* chunks) {
|
void CameraControl::update(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.value();
|
auto entity = *entityOpt;
|
||||||
if (lclick) {
|
if (lclick) {
|
||||||
scripting::on_attacked(entity, player.get(), player->getEntity());
|
scripting::on_attacked(entity, player.get(), player->getEntity());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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, const PlayerInput& input,
|
void updateFovEffects(const Hitbox& hitbox, 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(const PlayerInput& input, float delta, Chunks* chunks);
|
void update(PlayerInput input, float delta, Chunks* chunks);
|
||||||
void refresh();
|
void refresh();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -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.at(i);
|
auto& arg = args[i];
|
||||||
lua::createtable(L, 0, 2);
|
lua::createtable(L, 0, 2);
|
||||||
|
|
||||||
lua::pushstring(L, arg.name);
|
lua::pushstring(L, arg.name);
|
||||||
|
|||||||
@ -324,8 +324,6 @@ 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},
|
||||||
@ -367,6 +365,8 @@ 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;
|
||||||
|
|||||||
@ -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.at(i);
|
auto& dpack = pack.dependencies[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.at(0), content);
|
return l_pack_get_info(L, vec[0], content);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -151,20 +151,20 @@ namespace lua {
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int pushivec3_stack(lua::State* L, glm::ivec3 vec) {
|
inline int pushivec3_stack(lua::State* L, const 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, glm::vec3 vec) {
|
inline int pushvec3_stack(lua::State* L, const 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, glm::vec4 vec) {
|
inline int pushvec4_stack(lua::State* L, const 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, glm::vec2 vec) {
|
inline int pushvec2(lua::State* L, const glm::vec2 &vec) {
|
||||||
return pushvec(L, vec);
|
return pushvec(L, vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int pushvec3(lua::State* L, glm::vec3 vec) {
|
inline int pushvec3(lua::State* L, const glm::vec3 &vec) {
|
||||||
return pushvec(L, vec);
|
return pushvec(L, vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int pushvec4(lua::State* L, glm::vec4 vec) {
|
inline int pushvec4(lua::State* L, const 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, glm::mat4 matrix) {
|
inline int pushmat4(lua::State* L, const 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, glm::mat4 matrix) {
|
inline int setmat4(lua::State* L, int idx, const 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++) {
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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(L"");
|
return std::wstring();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
class Frustum {
|
class Frustum {
|
||||||
public:
|
public:
|
||||||
Frustum() {};
|
Frustum() = default;
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
@ -70,7 +70,7 @@ struct AABB {
|
|||||||
b = end;
|
b = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void addPoint(glm::vec3 p) {
|
inline void addPoint(const glm::vec3& p) {
|
||||||
a = glm::min(a, p);
|
a = glm::min(a, p);
|
||||||
b = glm::max(b, p);
|
b = glm::max(b, p);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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(){};
|
AABBFaces() = default;
|
||||||
AABBFaces(const rayvec3& parentBoxPos, const AABB& parentBox);
|
AABBFaces(const rayvec3& parentBoxPos, const AABB& parentBox);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -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, Entity entity) {
|
void Entities::loadEntity(const dynamic::Map_sptr& map, const 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, Entity entity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Entities::RaycastResult> Entities::rayCast(
|
std::optional<Entities::RaycastResult> Entities::rayCast(
|
||||||
glm::vec3 start, glm::vec3 dir, float maxDistance, entityid_t ignore
|
const glm::vec3 &start, const 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(AABB aabb) {
|
std::vector<Entity> Entities::getAllInside(const 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(AABB aabb) {
|
|||||||
return collected;
|
return collected;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Entity> Entities::getAllInRadius(glm::vec3 center, float radius) {
|
std::vector<Entity> Entities::getAllInRadius(const glm::vec3 ¢er, 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()) {
|
||||||
|
|||||||
@ -49,19 +49,19 @@ struct Transform {
|
|||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
inline void setRot(glm::mat3 m) {
|
inline void setRot(const glm::mat3 &m) {
|
||||||
rot = m;
|
rot = m;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setSize(glm::vec3 v) {
|
inline void setSize(const 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(glm::vec3 v) {
|
inline void setPos(const 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(
|
||||||
glm::vec3 start, glm::vec3 dir, float maxDistance, entityid_t ignore=-1);
|
const glm::vec3 &start, const 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, Entity entity);
|
void loadEntity(const dynamic::Map_sptr& map, const Entity &entity);
|
||||||
void onSave(const Entity& entity);
|
void onSave(const Entity& entity);
|
||||||
bool hasBlockingInside(AABB aabb);
|
bool hasBlockingInside(AABB aabb);
|
||||||
std::vector<Entity> getAllInside(AABB aabb);
|
std::vector<Entity> getAllInside(const AABB &aabb);
|
||||||
std::vector<Entity> getAllInRadius(glm::vec3 center, float radius);
|
std::vector<Entity> getAllInRadius(const glm::vec3 ¢er, float radius);
|
||||||
void despawn(entityid_t id);
|
void despawn(entityid_t id);
|
||||||
dynamic::Value serialize(const Entity& entity);
|
dynamic::Value serialize(const Entity& entity);
|
||||||
|
|
||||||
|
|||||||
@ -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(glm::vec3 position) {
|
void Player::teleport(const 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(glm::vec3 spawnpoint) {
|
void Player::setSpawnPoint(const glm::vec3 &spawnpoint) {
|
||||||
this->spawnpoint = spawnpoint;
|
this->spawnpoint = spawnpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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(glm::vec3 position);
|
void teleport(const 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(glm::vec3 point);
|
void setSpawnPoint(const glm::vec3 &spawnpoint);
|
||||||
glm::vec3 getSpawnPoint() const;
|
glm::vec3 getSpawnPoint() const;
|
||||||
|
|
||||||
std::unique_ptr<dynamic::Map> serialize() const override;
|
std::unique_ptr<dynamic::Map> serialize() const override;
|
||||||
|
|||||||
@ -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,
|
||||||
glm::mat4 matrix) const
|
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, glm::mat4 matrix) const {
|
void SkeletonConfig::update(Skeleton& skeleton, const glm::mat4& matrix) const {
|
||||||
update(0, skeleton, root.get(), matrix);
|
update(0, skeleton, root.get(), matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -103,12 +103,12 @@ namespace rigging {
|
|||||||
size_t index,
|
size_t index,
|
||||||
Skeleton& skeleton,
|
Skeleton& skeleton,
|
||||||
Bone* node,
|
Bone* node,
|
||||||
glm::mat4 matrix) const;
|
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, glm::mat4 matrix) const;
|
void update(Skeleton& skeleton, const glm::mat4& matrix) const;
|
||||||
void render(
|
void render(
|
||||||
Assets* assets,
|
Assets* assets,
|
||||||
ModelBatch& batch,
|
ModelBatch& batch,
|
||||||
|
|||||||
@ -28,8 +28,8 @@ struct ThreadPoolResult {
|
|||||||
template<class T, class R>
|
template<class T, class R>
|
||||||
class Worker {
|
class Worker {
|
||||||
public:
|
public:
|
||||||
Worker() {}
|
Worker() = default;
|
||||||
virtual ~Worker() {}
|
virtual ~Worker() = default;
|
||||||
virtual R operator()(const std::shared_ptr<T>&) = 0;
|
virtual R operator()(const std::shared_ptr<T>&) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -11,12 +11,12 @@
|
|||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
class ArgsReader {
|
class ArgsReader {
|
||||||
int argc;
|
|
||||||
char** argv;
|
|
||||||
int pos = 0;
|
|
||||||
const char* last = "";
|
const char* last = "";
|
||||||
|
char** argv;
|
||||||
|
int argc;
|
||||||
|
int pos = 0;
|
||||||
public:
|
public:
|
||||||
ArgsReader(int argc, char** argv) : argc(argc), argv(argv) {}
|
ArgsReader(int argc, char** argv) : argv(argv), argc(argc) {}
|
||||||
|
|
||||||
void skip() {
|
void skip() {
|
||||||
pos++;
|
pos++;
|
||||||
|
|||||||
@ -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.at(i));
|
ss << util::quote(vec[1]);
|
||||||
if (i < vec.size()-1) {
|
if (i < vec.size()-1) {
|
||||||
ss << ", ";
|
ss << ", ";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,7 +37,7 @@ std::string util::quote(const std::string& s) {
|
|||||||
return escape(s);
|
return escape(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring util::lfill(std::wstring s, uint length, wchar_t c) {
|
std::wstring util::lfill(const 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(std::wstring s, uint length, wchar_t c) {
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring util::rfill(std::wstring s, uint length, wchar_t c) {
|
std::wstring util::rfill(const std::wstring& s, uint length, wchar_t c) {
|
||||||
if (s.length() >= length) {
|
if (s.length() >= length) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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(std::wstring s, uint length, wchar_t c);
|
std::wstring lfill(const std::wstring& s, uint length, wchar_t c);
|
||||||
std::wstring rfill(std::wstring s, uint length, wchar_t c);
|
std::wstring rfill(const 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);
|
||||||
|
|||||||
@ -48,7 +48,7 @@ struct CoordSystem {
|
|||||||
|
|
||||||
void transform(AABB& aabb) const;
|
void transform(AABB& aabb) const;
|
||||||
|
|
||||||
inline bool isVectorHasNegatives(glm::ivec3 vec) {
|
inline bool isVectorHasNegatives(const glm::ivec3& vec) {
|
||||||
return (vec.x < 0 || vec.y < 0 || vec.z < 0);
|
return (vec.x < 0 || vec.y < 0 || vec.z < 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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, glm::ivec3 origin, blockid_t ignore) {
|
bool Chunks::checkReplaceability(const Block* def, blockstate state, const glm::ivec3 &coord, 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 = origin;
|
auto pos = coord;
|
||||||
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, glm::ivec3
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Chunks::setRotationExtended(
|
void Chunks::setRotationExtended(
|
||||||
Block* def, blockstate state, glm::ivec3 origin, uint8_t index
|
Block* def, blockstate state, const 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(
|
||||||
glm::vec3 start,
|
const glm::vec3 &start,
|
||||||
glm::vec3 dir,
|
const 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(glm::vec3 start, glm::vec3 dir, float maxDist) {
|
glm::vec3 Chunks::rayCastToObstacle(const glm::vec3 &start, const 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;
|
||||||
|
|||||||
@ -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, glm::ivec3 origin, uint8_t rotation);
|
void setRotationExtended(Block* def, blockstate state, const 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(glm::ivec3 pos) {
|
inline voxel* get(const 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, glm::ivec3 coord, blockid_t ignore=0);
|
bool checkReplaceability(const Block* def, blockstate state, const 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(
|
||||||
glm::vec3 start,
|
const glm::vec3 &start,
|
||||||
glm::vec3 dir,
|
const 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(glm::vec3 start, glm::vec3 dir, float maxDist);
|
glm::vec3 rayCastToObstacle(const glm::vec3 &start, const 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);
|
||||||
|
|||||||
@ -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.emplace(name, Binding(type, code));
|
bindings.try_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) {
|
||||||
|
|||||||
@ -205,11 +205,11 @@ void Window::clearDepth() {
|
|||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setBgColor(glm::vec3 color) {
|
void Window::setBgColor(const glm::vec3 &color) {
|
||||||
glClearColor(color.r, color.g, color.b, 1.0f);
|
glClearColor(color.r, color.g, color.b, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setBgColor(glm::vec4 color) {
|
void Window::setBgColor(const glm::vec4 &color) {
|
||||||
glClearColor(color.r, color.g, color.b, color.a);
|
glClearColor(color.r, color.g, color.b, color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -49,8 +49,8 @@ public:
|
|||||||
|
|
||||||
static void clear();
|
static void clear();
|
||||||
static void clearDepth();
|
static void clearDepth();
|
||||||
static void setBgColor(glm::vec3 color);
|
static void setBgColor(const glm::vec3 &color);
|
||||||
static void setBgColor(glm::vec4 color);
|
static void setBgColor(const 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);
|
||||||
|
|||||||
@ -142,7 +142,7 @@ struct Binding {
|
|||||||
bool state = false;
|
bool state = false;
|
||||||
bool justChange = false;
|
bool justChange = false;
|
||||||
|
|
||||||
Binding(){}
|
Binding() = default;
|
||||||
Binding(inputtype type, int code) : type(type), code(code) {}
|
Binding(inputtype type, int code) : type(type), code(code) {}
|
||||||
|
|
||||||
bool active() const {
|
bool active() const {
|
||||||
|
|||||||
@ -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 == "") {
|
if (generator.empty()) {
|
||||||
generator = WorldGenerators::getDefaultGeneratorID();
|
generator = WorldGenerators::getDefaultGeneratorID();
|
||||||
}
|
}
|
||||||
if (auto verobj = root->map("version")) {
|
if (auto verobj = root->map("version")) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user