mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 09:29:44 +00:00
Merge branch 'main' into release-0.32
Some checks failed
x86-64 AppImage / build-appimage (ubuntu-22.04) (push) Has been cancelled
Macos Build / build-dmg (push) Has been cancelled
Windows Build (CLang) / build-windows (clang, windows-latest) (push) Has been cancelled
MSVC Build / build-windows (windows-2022) (push) Has been cancelled
Some checks failed
x86-64 AppImage / build-appimage (ubuntu-22.04) (push) Has been cancelled
Macos Build / build-dmg (push) Has been cancelled
Windows Build (CLang) / build-windows (clang, windows-latest) (push) Has been cancelled
MSVC Build / build-windows (windows-2022) (push) Has been cancelled
This commit is contained in:
commit
8eff080f82
13 changed files with 91 additions and 30 deletions
|
|
@ -12,7 +12,7 @@ using namespace imageio;
|
|||
|
||||
using image_reader =
|
||||
std::function<std::unique_ptr<ImageData>(const ubyte*, size_t)>;
|
||||
using image_writer = std::function<void(const std::string&, const ImageData*)>;
|
||||
using image_writer = std::function<void(const io::path&, const ImageData*)>;
|
||||
|
||||
static std::unordered_map<ImageFileFormat, image_reader> readers {
|
||||
{ImageFileFormat::PNG, png::load_image},
|
||||
|
|
@ -75,7 +75,7 @@ void imageio::write(const io::path& file, const ImageData* image) {
|
|||
"file format is not supported (write): " + file.string()
|
||||
);
|
||||
}
|
||||
return found->second(io::resolve(file).u8string(), image);
|
||||
return found->second(file, image);
|
||||
}
|
||||
|
||||
util::Buffer<unsigned char> imageio::encode(
|
||||
|
|
|
|||
|
|
@ -47,8 +47,25 @@ std::unique_ptr<audio::PCM> ogg::load_pcm(
|
|||
const io::path& file, bool headerOnly
|
||||
) {
|
||||
OggVorbis_File vf;
|
||||
int code;
|
||||
if ((code = ov_fopen(io::resolve(file).u8string().c_str(), &vf))) {
|
||||
FILE* fileHandle = nullptr;
|
||||
#ifdef _WIN32
|
||||
if (errno_t err =
|
||||
_wfopen_s(
|
||||
&fileHandle, io::resolve(file).wstring().c_str(), L"rb"
|
||||
) != 0) {
|
||||
#else
|
||||
if ((fileHandle = fopen(io::resolve(file).u8string().c_str(), "rb")) ==
|
||||
nullptr) {
|
||||
#endif
|
||||
throw std::runtime_error(
|
||||
"could not open file " + file.string() + " for reading"
|
||||
);
|
||||
}
|
||||
|
||||
if (int code = ov_open(fileHandle, &vf, nullptr, 0)) {
|
||||
if (fileHandle) {
|
||||
fclose(fileHandle);
|
||||
}
|
||||
throw std::runtime_error("vorbis: " + vorbis_error_message(code));
|
||||
}
|
||||
std::vector<char> data;
|
||||
|
|
@ -169,8 +186,25 @@ public:
|
|||
|
||||
std::unique_ptr<PCMStream> ogg::create_stream(const io::path& file) {
|
||||
OggVorbis_File vf;
|
||||
int code;
|
||||
if ((code = ov_fopen(io::resolve(file).u8string().c_str(), &vf))) {
|
||||
FILE* fileHandle = nullptr;
|
||||
#ifdef _WIN32
|
||||
if (errno_t err =
|
||||
_wfopen_s(
|
||||
&fileHandle, io::resolve(file).wstring().c_str(), L"rb"
|
||||
) != 0) {
|
||||
#else
|
||||
if ((fileHandle = fopen(io::resolve(file).u8string().c_str(), "rb")) ==
|
||||
nullptr) {
|
||||
#endif
|
||||
throw std::runtime_error(
|
||||
"could not open file " + file.string() + " for reading"
|
||||
);
|
||||
}
|
||||
|
||||
if (int code = ov_open(fileHandle, &vf, nullptr, 0)) {
|
||||
if (fileHandle) {
|
||||
fclose(fileHandle);
|
||||
}
|
||||
throw std::runtime_error("vorbis: " + vorbis_error_message(code));
|
||||
}
|
||||
return std::make_unique<OggStream>(vf);
|
||||
|
|
|
|||
|
|
@ -67,14 +67,20 @@ static util::Buffer<ubyte> write_to_memory(uint width, uint height, const ubyte*
|
|||
|
||||
// returns 0 if all-right, 1 otherwise
|
||||
static int png_write(
|
||||
const char* filename, uint width, uint height, const ubyte* data, bool alpha
|
||||
const io::path& file, uint width, uint height, const ubyte* data, bool alpha
|
||||
) {
|
||||
uint pixsize = alpha ? 4 : 3;
|
||||
|
||||
// Open file for writing (binary mode)
|
||||
FILE* fp = fopen(filename, "wb");
|
||||
if (fp == nullptr) {
|
||||
logger.error() << "could not open file " << filename << " for writing";
|
||||
FILE* fp = nullptr;
|
||||
#ifdef _WIN32
|
||||
if (errno_t err =
|
||||
_wfopen_s(&fp, io::resolve(file).wstring().c_str(), L"wb") != 0) {
|
||||
#else
|
||||
if ((fp = fopen(io::resolve(file).u8string().c_str(), "wb")) == nullptr) {
|
||||
#endif
|
||||
logger.error() << "could not open file " << file.string()
|
||||
<< " for writing";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -290,9 +296,9 @@ std::unique_ptr<Texture> png::load_texture(const std::string& filename) {
|
|||
}
|
||||
}
|
||||
|
||||
void png::write_image(const std::string& filename, const ImageData* image) {
|
||||
void png::write_image(const io::path& file, const ImageData* image) {
|
||||
png_write(
|
||||
filename.c_str(),
|
||||
file,
|
||||
image->getWidth(),
|
||||
image->getHeight(),
|
||||
(const ubyte*)image->getData(),
|
||||
|
|
|
|||
|
|
@ -8,10 +8,13 @@
|
|||
|
||||
class Texture;
|
||||
class ImageData;
|
||||
namespace io {
|
||||
class path;
|
||||
}
|
||||
|
||||
namespace png {
|
||||
std::unique_ptr<ImageData> load_image(const ubyte* bytes, size_t size);
|
||||
void write_image(const std::string& filename, const ImageData* image);
|
||||
void write_image(const io::path& file, const ImageData* image);
|
||||
util::Buffer<ubyte> encode_image(const ImageData& image);
|
||||
std::unique_ptr<Texture> load_texture(const ubyte* bytes, size_t size);
|
||||
std::unique_ptr<Texture> load_texture(const std::string& filename);
|
||||
|
|
|
|||
|
|
@ -68,8 +68,8 @@ static void write(
|
|||
}
|
||||
}
|
||||
|
||||
void Logger::init(const std::string& filename) {
|
||||
file.open(filename);
|
||||
void Logger::init(const std::filesystem::path& path) {
|
||||
file.open(path);
|
||||
|
||||
time_t tm = std::time(nullptr);
|
||||
std::stringstream ss;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
|
||||
namespace debug {
|
||||
enum class LogLevel { print, debug, info, warning, error };
|
||||
|
|
@ -27,7 +28,7 @@ namespace debug {
|
|||
class Logger {
|
||||
std::string name;
|
||||
public:
|
||||
static void init(const std::string& filename);
|
||||
static void init(const std::filesystem::path& path);
|
||||
static void flush();
|
||||
|
||||
Logger(const std::string& name) : name(name) {
|
||||
|
|
|
|||
|
|
@ -682,7 +682,7 @@ static int l_get_field(lua::State* L) {
|
|||
return 0;
|
||||
}
|
||||
auto lx = x - cx * CHUNK_W;
|
||||
auto lz = z - cz * CHUNK_W;
|
||||
auto lz = z - cz * CHUNK_D;
|
||||
size_t voxelIndex = vox_index(lx, y, lz);
|
||||
|
||||
const auto& vox = chunk->voxels[voxelIndex];
|
||||
|
|
@ -751,7 +751,7 @@ static int l_set_field(lua::State* L) {
|
|||
auto cx = floordiv(x, CHUNK_W);
|
||||
auto cz = floordiv(z, CHUNK_D);
|
||||
auto lx = x - cx * CHUNK_W;
|
||||
auto lz = z - cz * CHUNK_W;
|
||||
auto lz = z - cz * CHUNK_D;
|
||||
auto chunk = blocks_agent::get_chunk(*level.chunks, cx, cz);
|
||||
if (chunk == nullptr || y < 0 || y >= CHUNK_H) {
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ static int l_push_ray(
|
|||
lua::pushvec3(L, ray ? ray->normal : normal);
|
||||
lua::setfield(L, "normal");
|
||||
|
||||
lua::pushnumber(L, glm::distance(start, end));
|
||||
lua::pushnumber(L, ray ? ray->distance : glm::distance(start, end));
|
||||
lua::setfield(L, "length");
|
||||
|
||||
lua::pushvec3(L, iend);
|
||||
|
|
@ -306,12 +306,12 @@ static int l_world_raycast(lua::State* L) {
|
|||
entityRaycast.ignoredUid = lua::tointeger(L, -1);
|
||||
lua::pop(L);
|
||||
}
|
||||
if (lua::getfield(L, "filter_entities")) {
|
||||
if (lua::getfield(L, "filter_entities", 1)) {
|
||||
load_entities_filter(L, -1, filteredEntities);
|
||||
blocksRaycast.filter = &filteredEntities;
|
||||
entityRaycast.entitiesFilter = &filteredEntities;
|
||||
lua::pop(L);
|
||||
}
|
||||
if (lua::getfield(L, "entities_exclusion")) {
|
||||
if (lua::getfield(L, "entities_exclusion", 1)) {
|
||||
entityRaycast.entityFilterExcludeMode = lua::toboolean(L, -1);
|
||||
lua::pop(L);
|
||||
}
|
||||
|
|
@ -324,7 +324,7 @@ static int l_world_raycast(lua::State* L) {
|
|||
blocksRaycast.filter = &filteredBlocks;
|
||||
lua::pop(L);
|
||||
}
|
||||
if (lua::getfield(L, "blocks_exclusion")) {
|
||||
if (lua::getfield(L, "blocks_exclusion", 1)) {
|
||||
blocksRaycast.blocksFilterExcludeMode = lua::toboolean(L, -1);
|
||||
lua::pop(L);
|
||||
}
|
||||
|
|
@ -357,7 +357,7 @@ static int l_raycast(lua::State* L) {
|
|||
}
|
||||
}
|
||||
if (luaStackSize >= 7) {
|
||||
blocksRaycast.includeNonSelectable = lua::toboolean(L, 6);
|
||||
blocksRaycast.includeNonSelectable = lua::toboolean(L, 7);
|
||||
}
|
||||
return l_raycast(
|
||||
L, start, dir, maxDistance, blocksRaycast, entityRaycast, true
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ int main(int argc, char** argv) {
|
|||
? ".sub" + std::to_string(coreParameters.subProcessDepth)
|
||||
: "") + ".log"s;
|
||||
}
|
||||
debug::Logger::init(logFile.u8string());
|
||||
debug::Logger::init(logFile);
|
||||
platform::configure_encoding();
|
||||
|
||||
auto& engine = Engine::getInstance();
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
#include "commons.hpp"
|
||||
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
|
||||
#define NOMINMAX
|
||||
#include <stdexcept>
|
||||
#include <limits>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define NOMINMAX
|
||||
#include <curl/curl.h>
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
#define SHUT_RDWR SD_BOTH
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,14 @@
|
|||
|
||||
#if defined(_WIN32)
|
||||
#include <malloc.h>
|
||||
#elif defined(__ANDROID__)
|
||||
static inline void* aligned_alloc(size_t alignment, size_t size) {
|
||||
void* ptr = nullptr;
|
||||
if (posix_memalign(&ptr, alignment, size) != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace util {
|
||||
|
|
@ -63,6 +71,8 @@ namespace util {
|
|||
std::unique_ptr<void, AlignedDeleter> ptr(
|
||||
#if defined(_WIN32)
|
||||
_aligned_malloc(sizeof(T), alignof(T))
|
||||
#elif defined(__ANDROID__)
|
||||
aligned_alloc(sizeof(T), alignof(T))
|
||||
#else
|
||||
std::aligned_alloc(alignof(T), sizeof(T))
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ TEST(SurroundMap, InitTest) {
|
|||
|
||||
#include "coders/png.hpp"
|
||||
#include "graphics/core/ImageData.hpp"
|
||||
#include "io/path.hpp"
|
||||
|
||||
void visualize(const SurroundMap& map, int mul, int max) {
|
||||
const auto& areaMap = map.getArea();
|
||||
|
|
@ -59,7 +60,7 @@ void visualize(const SurroundMap& map, int mul, int max) {
|
|||
bytes[(y * w + x) * 3 + 2] = val;
|
||||
}
|
||||
}
|
||||
png::write_image("test.png", &image);
|
||||
png::write_image("user:test.png", &image);
|
||||
}
|
||||
|
||||
TEST(SurroundMap, Visualize) {
|
||||
|
|
|
|||
|
|
@ -16,5 +16,12 @@
|
|||
"curl",
|
||||
"freetype",
|
||||
"openssl"
|
||||
],
|
||||
"builtin-baseline": "802d61d714db2714e3fefcfc59447431166b8367",
|
||||
"overrides": [
|
||||
{
|
||||
"name": "entt",
|
||||
"version": "3.16.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue