Merge branch 'main' into refactor-world-renderer

This commit is contained in:
MihailRis 2026-08-04 20:48:14 +03:00
commit a8886bccfb
18 changed files with 404 additions and 118 deletions

View file

@ -12,6 +12,7 @@ struct CoreParameters {
std::filesystem::path userFolder = ".";
std::filesystem::path scriptFile;
std::filesystem::path projectFolder;
std::filesystem::path logFile;
std::string debugServerString;
int tps = 20;
int subProcessDepth = 0;

View file

@ -403,6 +403,7 @@ static int l_start_background_instance(lua::State* L) {
"--script", io::resolve(scriptPath).u8string(),
"--sub-depth", std::to_string(engine->getCoreParameters()
.subProcessDepth + 1),
"--log", io::resolve(outputPath).u8string(),
};
args.emplace_back("--project");
args.emplace_back(io::resolve(engine->getProject().path).u8string());
@ -417,11 +418,9 @@ static int l_start_background_instance(lua::State* L) {
if (handle == -1) {
throw std::runtime_error("sub-processes limit exceeded");
}
::processes[handle] = platform::new_engine_instance(
std::move(args),
outputPath.empty() ? "" : io::resolve(outputPath),
true
);
::processes[handle] =
platform::new_engine_instance(std::move(args), "", true);
return lua::pushinteger(L, handle);
}

View file

@ -161,17 +161,13 @@ static LuaCanvas& require_canvas(State* L, int idx) {
static int l_clear(State* L) {
auto& canvas = require_canvas(L, 1);
auto& image = canvas.getData();
ubyte* data = image.getData();
RGBA rgba {};
size_t pixelscount = image.getWidth() * image.getHeight();
uint32_t* data = reinterpret_cast<uint32_t*>(image.getData());
if (gettop(L) == 1) {
std::fill(data, data + image.getDataSize(), 0);
return 0;
}
rgba = get_rgba(L, 2);
size_t pixels = image.getWidth() * image.getHeight();
const size_t channels = 4;
for (size_t i = 0; i < pixels * channels; i++) {
data[i] = rgba.arr[i % channels];
std::fill(data, data + pixelscount, 0);
} else {
std::fill(data, data + pixelscount, get_rgba(L, 2).rgba);
}
return 0;
}

View file

@ -7,6 +7,7 @@
#include <iostream>
#include <stdexcept>
using namespace std::literals;
static debug::Logger logger("main");
static void sigterm_handler(int signum) {
@ -36,7 +37,14 @@ int main(int argc, char** argv) {
#ifdef NDEBUG
std::signal(SIGINT, sigterm_handler);
#endif
debug::Logger::init(coreParameters.userFolder.string() + "/latest.log");
std::filesystem::path logFile = coreParameters.logFile;
if (logFile.empty()) {
logFile = coreParameters.userFolder.string() + "/latest"s +
(coreParameters.subProcessDepth > 0
? ".sub" + std::to_string(coreParameters.subProcessDepth)
: "") + ".log"s;
}
debug::Logger::init(logFile.u8string());
platform::configure_encoding();
auto& engine = Engine::getInstance();

View file

@ -82,6 +82,10 @@ static bool perform_keyword(
params.subProcessDepth = reader.nextInt();
return true;
}, "<depth>", "sub-process depth"),
ArgC("--log", [](auto& params, auto& reader) -> bool {
params.logFile = reader.next();
return true;
}, "<file>", "target log file"),
ArgC("--help", [](auto&, auto&) -> bool {
std::cout << "VoxelCore v" << ENGINE_VERSION_STRING << "\n\n";
std::cout << "Command-line arguments:\n";

View file

@ -28,6 +28,8 @@
#include <sys/wait.h>
#endif
using namespace std::literals;
namespace platform::internal {
std::filesystem::path get_executable_path();
}
@ -356,7 +358,7 @@ std::unique_ptr<Process> platform::new_engine_instance(
if (!outputFile.empty()) {
si.dwFlags |= STARTF_USESTDHANDLES;
si.hStdOutput = CreateFileW(
toWString(outputFile.u8string()).data(),
toWString(outputFile.empty() ? outputFile.u8string() : "NUL"s).data(),
GENERIC_WRITE,
FILE_SHARE_WRITE | FILE_SHARE_READ,
nullptr,
@ -434,9 +436,12 @@ std::unique_ptr<Process> platform::new_engine_instance(
if (subProcess) {
pid_t pid = fork();
if (outputFile.empty()) {
outputFile = "/dev/null";
}
int fd = open(
outputFile.string().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644
);
);
if (pid == 0) {
prctl(PR_SET_PDEATHSIG, SIGTERM);