mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 17:39:46 +00:00
Merge branch 'main' into dev
This commit is contained in:
commit
8226f73bf1
8 changed files with 210 additions and 15 deletions
|
|
@ -113,8 +113,6 @@ static inline auto shader_deleter = [](GLuint* shader) {
|
|||
delete shader;
|
||||
};
|
||||
|
||||
inline const uint GL_LOG_LEN = 512;
|
||||
|
||||
// shader should be deleted after shader program linking
|
||||
using glshader = std::unique_ptr<GLuint, decltype(shader_deleter)>;
|
||||
|
||||
|
|
@ -125,12 +123,14 @@ glshader compile_shader(GLenum type, const GLchar* source, const std::string& fi
|
|||
glCompileShader(shader);
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
GLchar infoLog[GL_LOG_LEN];
|
||||
glGetShaderInfoLog(shader, GL_LOG_LEN, nullptr, infoLog);
|
||||
GLint infoLogLength;
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
auto infoLog = std::make_unique<GLchar[]>(infoLogLength);
|
||||
glGetShaderInfoLog(shader, infoLogLength, nullptr, infoLog.get());
|
||||
glDeleteShader(shader);
|
||||
throw std::runtime_error(
|
||||
"vertex shader compilation failed (" + file + "):\n" +
|
||||
std::string(infoLog)
|
||||
std::string(infoLog.get(), infoLogLength)
|
||||
);
|
||||
}
|
||||
return glshader(new GLuint(shader), shader_deleter); //-V508
|
||||
|
|
@ -172,10 +172,14 @@ static GLuint compile_program(
|
|||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
||||
|
||||
if (!success) {
|
||||
GLchar infoLog[GL_LOG_LEN];
|
||||
glGetProgramInfoLog(program, GL_LOG_LEN, nullptr, infoLog);
|
||||
GLint infoLogLength;
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||
auto infoLog = std::make_unique<GLchar[]>(infoLogLength);
|
||||
glGetProgramInfoLog(program, infoLogLength, nullptr, infoLog.get());
|
||||
glDeleteProgram(program);
|
||||
throw std::runtime_error(
|
||||
"shader program linking failed:\n" + std::string(infoLog)
|
||||
"shader program linking failed:\n" +
|
||||
std::string(infoLog.get(), infoLogLength)
|
||||
);
|
||||
}
|
||||
return program;
|
||||
|
|
|
|||
|
|
@ -180,6 +180,10 @@ std::unique_ptr<io::PathsGenerator> io::MemoryDevice::list(std::string_view path
|
|||
}
|
||||
|
||||
io::MemoryDevice::Dir* io::MemoryDevice::createDir(std::string path) {
|
||||
const auto& found = nodes.find(path);
|
||||
if (found != nodes.end()) {
|
||||
return found->second.get_if<Dir>();
|
||||
}
|
||||
io::path filePath = path;
|
||||
io::path parent = filePath.parent();
|
||||
auto parentDir = getDir(parent.string());
|
||||
|
|
@ -195,6 +199,15 @@ io::MemoryDevice::Dir* io::MemoryDevice::createDir(std::string path) {
|
|||
io::MemoryDevice::Node* io::MemoryDevice::createFile(
|
||||
std::string path, util::Buffer<char>&& content
|
||||
) {
|
||||
const auto& found = nodes.find(path);
|
||||
if (found != nodes.end()) {
|
||||
auto& node = found->second;
|
||||
if (!node.holds_alternative<File>()) {
|
||||
return nullptr;
|
||||
}
|
||||
node.data = File {std::move(content)};
|
||||
return &node;
|
||||
}
|
||||
io::path filePath = path;
|
||||
io::path parent = filePath.parent();
|
||||
auto dir = getDir(parent.string());
|
||||
|
|
|
|||
|
|
@ -58,11 +58,20 @@ namespace {
|
|||
}
|
||||
|
||||
uint32_t to_ms_dos_timestamp(const file_time_type& fileTime) {
|
||||
// 1980-01-01 00:00, the earliest MS-DOS date
|
||||
constexpr uint32_t DOS_EPOCH = (0 << 9 | 1 << 5 | 1) << 16;
|
||||
if (fileTime == file_time_type::min()) {
|
||||
return DOS_EPOCH;
|
||||
}
|
||||
auto timePoint = time_point_cast<system_clock::duration>(
|
||||
fileTime - file_time_type::clock::now() + system_clock::now()
|
||||
);
|
||||
std::time_t timeT = system_clock::to_time_t(timePoint);
|
||||
std::tm tm = *std::localtime(&timeT);
|
||||
const std::tm* tmPtr = std::localtime(&timeT);
|
||||
if (tmPtr == nullptr || tmPtr->tm_year < 80) {
|
||||
return DOS_EPOCH;
|
||||
}
|
||||
const std::tm& tm = *tmPtr;
|
||||
uint16_t date = (tm.tm_year - 80) << 9 | (tm.tm_mon + 1) << 5 | tm.tm_mday;
|
||||
uint16_t time = (tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec / 2);
|
||||
return (date << 16) | time;
|
||||
|
|
@ -173,7 +182,12 @@ ZipFileDevice::ZipFileDevice(
|
|||
entries[entry.fileName] = std::move(entry);
|
||||
}
|
||||
|
||||
for (auto& [name, _] : entries) {
|
||||
std::vector<std::string> names;
|
||||
names.reserve(entries.size());
|
||||
for (const auto& [name, _] : entries) {
|
||||
names.push_back(name);
|
||||
}
|
||||
for (const auto& name : names) {
|
||||
io::path path = name;
|
||||
|
||||
while (!(path = path.parent()).pathPart().empty()) {
|
||||
|
|
@ -184,7 +198,6 @@ ZipFileDevice::ZipFileDevice(
|
|||
entry.isDirectory = true;
|
||||
entries[path.pathPart()] = entry;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (auto& [_, entry] : entries) {
|
||||
|
|
@ -253,6 +266,9 @@ file_time_type ZipFileDevice::lastWriteTime(std::string_view path) {
|
|||
}
|
||||
|
||||
bool ZipFileDevice::exists(std::string_view path) {
|
||||
if (path.empty()) {
|
||||
return true;
|
||||
}
|
||||
return entries.find(std::string(path)) != entries.end();
|
||||
}
|
||||
|
||||
|
|
@ -441,7 +457,11 @@ static size_t write_zip(
|
|||
void io::write_zip(const path& folder, const path& file) {
|
||||
ByteBuilder central_dir;
|
||||
auto out = io::write(file);
|
||||
size_t entries = write_zip(folder.pathPart(), folder, *out, central_dir);
|
||||
auto root = folder.pathPart();
|
||||
if (!root.empty() && root.back() != '/') {
|
||||
root += '/';
|
||||
}
|
||||
size_t entries = write_zip(root, folder, *out, central_dir);
|
||||
|
||||
size_t central_dir_offset = out->tellp();
|
||||
out->write(reinterpret_cast<const char*>(central_dir.data()), central_dir.size());
|
||||
|
|
|
|||
|
|
@ -50,6 +50,19 @@ protected:
|
|||
return c;
|
||||
}
|
||||
|
||||
pos_type seekoff(
|
||||
off_type off,
|
||||
std::ios_base::seekdir way,
|
||||
std::ios_base::openmode mode = std::ios_base::out
|
||||
) override {
|
||||
// only position query (tellp) is supported
|
||||
if (off == 0 && way == std::ios_base::cur &&
|
||||
(mode & std::ios_base::out)) {
|
||||
return pos_type(off_type(size()));
|
||||
}
|
||||
return pos_type(off_type(-1));
|
||||
}
|
||||
|
||||
std::streamsize xsputn(const char* s, std::streamsize count) override {
|
||||
const std::streamsize avail = epptr() - pptr();
|
||||
|
||||
|
|
|
|||
|
|
@ -480,15 +480,17 @@ void Entities::render(
|
|||
const Frustum* frustum,
|
||||
entityid_t fpsEntity
|
||||
) {
|
||||
auto view = registry->view<EntityId, Transform, rigging::Skeleton>();
|
||||
for (auto [entity, eid, transform, skeleton] : view.each()) {
|
||||
auto view = registry->view<EntityId, Transform, rigging::Skeleton, Rigidbody>();
|
||||
for (auto [entity, eid, transform, skeleton, rigidbody] : view.each()) {
|
||||
if (eid.uid == fpsEntity) {
|
||||
continue;
|
||||
}
|
||||
const auto& def = eid.def;
|
||||
const auto& pos = transform.pos;
|
||||
const auto& size = transform.size;
|
||||
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
||||
const auto& halfSize = rigidbody.hitbox.getHalfSize();
|
||||
// todo: more correct frustum culling
|
||||
if (frustum && !frustum->isBoxVisible(pos - halfSize, pos + halfSize)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue