Merge branch 'main' of https://github.com/MihailRis/VoxelEngine-Cpp
This commit is contained in:
+12
-12
@@ -11,59 +11,59 @@
|
||||
Assets::~Assets() {
|
||||
}
|
||||
|
||||
Texture* Assets::getTexture(std::string name) const {
|
||||
Texture* Assets::getTexture(const std::string& name) const {
|
||||
auto found = textures.find(name);
|
||||
if (found == textures.end())
|
||||
return nullptr;
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
void Assets::store(std::unique_ptr<Texture> texture, std::string name){
|
||||
void Assets::store(std::unique_ptr<Texture> texture, const std::string& name){
|
||||
textures.emplace(name, std::move(texture));
|
||||
}
|
||||
|
||||
|
||||
Shader* Assets::getShader(std::string name) const{
|
||||
Shader* Assets::getShader(const std::string& name) const{
|
||||
auto found = shaders.find(name);
|
||||
if (found == shaders.end())
|
||||
return nullptr;
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
void Assets::store(std::unique_ptr<Shader> shader, std::string name){
|
||||
void Assets::store(std::unique_ptr<Shader> shader, const std::string& name){
|
||||
shaders.emplace(name, std::move(shader));
|
||||
}
|
||||
|
||||
Font* Assets::getFont(std::string name) const {
|
||||
Font* Assets::getFont(const std::string& name) const {
|
||||
auto found = fonts.find(name);
|
||||
if (found == fonts.end())
|
||||
return nullptr;
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
void Assets::store(std::unique_ptr<Font> font, std::string name){
|
||||
void Assets::store(std::unique_ptr<Font> font, const std::string& name){
|
||||
fonts.emplace(name, std::move(font));
|
||||
}
|
||||
|
||||
Atlas* Assets::getAtlas(std::string name) const {
|
||||
Atlas* Assets::getAtlas(const std::string& name) const {
|
||||
auto found = atlases.find(name);
|
||||
if (found == atlases.end())
|
||||
return nullptr;
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
void Assets::store(std::unique_ptr<Atlas> atlas, std::string name){
|
||||
void Assets::store(std::unique_ptr<Atlas> atlas, const std::string& name){
|
||||
atlases.emplace(name, std::move(atlas));
|
||||
}
|
||||
|
||||
audio::Sound* Assets::getSound(std::string name) const {
|
||||
audio::Sound* Assets::getSound(const std::string& name) const {
|
||||
auto found = sounds.find(name);
|
||||
if (found == sounds.end())
|
||||
return nullptr;
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
void Assets::store(std::unique_ptr<audio::Sound> sound, std::string name) {
|
||||
void Assets::store(std::unique_ptr<audio::Sound> sound, const std::string& name) {
|
||||
sounds.emplace(name, std::move(sound));
|
||||
}
|
||||
|
||||
@@ -75,13 +75,13 @@ void Assets::store(const TextureAnimation& animation) {
|
||||
animations.emplace_back(animation);
|
||||
}
|
||||
|
||||
UiDocument* Assets::getLayout(std::string name) const {
|
||||
UiDocument* Assets::getLayout(const std::string& name) const {
|
||||
auto found = layouts.find(name);
|
||||
if (found == layouts.end())
|
||||
return nullptr;
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
void Assets::store(std::unique_ptr<UiDocument> layout, std::string name) {
|
||||
void Assets::store(std::unique_ptr<UiDocument> layout, const std::string& name) {
|
||||
layouts[name] = std::shared_ptr<UiDocument>(std::move(layout));
|
||||
}
|
||||
|
||||
+12
-12
@@ -38,26 +38,26 @@ public:
|
||||
Assets(const Assets&) = delete;
|
||||
~Assets();
|
||||
|
||||
Texture* getTexture(std::string name) const;
|
||||
void store(std::unique_ptr<Texture> texture, std::string name);
|
||||
Texture* getTexture(const std::string& name) const;
|
||||
void store(std::unique_ptr<Texture> texture, const std::string& name);
|
||||
|
||||
Shader* getShader(std::string name) const;
|
||||
void store(std::unique_ptr<Shader> shader, std::string name);
|
||||
Shader* getShader(const std::string& name) const;
|
||||
void store(std::unique_ptr<Shader> shader, const std::string& name);
|
||||
|
||||
Font* getFont(std::string name) const;
|
||||
void store(std::unique_ptr<Font> font, std::string name);
|
||||
Font* getFont(const std::string& name) const;
|
||||
void store(std::unique_ptr<Font> font, const std::string& name);
|
||||
|
||||
Atlas* getAtlas(std::string name) const;
|
||||
void store(std::unique_ptr<Atlas> atlas, std::string name);
|
||||
Atlas* getAtlas(const std::string& name) const;
|
||||
void store(std::unique_ptr<Atlas> atlas, const std::string& name);
|
||||
|
||||
audio::Sound* getSound(std::string name) const;
|
||||
void store(std::unique_ptr<audio::Sound> sound, std::string name);
|
||||
audio::Sound* getSound(const std::string& name) const;
|
||||
void store(std::unique_ptr<audio::Sound> sound, const std::string& name);
|
||||
|
||||
const std::vector<TextureAnimation>& getAnimations();
|
||||
void store(const TextureAnimation& animation);
|
||||
|
||||
UiDocument* getLayout(std::string name) const;
|
||||
void store(std::unique_ptr<UiDocument> layout, std::string name);
|
||||
UiDocument* getLayout(const std::string& name) const;
|
||||
void store(std::unique_ptr<UiDocument> layout, const std::string& name);
|
||||
};
|
||||
|
||||
#endif // ASSETS_ASSETS_HPP_
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
static debug::Logger logger("assets-loader");
|
||||
|
||||
@@ -32,11 +33,11 @@ AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
|
||||
}
|
||||
|
||||
void AssetsLoader::addLoader(AssetType tag, aloader_func func) {
|
||||
loaders[tag] = func;
|
||||
loaders[tag] = std::move(func);
|
||||
}
|
||||
|
||||
void AssetsLoader::add(AssetType tag, const std::string filename, const std::string alias, std::shared_ptr<AssetCfg> settings) {
|
||||
entries.push(aloader_entry{tag, filename, alias, settings});
|
||||
void AssetsLoader::add(AssetType tag, const std::string& filename, const std::string& alias, std::shared_ptr<AssetCfg> settings) {
|
||||
entries.push(aloader_entry{tag, filename, alias, std::move(settings)});
|
||||
}
|
||||
|
||||
bool AssetsLoader::hasNext() const {
|
||||
@@ -69,12 +70,12 @@ bool AssetsLoader::loadNext() {
|
||||
}
|
||||
}
|
||||
|
||||
void addLayouts(scriptenv env, const std::string& prefix, const fs::path& folder, AssetsLoader& loader) {
|
||||
void addLayouts(const scriptenv& env, const std::string& prefix, const fs::path& folder, AssetsLoader& loader) {
|
||||
if (!fs::is_directory(folder)) {
|
||||
return;
|
||||
}
|
||||
for (auto& entry : fs::directory_iterator(folder)) {
|
||||
const fs::path file = entry.path();
|
||||
const fs::path& file = entry.path();
|
||||
if (file.extension().u8string() != ".xml")
|
||||
continue;
|
||||
std::string name = prefix+":"+file.stem().u8string();
|
||||
@@ -82,7 +83,7 @@ void addLayouts(scriptenv env, const std::string& prefix, const fs::path& folder
|
||||
}
|
||||
}
|
||||
|
||||
void AssetsLoader::tryAddSound(std::string name) {
|
||||
void AssetsLoader::tryAddSound(const std::string& name) {
|
||||
if (name.empty()) {
|
||||
return;
|
||||
}
|
||||
@@ -148,7 +149,7 @@ void AssetsLoader::processPreloadList(AssetType tag, dynamic::List* list) {
|
||||
}
|
||||
}
|
||||
|
||||
void AssetsLoader::processPreloadConfig(fs::path file) {
|
||||
void AssetsLoader::processPreloadConfig(const fs::path& file) {
|
||||
auto root = files::read_json(file);
|
||||
processPreloadList(AssetType::font, root->list("fonts"));
|
||||
processPreloadList(AssetType::shader, root->list("shaders"));
|
||||
@@ -209,7 +210,7 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
|
||||
bool AssetsLoader::loadExternalTexture(
|
||||
Assets* assets,
|
||||
const std::string& name,
|
||||
std::vector<std::filesystem::path> alternatives
|
||||
const std::vector<std::filesystem::path>& alternatives
|
||||
) {
|
||||
if (assets->getTexture(name) != nullptr) {
|
||||
return true;
|
||||
@@ -255,7 +256,7 @@ std::shared_ptr<Task> AssetsLoader::startTask(runnable onDone) {
|
||||
func(assets);
|
||||
}
|
||||
);
|
||||
pool->setOnComplete(onDone);
|
||||
pool->setOnComplete(std::move(onDone));
|
||||
while (!entries.empty()) {
|
||||
const aloader_entry& entry = entries.front();
|
||||
auto ptr = std::make_shared<aloader_entry>(entry);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
|
||||
namespace dynamic {
|
||||
class Map;
|
||||
@@ -38,7 +39,7 @@ struct AssetCfg {
|
||||
struct LayoutCfg : AssetCfg {
|
||||
scriptenv env;
|
||||
|
||||
LayoutCfg(scriptenv env) : env(env) {}
|
||||
LayoutCfg(scriptenv env) : env(std::move(env)) {}
|
||||
};
|
||||
|
||||
struct SoundCfg : AssetCfg {
|
||||
@@ -68,11 +69,11 @@ class AssetsLoader {
|
||||
std::queue<aloader_entry> entries;
|
||||
const ResPaths* paths;
|
||||
|
||||
void tryAddSound(std::string name);
|
||||
void tryAddSound(const std::string& name);
|
||||
|
||||
void processPreload(AssetType tag, const std::string& name, dynamic::Map* map);
|
||||
void processPreloadList(AssetType tag, dynamic::List* list);
|
||||
void processPreloadConfig(std::filesystem::path file);
|
||||
void processPreloadConfig(const std::filesystem::path& file);
|
||||
void processPreloadConfigs(const Content* content);
|
||||
public:
|
||||
AssetsLoader(Assets* assets, const ResPaths* paths);
|
||||
@@ -85,8 +86,8 @@ public:
|
||||
/// @param settings asset loading settings (based on asset type)
|
||||
void add(
|
||||
AssetType tag,
|
||||
const std::string filename,
|
||||
const std::string alias,
|
||||
const std::string& filename,
|
||||
const std::string& alias,
|
||||
std::shared_ptr<AssetCfg> settings=nullptr
|
||||
);
|
||||
|
||||
@@ -106,7 +107,7 @@ public:
|
||||
static bool loadExternalTexture(
|
||||
Assets* assets,
|
||||
const std::string& name,
|
||||
std::vector<std::filesystem::path> alternatives
|
||||
const std::vector<std::filesystem::path>& alternatives
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ static bool animation(
|
||||
assetload::postfunc assetload::texture(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string filename,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg>
|
||||
const std::string& filename,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<AssetCfg>&
|
||||
) {
|
||||
std::shared_ptr<ImageData> image (
|
||||
imageio::read(paths->find(filename+".png").u8string()).release()
|
||||
@@ -51,9 +51,9 @@ assetload::postfunc assetload::texture(
|
||||
assetload::postfunc assetload::shader(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string filename,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg>
|
||||
const std::string& filename,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<AssetCfg>&
|
||||
) {
|
||||
fs::path vertexFile = paths->find(filename+".glslv");
|
||||
fs::path fragmentFile = paths->find(filename+".glslf");
|
||||
@@ -88,9 +88,9 @@ static bool append_atlas(AtlasBuilder& atlas, const fs::path& file) {
|
||||
assetload::postfunc assetload::atlas(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string directory,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg>
|
||||
const std::string& directory,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<AssetCfg>&
|
||||
) {
|
||||
AtlasBuilder builder;
|
||||
for (const auto& file : paths->listdir(directory)) {
|
||||
@@ -113,9 +113,9 @@ assetload::postfunc assetload::atlas(
|
||||
assetload::postfunc assetload::font(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string filename,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg>
|
||||
const std::string& filename,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<AssetCfg>&
|
||||
) {
|
||||
auto pages = std::make_shared<std::vector<std::unique_ptr<ImageData>>>();
|
||||
for (size_t i = 0; i <= 4; i++) {
|
||||
@@ -136,9 +136,9 @@ assetload::postfunc assetload::font(
|
||||
assetload::postfunc assetload::layout(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string file,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg> config
|
||||
const std::string& file,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<AssetCfg>& config
|
||||
) {
|
||||
return [=](auto assets) {
|
||||
try {
|
||||
@@ -154,9 +154,9 @@ assetload::postfunc assetload::layout(
|
||||
assetload::postfunc assetload::sound(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string file,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg> config
|
||||
const std::string& file,
|
||||
const std::string& name,
|
||||
const std::shared_ptr<AssetCfg>& config
|
||||
) {
|
||||
auto cfg = std::dynamic_pointer_cast<SoundCfg>(config);
|
||||
bool keepPCM = cfg ? cfg->keepPCM : false;
|
||||
|
||||
@@ -17,45 +17,45 @@ namespace assetload {
|
||||
postfunc texture(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string filename,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg> settings
|
||||
const std::string& filename,
|
||||
const std::string &name,
|
||||
const std::shared_ptr<AssetCfg>& settings
|
||||
);
|
||||
postfunc shader(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string filename,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg> settings
|
||||
const std::string& filename,
|
||||
const std::string &name,
|
||||
const std::shared_ptr<AssetCfg>& settings
|
||||
);
|
||||
postfunc atlas(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string directory,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg> settings
|
||||
const std::string &directory,
|
||||
const std::string &name,
|
||||
const std::shared_ptr<AssetCfg>& settings
|
||||
);
|
||||
postfunc font(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string filename,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg> settings
|
||||
const std::string& filename,
|
||||
const std::string &name,
|
||||
const std::shared_ptr<AssetCfg>& settings
|
||||
);
|
||||
postfunc layout(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string file,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg> settings
|
||||
const std::string& file,
|
||||
const std::string &name,
|
||||
const std::shared_ptr<AssetCfg>& settings
|
||||
);
|
||||
|
||||
postfunc sound(
|
||||
AssetsLoader*,
|
||||
const ResPaths* paths,
|
||||
const std::string file,
|
||||
const std::string name,
|
||||
std::shared_ptr<AssetCfg> settings
|
||||
const std::string& file,
|
||||
const std::string &name,
|
||||
const std::shared_ptr<AssetCfg>& settings
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
#include "../../debug/Logger.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
static debug::Logger logger("al-audio");
|
||||
|
||||
using namespace audio;
|
||||
|
||||
ALSound::ALSound(ALAudio* al, uint buffer, std::shared_ptr<PCM> pcm, bool keepPCM)
|
||||
ALSound::ALSound(ALAudio* al, uint buffer, const std::shared_ptr<PCM>& pcm, bool keepPCM)
|
||||
: al(al), buffer(buffer)
|
||||
{
|
||||
duration = pcm->getDuration();
|
||||
@@ -36,7 +37,7 @@ std::unique_ptr<Speaker> ALSound::newInstance(int priority, int channel) const {
|
||||
}
|
||||
|
||||
ALStream::ALStream(ALAudio* al, std::shared_ptr<PCMStream> source, bool keepSource)
|
||||
: al(al), source(source), keepSource(keepSource) {
|
||||
: al(al), source(std::move(source)), keepSource(keepSource) {
|
||||
}
|
||||
|
||||
ALStream::~ALStream() {
|
||||
@@ -457,7 +458,7 @@ std::vector<std::string> ALAudio::getAvailableDevices() const {
|
||||
|
||||
const char* ptr = devices;
|
||||
do {
|
||||
devicesVec.push_back(std::string(ptr));
|
||||
devicesVec.emplace_back(ptr);
|
||||
ptr += devicesVec.back().size() + 1;
|
||||
}
|
||||
while (ptr[0]);
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace audio {
|
||||
std::shared_ptr<PCM> pcm;
|
||||
duration_t duration;
|
||||
public:
|
||||
ALSound(ALAudio* al, uint buffer, std::shared_ptr<PCM> pcm, bool keepPCM);
|
||||
ALSound(ALAudio* al, uint buffer, const std::shared_ptr<PCM>& pcm, bool keepPCM);
|
||||
~ALSound();
|
||||
|
||||
duration_t getDuration() const override {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
using namespace audio;
|
||||
|
||||
NoSound::NoSound(std::shared_ptr<PCM> pcm, bool keepPCM) {
|
||||
NoSound::NoSound(const std::shared_ptr<PCM>& pcm, bool keepPCM) {
|
||||
duration = pcm->getDuration();
|
||||
if (keepPCM) {
|
||||
this->pcm = pcm;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace audio {
|
||||
std::shared_ptr<PCM> pcm;
|
||||
duration_t duration;
|
||||
public:
|
||||
NoSound(std::shared_ptr<PCM> pcm, bool keepPCM);
|
||||
NoSound(const std::shared_ptr<PCM>& pcm, bool keepPCM);
|
||||
~NoSound() {}
|
||||
|
||||
duration_t getDuration() const override {
|
||||
@@ -28,7 +28,7 @@ namespace audio {
|
||||
std::shared_ptr<PCMStream> source;
|
||||
duration_t duration;
|
||||
public:
|
||||
NoStream(std::shared_ptr<PCMStream> source, bool keepSource) {
|
||||
NoStream(const std::shared_ptr<PCMStream>& source, bool keepSource) {
|
||||
duration = source->getTotalDuration();
|
||||
if (keepSource) {
|
||||
this->source = source;
|
||||
|
||||
+5
-4
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace audio {
|
||||
static speakerid_t nextId = 1;
|
||||
@@ -19,7 +20,7 @@ namespace audio {
|
||||
|
||||
using namespace audio;
|
||||
|
||||
Channel::Channel(std::string name) : name(name) {
|
||||
Channel::Channel(std::string name) : name(std::move(name)) {
|
||||
}
|
||||
|
||||
float Channel::getVolume() const {
|
||||
@@ -175,7 +176,7 @@ std::unique_ptr<Sound> audio::load_sound(const fs::path& file, bool keepPCM) {
|
||||
}
|
||||
|
||||
std::unique_ptr<Sound> audio::create_sound(std::shared_ptr<PCM> pcm, bool keepPCM) {
|
||||
return backend->createSound(pcm, keepPCM);
|
||||
return backend->createSound(std::move(pcm), keepPCM);
|
||||
}
|
||||
|
||||
std::unique_ptr<PCMStream> audio::open_PCM_stream(const fs::path& file) {
|
||||
@@ -204,7 +205,7 @@ std::unique_ptr<Stream> audio::open_stream(const fs::path& file, bool keepSource
|
||||
}
|
||||
|
||||
std::unique_ptr<Stream> audio::open_stream(std::shared_ptr<PCMStream> stream, bool keepSource) {
|
||||
return backend->openStream(stream, keepSource);
|
||||
return backend->openStream(std::move(stream), keepSource);
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +277,7 @@ speakerid_t audio::play(
|
||||
}
|
||||
|
||||
speakerid_t audio::play(
|
||||
std::shared_ptr<Stream> stream,
|
||||
const std::shared_ptr<Stream>& stream,
|
||||
glm::vec3 position,
|
||||
bool relative,
|
||||
float volume,
|
||||
|
||||
+1
-1
@@ -437,7 +437,7 @@ namespace audio {
|
||||
/// @param channel channel index
|
||||
/// @return speaker id or 0
|
||||
speakerid_t play(
|
||||
std::shared_ptr<Stream> stream,
|
||||
const std::shared_ptr<Stream>& stream,
|
||||
glm::vec3 position,
|
||||
bool relative,
|
||||
float volume,
|
||||
|
||||
@@ -8,29 +8,30 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
void GLSLExtension::setVersion(std::string version) {
|
||||
this->version = version;
|
||||
this->version = std::move(version);
|
||||
}
|
||||
|
||||
void GLSLExtension::setPaths(const ResPaths* paths) {
|
||||
this->paths = paths;
|
||||
}
|
||||
|
||||
void GLSLExtension::loadHeader(std::string name) {
|
||||
void GLSLExtension::loadHeader(const std::string& name) {
|
||||
fs::path file = paths->find("shaders/lib/"+name+".glsl");
|
||||
std::string source = files::read_string(file);
|
||||
addHeader(name, source);
|
||||
}
|
||||
|
||||
void GLSLExtension::addHeader(std::string name, std::string source) {
|
||||
headers[name] = source;
|
||||
void GLSLExtension::addHeader(const std::string& name, std::string source) {
|
||||
headers[name] = std::move(source);
|
||||
}
|
||||
|
||||
void GLSLExtension::define(std::string name, std::string value) {
|
||||
defines[name] = value;
|
||||
void GLSLExtension::define(const std::string& name, std::string value) {
|
||||
defines[name] = std::move(value);
|
||||
}
|
||||
|
||||
const std::string& GLSLExtension::getHeader(const std::string& name) const {
|
||||
@@ -41,10 +42,10 @@ const std::string& GLSLExtension::getHeader(const std::string& name) const {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
const std::string GLSLExtension::getDefine(const std::string& name) const {
|
||||
const std::string& GLSLExtension::getDefine(const std::string& name) const {
|
||||
auto found = defines.find(name);
|
||||
if (found == defines.end()) {
|
||||
return "";
|
||||
throw std::runtime_error("name '"+name+"' is not defined");
|
||||
}
|
||||
return found->second;
|
||||
}
|
||||
@@ -57,7 +58,7 @@ bool GLSLExtension::hasHeader(const std::string& name) const {
|
||||
return headers.find(name) != headers.end();
|
||||
}
|
||||
|
||||
void GLSLExtension::undefine(std::string name) {
|
||||
void GLSLExtension::undefine(const std::string& name) {
|
||||
if (hasDefine(name)) {
|
||||
defines.erase(name);
|
||||
}
|
||||
@@ -66,7 +67,7 @@ void GLSLExtension::undefine(std::string name) {
|
||||
inline std::runtime_error parsing_error(
|
||||
const fs::path& file,
|
||||
uint linenum,
|
||||
const std::string message) {
|
||||
const std::string& message) {
|
||||
return std::runtime_error("file "+file.string()+": "+message+
|
||||
" at line "+std::to_string(linenum));
|
||||
}
|
||||
@@ -74,7 +75,7 @@ inline std::runtime_error parsing_error(
|
||||
inline void parsing_warning(
|
||||
const fs::path& file,
|
||||
uint linenum, const
|
||||
std::string message) {
|
||||
std::string& message) {
|
||||
std::cerr << "file "+file.string()+": warning: "+message+
|
||||
" at line "+std::to_string(linenum) << std::endl;
|
||||
}
|
||||
@@ -83,7 +84,7 @@ inline void source_line(std::stringstream& ss, uint linenum) {
|
||||
ss << "#line " << linenum << "\n";
|
||||
}
|
||||
|
||||
const std::string GLSLExtension::process(const fs::path& file, const std::string& source) {
|
||||
std::string GLSLExtension::process(const fs::path& file, const std::string& source) {
|
||||
std::stringstream ss;
|
||||
size_t pos = 0;
|
||||
uint linenum = 1;
|
||||
|
||||
@@ -14,22 +14,22 @@ class GLSLExtension {
|
||||
std::string version = "330 core";
|
||||
|
||||
const ResPaths* paths = nullptr;
|
||||
void loadHeader(std::string name);
|
||||
void loadHeader(const std::string& name);
|
||||
public:
|
||||
void setPaths(const ResPaths* paths);
|
||||
void setVersion(std::string version);
|
||||
|
||||
void define(std::string name, std::string value);
|
||||
void undefine(std::string name);
|
||||
void addHeader(std::string name, std::string source);
|
||||
void define(const std::string& name, std::string value);
|
||||
void undefine(const std::string& name);
|
||||
void addHeader(const std::string& name, std::string source);
|
||||
|
||||
const std::string& getHeader(const std::string& name) const;
|
||||
const std::string getDefine(const std::string& name) const;
|
||||
const std::string& getDefine(const std::string& name) const;
|
||||
|
||||
bool hasHeader(const std::string& name) const;
|
||||
bool hasDefine(const std::string& name) const;
|
||||
|
||||
const std::string process(
|
||||
std::string process(
|
||||
const std::filesystem::path& file,
|
||||
const std::string& source
|
||||
);
|
||||
|
||||
@@ -15,7 +15,7 @@ inline double power(double base, int64_t power) {
|
||||
}
|
||||
|
||||
parsing_error::parsing_error(
|
||||
std::string message,
|
||||
const std::string& message,
|
||||
std::string_view filename,
|
||||
std::string_view source,
|
||||
uint pos,
|
||||
@@ -332,6 +332,6 @@ std::string BasicParser::parseString(char quote, bool closeRequired) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
parsing_error BasicParser::error(std::string message) {
|
||||
parsing_error BasicParser::error(const std::string& message) {
|
||||
return parsing_error(message, filename, source, pos, line, linestart);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
uint linestart;
|
||||
|
||||
parsing_error(
|
||||
std::string message,
|
||||
const std::string& message,
|
||||
std::string_view filename,
|
||||
std::string_view source,
|
||||
uint pos,
|
||||
@@ -92,7 +92,7 @@ protected:
|
||||
dynamic::Value parseNumber(int sign);
|
||||
std::string parseString(char chr, bool closeRequired=true);
|
||||
|
||||
parsing_error error(std::string message);
|
||||
parsing_error error(const std::string& message);
|
||||
|
||||
public:
|
||||
std::string_view readUntil(char c);
|
||||
|
||||
+2
-2
@@ -80,7 +80,7 @@ class OggStream : public PCMStream {
|
||||
size_t totalSamples = 0;
|
||||
bool seekable;
|
||||
public:
|
||||
OggStream(OggVorbis_File vf) : vf(std::move(vf)) {
|
||||
OggStream(OggVorbis_File vf) : vf(vf) {
|
||||
vorbis_info* info = ov_info(&vf, -1);
|
||||
channels = info->channels;
|
||||
sampleRate = info->rate;
|
||||
@@ -158,5 +158,5 @@ std::unique_ptr<PCMStream> ogg::create_stream(const fs::path& file) {
|
||||
if ((code = ov_fopen(file.u8string().c_str(), &vf))) {
|
||||
throw std::runtime_error("vorbis: "+vorbis_error_message(code));
|
||||
}
|
||||
return std::make_unique<OggStream>(std::move(vf));
|
||||
return std::make_unique<OggStream>(vf);
|
||||
}
|
||||
|
||||
+14
-13
@@ -5,12 +5,13 @@
|
||||
#include <charconv>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
using namespace xml;
|
||||
|
||||
Attribute::Attribute(std::string name, std::string text)
|
||||
: name(name),
|
||||
text(text) {
|
||||
: name(std::move(name)),
|
||||
text(std::move(text)) {
|
||||
}
|
||||
|
||||
const std::string& Attribute::getName() const {
|
||||
@@ -104,14 +105,14 @@ glm::vec4 Attribute::asColor() const {
|
||||
}
|
||||
}
|
||||
|
||||
Node::Node(std::string tag) : tag(tag) {
|
||||
Node::Node(std::string tag) : tag(std::move(tag)) {
|
||||
}
|
||||
|
||||
void Node::add(xmlelement element) {
|
||||
void Node::add(const xmlelement& element) {
|
||||
elements.push_back(element);
|
||||
}
|
||||
|
||||
void Node::set(std::string name, std::string text) {
|
||||
void Node::set(const std::string& name, const std::string &text) {
|
||||
attrs[name] = Attribute(name, text);
|
||||
}
|
||||
|
||||
@@ -119,7 +120,7 @@ const std::string& Node::getTag() const {
|
||||
return tag;
|
||||
}
|
||||
|
||||
const xmlattribute Node::attr(const std::string& name) const {
|
||||
const xmlattribute& Node::attr(const std::string& name) const {
|
||||
auto found = attrs.find(name);
|
||||
if (found == attrs.end()) {
|
||||
throw std::runtime_error("element <"+tag+" ...> missing attribute "+name);
|
||||
@@ -127,7 +128,7 @@ const xmlattribute Node::attr(const std::string& name) const {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
const xmlattribute Node::attr(const std::string& name, const std::string& def) const {
|
||||
xmlattribute Node::attr(const std::string& name, const std::string& def) const {
|
||||
auto found = attrs.find(name);
|
||||
if (found == attrs.end()) {
|
||||
return Attribute(name, def);
|
||||
@@ -157,11 +158,11 @@ const xmlelements_map& Node::getAttributes() const {
|
||||
}
|
||||
|
||||
Document::Document(std::string version, std::string encoding)
|
||||
: version(version),
|
||||
encoding(encoding) {
|
||||
: version(std::move(version)),
|
||||
encoding(std::move(encoding)) {
|
||||
}
|
||||
|
||||
void Document::setRoot(xmlelement element) {
|
||||
void Document::setRoot(const xmlelement &element) {
|
||||
this->root = element;
|
||||
}
|
||||
|
||||
@@ -336,7 +337,7 @@ xmldocument Parser::parse() {
|
||||
return document;
|
||||
}
|
||||
|
||||
xmldocument xml::parse(std::string filename, std::string source) {
|
||||
xmldocument xml::parse(const std::string& filename, const std::string& source) {
|
||||
Parser parser(filename, source);
|
||||
return parser.parse();
|
||||
}
|
||||
@@ -357,7 +358,7 @@ inline void newline(
|
||||
|
||||
static void stringifyElement(
|
||||
std::stringstream& ss,
|
||||
const xmlelement element,
|
||||
const xmlelement& element,
|
||||
bool nice,
|
||||
const std::string& indentStr,
|
||||
int indent
|
||||
@@ -414,7 +415,7 @@ static void stringifyElement(
|
||||
}
|
||||
|
||||
std::string xml::stringify(
|
||||
const xmldocument document,
|
||||
const xmldocument& document,
|
||||
bool nice,
|
||||
const std::string& indentStr
|
||||
) {
|
||||
|
||||
+7
-7
@@ -46,12 +46,12 @@ namespace xml {
|
||||
Node(std::string tag);
|
||||
|
||||
/// @brief Add sub-element
|
||||
void add(xmlelement element);
|
||||
void add(const xmlelement& element);
|
||||
|
||||
/// @brief Set attribute value. Creates attribute if does not exists
|
||||
/// @param name attribute name
|
||||
/// @param text attribute value
|
||||
void set(std::string name, std::string text);
|
||||
void set(const std::string& name, const std::string &text);
|
||||
|
||||
/// @brief Get element tag
|
||||
const std::string& getTag() const;
|
||||
@@ -68,14 +68,14 @@ namespace xml {
|
||||
/// @param name attribute name
|
||||
/// @throws std::runtime_error if element has no attribute
|
||||
/// @return xmlattribute - {name, value}
|
||||
const xmlattribute attr(const std::string& name) const;
|
||||
const xmlattribute& attr(const std::string& name) const;
|
||||
|
||||
/// @brief Get attribute by name
|
||||
/// @param name attribute name
|
||||
/// @param def default value will be returned wrapped in xmlattribute
|
||||
/// if element has no attribute
|
||||
/// @return xmlattribute - {name, value} or {name, def} if not found*/
|
||||
const xmlattribute attr(const std::string& name, const std::string& def) const;
|
||||
xmlattribute attr(const std::string& name, const std::string& def) const;
|
||||
|
||||
/// @brief Check if element has attribute
|
||||
/// @param name attribute name
|
||||
@@ -101,7 +101,7 @@ namespace xml {
|
||||
public:
|
||||
Document(std::string version, std::string encoding);
|
||||
|
||||
void setRoot(xmlelement element);
|
||||
void setRoot(const xmlelement &element);
|
||||
xmlelement getRoot() const;
|
||||
|
||||
const std::string& getVersion() const;
|
||||
@@ -129,7 +129,7 @@ namespace xml {
|
||||
/// @param indentStr indentation characters sequence (default - 4 spaces)
|
||||
/// @return XML string
|
||||
extern std::string stringify(
|
||||
const xmldocument document,
|
||||
const xmldocument& document,
|
||||
bool nice=true,
|
||||
const std::string& indentStr=" "
|
||||
);
|
||||
@@ -138,7 +138,7 @@ namespace xml {
|
||||
/// @param filename file name will be shown in error messages
|
||||
/// @param source xml source code string
|
||||
/// @return xml document
|
||||
extern xmldocument parse(std::string filename, std::string source);
|
||||
extern xmldocument parse(const std::string& filename, const std::string& source);
|
||||
}
|
||||
|
||||
#endif // CODERS_XML_HPP_
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
inline constexpr int ENGINE_VERSION_MAJOR = 0;
|
||||
inline constexpr int ENGINE_VERSION_MINOR = 21;
|
||||
inline constexpr int ENGINE_VERSION_MINOR = 22;
|
||||
|
||||
#ifdef NDEBUG
|
||||
inline constexpr bool ENGINE_DEBUG_BUILD = false;
|
||||
@@ -15,7 +15,7 @@ inline constexpr bool ENGINE_DEBUG_BUILD = false;
|
||||
inline constexpr bool ENGINE_DEBUG_BUILD = true;
|
||||
#endif // NDEBUG
|
||||
|
||||
inline const std::string ENGINE_VERSION_STRING = "0.21";
|
||||
inline const std::string ENGINE_VERSION_STRING = "0.22";
|
||||
|
||||
inline constexpr blockid_t BLOCK_AIR = 0;
|
||||
inline constexpr itemid_t ITEM_EMPTY = 0;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
|
||||
#include "../voxels/Block.hpp"
|
||||
#include "../items/ItemDef.hpp"
|
||||
@@ -13,8 +14,8 @@
|
||||
ContentIndices::ContentIndices(
|
||||
std::vector<Block*> blockDefs,
|
||||
std::vector<ItemDef*> itemDefs
|
||||
) : blockDefs(blockDefs),
|
||||
itemDefs(itemDefs)
|
||||
) : blockDefs(std::move(blockDefs)),
|
||||
itemDefs(std::move(itemDefs))
|
||||
{}
|
||||
|
||||
Content::Content(
|
||||
@@ -35,7 +36,7 @@ Content::Content(
|
||||
Content::~Content() {
|
||||
}
|
||||
|
||||
Block* Content::findBlock(std::string id) const {
|
||||
Block* Content::findBlock(const std::string& id) const {
|
||||
auto found = blockDefs.find(id);
|
||||
if (found == blockDefs.end()) {
|
||||
return nullptr;
|
||||
@@ -43,7 +44,7 @@ Block* Content::findBlock(std::string id) const {
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
Block& Content::requireBlock(std::string id) const {
|
||||
Block& Content::requireBlock(const std::string& id) const {
|
||||
auto found = blockDefs.find(id);
|
||||
if (found == blockDefs.end()) {
|
||||
throw std::runtime_error("missing block "+id);
|
||||
@@ -51,7 +52,7 @@ Block& Content::requireBlock(std::string id) const {
|
||||
return *found->second;
|
||||
}
|
||||
|
||||
ItemDef* Content::findItem(std::string id) const {
|
||||
ItemDef* Content::findItem(const std::string& id) const {
|
||||
auto found = itemDefs.find(id);
|
||||
if (found == itemDefs.end()) {
|
||||
return nullptr;
|
||||
@@ -59,7 +60,7 @@ ItemDef* Content::findItem(std::string id) const {
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
ItemDef& Content::requireItem(std::string id) const {
|
||||
ItemDef& Content::requireItem(const std::string& id) const {
|
||||
auto found = itemDefs.find(id);
|
||||
if (found == itemDefs.end()) {
|
||||
throw std::runtime_error("missing item "+id);
|
||||
@@ -67,7 +68,7 @@ ItemDef& Content::requireItem(std::string id) const {
|
||||
return *found->second;
|
||||
}
|
||||
|
||||
const BlockMaterial* Content::findBlockMaterial(std::string id) const {
|
||||
const BlockMaterial* Content::findBlockMaterial(const std::string& id) const {
|
||||
auto found = blockMaterials.find(id);
|
||||
if (found == blockMaterials.end()) {
|
||||
return nullptr;
|
||||
@@ -75,7 +76,7 @@ const BlockMaterial* Content::findBlockMaterial(std::string id) const {
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
const ContentPackRuntime* Content::getPackRuntime(std::string id) const {
|
||||
const ContentPackRuntime* Content::getPackRuntime(const std::string& id) const {
|
||||
auto found = packs.find(id);
|
||||
if (found == packs.end()) {
|
||||
return nullptr;
|
||||
|
||||
@@ -107,15 +107,15 @@ public:
|
||||
return indices.get();
|
||||
}
|
||||
|
||||
Block* findBlock(std::string id) const;
|
||||
Block& requireBlock(std::string id) const;
|
||||
Block* findBlock(const std::string& id) const;
|
||||
Block& requireBlock(const std::string& id) const;
|
||||
|
||||
ItemDef* findItem(std::string id) const;
|
||||
ItemDef& requireItem(std::string id) const;
|
||||
ItemDef* findItem(const std::string& id) const;
|
||||
ItemDef& requireItem(const std::string& id) const;
|
||||
|
||||
const BlockMaterial* findBlockMaterial(std::string id) const;
|
||||
const BlockMaterial* findBlockMaterial(const std::string& id) const;
|
||||
|
||||
const ContentPackRuntime* getPackRuntime(std::string id) const;
|
||||
const ContentPackRuntime* getPackRuntime(const std::string& id) const;
|
||||
|
||||
const std::unordered_map<std::string, std::unique_ptr<BlockMaterial>>& getBlockMaterials() const;
|
||||
const std::unordered_map<std::string, std::unique_ptr<ContentPackRuntime>>& getPacks() const;
|
||||
|
||||
@@ -6,7 +6,7 @@ void ContentBuilder::add(std::unique_ptr<ContentPackRuntime> pack) {
|
||||
packs[pack->getId()] = std::move(pack);
|
||||
}
|
||||
|
||||
Block& ContentBuilder::createBlock(std::string id) {
|
||||
Block& ContentBuilder::createBlock(const std::string& id) {
|
||||
auto found = blockDefs.find(id);
|
||||
if (found != blockDefs.end()) {
|
||||
return *found->second;
|
||||
@@ -17,7 +17,7 @@ Block& ContentBuilder::createBlock(std::string id) {
|
||||
return *blockDefs[id];
|
||||
}
|
||||
|
||||
ItemDef& ContentBuilder::createItem(std::string id) {
|
||||
ItemDef& ContentBuilder::createItem(const std::string& id) {
|
||||
auto found = itemDefs.find(id);
|
||||
if (found != itemDefs.end()) {
|
||||
return *found->second;
|
||||
@@ -28,21 +28,21 @@ ItemDef& ContentBuilder::createItem(std::string id) {
|
||||
return *itemDefs[id];
|
||||
}
|
||||
|
||||
BlockMaterial& ContentBuilder::createBlockMaterial(std::string id) {
|
||||
BlockMaterial& ContentBuilder::createBlockMaterial(const std::string& id) {
|
||||
blockMaterials[id] = std::make_unique<BlockMaterial>();
|
||||
auto& material = *blockMaterials[id];
|
||||
material.name = id;
|
||||
return material;
|
||||
}
|
||||
|
||||
void ContentBuilder::checkIdentifier(std::string id) {
|
||||
void ContentBuilder::checkIdentifier(const std::string& id) {
|
||||
contenttype result;
|
||||
if (((result = checkContentType(id)) != contenttype::none)) {
|
||||
throw namereuse_error("name "+id+" is already used", result);
|
||||
}
|
||||
}
|
||||
|
||||
contenttype ContentBuilder::checkContentType(std::string id) {
|
||||
contenttype ContentBuilder::checkContentType(const std::string& id) {
|
||||
if (blockDefs.find(id) != blockDefs.end()) {
|
||||
return contenttype::block;
|
||||
}
|
||||
@@ -62,6 +62,7 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
||||
def.rt.id = blockDefsIndices.size();
|
||||
def.rt.emissive = *reinterpret_cast<uint32_t*>(def.emission);
|
||||
def.rt.solid = def.model == BlockModel::block;
|
||||
def.rt.extended = def.size.x > 1 || def.size.y > 1 || def.size.z > 1;
|
||||
|
||||
if (def.rotatable) {
|
||||
for (uint i = 0; i < BlockRotProfile::MAX_COUNT; i++) {
|
||||
|
||||
@@ -24,12 +24,12 @@ public:
|
||||
|
||||
void add(std::unique_ptr<ContentPackRuntime> pack);
|
||||
|
||||
Block& createBlock(std::string id);
|
||||
ItemDef& createItem(std::string id);
|
||||
BlockMaterial& createBlockMaterial(std::string id);
|
||||
Block& createBlock(const std::string& id);
|
||||
ItemDef& createItem(const std::string& id);
|
||||
BlockMaterial& createBlockMaterial(const std::string& id);
|
||||
|
||||
void checkIdentifier(std::string id);
|
||||
contenttype checkContentType(std::string id);
|
||||
void checkIdentifier(const std::string& id);
|
||||
contenttype checkContentType(const std::string& id);
|
||||
|
||||
std::unique_ptr<Content> build();
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ ContentLUT::ContentLUT(const Content* content, size_t blocksCount, size_t itemsC
|
||||
blockNames.push_back(indices->getBlockDef(i)->name);
|
||||
}
|
||||
for (size_t i = indices->countBlockDefs(); i < blocksCount; i++) {
|
||||
blockNames.push_back("");
|
||||
blockNames.emplace_back("");
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < itemsCount; i++) {
|
||||
@@ -29,7 +29,7 @@ ContentLUT::ContentLUT(const Content* content, size_t blocksCount, size_t itemsC
|
||||
itemNames.push_back(indices->getItemDef(i)->name);
|
||||
}
|
||||
for (size_t i = indices->countItemDefs(); i < itemsCount; i++) {
|
||||
itemNames.push_back("");
|
||||
itemNames.emplace_back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../constants.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
@@ -44,7 +45,7 @@ public:
|
||||
|
||||
inline void setBlock(blockid_t index, std::string name, blockid_t id) {
|
||||
blocks[index] = id;
|
||||
blockNames[index] = name;
|
||||
blockNames[index] = std::move(name);
|
||||
if (id == BLOCK_VOID) {
|
||||
missingContent = true;
|
||||
} else if (index != id) {
|
||||
@@ -62,7 +63,7 @@ public:
|
||||
|
||||
inline void setItem(itemid_t index, std::string name, itemid_t id) {
|
||||
items[index] = id;
|
||||
itemNames[index] = name;
|
||||
itemNames[index] = std::move(name);
|
||||
if (id == ITEM_VOID) {
|
||||
missingContent = true;
|
||||
} else if (index != id) {
|
||||
|
||||
@@ -28,15 +28,15 @@ ContentLoader::ContentLoader(ContentPack* pack) : pack(pack) {
|
||||
}
|
||||
|
||||
bool ContentLoader::fixPackIndices(
|
||||
fs::path folder,
|
||||
const fs::path& folder,
|
||||
dynamic::Map* indicesRoot,
|
||||
std::string contentSection
|
||||
const std::string& contentSection
|
||||
) {
|
||||
std::vector<std::string> detected;
|
||||
std::vector<std::string> indexed;
|
||||
if (fs::is_directory(folder)) {
|
||||
for (auto entry : fs::directory_iterator(folder)) {
|
||||
fs::path file = entry.path();
|
||||
for (const auto& entry : fs::directory_iterator(folder)) {
|
||||
const fs::path& file = entry.path();
|
||||
if (fs::is_regular_file(file) && file.extension() == ".json") {
|
||||
std::string name = file.stem().string();
|
||||
if (name[0] == '_')
|
||||
@@ -46,8 +46,8 @@ bool ContentLoader::fixPackIndices(
|
||||
std::string space = file.stem().string();
|
||||
if (space[0] == '_')
|
||||
continue;
|
||||
for (auto entry : fs::directory_iterator(file)) {
|
||||
fs::path file = entry.path();
|
||||
for (const auto& entry : fs::directory_iterator(file)) {
|
||||
const fs::path& file = entry.path();
|
||||
if (fs::is_regular_file(file) && file.extension() == ".json") {
|
||||
std::string name = file.stem().string();
|
||||
if (name[0] == '_')
|
||||
@@ -109,7 +109,7 @@ void ContentLoader::fixPackIndices() {
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadBlock(Block& def, std::string name, fs::path file) {
|
||||
void ContentLoader::loadBlock(Block& def, const std::string& name, const fs::path& file) {
|
||||
auto root = files::read_json(file);
|
||||
|
||||
root->str("caption", def.caption);
|
||||
@@ -137,16 +137,14 @@ void ContentLoader::loadBlock(Block& def, std::string name, fs::path file) {
|
||||
def.model = BlockModel::custom;
|
||||
if (root->has("model-primitives")) {
|
||||
loadCustomBlockModel(def, root->map("model-primitives"));
|
||||
}
|
||||
else {
|
||||
std::cerr << "ERROR occured while block "
|
||||
<< name << " parsed: no \"model-primitives\" found" << std::endl;
|
||||
} else {
|
||||
logger.error() << name << ": no 'model-primitives' found";
|
||||
}
|
||||
}
|
||||
else if (model == "X") def.model = BlockModel::xsprite;
|
||||
else if (model == "none") def.model = BlockModel::none;
|
||||
else {
|
||||
std::cerr << "unknown model " << model << std::endl;
|
||||
logger.error() << "unknown model " << model;
|
||||
def.model = BlockModel::none;
|
||||
}
|
||||
|
||||
@@ -156,12 +154,12 @@ void ContentLoader::loadBlock(Block& def, std::string name, fs::path file) {
|
||||
std::string profile = "none";
|
||||
root->str("rotation", profile);
|
||||
def.rotatable = profile != "none";
|
||||
if (profile == "pipe") {
|
||||
if (profile == BlockRotProfile::PIPE_NAME) {
|
||||
def.rotations = BlockRotProfile::PIPE;
|
||||
} else if (profile == "pane") {
|
||||
} else if (profile == BlockRotProfile::PANE_NAME) {
|
||||
def.rotations = BlockRotProfile::PANE;
|
||||
} else if (profile != "none") {
|
||||
std::cerr << "unknown rotation profile " << profile << std::endl;
|
||||
logger.error() << "unknown rotation profile " << profile;
|
||||
def.rotatable = false;
|
||||
}
|
||||
|
||||
@@ -175,29 +173,37 @@ void ContentLoader::loadBlock(Block& def, std::string name, fs::path file) {
|
||||
def.hitboxes[i].b = glm::vec3(box->num(3), box->num(4), box->num(5));
|
||||
def.hitboxes[i].b += def.hitboxes[i].a;
|
||||
}
|
||||
} else if (auto boxarr = root->list("hitbox")){
|
||||
AABB aabb;
|
||||
aabb.a = glm::vec3(boxarr->num(0), boxarr->num(1), boxarr->num(2));
|
||||
aabb.b = glm::vec3(boxarr->num(3), boxarr->num(4), boxarr->num(5));
|
||||
aabb.b += aabb.a;
|
||||
def.hitboxes = { aabb };
|
||||
} else if (!def.modelBoxes.empty()) {
|
||||
def.hitboxes = def.modelBoxes;
|
||||
} else {
|
||||
boxarr = root->list("hitbox");
|
||||
if (boxarr) {
|
||||
AABB aabb;
|
||||
aabb.a = glm::vec3(boxarr->num(0), boxarr->num(1), boxarr->num(2));
|
||||
aabb.b = glm::vec3(boxarr->num(3), boxarr->num(4), boxarr->num(5));
|
||||
aabb.b += aabb.a;
|
||||
def.hitboxes = { aabb };
|
||||
} else if (!def.modelBoxes.empty()) {
|
||||
def.hitboxes = def.modelBoxes;
|
||||
} else {
|
||||
def.hitboxes = { AABB() };
|
||||
}
|
||||
def.hitboxes = { AABB() };
|
||||
}
|
||||
|
||||
// block light emission [r, g, b] where r,g,b in range [0..15]
|
||||
auto emissionarr = root->list("emission");
|
||||
if (emissionarr) {
|
||||
if (auto emissionarr = root->list("emission")) {
|
||||
def.emission[0] = emissionarr->num(0);
|
||||
def.emission[1] = emissionarr->num(1);
|
||||
def.emission[2] = emissionarr->num(2);
|
||||
}
|
||||
|
||||
// block size
|
||||
if (auto sizearr = root->list("size")) {
|
||||
def.size.x = sizearr->num(0);
|
||||
def.size.y = sizearr->num(1);
|
||||
def.size.z = sizearr->num(2);
|
||||
if (def.model == BlockModel::block &&
|
||||
(def.size.x != 1 || def.size.y != 1 || def.size.z != 1)) {
|
||||
def.model = BlockModel::aabb;
|
||||
def.hitboxes = {AABB(def.size)};
|
||||
}
|
||||
}
|
||||
|
||||
// primitive properties
|
||||
root->flag("obstacle", def.obstacle);
|
||||
root->flag("replaceable", def.replaceable);
|
||||
@@ -244,7 +250,7 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
|
||||
}
|
||||
else
|
||||
for (uint j = 6; j < 12; j++) {
|
||||
def.modelTextures.push_back("notfound");
|
||||
def.modelTextures.emplace_back("notfound");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,8 +260,8 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
|
||||
/* Parse tetragon to points */
|
||||
auto tgonobj = modeltetragons->list(i);
|
||||
glm::vec3 p1(tgonobj->num(0), tgonobj->num(1), tgonobj->num(2)),
|
||||
xw(tgonobj->num(3), tgonobj->num(4), tgonobj->num(5)),
|
||||
yh(tgonobj->num(6), tgonobj->num(7), tgonobj->num(8));
|
||||
xw(tgonobj->num(3), tgonobj->num(4), tgonobj->num(5)),
|
||||
yh(tgonobj->num(6), tgonobj->num(7), tgonobj->num(8));
|
||||
def.modelExtraPoints.push_back(p1);
|
||||
def.modelExtraPoints.push_back(p1+xw);
|
||||
def.modelExtraPoints.push_back(p1+xw+yh);
|
||||
@@ -266,7 +272,7 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadItem(ItemDef& def, std::string name, fs::path file) {
|
||||
void ContentLoader::loadItem(ItemDef& def, const std::string& name, const fs::path& file) {
|
||||
auto root = files::read_json(file);
|
||||
root->str("caption", def.caption);
|
||||
|
||||
@@ -279,7 +285,7 @@ void ContentLoader::loadItem(ItemDef& def, std::string name, fs::path file) {
|
||||
} else if (iconTypeStr == "sprite") {
|
||||
def.iconType = item_icon_type::sprite;
|
||||
} else if (iconTypeStr.length()){
|
||||
std::cerr << "unknown icon type" << iconTypeStr << std::endl;
|
||||
logger.error() << name << ": unknown icon type" << iconTypeStr;
|
||||
}
|
||||
root->str("icon", def.icon);
|
||||
root->str("placing-block", def.placingBlock);
|
||||
@@ -295,7 +301,7 @@ void ContentLoader::loadItem(ItemDef& def, std::string name, fs::path file) {
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadBlock(Block& def, std::string full, std::string name) {
|
||||
void ContentLoader::loadBlock(Block& def, const std::string& full, const std::string& name) {
|
||||
auto folder = pack->folder;
|
||||
|
||||
fs::path configFile = folder/fs::path("blocks/"+name+".json");
|
||||
@@ -307,7 +313,7 @@ void ContentLoader::loadBlock(Block& def, std::string full, std::string name) {
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadItem(ItemDef& def, std::string full, std::string name) {
|
||||
void ContentLoader::loadItem(ItemDef& def, const std::string& full, const std::string& name) {
|
||||
auto folder = pack->folder;
|
||||
|
||||
fs::path configFile = folder/fs::path("items/"+name+".json");
|
||||
@@ -319,7 +325,7 @@ void ContentLoader::loadItem(ItemDef& def, std::string full, std::string name) {
|
||||
}
|
||||
}
|
||||
|
||||
void ContentLoader::loadBlockMaterial(BlockMaterial& def, fs::path file) {
|
||||
void ContentLoader::loadBlockMaterial(BlockMaterial& def, const fs::path& file) {
|
||||
auto root = files::read_json(file);
|
||||
root->str("steps-sound", def.stepsSound);
|
||||
root->str("place-sound", def.placeSound);
|
||||
@@ -394,8 +400,8 @@ void ContentLoader::load(ContentBuilder& builder) {
|
||||
|
||||
fs::path materialsDir = folder / fs::u8path("block_materials");
|
||||
if (fs::is_directory(materialsDir)) {
|
||||
for (auto entry : fs::directory_iterator(materialsDir)) {
|
||||
fs::path file = entry.path();
|
||||
for (const auto& entry : fs::directory_iterator(materialsDir)) {
|
||||
const fs::path& file = entry.path();
|
||||
std::string name = pack->id+":"+file.stem().u8string();
|
||||
loadBlockMaterial(builder.createBlockMaterial(name), file);
|
||||
}
|
||||
|
||||
@@ -22,21 +22,21 @@ class ContentLoader {
|
||||
const ContentPack* pack;
|
||||
scriptenv env;
|
||||
|
||||
void loadBlock(Block& def, std::string full, std::string name);
|
||||
void loadBlock(Block& def, const std::string& full, const std::string& name);
|
||||
void loadCustomBlockModel(Block& def, dynamic::Map* primitives);
|
||||
void loadItem(ItemDef& def, std::string full, std::string name);
|
||||
void loadBlockMaterial(BlockMaterial& def, fs::path file);
|
||||
void loadItem(ItemDef& def, const std::string& full, const std::string& name);
|
||||
void loadBlockMaterial(BlockMaterial& def, const fs::path& file);
|
||||
public:
|
||||
ContentLoader(ContentPack* pack);
|
||||
|
||||
bool fixPackIndices(
|
||||
fs::path folder,
|
||||
const fs::path& folder,
|
||||
dynamic::Map* indicesRoot,
|
||||
std::string contentSection
|
||||
const std::string& contentSection
|
||||
);
|
||||
void fixPackIndices();
|
||||
void loadBlock(Block& def, std::string name, fs::path file);
|
||||
void loadItem(ItemDef& def, std::string name, fs::path file);
|
||||
void loadBlock(Block& def, const std::string& name, const fs::path& file);
|
||||
void loadItem(ItemDef& def, const std::string& name, const fs::path& file);
|
||||
void load(ContentBuilder& builder);
|
||||
};
|
||||
|
||||
|
||||
+11
-10
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include "../coders/json.hpp"
|
||||
#include "../files/files.hpp"
|
||||
@@ -21,8 +22,8 @@ const std::vector<std::string> ContentPack::RESERVED_NAMES = {
|
||||
contentpack_error::contentpack_error(
|
||||
std::string packId,
|
||||
fs::path folder,
|
||||
std::string message)
|
||||
: std::runtime_error(message), packId(packId), folder(folder) {
|
||||
const std::string& message)
|
||||
: std::runtime_error(message), packId(std::move(packId)), folder(std::move(folder)) {
|
||||
}
|
||||
|
||||
std::string contentpack_error::getPackId() const {
|
||||
@@ -36,7 +37,7 @@ fs::path ContentPack::getContentFile() const {
|
||||
return folder/fs::path(CONTENT_FILENAME);
|
||||
}
|
||||
|
||||
bool ContentPack::is_pack(fs::path folder) {
|
||||
bool ContentPack::is_pack(const fs::path& folder) {
|
||||
return fs::is_regular_file(folder/fs::path(PACKAGE_FILENAME));
|
||||
}
|
||||
|
||||
@@ -61,7 +62,7 @@ static void checkContentPackId(const std::string& id, const fs::path& folder) {
|
||||
}
|
||||
}
|
||||
|
||||
ContentPack ContentPack::read(fs::path folder) {
|
||||
ContentPack ContentPack::read(const fs::path& folder) {
|
||||
auto root = files::read_json(folder/fs::path(PACKAGE_FILENAME));
|
||||
ContentPack pack;
|
||||
root->str("id", pack.id);
|
||||
@@ -89,14 +90,14 @@ ContentPack ContentPack::read(fs::path folder) {
|
||||
}
|
||||
|
||||
void ContentPack::scanFolder(
|
||||
fs::path folder,
|
||||
const fs::path& folder,
|
||||
std::vector<ContentPack>& packs
|
||||
) {
|
||||
if (!fs::is_directory(folder)) {
|
||||
return;
|
||||
}
|
||||
for (auto entry : fs::directory_iterator(folder)) {
|
||||
fs::path folder = entry.path();
|
||||
for (const auto& entry : fs::directory_iterator(folder)) {
|
||||
const fs::path& folder = entry.path();
|
||||
if (!fs::is_directory(folder))
|
||||
continue;
|
||||
if (!is_pack(folder))
|
||||
@@ -112,7 +113,7 @@ void ContentPack::scanFolder(
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> ContentPack::worldPacksList(fs::path folder) {
|
||||
std::vector<std::string> ContentPack::worldPacksList(const fs::path& folder) {
|
||||
fs::path listfile = folder / fs::path("packs.list");
|
||||
if (!fs::is_regular_file(listfile)) {
|
||||
std::cerr << "warning: packs.list not found (will be created)";
|
||||
@@ -122,7 +123,7 @@ std::vector<std::string> ContentPack::worldPacksList(fs::path folder) {
|
||||
return files::read_list(listfile);
|
||||
}
|
||||
|
||||
fs::path ContentPack::findPack(const EnginePaths* paths, fs::path worldDir, std::string name) {
|
||||
fs::path ContentPack::findPack(const EnginePaths* paths, const fs::path& worldDir, const std::string& name) {
|
||||
fs::path folder = worldDir / fs::path("content") / fs::path(name);
|
||||
if (fs::is_directory(folder)) {
|
||||
return folder;
|
||||
@@ -141,7 +142,7 @@ fs::path ContentPack::findPack(const EnginePaths* paths, fs::path worldDir, std:
|
||||
ContentPackRuntime::ContentPackRuntime(
|
||||
ContentPack info,
|
||||
scriptenv env
|
||||
) : info(info), env(std::move(env))
|
||||
) : info(std::move(info)), env(std::move(env))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class contentpack_error : public std::runtime_error {
|
||||
std::string packId;
|
||||
fs::path folder;
|
||||
public:
|
||||
contentpack_error(std::string packId, fs::path folder, std::string message);
|
||||
contentpack_error(std::string packId, fs::path folder, const std::string& message);
|
||||
|
||||
std::string getPackId() const;
|
||||
fs::path getFolder() const;
|
||||
@@ -52,20 +52,20 @@ struct ContentPack {
|
||||
static const fs::path ITEMS_FOLDER;
|
||||
static const std::vector<std::string> RESERVED_NAMES;
|
||||
|
||||
static bool is_pack(fs::path folder);
|
||||
static ContentPack read(fs::path folder);
|
||||
static bool is_pack(const fs::path& folder);
|
||||
static ContentPack read(const fs::path& folder);
|
||||
|
||||
static void scanFolder(
|
||||
fs::path folder,
|
||||
const fs::path& folder,
|
||||
std::vector<ContentPack>& packs
|
||||
);
|
||||
|
||||
static std::vector<std::string> worldPacksList(fs::path folder);
|
||||
static std::vector<std::string> worldPacksList(const fs::path& folder);
|
||||
|
||||
static fs::path findPack(
|
||||
const EnginePaths* paths,
|
||||
fs::path worldDir,
|
||||
std::string name
|
||||
const fs::path& worldDir,
|
||||
const std::string& name
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ void Map::str(const std::string& key, std::string& dst) const {
|
||||
dst = get(key, dst);
|
||||
}
|
||||
|
||||
std::string Map::get(const std::string& key, const std::string def) const {
|
||||
std::string Map::get(const std::string& key, const std::string& def) const {
|
||||
auto found = values.find(key);
|
||||
if (found == values.end())
|
||||
return def;
|
||||
@@ -213,7 +213,7 @@ void Map::flag(const std::string& key, bool& dst) const {
|
||||
dst = get(key, dst);
|
||||
}
|
||||
|
||||
Map& Map::put(std::string key, const Value& value) {
|
||||
Map& Map::put(const std::string& key, const Value& value) {
|
||||
values[key] = value;
|
||||
return *this;
|
||||
}
|
||||
@@ -222,13 +222,13 @@ void Map::remove(const std::string& key) {
|
||||
values.erase(key);
|
||||
}
|
||||
|
||||
List& Map::putList(std::string key) {
|
||||
List& Map::putList(const std::string& key) {
|
||||
auto arr = create_list();
|
||||
put(key, arr);
|
||||
return *arr;
|
||||
}
|
||||
|
||||
Map& Map::putMap(std::string key) {
|
||||
Map& Map::putMap(const std::string& key) {
|
||||
auto obj = create_map();
|
||||
put(key, obj);
|
||||
return *obj;
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace dynamic {
|
||||
return get(key, T());
|
||||
}
|
||||
|
||||
std::string get(const std::string& key, const std::string def) const;
|
||||
std::string get(const std::string& key, const std::string& def) const;
|
||||
number_t get(const std::string& key, double def) const;
|
||||
integer_t get(const std::string& key, integer_t def) const;
|
||||
bool get(const std::string& key, bool def) const;
|
||||
@@ -155,12 +155,12 @@ namespace dynamic {
|
||||
Map& put(std::string key, const char* value) {
|
||||
return put(key, Value(value));
|
||||
}
|
||||
Map& put(std::string key, const Value& value);
|
||||
Map& put(const std::string& key, const Value& value);
|
||||
|
||||
void remove(const std::string& key);
|
||||
|
||||
List& putList(std::string key);
|
||||
Map& putMap(std::string key);
|
||||
List& putList(const std::string& key);
|
||||
Map& putMap(const std::string& key);
|
||||
|
||||
bool has(const std::string& key) const;
|
||||
size_t size() const;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <iomanip>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
|
||||
using namespace debug;
|
||||
|
||||
@@ -16,10 +17,10 @@ LogMessage::~LogMessage() {
|
||||
logger->log(level, ss.str());
|
||||
}
|
||||
|
||||
Logger::Logger(std::string name) : name(name) {
|
||||
Logger::Logger(std::string name) : name(std::move(name)) {
|
||||
}
|
||||
|
||||
void Logger::log(LogLevel level, const std::string& name, std::string message) {
|
||||
void Logger::log(LogLevel level, const std::string& name, const std::string& message) {
|
||||
using namespace std::chrono;
|
||||
|
||||
std::stringstream ss;
|
||||
@@ -72,5 +73,5 @@ void Logger::flush() {
|
||||
}
|
||||
|
||||
void Logger::log(LogLevel level, std::string message) {
|
||||
log(level, name, message);
|
||||
log(level, name, std::move(message));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace debug {
|
||||
|
||||
std::string name;
|
||||
|
||||
static void log(LogLevel level, const std::string& name, std::string message);
|
||||
static void log(LogLevel level, const std::string& name, const std::string& message);
|
||||
public:
|
||||
static void init(const std::string& filename);
|
||||
static void flush();
|
||||
|
||||
+5
-11
@@ -42,6 +42,7 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <unordered_set>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
|
||||
static debug::Logger logger("engine");
|
||||
|
||||
@@ -65,6 +66,7 @@ Engine::Engine(EngineSettings& settings, SettingsHandler& settingsHandler, Engin
|
||||
: settings(settings), settingsHandler(settingsHandler), paths(paths),
|
||||
interpreter(std::make_unique<cmd::CommandsInterpreter>())
|
||||
{
|
||||
paths->prepare();
|
||||
loadSettings();
|
||||
|
||||
controller = std::make_unique<EngineController>(this);
|
||||
@@ -115,14 +117,6 @@ void Engine::loadControls() {
|
||||
logger.info() << "loading controls";
|
||||
std::string text = files::read_string(controls_file);
|
||||
Events::loadBindings(controls_file.u8string(), text);
|
||||
} else {
|
||||
controls_file = paths->getControlsFileOld();
|
||||
if (fs::is_regular_file(controls_file)) {
|
||||
logger.info() << "loading controls (old)";
|
||||
std::string text = files::read_string(controls_file);
|
||||
Events::loadBindingsOld(controls_file.u8string(), text);
|
||||
fs::remove(controls_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,11 +341,11 @@ double Engine::getDelta() const {
|
||||
void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
||||
audio::reset_channel(audio::get_channel_index("regular"));
|
||||
audio::reset_channel(audio::get_channel_index("ambient"));
|
||||
this->screen = screen;
|
||||
this->screen = std::move(screen);
|
||||
}
|
||||
|
||||
void Engine::setLanguage(std::string locale) {
|
||||
langs::setup(paths->getResources(), locale, contentPacks);
|
||||
langs::setup(paths->getResources(), std::move(locale), contentPacks);
|
||||
gui->getMenu()->setPageLoader(menus::create_page_loader(this));
|
||||
}
|
||||
|
||||
@@ -391,7 +385,7 @@ std::shared_ptr<Screen> Engine::getScreen() {
|
||||
return screen;
|
||||
}
|
||||
|
||||
void Engine::postRunnable(runnable callback) {
|
||||
void Engine::postRunnable(const runnable& callback) {
|
||||
std::lock_guard<std::recursive_mutex> lock(postRunnablesMutex);
|
||||
postRunnables.push(callback);
|
||||
}
|
||||
|
||||
+1
-1
@@ -137,7 +137,7 @@ public:
|
||||
std::shared_ptr<Screen> getScreen();
|
||||
|
||||
/// @brief Enqueue function call to the end of current frame in draw thread
|
||||
void postRunnable(runnable callback);
|
||||
void postRunnable(const runnable& callback);
|
||||
|
||||
void saveScreenshot();
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -22,7 +23,7 @@ class ConverterWorker : public util::Worker<convert_task, int> {
|
||||
std::shared_ptr<WorldConverter> converter;
|
||||
public:
|
||||
ConverterWorker(std::shared_ptr<WorldConverter> converter)
|
||||
: converter(converter) {}
|
||||
: converter(std::move(converter)) {}
|
||||
|
||||
int operator()(const std::shared_ptr<convert_task>& task) override {
|
||||
converter->convert(*task);
|
||||
@@ -31,11 +32,11 @@ public:
|
||||
};
|
||||
|
||||
WorldConverter::WorldConverter(
|
||||
fs::path folder,
|
||||
const fs::path& folder,
|
||||
const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut
|
||||
) : wfile(std::make_unique<WorldFiles>(folder)),
|
||||
lut(lut),
|
||||
lut(std::move(lut)),
|
||||
content(content)
|
||||
{
|
||||
fs::path regionsFolder = wfile->getRegions().getRegionsFolder(REGION_LAYER_VOXELS);
|
||||
@@ -44,7 +45,7 @@ WorldConverter::WorldConverter(
|
||||
return;
|
||||
}
|
||||
tasks.push(convert_task {convert_task_type::player, wfile->getPlayerFile()});
|
||||
for (auto file : fs::directory_iterator(regionsFolder)) {
|
||||
for (const auto& file : fs::directory_iterator(regionsFolder)) {
|
||||
tasks.push(convert_task {convert_task_type::region, file.path()});
|
||||
}
|
||||
}
|
||||
@@ -53,10 +54,10 @@ WorldConverter::~WorldConverter() {
|
||||
}
|
||||
|
||||
std::shared_ptr<Task> WorldConverter::startTask(
|
||||
fs::path folder,
|
||||
const fs::path& folder,
|
||||
const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut,
|
||||
runnable onDone,
|
||||
const std::shared_ptr<ContentLUT>& lut,
|
||||
const runnable& onDone,
|
||||
bool multithreading
|
||||
) {
|
||||
auto converter = std::make_shared<WorldConverter>(folder, content, lut);
|
||||
@@ -85,7 +86,7 @@ std::shared_ptr<Task> WorldConverter::startTask(
|
||||
return pool;
|
||||
}
|
||||
|
||||
void WorldConverter::convertRegion(fs::path file) const {
|
||||
void WorldConverter::convertRegion(const fs::path& file) const {
|
||||
int x, z;
|
||||
std::string name = file.stem().string();
|
||||
if (!WorldRegions::parseRegionFilename(name, x, z)) {
|
||||
@@ -101,14 +102,14 @@ void WorldConverter::convertRegion(fs::path file) const {
|
||||
});
|
||||
}
|
||||
|
||||
void WorldConverter::convertPlayer(fs::path file) const {
|
||||
void WorldConverter::convertPlayer(const fs::path& file) const {
|
||||
logger.info() << "converting player " << file.u8string();
|
||||
auto map = files::read_json(file);
|
||||
Player::convert(map.get(), lut.get());
|
||||
files::write_json(file, map.get());
|
||||
}
|
||||
|
||||
void WorldConverter::convert(convert_task task) const {
|
||||
void WorldConverter::convert(const convert_task& task) const {
|
||||
if (!fs::is_regular_file(task.file))
|
||||
return;
|
||||
|
||||
@@ -134,7 +135,7 @@ void WorldConverter::convertNext() {
|
||||
}
|
||||
|
||||
void WorldConverter::setOnComplete(runnable callback) {
|
||||
this->onComplete = callback;
|
||||
this->onComplete = std::move(callback);
|
||||
}
|
||||
|
||||
void WorldConverter::update() {
|
||||
|
||||
@@ -32,17 +32,17 @@ class WorldConverter : public Task {
|
||||
runnable onComplete;
|
||||
uint tasksDone = 0;
|
||||
|
||||
void convertPlayer(fs::path file) const;
|
||||
void convertRegion(fs::path file) const;
|
||||
void convertPlayer(const fs::path& file) const;
|
||||
void convertRegion(const fs::path& file) const;
|
||||
public:
|
||||
WorldConverter(
|
||||
fs::path folder,
|
||||
const fs::path& folder,
|
||||
const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut
|
||||
);
|
||||
~WorldConverter();
|
||||
|
||||
void convert(convert_task task) const;
|
||||
void convert(const convert_task& task) const;
|
||||
void convertNext();
|
||||
void setOnComplete(runnable callback);
|
||||
void write();
|
||||
@@ -55,10 +55,10 @@ public:
|
||||
uint getWorkDone() const override;
|
||||
|
||||
static std::shared_ptr<Task> startTask(
|
||||
fs::path folder,
|
||||
const fs::path& folder,
|
||||
const Content* content,
|
||||
std::shared_ptr<ContentLUT> lut,
|
||||
runnable onDone,
|
||||
const std::shared_ptr<ContentLUT>& lut,
|
||||
const runnable& onDone,
|
||||
bool multithreading
|
||||
);
|
||||
};
|
||||
|
||||
@@ -27,14 +27,15 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
|
||||
#define WORLD_FORMAT_MAGIC ".VOXWLD"
|
||||
|
||||
WorldFiles::WorldFiles(fs::path directory) : directory(directory), regions(directory) {
|
||||
WorldFiles::WorldFiles(const fs::path& directory) : directory(directory), regions(directory) {
|
||||
}
|
||||
|
||||
WorldFiles::WorldFiles(fs::path directory, const DebugSettings& settings)
|
||||
: WorldFiles(directory)
|
||||
WorldFiles::WorldFiles(const fs::path& directory, const DebugSettings& settings)
|
||||
: WorldFiles(directory)
|
||||
{
|
||||
generatorTestMode = settings.generatorTestMode.get();
|
||||
doWriteLights = settings.doWriteLights.get();
|
||||
|
||||
@@ -41,8 +41,8 @@ class WorldFiles {
|
||||
void writeWorldInfo(const World* world);
|
||||
void writeIndices(const ContentIndices* indices);
|
||||
public:
|
||||
WorldFiles(fs::path directory);
|
||||
WorldFiles(fs::path directory, const DebugSettings& settings);
|
||||
WorldFiles(const fs::path &directory);
|
||||
WorldFiles(const fs::path &directory, const DebugSettings& settings);
|
||||
~WorldFiles();
|
||||
|
||||
fs::path getPlayerFile() const;
|
||||
|
||||
+51
-52
@@ -8,10 +8,11 @@
|
||||
#include "../util/data_io.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
|
||||
#define REGION_FORMAT_MAGIC ".VOXREG"
|
||||
|
||||
regfile::regfile(fs::path filename) : file(filename) {
|
||||
regfile::regfile(fs::path filename) : file(std::move(filename)) {
|
||||
if (file.length() < REGION_HEADER_SIZE)
|
||||
throw std::runtime_error("incomplete region file header");
|
||||
char header[REGION_HEADER_SIZE];
|
||||
@@ -49,17 +50,12 @@ std::unique_ptr<ubyte[]> regfile::read(int index, uint32_t& length) {
|
||||
return data;
|
||||
}
|
||||
|
||||
WorldRegion::WorldRegion() {
|
||||
chunksData = new ubyte*[REGION_CHUNKS_COUNT]{};
|
||||
sizes = new uint32_t[REGION_CHUNKS_COUNT]{};
|
||||
}
|
||||
WorldRegion::WorldRegion()
|
||||
: chunksData(std::make_unique<std::unique_ptr<ubyte[]>[]>(REGION_CHUNKS_COUNT)),
|
||||
sizes(std::make_unique<uint32_t[]>(REGION_CHUNKS_COUNT))
|
||||
{}
|
||||
|
||||
WorldRegion::~WorldRegion() {
|
||||
for (uint i = 0; i < REGION_CHUNKS_COUNT; i++) {
|
||||
delete[] chunksData[i];
|
||||
}
|
||||
delete[] sizes;
|
||||
delete[] chunksData;
|
||||
}
|
||||
|
||||
void WorldRegion::setUnsaved(bool unsaved) {
|
||||
@@ -69,30 +65,29 @@ bool WorldRegion::isUnsaved() const {
|
||||
return unsaved;
|
||||
}
|
||||
|
||||
ubyte** WorldRegion::getChunks() const {
|
||||
return chunksData;
|
||||
std::unique_ptr<ubyte[]>* WorldRegion::getChunks() const {
|
||||
return chunksData.get();
|
||||
}
|
||||
|
||||
uint32_t* WorldRegion::getSizes() const {
|
||||
return sizes;
|
||||
return sizes.get();
|
||||
}
|
||||
|
||||
void WorldRegion::put(uint x, uint z, ubyte* data, uint32_t size) {
|
||||
size_t chunk_index = z * REGION_SIZE + x;
|
||||
delete[] chunksData[chunk_index];
|
||||
chunksData[chunk_index] = data;
|
||||
chunksData[chunk_index].reset(data);
|
||||
sizes[chunk_index] = size;
|
||||
}
|
||||
|
||||
ubyte* WorldRegion::getChunkData(uint x, uint z) {
|
||||
return chunksData[z * REGION_SIZE + x];
|
||||
return chunksData[z * REGION_SIZE + x].get();
|
||||
}
|
||||
|
||||
uint WorldRegion::getChunkDataSize(uint x, uint z) {
|
||||
return sizes[z * REGION_SIZE + x];
|
||||
}
|
||||
|
||||
WorldRegions::WorldRegions(fs::path directory) : directory(directory) {
|
||||
WorldRegions::WorldRegions(const fs::path& directory) : directory(directory) {
|
||||
for (uint i = 0; i < sizeof(layers)/sizeof(RegionsLayer); i++) {
|
||||
layers[i].layer = i;
|
||||
}
|
||||
@@ -108,19 +103,21 @@ WorldRegion* WorldRegions::getRegion(int x, int z, int layer) {
|
||||
RegionsLayer& regions = layers[layer];
|
||||
std::lock_guard lock(regions.mutex);
|
||||
auto found = regions.regions.find(glm::ivec2(x, z));
|
||||
if (found == regions.regions.end())
|
||||
if (found == regions.regions.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return found->second.get();
|
||||
}
|
||||
|
||||
WorldRegion* WorldRegions::getOrCreateRegion(int x, int z, int layer) {
|
||||
WorldRegion* region = getRegion(x, z, layer);
|
||||
if (region == nullptr) {
|
||||
RegionsLayer& regions = layers[layer];
|
||||
std::lock_guard lock(regions.mutex);
|
||||
region = new WorldRegion();
|
||||
regions.regions[glm::ivec2(x, z)].reset(region);
|
||||
if (auto region = getRegion(x, z, layer)) {
|
||||
return region;
|
||||
}
|
||||
RegionsLayer& regions = layers[layer];
|
||||
std::lock_guard lock(regions.mutex);
|
||||
auto region_ptr = std::make_unique<WorldRegion>();
|
||||
auto region = region_ptr.get();
|
||||
regions.regions[{x, z}] = std::move(region_ptr);
|
||||
return region;
|
||||
}
|
||||
|
||||
@@ -152,10 +149,7 @@ inline void calc_reg_coords(
|
||||
}
|
||||
|
||||
std::unique_ptr<ubyte[]> WorldRegions::readChunkData(
|
||||
int x,
|
||||
int z,
|
||||
uint32_t& length,
|
||||
regfile* rfile
|
||||
int x, int z, uint32_t& length, regfile* rfile
|
||||
){
|
||||
int regionX, regionZ, localX, localZ;
|
||||
calc_reg_coords(x, z, regionX, regionZ, localX, localZ);
|
||||
@@ -165,14 +159,14 @@ std::unique_ptr<ubyte[]> WorldRegions::readChunkData(
|
||||
|
||||
/// @brief Read missing chunks data (null pointers) from region file
|
||||
void WorldRegions::fetchChunks(WorldRegion* region, int x, int z, regfile* file) {
|
||||
ubyte** chunks = region->getChunks();
|
||||
auto* chunks = region->getChunks();
|
||||
uint32_t* sizes = region->getSizes();
|
||||
|
||||
for (size_t i = 0; i < REGION_CHUNKS_COUNT; i++) {
|
||||
int chunk_x = (i % REGION_SIZE) + x * REGION_SIZE;
|
||||
int chunk_z = (i / REGION_SIZE) + z * REGION_SIZE;
|
||||
if (chunks[i] == nullptr) {
|
||||
chunks[i] = readChunkData(chunk_x, chunk_z, sizes[i], file).release();
|
||||
chunks[i] = readChunkData(chunk_x, chunk_z, sizes[i], file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,13 +199,10 @@ ubyte* WorldRegions::getData(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<regfile> WorldRegions::useRegFile(glm::ivec3 coord) {
|
||||
regfile_ptr WorldRegions::useRegFile(glm::ivec3 coord) {
|
||||
auto* file = openRegFiles[coord].get();
|
||||
file->inUse = true;
|
||||
return std::shared_ptr<regfile>(file, [this](regfile* ptr) {
|
||||
ptr->inUse = false;
|
||||
regFilesCv.notify_one();
|
||||
});
|
||||
return regfile_ptr(file, ®FilesCv);
|
||||
}
|
||||
|
||||
void WorldRegions::closeRegFile(glm::ivec3 coord) {
|
||||
@@ -220,7 +211,7 @@ void WorldRegions::closeRegFile(glm::ivec3 coord) {
|
||||
}
|
||||
|
||||
// Marks regfile as used and unmarks when shared_ptr dies
|
||||
std::shared_ptr<regfile> WorldRegions::getRegFile(glm::ivec3 coord, bool create) {
|
||||
regfile_ptr WorldRegions::getRegFile(glm::ivec3 coord, bool create) {
|
||||
{
|
||||
std::lock_guard lock(regFilesMutex);
|
||||
const auto found = openRegFiles.find(coord);
|
||||
@@ -237,7 +228,7 @@ std::shared_ptr<regfile> WorldRegions::getRegFile(glm::ivec3 coord, bool create)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<regfile> WorldRegions::createRegFile(glm::ivec3 coord) {
|
||||
regfile_ptr WorldRegions::createRegFile(glm::ivec3 coord) {
|
||||
fs::path file = layers[coord[2]].folder/getRegionFilename(coord[0], coord[1]);
|
||||
if (!fs::exists(file)) {
|
||||
return nullptr;
|
||||
@@ -281,6 +272,7 @@ void WorldRegions::writeRegion(int x, int z, int layer, WorldRegion* entry){
|
||||
fetchChunks(entry, x, z, regfile.get());
|
||||
|
||||
std::lock_guard lock(regFilesMutex);
|
||||
regfile.reset();
|
||||
closeRegFile(regcoord);
|
||||
}
|
||||
|
||||
@@ -294,18 +286,18 @@ void WorldRegions::writeRegion(int x, int z, int layer, WorldRegion* entry){
|
||||
char intbuf[4]{};
|
||||
uint offsets[REGION_CHUNKS_COUNT]{};
|
||||
|
||||
ubyte** region = entry->getChunks();
|
||||
auto* region = entry->getChunks();
|
||||
uint32_t* sizes = entry->getSizes();
|
||||
|
||||
for (size_t i = 0; i < REGION_CHUNKS_COUNT; i++) {
|
||||
ubyte* chunk = region[i];
|
||||
ubyte* chunk = region[i].get();
|
||||
if (chunk == nullptr){
|
||||
offsets[i] = 0;
|
||||
} else {
|
||||
offsets[i] = offset;
|
||||
|
||||
size_t compressedSize = sizes[i];
|
||||
dataio::write_int32_big(compressedSize, (ubyte*)intbuf, 0);
|
||||
dataio::write_int32_big(compressedSize, reinterpret_cast<ubyte*>(intbuf), 0);
|
||||
offset += 4 + compressedSize;
|
||||
|
||||
file.write(intbuf, 4);
|
||||
@@ -313,7 +305,7 @@ void WorldRegions::writeRegion(int x, int z, int layer, WorldRegion* entry){
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < REGION_CHUNKS_COUNT; i++) {
|
||||
dataio::write_int32_big(offsets[i], (ubyte*)intbuf, 0);
|
||||
dataio::write_int32_big(offsets[i], reinterpret_cast<ubyte*>(intbuf), 0);
|
||||
file.write(intbuf, 4);
|
||||
}
|
||||
}
|
||||
@@ -357,15 +349,20 @@ static std::unique_ptr<ubyte[]> write_inventories(Chunk* chunk, uint& datasize)
|
||||
auto datavec = builder.data();
|
||||
datasize = builder.size();
|
||||
auto data = std::make_unique<ubyte[]>(datasize);
|
||||
for (uint i = 0; i < datasize; i++) {
|
||||
data[i] = datavec[i];
|
||||
}
|
||||
std::memcpy(data.get(), datavec, datasize);
|
||||
return data;
|
||||
}
|
||||
|
||||
/// @brief Store chunk (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){
|
||||
assert(chunk != nullptr);
|
||||
if (!chunk->flags.lighted) {
|
||||
return;
|
||||
}
|
||||
bool lightsUnsaved = !chunk->flags.loadedLights && doWriteLights;
|
||||
if (!chunk->flags.unsaved && !lightsUnsaved) {
|
||||
return;
|
||||
}
|
||||
|
||||
int regionX, regionZ, localX, localZ;
|
||||
calc_reg_coords(chunk->x, chunk->z, regionX, regionZ, localX, localZ);
|
||||
@@ -408,11 +405,12 @@ std::unique_ptr<light_t[]> WorldRegions::getLights(int x, int z) {
|
||||
}
|
||||
|
||||
chunk_inventories_map WorldRegions::fetchInventories(int x, int z) {
|
||||
chunk_inventories_map inventories;
|
||||
chunk_inventories_map meta;
|
||||
uint32_t bytesSize;
|
||||
const ubyte* data = getData(x, z, REGION_LAYER_INVENTORIES, bytesSize);
|
||||
if (data == nullptr)
|
||||
return inventories;
|
||||
if (data == nullptr) {
|
||||
return meta;
|
||||
}
|
||||
ByteReader reader(data, bytesSize);
|
||||
int count = reader.getInt32();
|
||||
for (int i = 0; i < count; i++) {
|
||||
@@ -422,12 +420,12 @@ chunk_inventories_map WorldRegions::fetchInventories(int x, int z) {
|
||||
reader.skip(size);
|
||||
auto inv = std::make_shared<Inventory>(0, 0);
|
||||
inv->deserialize(map.get());
|
||||
inventories[index] = inv;
|
||||
meta[index] = inv;
|
||||
}
|
||||
return inventories;
|
||||
return meta;
|
||||
}
|
||||
|
||||
void WorldRegions::processRegionVoxels(int x, int z, regionproc func) {
|
||||
void WorldRegions::processRegionVoxels(int x, int z, const regionproc& func) {
|
||||
if (getRegion(x, z, REGION_LAYER_VOXELS)) {
|
||||
throw std::runtime_error("not implemented for in-memory regions");
|
||||
}
|
||||
@@ -465,8 +463,9 @@ void WorldRegions::write() {
|
||||
|
||||
bool WorldRegions::parseRegionFilename(const std::string& name, int& x, int& z) {
|
||||
size_t sep = name.find('_');
|
||||
if (sep == std::string::npos || sep == 0 || sep == name.length()-1)
|
||||
if (sep == std::string::npos || sep == 0 || sep == name.length()-1) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
x = std::stoi(name.substr(0, sep));
|
||||
z = std::stoi(name.substr(sep+1));
|
||||
|
||||
@@ -38,8 +38,8 @@ public:
|
||||
};
|
||||
|
||||
class WorldRegion {
|
||||
ubyte** chunksData;
|
||||
uint32_t* sizes;
|
||||
std::unique_ptr<std::unique_ptr<ubyte[]>[]> chunksData;
|
||||
std::unique_ptr<uint32_t[]> sizes;
|
||||
bool unsaved = false;
|
||||
public:
|
||||
WorldRegion();
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
void setUnsaved(bool unsaved);
|
||||
bool isUnsaved() const;
|
||||
|
||||
ubyte** getChunks() const;
|
||||
std::unique_ptr<ubyte[]>* getChunks() const;
|
||||
uint32_t* getSizes() const;
|
||||
};
|
||||
|
||||
@@ -77,6 +77,43 @@ struct RegionsLayer {
|
||||
std::mutex mutex;
|
||||
};
|
||||
|
||||
class regfile_ptr {
|
||||
regfile* file;
|
||||
std::condition_variable* cv;
|
||||
public:
|
||||
regfile_ptr(
|
||||
regfile* file,
|
||||
std::condition_variable* cv
|
||||
) : file(file), cv(cv) {}
|
||||
|
||||
regfile_ptr(const regfile_ptr&) = delete;
|
||||
|
||||
regfile_ptr(std::nullptr_t) : file(nullptr), cv(nullptr) {}
|
||||
|
||||
bool operator==(std::nullptr_t) const {
|
||||
return file == nullptr;
|
||||
}
|
||||
bool operator!=(std::nullptr_t) const {
|
||||
return file != nullptr;
|
||||
}
|
||||
operator bool() const {
|
||||
return file != nullptr;
|
||||
}
|
||||
~regfile_ptr() {
|
||||
reset();
|
||||
}
|
||||
regfile* get() {
|
||||
return file;
|
||||
}
|
||||
void reset() {
|
||||
if (file) {
|
||||
file->inUse = false;
|
||||
cv->notify_one();
|
||||
file = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class WorldRegions {
|
||||
fs::path directory;
|
||||
std::unordered_map<glm::ivec3, std::unique_ptr<regfile>> openRegFiles;
|
||||
@@ -110,10 +147,10 @@ class WorldRegions {
|
||||
|
||||
ubyte* getData(int x, int z, int layer, uint32_t& size);
|
||||
|
||||
std::shared_ptr<regfile> getRegFile(glm::ivec3 coord, bool create=true);
|
||||
regfile_ptr getRegFile(glm::ivec3 coord, bool create=true);
|
||||
void closeRegFile(glm::ivec3 coord);
|
||||
std::shared_ptr<regfile> useRegFile(glm::ivec3 coord);
|
||||
std::shared_ptr<regfile> createRegFile(glm::ivec3 coord);
|
||||
regfile_ptr useRegFile(glm::ivec3 coord);
|
||||
regfile_ptr createRegFile(glm::ivec3 coord);
|
||||
|
||||
fs::path getRegionFilename(int x, int y) const;
|
||||
|
||||
@@ -128,7 +165,7 @@ public:
|
||||
bool generatorTestMode = false;
|
||||
bool doWriteLights = true;
|
||||
|
||||
WorldRegions(fs::path directory);
|
||||
WorldRegions(const fs::path& directory);
|
||||
WorldRegions(const WorldRegions&) = delete;
|
||||
~WorldRegions();
|
||||
|
||||
@@ -148,7 +185,7 @@ public:
|
||||
std::unique_ptr<light_t[]> getLights(int x, int z);
|
||||
chunk_inventories_map fetchInventories(int x, int z);
|
||||
|
||||
void processRegionVoxels(int x, int z, regionproc func);
|
||||
void processRegionVoxels(int x, int z, const regionproc& func);
|
||||
|
||||
fs::path getRegionsFolder(int layer) const;
|
||||
|
||||
|
||||
+18
-13
@@ -4,15 +4,24 @@
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include "../util/stringutil.hpp"
|
||||
#include "../typedefs.hpp"
|
||||
#include "WorldFiles.hpp"
|
||||
|
||||
const fs::path SCREENSHOTS_FOLDER {"screenshots"};
|
||||
const fs::path CONTENT_FOLDER {"content"};
|
||||
const fs::path CONTROLS_FILE {"controls.toml"};
|
||||
const fs::path SETTINGS_FILE {"settings.toml"};
|
||||
|
||||
void EnginePaths::prepare() {
|
||||
fs::path contentFolder = userfiles/fs::path(CONTENT_FOLDER);
|
||||
if (!fs::is_directory(contentFolder)) {
|
||||
fs::create_directories(contentFolder);
|
||||
}
|
||||
}
|
||||
|
||||
fs::path EnginePaths::getUserfiles() const {
|
||||
return userfiles;
|
||||
}
|
||||
@@ -21,7 +30,7 @@ fs::path EnginePaths::getResources() const {
|
||||
return resources;
|
||||
}
|
||||
|
||||
fs::path EnginePaths::getScreenshotFile(std::string ext) {
|
||||
fs::path EnginePaths::getScreenshotFile(const std::string& ext) {
|
||||
fs::path folder = userfiles/fs::path(SCREENSHOTS_FOLDER);
|
||||
if (!fs::is_directory(folder)) {
|
||||
fs::create_directory(folder);
|
||||
@@ -60,10 +69,6 @@ fs::path EnginePaths::getControlsFile() {
|
||||
return userfiles/fs::path(CONTROLS_FILE);
|
||||
}
|
||||
|
||||
fs::path EnginePaths::getControlsFileOld() {
|
||||
return userfiles/fs::path("controls.json");
|
||||
}
|
||||
|
||||
fs::path EnginePaths::getSettingsFile() {
|
||||
return userfiles/fs::path(SETTINGS_FILE);
|
||||
}
|
||||
@@ -75,11 +80,11 @@ std::vector<fs::path> EnginePaths::scanForWorlds() {
|
||||
if (!fs::is_directory(folder))
|
||||
return folders;
|
||||
|
||||
for (auto entry : fs::directory_iterator(folder)) {
|
||||
for (const auto& entry : fs::directory_iterator(folder)) {
|
||||
if (!entry.is_directory()) {
|
||||
continue;
|
||||
}
|
||||
fs::path worldFolder = entry.path();
|
||||
const fs::path& worldFolder = entry.path();
|
||||
fs::path worldFile = worldFolder/fs::u8path(WorldFiles::WORLD_FILE);
|
||||
if (!fs::is_regular_file(worldFile)) {
|
||||
continue;
|
||||
@@ -94,20 +99,20 @@ std::vector<fs::path> EnginePaths::scanForWorlds() {
|
||||
return folders;
|
||||
}
|
||||
|
||||
bool EnginePaths::isWorldNameUsed(std::string name) {
|
||||
bool EnginePaths::isWorldNameUsed(const std::string& name) {
|
||||
return fs::exists(EnginePaths::getWorldsFolder()/fs::u8path(name));
|
||||
}
|
||||
|
||||
void EnginePaths::setUserfiles(fs::path folder) {
|
||||
this->userfiles = folder;
|
||||
this->userfiles = std::move(folder);
|
||||
}
|
||||
|
||||
void EnginePaths::setResources(fs::path folder) {
|
||||
this->resources = folder;
|
||||
this->resources = std::move(folder);
|
||||
}
|
||||
|
||||
void EnginePaths::setWorldFolder(fs::path folder) {
|
||||
this->worldFolder = folder;
|
||||
this->worldFolder = std::move(folder);
|
||||
}
|
||||
|
||||
void EnginePaths::setContentPacks(std::vector<ContentPack>* contentPacks) {
|
||||
@@ -139,7 +144,7 @@ static fs::path toCanonic(fs::path path) {
|
||||
return path;
|
||||
}
|
||||
|
||||
fs::path EnginePaths::resolve(std::string path, bool throwErr) {
|
||||
fs::path EnginePaths::resolve(const std::string& path, bool throwErr) {
|
||||
size_t separator = path.find(':');
|
||||
if (separator == std::string::npos) {
|
||||
throw files_access_error("no entry point specified");
|
||||
@@ -172,7 +177,7 @@ fs::path EnginePaths::resolve(std::string path, bool throwErr) {
|
||||
}
|
||||
|
||||
ResPaths::ResPaths(fs::path mainRoot, std::vector<PathsRoot> roots)
|
||||
: mainRoot(mainRoot), roots(roots) {
|
||||
: mainRoot(std::move(mainRoot)), roots(std::move(roots)) {
|
||||
}
|
||||
|
||||
fs::path ResPaths::find(const std::string& filename) const {
|
||||
|
||||
@@ -21,17 +21,18 @@ class EnginePaths {
|
||||
fs::path worldFolder;
|
||||
std::vector<ContentPack>* contentPacks = nullptr;
|
||||
public:
|
||||
void prepare();
|
||||
|
||||
fs::path getUserfiles() const;
|
||||
fs::path getResources() const;
|
||||
|
||||
fs::path getScreenshotFile(std::string ext);
|
||||
fs::path getScreenshotFile(const std::string& ext);
|
||||
fs::path getWorldsFolder();
|
||||
fs::path getWorldFolder();
|
||||
fs::path getWorldFolder(const std::string& name);
|
||||
fs::path getControlsFile();
|
||||
fs::path getControlsFileOld(); // TODO: remove in 0.22
|
||||
fs::path getSettingsFile();
|
||||
bool isWorldNameUsed(std::string name);
|
||||
bool isWorldNameUsed(const std::string& name);
|
||||
|
||||
void setUserfiles(fs::path folder);
|
||||
void setResources(fs::path folder);
|
||||
@@ -40,7 +41,7 @@ public:
|
||||
|
||||
std::vector<fs::path> scanForWorlds();
|
||||
|
||||
fs::path resolve(std::string path, bool throwErr=true);
|
||||
fs::path resolve(const std::string& path, bool throwErr=true);
|
||||
};
|
||||
|
||||
struct PathsRoot {
|
||||
|
||||
+13
-13
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
files::rafile::rafile(fs::path filename)
|
||||
files::rafile::rafile(const fs::path& filename)
|
||||
: file(filename, std::ios::binary | std::ios::ate) {
|
||||
if (!file) {
|
||||
throw std::runtime_error("could not to open file "+filename.string());
|
||||
@@ -36,7 +36,7 @@ void files::rafile::read(char* buffer, std::streamsize size) {
|
||||
file.read(buffer, size);
|
||||
}
|
||||
|
||||
bool files::write_bytes(fs::path filename, const ubyte* data, size_t size) {
|
||||
bool files::write_bytes(const fs::path& filename, const ubyte* data, size_t size) {
|
||||
std::ofstream output(filename, std::ios::binary);
|
||||
if (!output.is_open())
|
||||
return false;
|
||||
@@ -45,7 +45,7 @@ bool files::write_bytes(fs::path filename, const ubyte* data, size_t size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint files::append_bytes(fs::path filename, const ubyte* data, size_t size) {
|
||||
uint files::append_bytes(const fs::path& filename, const ubyte* data, size_t size) {
|
||||
std::ofstream output(filename, std::ios::binary | std::ios::app);
|
||||
if (!output.is_open())
|
||||
return 0;
|
||||
@@ -55,7 +55,7 @@ uint files::append_bytes(fs::path filename, const ubyte* data, size_t size) {
|
||||
return position;
|
||||
}
|
||||
|
||||
bool files::read(fs::path filename, char* data, size_t size) {
|
||||
bool files::read(const fs::path& filename, char* data, size_t size) {
|
||||
std::ifstream output(filename, std::ios::binary);
|
||||
if (!output.is_open())
|
||||
return false;
|
||||
@@ -64,7 +64,7 @@ bool files::read(fs::path filename, char* data, size_t size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<ubyte[]> files::read_bytes(fs::path filename, size_t& length) {
|
||||
std::unique_ptr<ubyte[]> files::read_bytes(const fs::path& filename, size_t& length) {
|
||||
std::ifstream input(filename, std::ios::binary);
|
||||
if (!input.is_open())
|
||||
return nullptr;
|
||||
@@ -78,7 +78,7 @@ std::unique_ptr<ubyte[]> files::read_bytes(fs::path filename, size_t& length) {
|
||||
return data;
|
||||
}
|
||||
|
||||
std::string files::read_string(fs::path filename) {
|
||||
std::string files::read_string(const fs::path& filename) {
|
||||
size_t size;
|
||||
std::unique_ptr<ubyte[]> bytes (read_bytes(filename, size));
|
||||
if (bytes == nullptr) {
|
||||
@@ -88,7 +88,7 @@ std::string files::read_string(fs::path filename) {
|
||||
return std::string((const char*)bytes.get(), size);
|
||||
}
|
||||
|
||||
bool files::write_string(fs::path filename, const std::string content) {
|
||||
bool files::write_string(const fs::path& filename, const std::string content) {
|
||||
std::ofstream file(filename);
|
||||
if (!file) {
|
||||
return false;
|
||||
@@ -97,16 +97,16 @@ bool files::write_string(fs::path filename, const std::string content) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool files::write_json(fs::path filename, const dynamic::Map* obj, bool nice) {
|
||||
bool files::write_json(const fs::path& filename, const dynamic::Map* obj, bool nice) {
|
||||
return files::write_string(filename, json::stringify(obj, nice, " "));
|
||||
}
|
||||
|
||||
bool files::write_binary_json(fs::path filename, const dynamic::Map* obj, bool compression) {
|
||||
bool files::write_binary_json(const fs::path& filename, const dynamic::Map* obj, bool compression) {
|
||||
auto bytes = json::to_binary(obj, compression);
|
||||
return files::write_bytes(filename, bytes.data(), bytes.size());
|
||||
}
|
||||
|
||||
std::shared_ptr<dynamic::Map> files::read_json(fs::path filename) {
|
||||
std::shared_ptr<dynamic::Map> files::read_json(const fs::path& filename) {
|
||||
std::string text = files::read_string(filename);
|
||||
try {
|
||||
return json::parse(filename.string(), text);;
|
||||
@@ -116,17 +116,17 @@ std::shared_ptr<dynamic::Map> files::read_json(fs::path filename) {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<dynamic::Map> files::read_binary_json(fs::path file) {
|
||||
std::shared_ptr<dynamic::Map> files::read_binary_json(const fs::path& file) {
|
||||
size_t size;
|
||||
std::unique_ptr<ubyte[]> bytes (files::read_bytes(file, size));
|
||||
return json::from_binary(bytes.get(), size);
|
||||
}
|
||||
|
||||
std::shared_ptr<dynamic::Map> files::read_toml(fs::path file) {
|
||||
std::shared_ptr<dynamic::Map> files::read_toml(const fs::path& file) {
|
||||
return toml::parse(file.u8string(), files::read_string(file));
|
||||
}
|
||||
|
||||
std::vector<std::string> files::read_list(fs::path filename) {
|
||||
std::vector<std::string> files::read_list(const fs::path& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file) {
|
||||
throw std::runtime_error("could not to open file "+filename.u8string());
|
||||
|
||||
+13
-13
@@ -20,7 +20,7 @@ namespace files {
|
||||
std::ifstream file;
|
||||
size_t filelength;
|
||||
public:
|
||||
rafile(fs::path filename);
|
||||
rafile(const fs::path& filename);
|
||||
|
||||
void seekg(std::streampos pos);
|
||||
void read(char* buffer, std::streamsize size);
|
||||
@@ -31,40 +31,40 @@ namespace files {
|
||||
/// @param file target file
|
||||
/// @param data data bytes array
|
||||
/// @param size size of data bytes array
|
||||
bool write_bytes(fs::path file, const ubyte* data, size_t size);
|
||||
bool write_bytes(const fs::path& file, const ubyte* data, size_t size);
|
||||
|
||||
/// @brief Append bytes array to the file without any extra data
|
||||
/// @param file target file
|
||||
/// @param data data bytes array
|
||||
/// @param size size of data bytes array
|
||||
uint append_bytes(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
|
||||
bool write_string(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
|
||||
/// @param nice if true, human readable format will be used, otherwise minimal
|
||||
bool write_json(fs::path filename, const dynamic::Map* obj, bool nice=true);
|
||||
bool write_json(const fs::path& filename, const dynamic::Map* obj, bool nice=true);
|
||||
|
||||
/// @brief Write dynamic data to the binary JSON file
|
||||
/// (see src/coders/binary_json_spec.md)
|
||||
/// @param compressed use gzip compression
|
||||
bool write_binary_json(
|
||||
fs::path filename,
|
||||
const fs::path& filename,
|
||||
const dynamic::Map* obj,
|
||||
bool compressed=false
|
||||
);
|
||||
|
||||
bool read(fs::path, char* data, size_t size);
|
||||
std::unique_ptr<ubyte[]> read_bytes(fs::path, size_t& length);
|
||||
std::string read_string(fs::path filename);
|
||||
bool read(const fs::path&, char* data, size_t size);
|
||||
std::unique_ptr<ubyte[]> read_bytes(const fs::path&, size_t& length);
|
||||
std::string read_string(const fs::path& filename);
|
||||
|
||||
/// @brief Read JSON or BJSON file
|
||||
/// @param file *.json or *.bjson file
|
||||
std::shared_ptr<dynamic::Map> read_json(fs::path file);
|
||||
std::shared_ptr<dynamic::Map> read_binary_json(fs::path file);
|
||||
std::shared_ptr<dynamic::Map> read_toml(fs::path file);
|
||||
std::vector<std::string> read_list(fs::path file);
|
||||
std::shared_ptr<dynamic::Map> read_json(const fs::path& file);
|
||||
std::shared_ptr<dynamic::Map> read_binary_json(const fs::path& file);
|
||||
std::shared_ptr<dynamic::Map> read_toml(const fs::path& file);
|
||||
std::vector<std::string> read_list(const fs::path& file);
|
||||
}
|
||||
|
||||
#endif /* FILES_FILES_HPP_ */
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "../settings.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
static debug::Logger logger("settings_io");
|
||||
|
||||
@@ -22,10 +23,10 @@ struct SectionsBuilder {
|
||||
}
|
||||
|
||||
void section(std::string name) {
|
||||
sections.push_back(Section {name, {}});
|
||||
sections.push_back(Section {std::move(name), {}});
|
||||
}
|
||||
|
||||
void add(std::string name, Setting* setting, bool writeable=true) {
|
||||
void add(const std::string& name, Setting* setting, bool writeable=true) {
|
||||
Section& section = sections.at(sections.size()-1);
|
||||
map[section.name+"."+name] = setting;
|
||||
section.keys.push_back(name);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "UiDocument.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../files/files.hpp"
|
||||
#include "../graphics/ui/elements/UINode.hpp"
|
||||
#include "../graphics/ui/elements/InventoryView.hpp"
|
||||
@@ -9,9 +11,9 @@
|
||||
UiDocument::UiDocument(
|
||||
std::string id,
|
||||
uidocscript script,
|
||||
std::shared_ptr<gui::UINode> root,
|
||||
const std::shared_ptr<gui::UINode>& root,
|
||||
scriptenv env
|
||||
) : id(id), script(script), root(root), env(env) {
|
||||
) : id(std::move(id)), script(script), root(root), env(std::move(env)) {
|
||||
gui::UINode::getIndices(root, map);
|
||||
}
|
||||
|
||||
@@ -31,11 +33,11 @@ const std::string& UiDocument::getId() const {
|
||||
return id;
|
||||
}
|
||||
|
||||
const std::shared_ptr<gui::UINode> UiDocument::getRoot() const {
|
||||
std::shared_ptr<gui::UINode> UiDocument::getRoot() const {
|
||||
return root;
|
||||
}
|
||||
|
||||
const std::shared_ptr<gui::UINode> UiDocument::get(const std::string& id) const {
|
||||
std::shared_ptr<gui::UINode> UiDocument::get(const std::string& id) const {
|
||||
auto found = map.find(id);
|
||||
if (found == map.end()) {
|
||||
return nullptr;
|
||||
@@ -51,7 +53,7 @@ scriptenv UiDocument::getEnvironment() const {
|
||||
return env;
|
||||
}
|
||||
|
||||
std::unique_ptr<UiDocument> UiDocument::read(scriptenv penv, std::string name, fs::path file) {
|
||||
std::unique_ptr<UiDocument> UiDocument::read(const scriptenv& penv, const std::string& name, const fs::path& file) {
|
||||
const std::string text = files::read_string(file);
|
||||
auto xmldoc = xml::parse(file.u8string(), text);
|
||||
|
||||
@@ -72,7 +74,7 @@ std::unique_ptr<UiDocument> UiDocument::read(scriptenv penv, std::string name, f
|
||||
return std::make_unique<UiDocument>(name, script, view, env);
|
||||
}
|
||||
|
||||
std::shared_ptr<gui::UINode> UiDocument::readElement(fs::path file) {
|
||||
std::shared_ptr<gui::UINode> UiDocument::readElement(const fs::path& file) {
|
||||
auto document = read(nullptr, file.filename().u8string(), file);
|
||||
return document->getRoot();
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
UiDocument(
|
||||
std::string id,
|
||||
uidocscript script,
|
||||
std::shared_ptr<gui::UINode> root,
|
||||
const std::shared_ptr<gui::UINode> &root,
|
||||
scriptenv env
|
||||
);
|
||||
|
||||
@@ -41,13 +41,13 @@ public:
|
||||
const std::string& getId() const;
|
||||
const uinodes_map& getMap() const;
|
||||
uinodes_map& getMapWriteable();
|
||||
const std::shared_ptr<gui::UINode> getRoot() const;
|
||||
const std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
||||
std::shared_ptr<gui::UINode> getRoot() const;
|
||||
std::shared_ptr<gui::UINode> get(const std::string& id) const;
|
||||
const uidocscript& getScript() const;
|
||||
scriptenv getEnvironment() const;
|
||||
|
||||
static std::unique_ptr<UiDocument> read(scriptenv parent_env, std::string name, fs::path file);
|
||||
static std::shared_ptr<gui::UINode> readElement(fs::path file);
|
||||
static std::unique_ptr<UiDocument> read(const scriptenv& parent_env, const std::string& name, const fs::path& file);
|
||||
static std::shared_ptr<gui::UINode> readElement(const fs::path& file);
|
||||
};
|
||||
|
||||
#endif // FRONTEND_UI_DOCUMENT_HPP_
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "../graphics/ui/elements/TrackBar.hpp"
|
||||
#include "../graphics/ui/elements/InputBindBox.hpp"
|
||||
#include "../graphics/render/WorldRenderer.hpp"
|
||||
#include "../logic/scripting/scripting.hpp"
|
||||
#include "../objects/Player.hpp"
|
||||
#include "../physics/Hitbox.hpp"
|
||||
#include "../util/stringutil.hpp"
|
||||
@@ -21,12 +22,13 @@
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <bitset>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
static std::shared_ptr<Label> create_label(wstringsupplier supplier) {
|
||||
auto label = std::make_shared<Label>(L"-");
|
||||
label->textSupplier(supplier);
|
||||
label->textSupplier(std::move(supplier));
|
||||
return label;
|
||||
}
|
||||
|
||||
@@ -36,6 +38,7 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
Player* player
|
||||
) {
|
||||
auto panel = std::make_shared<Panel>(glm::vec2(250, 200), glm::vec4(5.0f), 2.0f);
|
||||
panel->setId("hud.debug-panel");
|
||||
panel->setPos(glm::vec2(10, 10));
|
||||
|
||||
static int fps = 0;
|
||||
@@ -63,6 +66,9 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
return L"speakers: " + std::to_wstring(audio::count_speakers())+
|
||||
L" streams: " + std::to_wstring(audio::count_streams());
|
||||
}));
|
||||
panel->add(create_label([](){
|
||||
return L"lua-stack: " + std::to_wstring(scripting::get_values_on_stack());
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
auto& settings = engine->getSettings();
|
||||
bool culling = settings.graphics.frustumCulling.get();
|
||||
@@ -73,20 +79,21 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
L" visible: "+std::to_wstring(level->chunks->visible);
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
const auto& vox = player->selection.vox;
|
||||
std::wstringstream stream;
|
||||
stream << "r:" << player->selectedVoxel.state.rotation << " s:"
|
||||
<< player->selectedVoxel.state.segment << " u:"
|
||||
<< std::bitset<8>(player->selectedVoxel.state.userbits);
|
||||
if (player->selectedVoxel.id == BLOCK_VOID) {
|
||||
stream << "r:" << vox.state.rotation << " s:"
|
||||
<< std::bitset<3>(vox.state.segment) << " u:"
|
||||
<< std::bitset<8>(vox.state.userbits);
|
||||
if (vox.id == BLOCK_VOID) {
|
||||
return std::wstring {L"block: -"};
|
||||
} else {
|
||||
return L"block: "+std::to_wstring(player->selectedVoxel.id)+
|
||||
L" "+stream.str();
|
||||
return L"block: "+std::to_wstring(vox.id)+
|
||||
L" "+stream.str();
|
||||
}
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
auto* indices = level->content->getIndices();
|
||||
if (auto def = indices->getBlockDef(player->selectedVoxel.id)) {
|
||||
if (auto def = indices->getBlockDef(player->selection.vox.id)) {
|
||||
return L"name: " + util::str2wstr_utf8(def->name);
|
||||
} else {
|
||||
return std::wstring {L"name: void"};
|
||||
@@ -114,7 +121,7 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
Hitbox* hitbox = player->hitbox.get();
|
||||
return util::to_wstring(hitbox->position[ax], 2);
|
||||
});
|
||||
box->setTextConsumer([=](std::wstring text) {
|
||||
box->setTextConsumer([=](const std::wstring& text) {
|
||||
try {
|
||||
glm::vec3 position = player->hitbox->position;
|
||||
position[ax] = std::stoi(text);
|
||||
@@ -136,8 +143,8 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
timeutil::from_value(level->getWorld()->daytime, hour, minute, second);
|
||||
|
||||
std::wstring timeString =
|
||||
util::lfill(std::to_wstring(hour), 2, L'0') + L":" +
|
||||
util::lfill(std::to_wstring(minute), 2, L'0');
|
||||
util::lfill(std::to_wstring(hour), 2, L'0') + L":" +
|
||||
util::lfill(std::to_wstring(minute), 2, L'0');
|
||||
return L"time: "+timeString;
|
||||
}));
|
||||
{
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -63,7 +64,7 @@ HudElement::HudElement(
|
||||
UiDocument* document,
|
||||
std::shared_ptr<UINode> node,
|
||||
bool debug
|
||||
) : mode(mode), document(document), node(node), debug(debug) {
|
||||
) : mode(mode), document(document), node(std::move(node)), debug(debug) {
|
||||
}
|
||||
|
||||
void HudElement::update(bool pause, bool inventoryOpen, bool debugMode) {
|
||||
@@ -132,7 +133,7 @@ std::shared_ptr<InventoryView> Hud::createHotbar() {
|
||||
InventoryBuilder builder;
|
||||
builder.addGrid(10, 10, glm::vec2(), 4, true, slotLayout);
|
||||
auto view = builder.build();
|
||||
|
||||
view->setId("hud.hotbar");
|
||||
view->setOrigin(glm::vec2(view->getSize().x/2, 0));
|
||||
view->bind(inventory, content);
|
||||
view->setInteractive(false);
|
||||
@@ -146,12 +147,14 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
|
||||
player(player)
|
||||
{
|
||||
contentAccess = createContentAccess();
|
||||
contentAccess->setId("hud.content-access");
|
||||
contentAccessPanel = std::make_shared<Panel>(
|
||||
contentAccess->getSize(), glm::vec4(0.0f), 0.0f
|
||||
);
|
||||
contentAccessPanel->setColor(glm::vec4());
|
||||
contentAccessPanel->add(contentAccess);
|
||||
contentAccessPanel->setScrollable(true);
|
||||
contentAccessPanel->setId("hud.content-access-panel");
|
||||
|
||||
hotbarView = createHotbar();
|
||||
darkOverlay = guiutil::create(
|
||||
@@ -398,7 +401,7 @@ void Hud::closeInventory() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void Hud::add(HudElement element) {
|
||||
void Hud::add(const HudElement& element) {
|
||||
using namespace dynamic;
|
||||
|
||||
gui->add(element.getNode());
|
||||
@@ -407,9 +410,9 @@ void Hud::add(HudElement element) {
|
||||
if (document) {
|
||||
auto inventory = invview ? invview->getInventory() : nullptr;
|
||||
std::vector<Value> args;
|
||||
args.push_back(inventory ? inventory.get()->getId() : 0);
|
||||
args.emplace_back(inventory ? inventory.get()->getId() : 0);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
args.push_back(static_cast<integer_t>(blockPos[i]));
|
||||
args.emplace_back(static_cast<integer_t>(blockPos[i]));
|
||||
}
|
||||
scripting::on_ui_open(
|
||||
element.getDocument(),
|
||||
@@ -435,7 +438,7 @@ void Hud::onRemove(const HudElement& element) {
|
||||
gui->remove(element.getNode());
|
||||
}
|
||||
|
||||
void Hud::remove(std::shared_ptr<UINode> node) {
|
||||
void Hud::remove(const std::shared_ptr<UINode>& node) {
|
||||
for (auto& element : elements) {
|
||||
if (element.getNode() == node) {
|
||||
element.setRemoved();
|
||||
|
||||
@@ -161,9 +161,9 @@ public:
|
||||
/// @param doc element layout
|
||||
void openPermanent(UiDocument* doc);
|
||||
|
||||
void add(HudElement element);
|
||||
void add(const HudElement& element);
|
||||
void onRemove(const HudElement& element);
|
||||
void remove(std::shared_ptr<gui::UINode> node);
|
||||
void remove(const std::shared_ptr<gui::UINode>& node);
|
||||
|
||||
Player* getPlayer() const;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "locale.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../coders/json.hpp"
|
||||
#include "../coders/commons.hpp"
|
||||
#include "../content/ContentPack.hpp"
|
||||
@@ -16,7 +18,7 @@ using namespace std::literals;
|
||||
std::unique_ptr<langs::Lang> langs::current;
|
||||
std::unordered_map<std::string, langs::LocaleInfo> langs::locales_info;
|
||||
|
||||
langs::Lang::Lang(std::string locale) : locale(locale) {
|
||||
langs::Lang::Lang(std::string locale) : locale(std::move(locale)) {
|
||||
}
|
||||
|
||||
const std::wstring& langs::Lang::get(const std::wstring& key) const {
|
||||
@@ -50,7 +52,7 @@ public:
|
||||
Reader(std::string_view file, std::string_view source) : BasicParser(file, source) {
|
||||
}
|
||||
|
||||
void read(langs::Lang& lang, std::string prefix) {
|
||||
void read(langs::Lang& lang, const std::string &prefix) {
|
||||
skipWhitespace();
|
||||
while (hasNext()) {
|
||||
std::string key = parseString('=', true);
|
||||
|
||||
@@ -54,7 +54,7 @@ gui::page_loader_func menus::create_page_loader(Engine* engine) {
|
||||
auto value = std::string(parser.readUntil('&'));
|
||||
map->put(key, value);
|
||||
}
|
||||
args.push_back(map);
|
||||
args.emplace_back(map);
|
||||
} else {
|
||||
name = query;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ UiDocument* menus::show(Engine* engine, const std::string& name, std::vector<dyn
|
||||
return document;
|
||||
}
|
||||
|
||||
void menus::show_process_panel(Engine* engine, std::shared_ptr<Task> task, std::wstring text) {
|
||||
void menus::show_process_panel(Engine* engine, const std::shared_ptr<Task>& task, const std::wstring& text) {
|
||||
using namespace dynamic;
|
||||
|
||||
uint initialWork = task->getWorkTotal();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace menus {
|
||||
std::vector<dynamic::Value> args
|
||||
);
|
||||
|
||||
void show_process_panel(Engine* engine, std::shared_ptr<Task> task, std::wstring text=L"");
|
||||
void show_process_panel(Engine* engine, const std::shared_ptr<Task>& task, const std::wstring& text=L"");
|
||||
}
|
||||
|
||||
#endif // FRONTEND_MENU_MENU_HPP_
|
||||
|
||||
@@ -42,7 +42,7 @@ ImageData* Atlas::getImage() const {
|
||||
return image.get();
|
||||
}
|
||||
|
||||
void AtlasBuilder::add(std::string name, std::unique_ptr<ImageData> image) {
|
||||
void AtlasBuilder::add(const std::string& name, std::unique_ptr<ImageData> image) {
|
||||
entries.push_back(atlasentry{name, std::shared_ptr<ImageData>(image.release())});
|
||||
names.insert(name);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class AtlasBuilder {
|
||||
std::set<std::string> names;
|
||||
public:
|
||||
AtlasBuilder() {}
|
||||
void add(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;
|
||||
const std::set<std::string>& getNames() { return names; };
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Batch2D.hpp"
|
||||
#include "Framebuffer.hpp"
|
||||
#include "../../window/Window.hpp"
|
||||
@@ -23,10 +25,10 @@ static void set_blend_mode(BlendMode mode) {
|
||||
|
||||
DrawContext::DrawContext(
|
||||
const DrawContext* parent,
|
||||
const Viewport& viewport,
|
||||
Viewport viewport,
|
||||
Batch2D* g2d
|
||||
) : parent(parent),
|
||||
viewport(viewport),
|
||||
viewport(std::move(viewport)),
|
||||
g2d(g2d)
|
||||
{}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class DrawContext {
|
||||
BlendMode blendMode = BlendMode::normal;
|
||||
int scissorsCount = 0;
|
||||
public:
|
||||
DrawContext(const DrawContext* parent, const Viewport& viewport, Batch2D* g2d);
|
||||
DrawContext(const DrawContext* parent, Viewport viewport, Batch2D* g2d);
|
||||
~DrawContext();
|
||||
|
||||
Batch2D* getBatch2D() const;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "Font.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include "Texture.hpp"
|
||||
#include "Batch2D.hpp"
|
||||
|
||||
@@ -43,7 +45,7 @@ int Font::calcWidth(const std::wstring& text, size_t offset, size_t length) {
|
||||
}
|
||||
|
||||
void Font::draw(Batch2D* batch, std::wstring text, int x, int y) {
|
||||
draw(batch, text, x, y, FontStyle::none);
|
||||
draw(batch, std::move(text), x, y, FontStyle::none);
|
||||
}
|
||||
|
||||
static inline void drawGlyph(Batch2D* batch, int x, int y, uint c, FontStyle style) {
|
||||
@@ -66,7 +68,7 @@ static inline void drawGlyph(Batch2D* batch, int x, int y, uint c, FontStyle sty
|
||||
batch->sprite(x, y, GLYPH_SIZE, GLYPH_SIZE, 16, c, batch->getColor());
|
||||
}
|
||||
|
||||
void Font::draw(Batch2D* batch, std::wstring text, int x, int y, FontStyle style) {
|
||||
void Font::draw(Batch2D* batch, const std::wstring& text, int x, int y, FontStyle style) {
|
||||
draw(batch, std::wstring_view(text.c_str(), text.length()), x, y, style);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
/// @param codepoint character unicode codepoint
|
||||
bool isPrintableChar(uint codepoint) const;
|
||||
void draw(Batch2D* batch, std::wstring text, int x, int y);
|
||||
void draw(Batch2D* batch, std::wstring text, int x, int y, FontStyle style);
|
||||
void draw(Batch2D* batch, const std::wstring& text, int x, int y, FontStyle style);
|
||||
void draw(Batch2D* batch, std::wstring_view text, int x, int y, FontStyle style);
|
||||
};
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ BlocksRenderer::BlocksRenderer(
|
||||
const ContentGfxCache* cache,
|
||||
const EngineSettings* settings
|
||||
) : content(content),
|
||||
vertexBuffer(std::make_unique<float[]>(capacity)),
|
||||
indexBuffer(std::make_unique<int[]>(capacity)),
|
||||
vertexOffset(0),
|
||||
indexOffset(0),
|
||||
indexSize(0),
|
||||
@@ -34,16 +36,14 @@ BlocksRenderer::BlocksRenderer(
|
||||
cache(cache),
|
||||
settings(settings)
|
||||
{
|
||||
vertexBuffer = new float[capacity];
|
||||
indexBuffer = new int[capacity];
|
||||
voxelsBuffer = new VoxelsVolume(CHUNK_W + 2, CHUNK_H, CHUNK_D + 2);
|
||||
voxelsBuffer = std::make_unique<VoxelsVolume>(
|
||||
CHUNK_W + voxelBufferPadding*2,
|
||||
CHUNK_H,
|
||||
CHUNK_D + voxelBufferPadding*2);
|
||||
blockDefsCache = content->getIndices()->getBlockDefs();
|
||||
}
|
||||
|
||||
BlocksRenderer::~BlocksRenderer() {
|
||||
delete voxelsBuffer;
|
||||
delete[] vertexBuffer;
|
||||
delete[] indexBuffer;
|
||||
}
|
||||
|
||||
/* Basic vertex add method */
|
||||
@@ -60,10 +60,10 @@ void BlocksRenderer::vertex(const vec3& coord, float u, float v, const vec4& lig
|
||||
uint32_t integer;
|
||||
} compressed;
|
||||
|
||||
compressed.integer = (uint32_t(light.r * 255) & 0xff) << 24;
|
||||
compressed.integer |= (uint32_t(light.g * 255) & 0xff) << 16;
|
||||
compressed.integer |= (uint32_t(light.b * 255) & 0xff) << 8;
|
||||
compressed.integer |= (uint32_t(light.a * 255) & 0xff);
|
||||
compressed.integer = (static_cast<uint32_t>(light.r * 255) & 0xff) << 24;
|
||||
compressed.integer |= (static_cast<uint32_t>(light.g * 255) & 0xff) << 16;
|
||||
compressed.integer |= (static_cast<uint32_t>(light.b * 255) & 0xff) << 8;
|
||||
compressed.integer |= (static_cast<uint32_t>(light.a * 255) & 0xff);
|
||||
|
||||
vertexBuffer[vertexOffset++] = compressed.floating;
|
||||
}
|
||||
@@ -78,15 +78,17 @@ void BlocksRenderer::index(int a, int b, int c, int d, int e, int f) {
|
||||
indexOffset += 4;
|
||||
}
|
||||
|
||||
/* Add face with precalculated lights */
|
||||
void BlocksRenderer::face(const vec3& coord,
|
||||
float w, float h, float d,
|
||||
const vec3& axisX,
|
||||
const vec3& axisY,
|
||||
const vec3& axisZ,
|
||||
const UVRegion& region,
|
||||
const vec4(&lights)[4],
|
||||
const vec4& tint) {
|
||||
/// @brief Add face with precalculated lights
|
||||
void BlocksRenderer::face(
|
||||
const vec3& coord,
|
||||
float w, float h, float d,
|
||||
const vec3& axisX,
|
||||
const vec3& axisY,
|
||||
const vec3& axisZ,
|
||||
const UVRegion& region,
|
||||
const vec4(&lights)[4],
|
||||
const vec4& tint
|
||||
) {
|
||||
if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
@@ -102,23 +104,27 @@ void BlocksRenderer::face(const vec3& coord,
|
||||
index(0, 1, 3, 1, 2, 3);
|
||||
}
|
||||
|
||||
void BlocksRenderer::vertex(const vec3& coord,
|
||||
float u, float v,
|
||||
const vec4& tint,
|
||||
const vec3& axisX,
|
||||
const vec3& axisY,
|
||||
const vec3& axisZ) {
|
||||
void BlocksRenderer::vertex(
|
||||
const vec3& coord,
|
||||
float u, float v,
|
||||
const vec4& tint,
|
||||
const vec3& axisX,
|
||||
const vec3& axisY,
|
||||
const vec3& axisZ
|
||||
) {
|
||||
vec3 pos = coord+axisZ*0.5f+(axisX+axisY)*0.5f;
|
||||
vec4 light = pickSoftLight(ivec3(round(pos.x), round(pos.y), round(pos.z)), axisX, axisY);
|
||||
vertex(coord, u, v, light * tint);
|
||||
}
|
||||
|
||||
void BlocksRenderer::face(const vec3& coord,
|
||||
const vec3& X,
|
||||
const vec3& Y,
|
||||
const vec3& Z,
|
||||
const UVRegion& region,
|
||||
bool lights) {
|
||||
void BlocksRenderer::face(
|
||||
const vec3& coord,
|
||||
const vec3& X,
|
||||
const vec3& Y,
|
||||
const vec3& Z,
|
||||
const UVRegion& region,
|
||||
bool lights
|
||||
) {
|
||||
if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
@@ -126,7 +132,7 @@ void BlocksRenderer::face(const vec3& coord,
|
||||
|
||||
float s = 0.5f;
|
||||
if (lights) {
|
||||
float d = glm::dot(Z, SUN_VECTOR);
|
||||
float d = glm::dot(glm::normalize(Z), SUN_VECTOR);
|
||||
d = 0.8f + d * 0.2f;
|
||||
|
||||
vec3 axisX = glm::normalize(X);
|
||||
@@ -148,14 +154,13 @@ void BlocksRenderer::face(const vec3& coord,
|
||||
index(0, 1, 2, 0, 2, 3);
|
||||
}
|
||||
|
||||
void BlocksRenderer::tetragonicFace(const vec3& coord, const vec3& p1,
|
||||
const vec3& p2, const vec3& p3, const vec3& p4,
|
||||
const vec3& X,
|
||||
const vec3& Y,
|
||||
const vec3& Z,
|
||||
const UVRegion& texreg,
|
||||
bool lights) {
|
||||
|
||||
void BlocksRenderer::tetragonicFace(
|
||||
const vec3& coord,
|
||||
const vec3& p1, const vec3& p2, const vec3& p3, const vec3& p4,
|
||||
const vec3& X, const vec3& Y, const vec3& Z,
|
||||
const UVRegion& texreg,
|
||||
bool lights
|
||||
) {
|
||||
const vec3 fp1 = (p1.x - 0.5f) * X + (p1.y - 0.5f) * Y + (p1.z - 0.5f) * Z;
|
||||
const vec3 fp2 = (p2.x - 0.5f) * X + (p2.y - 0.5f) * Y + (p2.z - 0.5f) * Z;
|
||||
const vec3 fp3 = (p3.x - 0.5f) * X + (p3.y - 0.5f) * Y + (p3.z - 0.5f) * Z;
|
||||
@@ -182,17 +187,19 @@ void BlocksRenderer::tetragonicFace(const vec3& coord, const vec3& p1,
|
||||
index(0, 1, 3, 1, 2, 3);
|
||||
}
|
||||
|
||||
void BlocksRenderer::blockXSprite(int x, int y, int z,
|
||||
const vec3& size,
|
||||
const UVRegion& texface1,
|
||||
const UVRegion& texface2,
|
||||
float spread) {
|
||||
vec4 lights[]{
|
||||
pickSoftLight({x, y + 1, z}, {1, 0, 0}, {0, 1, 0}),
|
||||
pickSoftLight({x + 1, y + 1, z}, {1, 0, 0}, {0, 1, 0}),
|
||||
pickSoftLight({x + 1, y + 1, z}, {1, 0, 0}, {0, 1, 0}),
|
||||
pickSoftLight({x, y + 1, z}, {1, 0, 0}, {0, 1, 0}) };
|
||||
|
||||
void BlocksRenderer::blockXSprite(
|
||||
int x, int y, int z,
|
||||
const vec3& size,
|
||||
const UVRegion& texface1,
|
||||
const UVRegion& texface2,
|
||||
float spread
|
||||
) {
|
||||
vec4 lights[] {
|
||||
pickSoftLight({x, y + 1, z}, {1, 0, 0}, {0, 1, 0}),
|
||||
pickSoftLight({x + 1, y + 1, z}, {1, 0, 0}, {0, 1, 0}),
|
||||
pickSoftLight({x + 1, y + 1, z}, {1, 0, 0}, {0, 1, 0}),
|
||||
pickSoftLight({x, y + 1, z}, {1, 0, 0}, {0, 1, 0})
|
||||
};
|
||||
int rand = ((x * z + y) ^ (z * y - x)) * (z + y);
|
||||
|
||||
float xs = ((float)(char)rand / 512) * spread;
|
||||
@@ -218,7 +225,7 @@ void BlocksRenderer::blockXSprite(int x, int y, int z,
|
||||
|
||||
// HINT: texture faces order: {east, west, bottom, top, south, north}
|
||||
|
||||
/* AABB blocks render method */
|
||||
/// @brief AABB blocks render method
|
||||
void BlocksRenderer::blockAABB(
|
||||
const ivec3& icoord,
|
||||
const UVRegion(&texfaces)[6],
|
||||
@@ -229,13 +236,11 @@ void BlocksRenderer::blockAABB(
|
||||
if (block->hitboxes.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AABB hitbox = block->hitboxes[0];
|
||||
for (const auto& box : block->hitboxes) {
|
||||
hitbox.a = glm::min(hitbox.a, box.a);
|
||||
hitbox.b = glm::max(hitbox.b, box.b);
|
||||
}
|
||||
|
||||
vec3 size = hitbox.size();
|
||||
vec3 X(1, 0, 0);
|
||||
vec3 Y(0, 1, 0);
|
||||
@@ -249,7 +254,6 @@ void BlocksRenderer::blockAABB(
|
||||
Z = orient.axisZ;
|
||||
orient.transform(hitbox);
|
||||
}
|
||||
|
||||
coord = vec3(icoord) - vec3(0.5f) + hitbox.center();
|
||||
|
||||
face(coord, X*size.x, Y*size.y, Z*size.z, texfaces[5], lights); // north
|
||||
@@ -262,8 +266,9 @@ void BlocksRenderer::blockAABB(
|
||||
face(coord, Z*size.z, Y*size.y, -X*size.x, texfaces[0], lights); // east
|
||||
}
|
||||
|
||||
void BlocksRenderer::blockCustomModel(const ivec3& icoord,
|
||||
const Block* block, ubyte rotation, bool lights) {
|
||||
void BlocksRenderer::blockCustomModel(
|
||||
const ivec3& icoord, const Block* block, ubyte rotation, bool lights
|
||||
) {
|
||||
vec3 X(1, 0, 0);
|
||||
vec3 Y(0, 1, 0);
|
||||
vec3 Z(0, 0, 1);
|
||||
@@ -350,8 +355,9 @@ bool BlocksRenderer::isOpen(int x, int y, int z, ubyte group) const {
|
||||
blockid_t id = voxelsBuffer->pickBlockId(chunk->x * CHUNK_W + x,
|
||||
y,
|
||||
chunk->z * CHUNK_D + z);
|
||||
if (id == BLOCK_VOID)
|
||||
if (id == BLOCK_VOID) {
|
||||
return false;
|
||||
}
|
||||
const Block& block = *blockDefsCache[id];
|
||||
if ((block.drawGroup != group && block.lightPassing) || !block.rt.solid) {
|
||||
return true;
|
||||
@@ -363,8 +369,9 @@ bool BlocksRenderer::isOpenForLight(int x, int y, int z) const {
|
||||
blockid_t id = voxelsBuffer->pickBlockId(chunk->x * CHUNK_W + x,
|
||||
y,
|
||||
chunk->z * CHUNK_D + z);
|
||||
if (id == BLOCK_VOID)
|
||||
if (id == BLOCK_VOID) {
|
||||
return false;
|
||||
}
|
||||
const Block& block = *blockDefsCache[id];
|
||||
if (block.lightPassing) {
|
||||
return true;
|
||||
@@ -374,15 +381,13 @@ bool BlocksRenderer::isOpenForLight(int x, int y, int z) const {
|
||||
|
||||
vec4 BlocksRenderer::pickLight(int x, int y, int z) const {
|
||||
if (isOpenForLight(x, y, z)) {
|
||||
light_t light = voxelsBuffer->pickLight(chunk->x * CHUNK_W + x,
|
||||
y,
|
||||
light_t light = voxelsBuffer->pickLight(chunk->x * CHUNK_W + x, y,
|
||||
chunk->z * CHUNK_D + z);
|
||||
return vec4(Lightmap::extract(light, 0) / 15.0f,
|
||||
Lightmap::extract(light, 1) / 15.0f,
|
||||
Lightmap::extract(light, 2) / 15.0f,
|
||||
Lightmap::extract(light, 3) / 15.0f);
|
||||
}
|
||||
else {
|
||||
Lightmap::extract(light, 1) / 15.0f,
|
||||
Lightmap::extract(light, 2) / 15.0f,
|
||||
Lightmap::extract(light, 3) / 15.0f);
|
||||
} else {
|
||||
return vec4(0.0f);
|
||||
}
|
||||
}
|
||||
@@ -394,17 +399,20 @@ vec4 BlocksRenderer::pickLight(const ivec3& coord) const {
|
||||
vec4 BlocksRenderer::pickSoftLight(const ivec3& coord,
|
||||
const ivec3& right,
|
||||
const ivec3& up) const {
|
||||
return (
|
||||
pickLight(coord) +
|
||||
pickLight(coord - right) +
|
||||
pickLight(coord - right - up) +
|
||||
pickLight(coord - up)) * 0.25f;
|
||||
return (pickLight(coord) +
|
||||
pickLight(coord - right) +
|
||||
pickLight(coord - right - up) +
|
||||
pickLight(coord - up)) * 0.25f;
|
||||
}
|
||||
|
||||
vec4 BlocksRenderer::pickSoftLight(float x, float y, float z,
|
||||
const ivec3& right,
|
||||
const ivec3& up) const {
|
||||
return pickSoftLight({int(round(x)), int(round(y)), int(round(z))}, right, up);
|
||||
const ivec3& right,
|
||||
const ivec3& up) const {
|
||||
return pickSoftLight({
|
||||
static_cast<int>(round(x)),
|
||||
static_cast<int>(round(y)),
|
||||
static_cast<int>(round(z))},
|
||||
right, up);
|
||||
}
|
||||
|
||||
void BlocksRenderer::render(const voxel* voxels) {
|
||||
@@ -414,48 +422,55 @@ void BlocksRenderer::render(const voxel* voxels) {
|
||||
for (int i = begin; i < end; i++) {
|
||||
const voxel& vox = voxels[i];
|
||||
blockid_t id = vox.id;
|
||||
blockstate state = vox.state;
|
||||
const Block& def = *blockDefsCache[id];
|
||||
if (id == 0 || def.drawGroup != drawGroup)
|
||||
if (id == 0 || def.drawGroup != drawGroup || state.segment) {
|
||||
continue;
|
||||
const UVRegion texfaces[6]{ cache->getRegion(id, 0),
|
||||
cache->getRegion(id, 1),
|
||||
cache->getRegion(id, 2),
|
||||
cache->getRegion(id, 3),
|
||||
cache->getRegion(id, 4),
|
||||
cache->getRegion(id, 5)};
|
||||
}
|
||||
const UVRegion texfaces[6] {
|
||||
cache->getRegion(id, 0),
|
||||
cache->getRegion(id, 1),
|
||||
cache->getRegion(id, 2),
|
||||
cache->getRegion(id, 3),
|
||||
cache->getRegion(id, 4),
|
||||
cache->getRegion(id, 5)
|
||||
};
|
||||
int x = i % CHUNK_W;
|
||||
int y = i / (CHUNK_D * CHUNK_W);
|
||||
int z = (i / CHUNK_D) % CHUNK_W;
|
||||
switch (def.model) {
|
||||
case BlockModel::block:
|
||||
blockCube(x, y, z, texfaces, &def, vox.state, !def.rt.emissive);
|
||||
break;
|
||||
case BlockModel::xsprite: {
|
||||
blockXSprite(x, y, z, vec3(1.0f),
|
||||
texfaces[FACE_MX], texfaces[FACE_MZ], 1.0f);
|
||||
break;
|
||||
case BlockModel::block:
|
||||
blockCube(x, y, z, texfaces, &def, vox.state, !def.rt.emissive);
|
||||
break;
|
||||
case BlockModel::xsprite: {
|
||||
blockXSprite(x, y, z, vec3(1.0f),
|
||||
texfaces[FACE_MX], texfaces[FACE_MZ], 1.0f);
|
||||
break;
|
||||
}
|
||||
case BlockModel::aabb: {
|
||||
blockAABB(ivec3(x,y,z), texfaces, &def, vox.state.rotation, !def.rt.emissive);
|
||||
break;
|
||||
}
|
||||
case BlockModel::custom: {
|
||||
blockCustomModel(ivec3(x, y, z), &def, vox.state.rotation, !def.rt.emissive);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case BlockModel::aabb: {
|
||||
blockAABB(ivec3(x,y,z), texfaces, &def, vox.state.rotation, !def.rt.emissive);
|
||||
break;
|
||||
}
|
||||
case BlockModel::custom: {
|
||||
blockCustomModel(ivec3(x, y, z), &def, vox.state.rotation, !def.rt.emissive);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (overflow)
|
||||
if (overflow) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BlocksRenderer::build(const Chunk* chunk, const ChunksStorage* chunks) {
|
||||
this->chunk = chunk;
|
||||
voxelsBuffer->setPosition(chunk->x * CHUNK_W - 1, 0, chunk->z * CHUNK_D - 1);
|
||||
chunks->getVoxels(voxelsBuffer, settings->graphics.backlight.get());
|
||||
voxelsBuffer->setPosition(
|
||||
chunk->x * CHUNK_W - voxelBufferPadding, 0,
|
||||
chunk->z * CHUNK_D - voxelBufferPadding);
|
||||
chunks->getVoxels(voxelsBuffer.get(), settings->graphics.backlight.get());
|
||||
overflow = false;
|
||||
vertexOffset = 0;
|
||||
indexOffset = indexSize = 0;
|
||||
@@ -466,7 +481,9 @@ void BlocksRenderer::build(const Chunk* chunk, const ChunksStorage* chunks) {
|
||||
std::shared_ptr<Mesh> BlocksRenderer::createMesh() {
|
||||
const vattr attrs[]{ {3}, {2}, {1}, {0} };
|
||||
size_t vcount = vertexOffset / BlocksRenderer::VERTEX_SIZE;
|
||||
return std::make_shared<Mesh>(vertexBuffer, vcount, indexBuffer, indexSize, attrs);
|
||||
return std::make_shared<Mesh>(
|
||||
vertexBuffer.get(), vcount, indexBuffer.get(), indexSize, attrs
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<Mesh> BlocksRenderer::render(const Chunk* chunk, const ChunksStorage* chunks) {
|
||||
@@ -475,5 +492,5 @@ std::shared_ptr<Mesh> BlocksRenderer::render(const Chunk* chunk, const ChunksSto
|
||||
}
|
||||
|
||||
VoxelsVolume* BlocksRenderer::getVoxelsBuffer() const {
|
||||
return voxelsBuffer;
|
||||
return voxelsBuffer.get();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <glm/glm.hpp>
|
||||
#include "../../voxels/voxel.hpp"
|
||||
#include "../../typedefs.hpp"
|
||||
@@ -22,16 +23,15 @@ class BlocksRenderer {
|
||||
static const glm::vec3 SUN_VECTOR;
|
||||
static const uint VERTEX_SIZE;
|
||||
const Content* const content;
|
||||
float* vertexBuffer;
|
||||
int* indexBuffer;
|
||||
std::unique_ptr<float[]> vertexBuffer;
|
||||
std::unique_ptr<int[]> indexBuffer;
|
||||
size_t vertexOffset;
|
||||
size_t indexOffset, indexSize;
|
||||
size_t capacity;
|
||||
|
||||
int voxelBufferPadding = 2;
|
||||
bool overflow = false;
|
||||
|
||||
const Chunk* chunk = nullptr;
|
||||
VoxelsVolume* voxelsBuffer;
|
||||
std::unique_ptr<VoxelsVolume> voxelsBuffer;
|
||||
|
||||
const Block* const* blockDefsCache;
|
||||
const ContentGfxCache* const cache;
|
||||
@@ -40,36 +40,41 @@ class BlocksRenderer {
|
||||
void vertex(const glm::vec3& coord, float u, float v, const glm::vec4& light);
|
||||
void index(int a, int b, int c, int d, int e, int f);
|
||||
|
||||
void vertex(const glm::vec3& coord, float u, float v,
|
||||
const glm::vec4& brightness,
|
||||
const glm::vec3& axisX,
|
||||
const glm::vec3& axisY,
|
||||
const glm::vec3& axisZ);
|
||||
|
||||
void face(const glm::vec3& coord, float w, float h, float d,
|
||||
void vertex(
|
||||
const glm::vec3& coord, float u, float v,
|
||||
const glm::vec4& brightness,
|
||||
const glm::vec3& axisX,
|
||||
const glm::vec3& axisY,
|
||||
const glm::vec3& axisZ
|
||||
);
|
||||
void face(
|
||||
const glm::vec3& coord,
|
||||
float w, float h, float d,
|
||||
const glm::vec3& axisX,
|
||||
const glm::vec3& axisY,
|
||||
const glm::vec3& axisZ,
|
||||
const UVRegion& region,
|
||||
const glm::vec4(&lights)[4],
|
||||
const glm::vec4& tint);
|
||||
|
||||
void face(const glm::vec3& coord,
|
||||
const glm::vec4& tint
|
||||
);
|
||||
void face(
|
||||
const glm::vec3& coord,
|
||||
const glm::vec3& axisX,
|
||||
const glm::vec3& axisY,
|
||||
const glm::vec3& axisZ,
|
||||
const UVRegion& region,
|
||||
bool lights);
|
||||
|
||||
void tetragonicFace(const glm::vec3& coord,
|
||||
bool lights
|
||||
);
|
||||
void tetragonicFace(
|
||||
const glm::vec3& coord,
|
||||
const glm::vec3& p1, const glm::vec3& p2,
|
||||
const glm::vec3& p3, const glm::vec3& p4,
|
||||
const glm::vec3& X,
|
||||
const glm::vec3& Y,
|
||||
const glm::vec3& Z,
|
||||
const UVRegion& texreg,
|
||||
bool lights);
|
||||
|
||||
bool lights
|
||||
);
|
||||
void blockCube(
|
||||
int x, int y, int z,
|
||||
const UVRegion(&faces)[6],
|
||||
|
||||
@@ -55,7 +55,7 @@ ChunksRenderer::ChunksRenderer(
|
||||
ChunksRenderer::~ChunksRenderer() {
|
||||
}
|
||||
|
||||
std::shared_ptr<Mesh> ChunksRenderer::render(std::shared_ptr<Chunk> chunk, bool important) {
|
||||
std::shared_ptr<Mesh> ChunksRenderer::render(const std::shared_ptr<Chunk>& chunk, bool important) {
|
||||
chunk->flags.modified = false;
|
||||
if (important) {
|
||||
auto mesh = renderer->render(chunk.get(), level->chunksStorage.get());
|
||||
@@ -78,7 +78,7 @@ void ChunksRenderer::unload(const Chunk* chunk) {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Mesh> ChunksRenderer::getOrRender(std::shared_ptr<Chunk> chunk, bool important) {
|
||||
std::shared_ptr<Mesh> ChunksRenderer::getOrRender(const std::shared_ptr<Chunk>& chunk, bool important) {
|
||||
auto found = meshes.find(glm::ivec2(chunk->x, chunk->z));
|
||||
if (found == meshes.end()) {
|
||||
return render(chunk, important);
|
||||
|
||||
@@ -38,10 +38,10 @@ public:
|
||||
);
|
||||
virtual ~ChunksRenderer();
|
||||
|
||||
std::shared_ptr<Mesh> render(std::shared_ptr<Chunk> chunk, bool important);
|
||||
std::shared_ptr<Mesh> render(const std::shared_ptr<Chunk>& chunk, bool important);
|
||||
void unload(const Chunk* chunk);
|
||||
|
||||
std::shared_ptr<Mesh> getOrRender(std::shared_ptr<Chunk> chunk, bool important);
|
||||
std::shared_ptr<Mesh> getOrRender(const std::shared_ptr<Chunk>& chunk, bool important);
|
||||
std::shared_ptr<Mesh> get(Chunk* chunk);
|
||||
|
||||
void update();
|
||||
|
||||
@@ -195,15 +195,16 @@ void WorldRenderer::renderLevel(
|
||||
}
|
||||
|
||||
void WorldRenderer::renderBlockSelection(Camera* camera, Shader* linesShader) {
|
||||
const auto& selection = player->selection;
|
||||
auto indices = level->content->getIndices();
|
||||
blockid_t id = PlayerController::selectedBlockId;
|
||||
blockid_t id = selection.vox.id;
|
||||
auto block = indices->getBlockDef(id);
|
||||
const glm::ivec3 pos = player->selectedBlockPosition;
|
||||
const glm::vec3 point = PlayerController::selectedPointPosition;
|
||||
const glm::vec3 norm = PlayerController::selectedBlockNormal;
|
||||
const glm::ivec3 pos = player->selection.position;
|
||||
const glm::vec3 point = selection.hitPosition;
|
||||
const glm::vec3 norm = selection.normal;
|
||||
|
||||
const std::vector<AABB>& hitboxes = block->rotatable
|
||||
? block->rt.hitboxes[PlayerController::selectedBlockRotation]
|
||||
? block->rt.hitboxes[selection.vox.state.rotation]
|
||||
: block->hitboxes;
|
||||
|
||||
linesShader->use();
|
||||
@@ -305,7 +306,7 @@ void WorldRenderer::draw(
|
||||
ctx.setCullFace(true);
|
||||
renderLevel(ctx, camera, settings);
|
||||
// Selected block
|
||||
if (PlayerController::selectedBlockId != -1 && hudVisible){
|
||||
if (player->selection.vox.id != BLOCK_VOID && hudVisible){
|
||||
renderBlockSelection(camera, linesShader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -221,18 +222,18 @@ bool GUI::isFocusCaught() const {
|
||||
}
|
||||
|
||||
void GUI::add(std::shared_ptr<UINode> node) {
|
||||
container->add(node);
|
||||
container->add(std::move(node));
|
||||
}
|
||||
|
||||
void GUI::remove(std::shared_ptr<UINode> node) noexcept {
|
||||
container->remove(node);
|
||||
container->remove(std::move(node));
|
||||
}
|
||||
|
||||
void GUI::store(std::string name, std::shared_ptr<UINode> node) {
|
||||
storage[name] = node;
|
||||
void GUI::store(const std::string& name, std::shared_ptr<UINode> node) {
|
||||
storage[name] = std::move(node);
|
||||
}
|
||||
|
||||
std::shared_ptr<UINode> GUI::get(std::string name) noexcept {
|
||||
std::shared_ptr<UINode> GUI::get(const std::string& name) noexcept {
|
||||
auto found = storage.find(name);
|
||||
if (found == storage.end()) {
|
||||
return nullptr;
|
||||
@@ -240,7 +241,7 @@ std::shared_ptr<UINode> GUI::get(std::string name) noexcept {
|
||||
return found->second;
|
||||
}
|
||||
|
||||
void GUI::remove(std::string name) noexcept {
|
||||
void GUI::remove(const std::string& name) noexcept {
|
||||
storage.erase(name);
|
||||
}
|
||||
|
||||
@@ -248,7 +249,7 @@ void GUI::setFocus(std::shared_ptr<UINode> node) {
|
||||
if (focus) {
|
||||
focus->defocus();
|
||||
}
|
||||
focus = node;
|
||||
focus = std::move(node);
|
||||
if (focus) {
|
||||
focus->onFocus(this);
|
||||
}
|
||||
@@ -258,7 +259,7 @@ std::shared_ptr<Container> GUI::getContainer() const {
|
||||
return container;
|
||||
}
|
||||
|
||||
void GUI::postRunnable(runnable callback) {
|
||||
void GUI::postRunnable(const runnable& callback) {
|
||||
postRunnables.push(callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,16 +108,16 @@ namespace gui {
|
||||
/// (does not add node to the main container)
|
||||
/// @param name node key
|
||||
/// @param node target node
|
||||
void store(std::string name, std::shared_ptr<UINode> node);
|
||||
void store(const std::string& name, std::shared_ptr<UINode> node);
|
||||
|
||||
/// @brief Get node from the GUI nodes dictionary
|
||||
/// @param name node key
|
||||
/// @return stored node or nullptr
|
||||
std::shared_ptr<UINode> get(std::string name) noexcept;
|
||||
std::shared_ptr<UINode> get(const std::string& name) noexcept;
|
||||
|
||||
/// @brief Remove node from the GUI nodes dictionary
|
||||
/// @param name node key
|
||||
void remove(std::string name) noexcept;
|
||||
void remove(const std::string& name) noexcept;
|
||||
|
||||
/// @brief Set node as focused
|
||||
/// @param node new focused node or nullptr to remove focus
|
||||
@@ -129,7 +129,7 @@ namespace gui {
|
||||
|
||||
void onAssetsLoad(Assets* assets);
|
||||
|
||||
void postRunnable(runnable callback);
|
||||
void postRunnable(const runnable& callback);
|
||||
|
||||
void setDoubleClickDelay(float delay);
|
||||
float getDoubleClickDelay() const;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
#include "Button.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Label.hpp"
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
|
||||
using namespace gui;
|
||||
|
||||
Button::Button(std::shared_ptr<UINode> content, glm::vec4 padding)
|
||||
Button::Button(const std::shared_ptr<UINode>& content, glm::vec4 padding)
|
||||
: Panel(glm::vec2(), padding, 0) {
|
||||
glm::vec4 margin = getMargin();
|
||||
setSize(content->getSize()+
|
||||
@@ -20,9 +22,9 @@ Button::Button(std::shared_ptr<UINode> content, glm::vec4 padding)
|
||||
}
|
||||
|
||||
Button::Button(
|
||||
std::wstring text,
|
||||
const std::wstring& text,
|
||||
glm::vec4 padding,
|
||||
onaction action,
|
||||
const onaction& action,
|
||||
glm::vec2 size
|
||||
) : Panel(size, padding, 0)
|
||||
{
|
||||
@@ -63,7 +65,7 @@ std::wstring Button::getText() const {
|
||||
|
||||
Button* Button::textSupplier(wstringsupplier supplier) {
|
||||
if (label) {
|
||||
label->textSupplier(supplier);
|
||||
label->textSupplier(std::move(supplier));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ namespace gui {
|
||||
protected:
|
||||
std::shared_ptr<Label> label = nullptr;
|
||||
public:
|
||||
Button(std::shared_ptr<UINode> content,
|
||||
Button(const std::shared_ptr<UINode>& content,
|
||||
glm::vec4 padding=glm::vec4(2.0f));
|
||||
|
||||
Button(std::wstring text,
|
||||
Button(const std::wstring& text,
|
||||
glm::vec4 padding,
|
||||
onaction action,
|
||||
const onaction& action,
|
||||
glm::vec2 size=glm::vec2(-1));
|
||||
|
||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets) override;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "CheckBox.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
#include "Label.hpp"
|
||||
@@ -30,11 +32,11 @@ void CheckBox::mouseRelease(GUI*, int, int) {
|
||||
}
|
||||
|
||||
void CheckBox::setSupplier(boolsupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
this->supplier = std::move(supplier);
|
||||
}
|
||||
|
||||
void CheckBox::setConsumer(boolconsumer consumer) {
|
||||
this->consumer = consumer;
|
||||
this->consumer = std::move(consumer);
|
||||
}
|
||||
|
||||
CheckBox* CheckBox::setChecked(bool flag) {
|
||||
@@ -42,7 +44,7 @@ CheckBox* CheckBox::setChecked(bool flag) {
|
||||
return this;
|
||||
}
|
||||
|
||||
FullCheckBox::FullCheckBox(std::wstring text, glm::vec2 size, bool checked)
|
||||
FullCheckBox::FullCheckBox(const std::wstring& text, glm::vec2 size, bool checked)
|
||||
: Panel(size),
|
||||
checkbox(std::make_shared<CheckBox>(checked)){
|
||||
setColor(glm::vec4(0.0f));
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef GRAPHICS_UI_ELEMENTS_CHECKBOX_HPP_
|
||||
#define GRAPHICS_UI_ELEMENTS_CHECKBOX_HPP_
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Panel.hpp"
|
||||
|
||||
namespace gui {
|
||||
@@ -33,14 +35,14 @@ namespace gui {
|
||||
protected:
|
||||
std::shared_ptr<CheckBox> checkbox;
|
||||
public:
|
||||
FullCheckBox(std::wstring text, glm::vec2 size, bool checked=false);
|
||||
FullCheckBox(const std::wstring& text, glm::vec2 size, bool checked=false);
|
||||
|
||||
virtual void setSupplier(boolsupplier supplier) {
|
||||
checkbox->setSupplier(supplier);
|
||||
checkbox->setSupplier(std::move(supplier));
|
||||
}
|
||||
|
||||
virtual void setConsumer(boolconsumer consumer) {
|
||||
checkbox->setConsumer(consumer);
|
||||
checkbox->setConsumer(std::move(consumer));
|
||||
}
|
||||
|
||||
virtual void setChecked(bool flag) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../../core/Batch2D.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -12,6 +13,10 @@ Container::Container(glm::vec2 size) : UINode(size) {
|
||||
setColor(glm::vec4());
|
||||
}
|
||||
|
||||
Container::~Container() {
|
||||
Container::clear();
|
||||
}
|
||||
|
||||
std::shared_ptr<UINode> Container::getAt(glm::vec2 pos, std::shared_ptr<UINode> self) {
|
||||
if (!isInteractive() || !isEnabled()) {
|
||||
return nullptr;
|
||||
@@ -31,7 +36,7 @@ std::shared_ptr<UINode> Container::getAt(glm::vec2 pos, std::shared_ptr<UINode>
|
||||
}
|
||||
|
||||
void Container::act(float delta) {
|
||||
for (auto node : nodes) {
|
||||
for (const auto& node : nodes) {
|
||||
if (node->isVisible()) {
|
||||
node->act(delta);
|
||||
}
|
||||
@@ -86,7 +91,7 @@ void Container::draw(const DrawContext* pctx, Assets* assets) {
|
||||
{
|
||||
DrawContext ctx = pctx->sub();
|
||||
ctx.setScissors(glm::vec4(pos.x, pos.y, size.x, size.y));
|
||||
for (auto node : nodes) {
|
||||
for (const auto& node : nodes) {
|
||||
if (node->isVisible())
|
||||
node->draw(pctx, assets);
|
||||
}
|
||||
@@ -105,22 +110,22 @@ void Container::drawBackground(const DrawContext* pctx, Assets*) {
|
||||
batch->rect(pos.x, pos.y, size.x, size.y);
|
||||
}
|
||||
|
||||
void Container::add(std::shared_ptr<UINode> node) {
|
||||
void Container::add(const std::shared_ptr<UINode> &node) {
|
||||
nodes.push_back(node);
|
||||
node->setParent(this);
|
||||
node->reposition();
|
||||
refresh();
|
||||
}
|
||||
|
||||
void Container::add(std::shared_ptr<UINode> node, glm::vec2 pos) {
|
||||
void Container::add(const std::shared_ptr<UINode>& node, glm::vec2 pos) {
|
||||
node->setPos(pos);
|
||||
add(node);
|
||||
}
|
||||
|
||||
void Container::remove(std::shared_ptr<UINode> selected) {
|
||||
void Container::remove(const std::shared_ptr<UINode>& selected) {
|
||||
selected->setParent(nullptr);
|
||||
nodes.erase(std::remove_if(nodes.begin(), nodes.end(),
|
||||
[selected](const std::shared_ptr<UINode> node) {
|
||||
[selected](const std::shared_ptr<UINode>& node) {
|
||||
return node == selected;
|
||||
}
|
||||
), nodes.end());
|
||||
@@ -136,7 +141,7 @@ void Container::remove(const std::string& id) {
|
||||
}
|
||||
|
||||
void Container::clear() {
|
||||
for (auto node : nodes) {
|
||||
for (const auto& node : nodes) {
|
||||
node->setParent(nullptr);
|
||||
}
|
||||
nodes.clear();
|
||||
@@ -144,7 +149,7 @@ void Container::clear() {
|
||||
}
|
||||
|
||||
void Container::listenInterval(float interval, ontimeout callback, int repeat) {
|
||||
intervalEvents.push_back({callback, interval, 0.0f, repeat});
|
||||
intervalEvents.push_back({std::move(callback), interval, 0.0f, repeat});
|
||||
}
|
||||
|
||||
void Container::setSize(glm::vec2 size) {
|
||||
|
||||
@@ -17,15 +17,16 @@ namespace gui {
|
||||
bool scrollable = true;
|
||||
public:
|
||||
Container(glm::vec2 size);
|
||||
virtual ~Container();
|
||||
|
||||
virtual void act(float delta) override;
|
||||
virtual void drawBackground(const DrawContext* pctx, Assets* assets);
|
||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||
virtual void add(std::shared_ptr<UINode> node);
|
||||
virtual void add(std::shared_ptr<UINode> node, glm::vec2 pos);
|
||||
virtual void add(const std::shared_ptr<UINode> &node);
|
||||
virtual void add(const std::shared_ptr<UINode> &node, glm::vec2 pos);
|
||||
virtual void clear();
|
||||
virtual void remove(std::shared_ptr<UINode> node);
|
||||
virtual void remove(const std::shared_ptr<UINode>& node);
|
||||
virtual void remove(const std::string& id);
|
||||
virtual void scrolled(int value) override;
|
||||
virtual void setScrollable(bool flag);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "Image.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
#include "../../core/Texture.hpp"
|
||||
@@ -8,7 +10,7 @@
|
||||
|
||||
using namespace gui;
|
||||
|
||||
Image::Image(std::string texture, glm::vec2 size) : UINode(size), texture(texture) {
|
||||
Image::Image(std::string texture, glm::vec2 size) : UINode(size), texture(std::move(texture)) {
|
||||
setInteractive(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "../GUI.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -40,9 +41,9 @@ SlotLayout::SlotLayout(
|
||||
position(position),
|
||||
background(background),
|
||||
itemSource(itemSource),
|
||||
updateFunc(updateFunc),
|
||||
shareFunc(shareFunc),
|
||||
rightClick(rightClick) {}
|
||||
updateFunc(std::move(updateFunc)),
|
||||
shareFunc(std::move(shareFunc)),
|
||||
rightClick(std::move(rightClick)) {}
|
||||
|
||||
InventoryBuilder::InventoryBuilder() {
|
||||
view = std::make_shared<InventoryView>();
|
||||
@@ -53,7 +54,7 @@ void InventoryBuilder::addGrid(
|
||||
glm::vec2 pos,
|
||||
int padding,
|
||||
bool addpanel,
|
||||
SlotLayout slotLayout
|
||||
const SlotLayout& slotLayout
|
||||
) {
|
||||
const int slotSize = InventoryView::SLOT_SIZE;
|
||||
const int interval = InventoryView::SLOT_INTERVAL;
|
||||
@@ -95,7 +96,7 @@ void InventoryBuilder::addGrid(
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryBuilder::add(SlotLayout layout) {
|
||||
void InventoryBuilder::add(const SlotLayout& layout) {
|
||||
view->add(view->addSlot(layout), layout.position);
|
||||
}
|
||||
|
||||
@@ -106,15 +107,28 @@ std::shared_ptr<InventoryView> InventoryBuilder::build() {
|
||||
SlotView::SlotView(
|
||||
SlotLayout layout
|
||||
) : UINode(glm::vec2(InventoryView::SLOT_SIZE)),
|
||||
layout(layout)
|
||||
layout(std::move(layout))
|
||||
{
|
||||
setColor(glm::vec4(0, 0, 0, 0.2f));
|
||||
setTooltipDelay(0.05f);
|
||||
}
|
||||
|
||||
void SlotView::draw(const DrawContext* pctx, Assets* assets) {
|
||||
if (bound == nullptr)
|
||||
if (bound == nullptr) {
|
||||
return;
|
||||
}
|
||||
itemid_t itemid = bound->getItemId();
|
||||
if (itemid != prevItem) {
|
||||
if (itemid) {
|
||||
auto def = content->getIndices()->getItemDef(itemid);
|
||||
tooltip = util::pascal_case(
|
||||
langs::get(util::str2wstr_utf8(def->caption))
|
||||
);
|
||||
} else {
|
||||
tooltip = L"";
|
||||
}
|
||||
}
|
||||
prevItem = itemid;
|
||||
|
||||
const int slotSize = InventoryView::SLOT_SIZE;
|
||||
|
||||
@@ -273,15 +287,12 @@ void SlotView::onFocus(gui::GUI* gui) {
|
||||
clicked(gui, mousecode::BUTTON_1);
|
||||
}
|
||||
|
||||
const std::wstring SlotView::getTooltip() const {
|
||||
const auto str = UINode::getTooltip();
|
||||
if (!str.empty() || bound->isEmpty()) {
|
||||
const std::wstring& SlotView::getTooltip() const {
|
||||
const auto& str = UINode::getTooltip();
|
||||
if (!str.empty() || tooltip.empty()) {
|
||||
return str;
|
||||
}
|
||||
auto def = content->getIndices()->getItemDef(bound->getItemId());
|
||||
return util::pascal_case(
|
||||
langs::get(util::str2wstr_utf8(def->caption))
|
||||
); // TODO: cache
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
void SlotView::bind(
|
||||
@@ -309,7 +320,7 @@ InventoryView::InventoryView() : Container(glm::vec2()) {
|
||||
InventoryView::~InventoryView() {}
|
||||
|
||||
|
||||
std::shared_ptr<SlotView> InventoryView::addSlot(SlotLayout layout) {
|
||||
std::shared_ptr<SlotView> InventoryView::addSlot(const SlotLayout& layout) {
|
||||
uint width = InventoryView::SLOT_SIZE + layout.padding;
|
||||
uint height = InventoryView::SLOT_SIZE + layout.padding;
|
||||
|
||||
@@ -341,7 +352,7 @@ size_t InventoryView::getSlotsCount() const {
|
||||
}
|
||||
|
||||
void InventoryView::bind(
|
||||
std::shared_ptr<Inventory> inventory,
|
||||
const std::shared_ptr<Inventory>& inventory,
|
||||
const Content* content
|
||||
) {
|
||||
this->inventory = inventory;
|
||||
|
||||
@@ -53,6 +53,9 @@ namespace gui {
|
||||
|
||||
int64_t inventoryid = 0;
|
||||
ItemStack* bound = nullptr;
|
||||
|
||||
std::wstring tooltip;
|
||||
itemid_t prevItem = 0;
|
||||
public:
|
||||
SlotView(SlotLayout layout);
|
||||
|
||||
@@ -63,7 +66,7 @@ namespace gui {
|
||||
|
||||
virtual void clicked(gui::GUI*, mousecode) override;
|
||||
virtual void onFocus(gui::GUI*) override;
|
||||
virtual const std::wstring getTooltip() const override;
|
||||
virtual const std::wstring& getTooltip() const override;
|
||||
|
||||
void bind(
|
||||
int64_t inventoryid,
|
||||
@@ -96,13 +99,13 @@ namespace gui {
|
||||
void setSelected(int index);
|
||||
|
||||
void bind(
|
||||
std::shared_ptr<Inventory> inventory,
|
||||
const std::shared_ptr<Inventory>& inventory,
|
||||
const Content* content
|
||||
);
|
||||
|
||||
void unbind();
|
||||
|
||||
std::shared_ptr<SlotView> addSlot(SlotLayout layout);
|
||||
std::shared_ptr<SlotView> addSlot(const SlotLayout& layout);
|
||||
|
||||
std::shared_ptr<Inventory> getInventory() const;
|
||||
|
||||
@@ -130,10 +133,10 @@ namespace gui {
|
||||
glm::vec2 pos,
|
||||
int padding,
|
||||
bool addpanel,
|
||||
SlotLayout slotLayout
|
||||
const SlotLayout& slotLayout
|
||||
);
|
||||
|
||||
void add(SlotLayout slotLayout);
|
||||
void add(const SlotLayout& slotLayout);
|
||||
std::shared_ptr<InventoryView> build();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "Label.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
#include "../../core/Font.hpp"
|
||||
@@ -45,20 +47,20 @@ void LabelCache::update(const std::wstring& text, bool multiline, bool wrap) {
|
||||
}
|
||||
}
|
||||
|
||||
Label::Label(std::string text, std::string fontName)
|
||||
Label::Label(const std::string& text, std::string fontName)
|
||||
: UINode(glm::vec2(text.length() * 8, 15)),
|
||||
text(util::str2wstr_utf8(text)),
|
||||
fontName(fontName)
|
||||
fontName(std::move(fontName))
|
||||
{
|
||||
setInteractive(false);
|
||||
cache.update(this->text, multiline, textWrap);
|
||||
}
|
||||
|
||||
|
||||
Label::Label(std::wstring text, std::string fontName)
|
||||
Label::Label(const std::wstring& text, std::string fontName)
|
||||
: UINode(glm::vec2(text.length() * 8, 15)),
|
||||
text(text),
|
||||
fontName(fontName)
|
||||
fontName(std::move(fontName))
|
||||
{
|
||||
setInteractive(false);
|
||||
cache.update(this->text, multiline, textWrap);
|
||||
@@ -76,7 +78,7 @@ glm::vec2 Label::calcSize() {
|
||||
);
|
||||
}
|
||||
|
||||
void Label::setText(std::wstring text) {
|
||||
void Label::setText(const std::wstring& text) {
|
||||
if (text == this->text && !cache.resetFlag) {
|
||||
return;
|
||||
}
|
||||
@@ -93,7 +95,7 @@ const std::wstring& Label::getText() const {
|
||||
}
|
||||
|
||||
void Label::setFontName(std::string name) {
|
||||
this->fontName = name;
|
||||
this->fontName = std::move(name);
|
||||
}
|
||||
|
||||
const std::string& Label::getFontName() const {
|
||||
@@ -207,7 +209,7 @@ void Label::draw(const DrawContext* pctx, Assets* assets) {
|
||||
}
|
||||
|
||||
void Label::textSupplier(wstringsupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
this->supplier = std::move(supplier);
|
||||
}
|
||||
|
||||
void Label::setAutoResize(bool flag) {
|
||||
|
||||
@@ -53,10 +53,10 @@ namespace gui {
|
||||
/// @brief Auto resize label to fit text
|
||||
bool autoresize = false;
|
||||
public:
|
||||
Label(std::string text, std::string fontName="normal");
|
||||
Label(std::wstring text, std::string fontName="normal");
|
||||
Label(const std::string& text, std::string fontName="normal");
|
||||
Label(const std::wstring& text, std::string fontName="normal");
|
||||
|
||||
virtual void setText(std::wstring text);
|
||||
virtual void setText(const std::wstring& text);
|
||||
const std::wstring& getText() const;
|
||||
|
||||
virtual void setFontName(std::string name);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Menu.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -12,11 +13,11 @@ bool Menu::has(const std::string& name) {
|
||||
pageSuppliers.find(name) != pageSuppliers.end();
|
||||
}
|
||||
|
||||
void Menu::addPage(std::string name, std::shared_ptr<UINode> panel) {
|
||||
void Menu::addPage(const std::string& name, const std::shared_ptr<UINode> &panel) {
|
||||
pages[name] = Page{name, panel};
|
||||
}
|
||||
|
||||
void Menu::addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier) {
|
||||
void Menu::addSupplier(const std::string &name, const supplier<std::shared_ptr<UINode>> &pageSupplier) {
|
||||
pageSuppliers[name] = pageSupplier;
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ std::shared_ptr<UINode> Menu::fetchPage(const std::string& name) {
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::setPage(std::string name, bool history) {
|
||||
void Menu::setPage(const std::string &name, bool history) {
|
||||
Page page {name, fetchPage(name)};
|
||||
if (page.panel == nullptr) {
|
||||
throw std::runtime_error("no page found");
|
||||
@@ -53,7 +54,7 @@ void Menu::setPage(Page page, bool history) {
|
||||
pageStack.push(current);
|
||||
}
|
||||
}
|
||||
current = page;
|
||||
current = std::move(page);
|
||||
Container::add(current.panel);
|
||||
setSize(current.panel->getSize());
|
||||
}
|
||||
@@ -73,7 +74,7 @@ void Menu::back() {
|
||||
}
|
||||
|
||||
void Menu::setPageLoader(page_loader_func loader) {
|
||||
pagesLoader = loader;
|
||||
pagesLoader = std::move(loader);
|
||||
}
|
||||
|
||||
Page& Menu::getCurrent() {
|
||||
|
||||
@@ -30,15 +30,15 @@ namespace gui {
|
||||
/// @brief Set current page to specified one.
|
||||
/// @param name page or page supplier name
|
||||
/// @param history previous page will not be saved in history if false
|
||||
void setPage(std::string name, bool history=true);
|
||||
void setPage(const std::string &name, bool history=true);
|
||||
void setPage(Page page, bool history=true);
|
||||
void addPage(std::string name, std::shared_ptr<UINode> panel);
|
||||
void addPage(const std::string& name, const std::shared_ptr<UINode> &panel);
|
||||
std::shared_ptr<UINode> fetchPage(const std::string& name);
|
||||
|
||||
/// @brief Add page supplier used if page is not found
|
||||
/// @param name page name
|
||||
/// @param pageSupplier page supplier function
|
||||
void addSupplier(std::string name, supplier<std::shared_ptr<UINode>> pageSupplier);
|
||||
void addSupplier(const std::string &name, const supplier<std::shared_ptr<UINode>> &pageSupplier);
|
||||
|
||||
/// @brief Page loader is called if accessed page is not found
|
||||
void setPageLoader(page_loader_func loader);
|
||||
|
||||
@@ -46,7 +46,7 @@ void Panel::fullRefresh() {
|
||||
Container::fullRefresh();
|
||||
}
|
||||
|
||||
void Panel::add(std::shared_ptr<UINode> node) {
|
||||
void Panel::add(const std::shared_ptr<UINode> &node) {
|
||||
node->setResizing(true);
|
||||
Container::add(node);
|
||||
fullRefresh();
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace gui {
|
||||
virtual void setOrientation(Orientation orientation);
|
||||
Orientation getOrientation() const;
|
||||
|
||||
virtual void add(std::shared_ptr<UINode> node) override;
|
||||
virtual void add(const std::shared_ptr<UINode> &node) override;
|
||||
|
||||
virtual void refresh() override;
|
||||
virtual void fullRefresh() override;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "TextBox.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Label.hpp"
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
@@ -14,7 +17,7 @@ using namespace gui;
|
||||
TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
|
||||
: Panel(glm::vec2(200,32), padding, 0),
|
||||
input(L""),
|
||||
placeholder(placeholder)
|
||||
placeholder(std::move(placeholder))
|
||||
{
|
||||
setOnUpPressed(nullptr);
|
||||
setOnDownPressed(nullptr);
|
||||
@@ -556,7 +559,7 @@ std::shared_ptr<UINode> TextBox::getAt(glm::vec2 pos, std::shared_ptr<UINode> se
|
||||
return UINode::getAt(pos, self);
|
||||
}
|
||||
|
||||
void TextBox::setOnUpPressed(runnable callback) {
|
||||
void TextBox::setOnUpPressed(const runnable &callback) {
|
||||
if (callback == nullptr) {
|
||||
onUpPressed = [this]() {
|
||||
bool shiftPressed = Events::pressed(keycode::LEFT_SHIFT);
|
||||
@@ -568,7 +571,7 @@ void TextBox::setOnUpPressed(runnable callback) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextBox::setOnDownPressed(runnable callback) {
|
||||
void TextBox::setOnDownPressed(const runnable &callback) {
|
||||
if (callback == nullptr) {
|
||||
onDownPressed = [this]() {
|
||||
bool shiftPressed = Events::pressed(keycode::LEFT_SHIFT);
|
||||
@@ -581,15 +584,15 @@ void TextBox::setOnDownPressed(runnable callback) {
|
||||
}
|
||||
|
||||
void TextBox::setTextSupplier(wstringsupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
this->supplier = std::move(supplier);
|
||||
}
|
||||
|
||||
void TextBox::setTextConsumer(wstringconsumer consumer) {
|
||||
this->consumer = consumer;
|
||||
this->consumer = std::move(consumer);
|
||||
}
|
||||
|
||||
void TextBox::setTextValidator(wstringchecker validator) {
|
||||
this->validator = validator;
|
||||
this->validator = std::move(validator);
|
||||
}
|
||||
|
||||
void TextBox::setFocusedColor(glm::vec4 color) {
|
||||
@@ -614,7 +617,7 @@ std::wstring TextBox::getText() const {
|
||||
return input;
|
||||
}
|
||||
|
||||
void TextBox::setText(const std::wstring value) {
|
||||
void TextBox::setText(const std::wstring& value) {
|
||||
this->input = value;
|
||||
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
|
||||
}
|
||||
@@ -637,8 +640,10 @@ size_t TextBox::getCaret() const {
|
||||
|
||||
void TextBox::setCaret(size_t position) {
|
||||
this->caret = std::min(static_cast<size_t>(position), input.length());
|
||||
if (font == nullptr) {
|
||||
return;
|
||||
}
|
||||
caretLastMove = Window::time();
|
||||
|
||||
int width = label->getSize().x;
|
||||
uint line = label->getLineByTextIndex(caret);
|
||||
int offset = label->getLineYOffset(line) + contentOffset().y;
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace gui {
|
||||
virtual std::wstring getText() const;
|
||||
|
||||
/// @brief Set TextBox content text
|
||||
virtual void setText(std::wstring value);
|
||||
virtual void setText(const std::wstring &value);
|
||||
|
||||
/// @brief Get text placeholder
|
||||
virtual std::wstring getPlaceholder() const;
|
||||
@@ -169,8 +169,8 @@ namespace gui {
|
||||
virtual void typed(unsigned int codepoint) override;
|
||||
virtual void keyPressed(keycode key) override;
|
||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self) override;
|
||||
virtual void setOnUpPressed(runnable callback);
|
||||
virtual void setOnDownPressed(runnable callback);
|
||||
virtual void setOnUpPressed(const runnable &callback);
|
||||
virtual void setOnDownPressed(const runnable &callback);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "TrackBar.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../../core/DrawContext.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
#include "../../../assets/Assets.hpp"
|
||||
@@ -41,11 +43,11 @@ void TrackBar::draw(const DrawContext* pctx, Assets*) {
|
||||
}
|
||||
|
||||
void TrackBar::setSupplier(doublesupplier supplier) {
|
||||
this->supplier = supplier;
|
||||
this->supplier = std::move(supplier);
|
||||
}
|
||||
|
||||
void TrackBar::setConsumer(doubleconsumer consumer) {
|
||||
this->consumer = consumer;
|
||||
this->consumer = std::move(consumer);
|
||||
}
|
||||
|
||||
void TrackBar::mouseMove(GUI*, int x, int) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "UINode.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Container.hpp"
|
||||
#include "../../core/Batch2D.hpp"
|
||||
|
||||
@@ -62,12 +64,12 @@ UINode* UINode::getParent() const {
|
||||
return parent;
|
||||
}
|
||||
|
||||
UINode* UINode::listenAction(onaction action) {
|
||||
UINode* UINode::listenAction(const onaction& action) {
|
||||
actions.listen(action);
|
||||
return this;
|
||||
}
|
||||
|
||||
UINode* UINode::listenDoubleClick(onaction action) {
|
||||
UINode* UINode::listenDoubleClick(const onaction& action) {
|
||||
doubleClickCallbacks.listen(action);
|
||||
return this;
|
||||
}
|
||||
@@ -113,7 +115,7 @@ std::shared_ptr<UINode> UINode::getAt(glm::vec2 point, std::shared_ptr<UINode> s
|
||||
if (!isInteractive() || !enabled) {
|
||||
return nullptr;
|
||||
}
|
||||
return isInside(point) ? self : nullptr;
|
||||
return isInside(point) ? std::move(self) : nullptr;
|
||||
}
|
||||
|
||||
bool UINode::isInteractive() const {
|
||||
@@ -136,7 +138,7 @@ void UINode::setTooltip(const std::wstring& text) {
|
||||
this->tooltip = text;
|
||||
}
|
||||
|
||||
const std::wstring UINode::getTooltip() const {
|
||||
const std::wstring& UINode::getTooltip() const {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@@ -241,8 +243,8 @@ int UINode::getZIndex() const {
|
||||
}
|
||||
|
||||
void UINode::moveInto(
|
||||
std::shared_ptr<UINode> node,
|
||||
std::shared_ptr<Container> dest
|
||||
const std::shared_ptr<UINode>& node,
|
||||
const std::shared_ptr<Container>& dest
|
||||
) {
|
||||
auto parent = node->getParent();
|
||||
if (auto container = dynamic_cast<Container*>(parent)) {
|
||||
@@ -259,7 +261,7 @@ vec2supplier UINode::getPositionFunc() const {
|
||||
}
|
||||
|
||||
void UINode::setPositionFunc(vec2supplier func) {
|
||||
positionfunc = func;
|
||||
positionfunc = std::move(func);
|
||||
}
|
||||
|
||||
vec2supplier UINode::getSizeFunc() const {
|
||||
@@ -267,7 +269,7 @@ vec2supplier UINode::getSizeFunc() const {
|
||||
}
|
||||
|
||||
void UINode::setSizeFunc(vec2supplier func) {
|
||||
sizefunc = func;
|
||||
sizefunc = std::move(func);
|
||||
}
|
||||
|
||||
void UINode::setId(const std::string& id) {
|
||||
@@ -345,7 +347,7 @@ bool UINode::isSubnodeOf(const UINode* node) {
|
||||
}
|
||||
|
||||
void UINode::getIndices(
|
||||
const std::shared_ptr<UINode> node,
|
||||
const std::shared_ptr<UINode>& node,
|
||||
std::unordered_map<std::string, std::shared_ptr<UINode>>& map
|
||||
) {
|
||||
const std::string& id = node->getId();
|
||||
@@ -354,20 +356,20 @@ void UINode::getIndices(
|
||||
}
|
||||
auto container = std::dynamic_pointer_cast<gui::Container>(node);
|
||||
if (container) {
|
||||
for (auto subnode : container->getNodes()) {
|
||||
for (const auto& subnode : container->getNodes()) {
|
||||
getIndices(subnode, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::shared_ptr<UINode> UINode::find(
|
||||
const std::shared_ptr<UINode> node,
|
||||
const std::shared_ptr<UINode>& node,
|
||||
const std::string& id
|
||||
) {
|
||||
if (node->getId() == id) {
|
||||
return node;
|
||||
}
|
||||
if (auto container = std::dynamic_pointer_cast<Container>(node)) {
|
||||
for (auto subnode : container->getNodes()) {
|
||||
for (const auto& subnode : container->getNodes()) {
|
||||
if (auto found = UINode::find(subnode, id)) {
|
||||
return found;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace gui {
|
||||
class ActionsSet {
|
||||
std::unique_ptr<std::vector<onaction>> callbacks;
|
||||
public:
|
||||
void listen(onaction callback) {
|
||||
void listen(const onaction& callback) {
|
||||
if (callbacks == nullptr) {
|
||||
callbacks = std::make_unique<std::vector<onaction>>();
|
||||
}
|
||||
@@ -162,8 +162,8 @@ namespace gui {
|
||||
/// @brief Get element z-index
|
||||
int getZIndex() const;
|
||||
|
||||
virtual UINode* listenAction(onaction action);
|
||||
virtual UINode* listenDoubleClick(onaction action);
|
||||
virtual UINode* listenAction(const onaction &action);
|
||||
virtual UINode* listenDoubleClick(const onaction &action);
|
||||
|
||||
virtual void onFocus(GUI*) {focused = true;}
|
||||
virtual void doubleClick(GUI*, int x, int y);
|
||||
@@ -202,7 +202,7 @@ namespace gui {
|
||||
virtual bool isResizing() const;
|
||||
|
||||
virtual void setTooltip(const std::wstring& text);
|
||||
virtual const std::wstring getTooltip() const;
|
||||
virtual const std::wstring& getTooltip() const;
|
||||
|
||||
virtual void setTooltipDelay(float delay);
|
||||
virtual float getTooltipDelay() const;
|
||||
@@ -227,8 +227,8 @@ namespace gui {
|
||||
}
|
||||
};
|
||||
static void moveInto(
|
||||
std::shared_ptr<UINode> node,
|
||||
std::shared_ptr<Container> dest
|
||||
const std::shared_ptr<UINode>& node,
|
||||
const std::shared_ptr<Container>& dest
|
||||
);
|
||||
|
||||
virtual vec2supplier getPositionFunc() const;
|
||||
@@ -249,12 +249,12 @@ namespace gui {
|
||||
|
||||
/// @brief collect all nodes having id
|
||||
static void getIndices(
|
||||
const std::shared_ptr<UINode> node,
|
||||
const std::shared_ptr<UINode>& node,
|
||||
std::unordered_map<std::string, std::shared_ptr<UINode>>& map
|
||||
);
|
||||
|
||||
static std::shared_ptr<UINode> find(
|
||||
const std::shared_ptr<UINode> node,
|
||||
const std::shared_ptr<UINode>& node,
|
||||
const std::string& id
|
||||
);
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ std::shared_ptr<gui::UINode> guiutil::create(const std::string& source, scripten
|
||||
return reader.readXML("<string>", source);
|
||||
}
|
||||
|
||||
void guiutil::alert(GUI* gui, const std::wstring& text, runnable on_hidden) {
|
||||
void guiutil::alert(GUI* gui, const std::wstring& text, const runnable& on_hidden) {
|
||||
auto menu = gui->getMenu();
|
||||
auto panel = std::make_shared<Panel>(glm::vec2(500, 300), glm::vec4(8.0f), 8.0f);
|
||||
panel->setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.5f));
|
||||
@@ -48,7 +48,7 @@ void guiutil::alert(GUI* gui, const std::wstring& text, runnable on_hidden) {
|
||||
void guiutil::confirm(
|
||||
GUI* gui,
|
||||
const std::wstring& text,
|
||||
runnable on_confirm,
|
||||
const runnable& on_confirm,
|
||||
std::wstring yestext,
|
||||
std::wstring notext) {
|
||||
if (yestext.empty()) yestext = langs::get(L"Yes");
|
||||
|
||||
@@ -16,13 +16,13 @@ namespace guiutil {
|
||||
void alert(
|
||||
gui::GUI* gui,
|
||||
const std::wstring& text,
|
||||
runnable on_hidden=nullptr
|
||||
const runnable& on_hidden=nullptr
|
||||
);
|
||||
|
||||
void confirm(
|
||||
gui::GUI* gui,
|
||||
const std::wstring& text,
|
||||
runnable on_confirm=nullptr,
|
||||
const runnable& on_confirm=nullptr,
|
||||
std::wstring yestext=L"",
|
||||
std::wstring notext=L"");
|
||||
}
|
||||
|
||||
+24
-23
@@ -19,6 +19,7 @@
|
||||
#include "../../window/Events.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -52,7 +53,7 @@ static Gravity gravity_from_string(const std::string& str) {
|
||||
|
||||
static runnable create_runnable(
|
||||
const UiXmlReader& reader,
|
||||
xml::xmlelement element,
|
||||
const xml::xmlelement& element,
|
||||
const std::string& name
|
||||
) {
|
||||
if (element->has(name)) {
|
||||
@@ -66,7 +67,7 @@ static runnable create_runnable(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static onaction create_action(UiXmlReader& reader, xml::xmlelement element, const std::string& name) {
|
||||
static onaction create_action(UiXmlReader& reader, const xml::xmlelement& element, const std::string& name) {
|
||||
auto callback = create_runnable(reader, element, name);
|
||||
if (callback == nullptr) {
|
||||
return nullptr;
|
||||
@@ -75,7 +76,7 @@ static onaction create_action(UiXmlReader& reader, xml::xmlelement element, cons
|
||||
}
|
||||
|
||||
/* Read basic UINode properties */
|
||||
static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& node) {
|
||||
static void _readUINode(UiXmlReader& reader, const xml::xmlelement& element, UINode& node) {
|
||||
if (element->has("id")) {
|
||||
node.setId(element->attr("id").getText());
|
||||
}
|
||||
@@ -159,7 +160,7 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
||||
}
|
||||
}
|
||||
|
||||
static void _readContainer(UiXmlReader& reader, xml::xmlelement element, Container& container) {
|
||||
static void _readContainer(UiXmlReader& reader, const xml::xmlelement& element, Container& container) {
|
||||
_readUINode(reader, element, container);
|
||||
|
||||
if (element->has("scrollable")) {
|
||||
@@ -175,15 +176,15 @@ static void _readContainer(UiXmlReader& reader, xml::xmlelement element, Contain
|
||||
}
|
||||
}
|
||||
|
||||
void UiXmlReader::readUINode(UiXmlReader& reader, xml::xmlelement element, Container& container) {
|
||||
void UiXmlReader::readUINode(UiXmlReader& reader, const xml::xmlelement& element, Container& container) {
|
||||
_readContainer(reader, element, container);
|
||||
}
|
||||
|
||||
void UiXmlReader::readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& node) {
|
||||
void UiXmlReader::readUINode(UiXmlReader& reader, const xml::xmlelement& element, UINode& node) {
|
||||
_readUINode(reader, element, node);
|
||||
}
|
||||
|
||||
static void _readPanel(UiXmlReader& reader, xml::xmlelement element, Panel& panel, bool subnodes=true) {
|
||||
static void _readPanel(UiXmlReader& reader, const xml::xmlelement& element, Panel& panel, bool subnodes=true) {
|
||||
_readUINode(reader, element, panel);
|
||||
|
||||
if (element->has("padding")) {
|
||||
@@ -219,7 +220,7 @@ static void _readPanel(UiXmlReader& reader, xml::xmlelement element, Panel& pane
|
||||
}
|
||||
}
|
||||
|
||||
static std::wstring readAndProcessInnerText(xml::xmlelement element, const std::string& context) {
|
||||
static std::wstring readAndProcessInnerText(const xml::xmlelement& element, const std::string& context) {
|
||||
std::wstring text = L"";
|
||||
if (element->size() == 1) {
|
||||
std::string source = element->sub(0)->attr("#").getText();
|
||||
@@ -236,7 +237,7 @@ static std::wstring readAndProcessInnerText(xml::xmlelement element, const std::
|
||||
return text;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readLabel(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readLabel(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
std::wstring text = readAndProcessInnerText(element, reader.getContext());
|
||||
auto label = std::make_shared<Label>(text);
|
||||
_readUINode(reader, element, *label);
|
||||
@@ -267,20 +268,20 @@ static std::shared_ptr<UINode> readLabel(UiXmlReader& reader, xml::xmlelement el
|
||||
return label;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readContainer(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readContainer(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
auto container = std::make_shared<Container>(glm::vec2());
|
||||
_readContainer(reader, element, *container);
|
||||
return container;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readPanel(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readPanel(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
float interval = element->attr("interval", "2").asFloat();
|
||||
auto panel = std::make_shared<Panel>(glm::vec2(), glm::vec4(), interval);
|
||||
_readPanel(reader, element, *panel);
|
||||
return panel;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readButton(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readButton(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
glm::vec4 padding = element->attr("padding", "10").asVec4();
|
||||
|
||||
std::shared_ptr<Button> button;
|
||||
@@ -304,7 +305,7 @@ static std::shared_ptr<UINode> readButton(UiXmlReader& reader, xml::xmlelement e
|
||||
return button;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readCheckBox(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readCheckBox(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
auto text = readAndProcessInnerText(element, reader.getContext());
|
||||
bool checked = element->attr("checked", "false").asBool();
|
||||
auto checkbox = std::make_shared<FullCheckBox>(text, glm::vec2(32), checked);
|
||||
@@ -328,7 +329,7 @@ static std::shared_ptr<UINode> readCheckBox(UiXmlReader& reader, xml::xmlelement
|
||||
return checkbox;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
auto placeholder = util::str2wstr_utf8(element->attr("placeholder", "").getText());
|
||||
auto text = readAndProcessInnerText(element, reader.getContext());
|
||||
auto textbox = std::make_shared<TextBox>(placeholder, glm::vec4(0.0f));
|
||||
@@ -383,14 +384,14 @@ static std::shared_ptr<UINode> readTextBox(UiXmlReader& reader, xml::xmlelement
|
||||
return textbox;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readImage(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readImage(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
std::string src = element->attr("src", "").getText();
|
||||
auto image = std::make_shared<Image>(src);
|
||||
_readUINode(reader, element, *image);
|
||||
return image;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
float min = element->attr("min", "0.0").asFloat();
|
||||
float max = element->attr("max", "1.0").asFloat();
|
||||
float def = element->attr("value", "0.0").asFloat();
|
||||
@@ -418,7 +419,7 @@ static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, xml::xmlelement
|
||||
return bar;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readInputBindBox(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readInputBindBox(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
auto bindname = element->attr("binding").getText();
|
||||
auto found = Events::bindings.find(bindname);
|
||||
if (found == Events::bindings.end()) {
|
||||
@@ -518,7 +519,7 @@ static void readSlotsGrid(InventoryView* view, UiXmlReader& reader, xml::xmlelem
|
||||
}
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readInventory(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readInventory(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
auto view = std::make_shared<InventoryView>();
|
||||
view->setColor(glm::vec4(0.122f, 0.122f, 0.122f, 0.878f)); // todo: fixme
|
||||
reader.addIgnore("slot");
|
||||
@@ -535,7 +536,7 @@ static std::shared_ptr<UINode> readInventory(UiXmlReader& reader, xml::xmlelemen
|
||||
return view;
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readPageBox(UiXmlReader& reader, xml::xmlelement element) {
|
||||
static std::shared_ptr<UINode> readPageBox(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
auto menu = std::make_shared<Menu>();
|
||||
// fixme
|
||||
menu->setPageLoader(menus::create_page_loader(scripting::engine));
|
||||
@@ -545,7 +546,7 @@ static std::shared_ptr<UINode> readPageBox(UiXmlReader& reader, xml::xmlelement
|
||||
}
|
||||
|
||||
UiXmlReader::UiXmlReader(const scriptenv& env) : env(env) {
|
||||
contextStack.push("");
|
||||
contextStack.emplace("");
|
||||
add("image", readImage);
|
||||
add("label", readLabel);
|
||||
add("panel", readPanel);
|
||||
@@ -560,7 +561,7 @@ UiXmlReader::UiXmlReader(const scriptenv& env) : env(env) {
|
||||
}
|
||||
|
||||
void UiXmlReader::add(const std::string& tag, uinode_reader reader) {
|
||||
readers[tag] = reader;
|
||||
readers[tag] = std::move(reader);
|
||||
}
|
||||
|
||||
bool UiXmlReader::hasReader(const std::string& tag) const {
|
||||
@@ -571,7 +572,7 @@ void UiXmlReader::addIgnore(const std::string& tag) {
|
||||
ignored.insert(tag);
|
||||
}
|
||||
|
||||
std::shared_ptr<UINode> UiXmlReader::readUINode(xml::xmlelement element) {
|
||||
std::shared_ptr<UINode> UiXmlReader::readUINode(const xml::xmlelement& element) {
|
||||
if (element->has("if")) {
|
||||
const auto& cond = element->attr("if").getText();
|
||||
if (cond.empty() || cond == "false" || cond == "nil")
|
||||
@@ -615,7 +616,7 @@ std::shared_ptr<UINode> UiXmlReader::readXML(
|
||||
|
||||
std::shared_ptr<UINode> UiXmlReader::readXML(
|
||||
const std::string& filename,
|
||||
xml::xmlelement root
|
||||
const xml::xmlelement& root
|
||||
) {
|
||||
this->filename = filename;
|
||||
return readUINode(root);
|
||||
|
||||
@@ -27,17 +27,17 @@ namespace gui {
|
||||
bool hasReader(const std::string& tag) const;
|
||||
void addIgnore(const std::string& tag);
|
||||
|
||||
std::shared_ptr<UINode> readUINode(xml::xmlelement element);
|
||||
std::shared_ptr<UINode> readUINode(const xml::xmlelement& element);
|
||||
|
||||
void readUINode(
|
||||
UiXmlReader& reader,
|
||||
xml::xmlelement element,
|
||||
const xml::xmlelement& element,
|
||||
UINode& node
|
||||
);
|
||||
|
||||
void readUINode(
|
||||
UiXmlReader& reader,
|
||||
xml::xmlelement element,
|
||||
const xml::xmlelement& element,
|
||||
Container& container
|
||||
);
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace gui {
|
||||
|
||||
std::shared_ptr<UINode> readXML(
|
||||
const std::string& filename,
|
||||
xml::xmlelement root
|
||||
const xml::xmlelement& root
|
||||
);
|
||||
|
||||
const std::string& getContext() const;
|
||||
|
||||
@@ -31,7 +31,7 @@ std::shared_ptr<Inventory> Inventories::createVirtual(size_t size) {
|
||||
});
|
||||
}
|
||||
|
||||
void Inventories::store(std::shared_ptr<Inventory> inv) {
|
||||
void Inventories::store(const std::shared_ptr<Inventory>& inv) {
|
||||
map[inv->getId()] = inv;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
std::shared_ptr<Inventory> createVirtual(size_t size);
|
||||
|
||||
/* Store inventory */
|
||||
void store(std::shared_ptr<Inventory> inv);
|
||||
void store(const std::shared_ptr<Inventory>& inv);
|
||||
|
||||
/* Remove inventory from map */
|
||||
void remove(int64_t id);
|
||||
|
||||
@@ -54,7 +54,7 @@ void Inventory::deserialize(dynamic::Map* src) {
|
||||
auto slotsarr = src->list("slots");
|
||||
size_t slotscount = slotsarr->size();
|
||||
while (slots.size() < slotscount) {
|
||||
slots.push_back(ItemStack());
|
||||
slots.emplace_back();
|
||||
}
|
||||
for (size_t i = 0; i < slotscount; i++) {
|
||||
auto item = slotsarr->map(i);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "ItemDef.hpp"
|
||||
#include "../util/stringutil.hpp"
|
||||
|
||||
ItemDef::ItemDef(std::string name) : name(name) {
|
||||
ItemDef::ItemDef(const std::string& name) : name(name) {
|
||||
caption = util::id_to_caption(name);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
bool emissive = false;
|
||||
} rt;
|
||||
|
||||
ItemDef(std::string name);
|
||||
ItemDef(const std::string& name);
|
||||
ItemDef(const ItemDef&) = delete;
|
||||
};
|
||||
|
||||
|
||||
@@ -130,11 +130,13 @@ void BlocksController::randomTick(int tickid, int parts) {
|
||||
for (uint z = padding; z < d-padding; z++){
|
||||
for (uint x = padding; x < w-padding; x++){
|
||||
int index = z * w + x;
|
||||
if ((index + tickid) % parts != 0)
|
||||
if ((index + tickid) % parts != 0) {
|
||||
continue;
|
||||
}
|
||||
auto& chunk = chunks->chunks[index];
|
||||
if (chunk == nullptr || !chunk->flags.lighted)
|
||||
if (chunk == nullptr || !chunk->flags.lighted) {
|
||||
continue;
|
||||
}
|
||||
for (int s = 0; s < segments; s++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int bx = random.rand() % CHUNK_W;
|
||||
@@ -146,7 +148,8 @@ void BlocksController::randomTick(int tickid, int parts) {
|
||||
scripting::random_update_block(
|
||||
block,
|
||||
chunk->x * CHUNK_W + bx, by,
|
||||
chunk->z * CHUNK_D + bz);
|
||||
chunk->z * CHUNK_D + bz
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ bool ChunksController::loadVisible(){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ChunksController::buildLights(std::shared_ptr<Chunk> chunk) {
|
||||
bool ChunksController::buildLights(const std::shared_ptr<Chunk>& chunk) {
|
||||
int surrounding = 0;
|
||||
for (int oz = -1; oz <= 1; oz++){
|
||||
for (int ox = -1; ox <= 1; ox++){
|
||||
|
||||
@@ -21,7 +21,7 @@ private:
|
||||
|
||||
/// @brief Process one chunk: load it or calculate lights for it
|
||||
bool loadVisible();
|
||||
bool buildLights(std::shared_ptr<Chunk> chunk);
|
||||
bool buildLights(const std::shared_ptr<Chunk>& chunk);
|
||||
void createChunk(int x, int y);
|
||||
public:
|
||||
ChunksController(Level* level, uint padding);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user