From 96bd73ae020ecca1f94698744c77498a89ad19f7 Mon Sep 17 00:00:00 2001 From: untodesu Date: Thu, 11 Sep 2025 13:10:52 +0500 Subject: Graft build scripts and buffer code from QFengine --- .gitignore | 2 - CMakeLists.txt | 10 +- build.unix.generic.sh | 4 - build.windows.x32.sh | 4 - build.windows.x64.sh | 4 - core/io/buffer.cc | 213 +++++++++++++++++++++----- core/io/buffer.hh | 221 ++++----------------------- core/math/CMakeLists.txt | 1 - core/math/floathacks.hh | 56 ------- deps/CMakeLists.txt | 8 + deps/glfw/CMakeLists.txt | 2 +- deps/imgui/CMakeLists.txt | 2 +- deps/thirdparty.py | 60 ++++++++ game/client/CMakeLists.txt | 2 +- game/shared/protocol.cc | 299 ++++++++++++++++++++----------------- game/shared/world/voxel_storage.cc | 8 +- package.unix.generic.sh | 4 - package.windows.x32.sh | 4 - package.windows.x64.sh | 4 - thirdpartylegalnotices.py | 60 -------- tools/build-unix.sh | 5 + tools/build-win32.sh | 5 + tools/build-win64.sh | 5 + tools/pack-unix.sh | 5 + tools/pack-win32.sh | 5 + tools/pack-win64.sh | 5 + 26 files changed, 466 insertions(+), 532 deletions(-) delete mode 100755 build.unix.generic.sh delete mode 100644 build.windows.x32.sh delete mode 100644 build.windows.x64.sh delete mode 100644 core/math/floathacks.hh create mode 100644 deps/thirdparty.py delete mode 100755 package.unix.generic.sh delete mode 100644 package.windows.x32.sh delete mode 100644 package.windows.x64.sh delete mode 100644 thirdpartylegalnotices.py create mode 100755 tools/build-unix.sh create mode 100644 tools/build-win32.sh create mode 100644 tools/build-win64.sh create mode 100644 tools/pack-unix.sh create mode 100644 tools/pack-win32.sh create mode 100644 tools/pack-win64.sh diff --git a/.gitignore b/.gitignore index 2d55cb3..ef4a3db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ /.vscode/* !/.vscode/c_cpp_properties.json /core/version.cc -/build32/ -/build64/ /build/ /*.log /*.ini diff --git a/CMakeLists.txt b/CMakeLists.txt index a82c4c0..fac2024 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.15 FATAL_ERROR) -project(Voxelius LANGUAGES C CXX VERSION 0.0.1.2526) +project(Voxelius LANGUAGES C CXX VERSION 0.0.1.2537) ## Declare build options option(BUILD_VCLIENT "Build Voxelius client" ON) @@ -31,14 +31,6 @@ add_subdirectory(core) add_subdirectory(deps) add_subdirectory(game) -find_package(Python3 REQUIRED COMPONENTS Interpreter) -add_custom_target(thirdpartylegalnotices ALL - COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR}/thirdpartylegalnotices.py" "${CMAKE_CURRENT_LIST_DIR}/deps" - BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/thirdpartylegalnotices.txt" - DEPENDS "${CMAKE_CURRENT_LIST_DIR}/thirdpartylegalnotices.py" - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/thirdpartylegalnotices.txt" DESTINATION ".") - install(FILES "${CMAKE_CURRENT_LIST_DIR}/LICENSE" DESTINATION ".") install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/data" DESTINATION ".") diff --git a/build.unix.generic.sh b/build.unix.generic.sh deleted file mode 100755 index 21be74d..0000000 --- a/build.unix.generic.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -cmake -B build -DCMAKE_BUILD_TYPE=Release || exit 1 -cmake --build build --parallel $(nproc) || exit 1 -exit 0 diff --git a/build.windows.x32.sh b/build.windows.x32.sh deleted file mode 100644 index 010a23c..0000000 --- a/build.windows.x32.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -cmake -B build32 -A Win32 || exit 1 -cmake --build build32 --config Release --parallel || exit 1 -exit 0 diff --git a/build.windows.x64.sh b/build.windows.x64.sh deleted file mode 100644 index 10c9c0e..0000000 --- a/build.windows.x64.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -cmake -B build64 -A x64 || exit 1 -cmake --build build64 --config Release --parallel || exit 1 -exit 0 diff --git a/core/io/buffer.cc b/core/io/buffer.cc index 62f981c..02b810e 100644 --- a/core/io/buffer.cc +++ b/core/io/buffer.cc @@ -4,18 +4,29 @@ #include "core/math/constexpr.hh" +io::ReadBuffer::ReadBuffer(const ReadBuffer& other) +{ + reset(other.data(), other.size()); +} + io::ReadBuffer::ReadBuffer(const void* data, std::size_t size) { + assert(data); + reset(data, size); } io::ReadBuffer::ReadBuffer(const ENetPacket* packet) { + assert(packet); + reset(packet); } io::ReadBuffer::ReadBuffer(PHYSFS_File* file) { + assert(file); + reset(file); } @@ -31,6 +42,8 @@ const std::byte* io::ReadBuffer::data(void) const void io::ReadBuffer::reset(const void* data, std::size_t size) { + assert(data); + auto bytes = reinterpret_cast(data); m_vector.assign(bytes, bytes + size); m_position = 0U; @@ -38,6 +51,8 @@ void io::ReadBuffer::reset(const void* data, std::size_t size) void io::ReadBuffer::reset(const ENetPacket* packet) { + assert(packet); + auto bytes_ptr = reinterpret_cast(packet->data); m_vector.assign(bytes_ptr, bytes_ptr + packet->dataLength); m_position = 0; @@ -45,6 +60,8 @@ void io::ReadBuffer::reset(const ENetPacket* packet) void io::ReadBuffer::reset(PHYSFS_File* file) { + assert(file); + m_vector.resize(PHYSFS_fileLength(file)); m_position = 0; @@ -52,12 +69,21 @@ void io::ReadBuffer::reset(PHYSFS_File* file) PHYSFS_readBytes(file, m_vector.data(), m_vector.size()); } -float io::ReadBuffer::read_FP32(void) +template<> +std::byte io::ReadBuffer::read(void) { - return math::uint32_to_float(read_UI32()); + if(m_position < m_vector.size()) { + auto result = m_vector[m_position]; + m_position += 1U; + return result; + } + + m_position += 1U; + return static_cast(0x00); } -std::uint8_t io::ReadBuffer::read_UI8(void) +template<> +std::uint8_t io::ReadBuffer::read(void) { if((m_position + 1U) <= m_vector.size()) { auto result = static_cast(m_vector[m_position]); @@ -69,12 +95,13 @@ std::uint8_t io::ReadBuffer::read_UI8(void) return 0; } -std::uint16_t io::ReadBuffer::read_UI16(void) +template<> +std::uint16_t io::ReadBuffer::read(void) { if((m_position + 2U) <= m_vector.size()) { auto result = UINT16_C(0x0000); - result |= static_cast(m_vector[m_position + 0U]) << 8U; - result |= static_cast(m_vector[m_position + 1U]) << 0U; + result |= (UINT16_C(0x00FF) & static_cast(m_vector[m_position + 0U])) << 8U; + result |= (UINT16_C(0x00FF) & static_cast(m_vector[m_position + 1U])) << 0U; m_position += 2U; return result; } @@ -83,14 +110,15 @@ std::uint16_t io::ReadBuffer::read_UI16(void) return 0; } -std::uint32_t io::ReadBuffer::read_UI32(void) +template<> +std::uint32_t io::ReadBuffer::read(void) { if((m_position + 4U) <= m_vector.size()) { auto result = UINT32_C(0x00000000); - result |= static_cast(m_vector[m_position + 0U]) << 24U; - result |= static_cast(m_vector[m_position + 1U]) << 16U; - result |= static_cast(m_vector[m_position + 2U]) << 8U; - result |= static_cast(m_vector[m_position + 3U]) << 0U; + result |= (UINT32_C(0x000000FF) & static_cast(m_vector[m_position + 0U])) << 24U; + result |= (UINT32_C(0x000000FF) & static_cast(m_vector[m_position + 1U])) << 16U; + result |= (UINT32_C(0x000000FF) & static_cast(m_vector[m_position + 2U])) << 8U; + result |= (UINT32_C(0x000000FF) & static_cast(m_vector[m_position + 3U])) << 0U; m_position += 4U; return result; } @@ -99,18 +127,19 @@ std::uint32_t io::ReadBuffer::read_UI32(void) return 0; } -std::uint64_t io::ReadBuffer::read_UI64(void) +template<> +std::uint64_t io::ReadBuffer::read(void) { if((m_position + 8U) <= m_vector.size()) { auto result = UINT64_C(0x0000000000000000); - result |= (0x00000000000000FF & static_cast(m_vector[m_position + 0U])) << 56U; - result |= (0x00000000000000FF & static_cast(m_vector[m_position + 1U])) << 48U; - result |= (0x00000000000000FF & static_cast(m_vector[m_position + 2U])) << 40U; - result |= (0x00000000000000FF & static_cast(m_vector[m_position + 3U])) << 32U; - result |= (0x00000000000000FF & static_cast(m_vector[m_position + 4U])) << 24U; - result |= (0x00000000000000FF & static_cast(m_vector[m_position + 5U])) << 16U; - result |= (0x00000000000000FF & static_cast(m_vector[m_position + 6U])) << 8U; - result |= (0x00000000000000FF & static_cast(m_vector[m_position + 7U])) << 0U; + result |= (UINT64_C(0x00000000000000FF) & static_cast(m_vector[m_position + 0U])) << 56U; + result |= (UINT64_C(0x00000000000000FF) & static_cast(m_vector[m_position + 1U])) << 48U; + result |= (UINT64_C(0x00000000000000FF) & static_cast(m_vector[m_position + 2U])) << 40U; + result |= (UINT64_C(0x00000000000000FF) & static_cast(m_vector[m_position + 3U])) << 32U; + result |= (UINT64_C(0x00000000000000FF) & static_cast(m_vector[m_position + 4U])) << 24U; + result |= (UINT64_C(0x00000000000000FF) & static_cast(m_vector[m_position + 5U])) << 16U; + result |= (UINT64_C(0x00000000000000FF) & static_cast(m_vector[m_position + 6U])) << 8U; + result |= (UINT64_C(0x00000000000000FF) & static_cast(m_vector[m_position + 7U])) << 0U; m_position += 8U; return result; } @@ -119,14 +148,45 @@ std::uint64_t io::ReadBuffer::read_UI64(void) return 0; } -std::string io::ReadBuffer::read_string(void) +template<> +float io::ReadBuffer::read(void) +{ + return std::bit_cast(read()); +} + +template<> +std::int8_t io::ReadBuffer::read(void) { - auto size = static_cast(read_UI16()); - auto result = std::string(); + return std::bit_cast(read()); +} - for(std::size_t i = 0; i < size; ++i) { +template<> +std::int16_t io::ReadBuffer::read(void) +{ + return std::bit_cast(read()); +} + +template<> +std::int32_t io::ReadBuffer::read(void) +{ + return std::bit_cast(read()); +} + +template<> +std::int64_t io::ReadBuffer::read(void) +{ + return std::bit_cast(read()); +} + +template<> +std::string io::ReadBuffer::read(void) +{ + std::string result; + result.resize(read()); + + for(std::size_t i = 0; i < result.size(); ++i) { if(m_position < m_vector.size()) { - result.push_back(static_cast(m_vector[m_position])); + result[i] = static_cast(m_vector[m_position]); } m_position += 1U; @@ -135,6 +195,23 @@ std::string io::ReadBuffer::read_string(void) return result; } +void io::ReadBuffer::read(void* buffer, std::size_t size) +{ + auto bytes = reinterpret_cast(buffer); + auto amount_to_read = std::min(size, m_vector.size() - m_position); + + if(amount_to_read > 0) { + std::copy(m_vector.cbegin() + m_position, m_vector.cbegin() + m_position + amount_to_read, bytes); + } + + m_position += size; +} + +io::WriteBuffer::WriteBuffer(const WriteBuffer& other) +{ + m_vector = other.m_vector; +} + std::size_t io::WriteBuffer::size(void) const { return m_vector.size(); @@ -150,18 +227,40 @@ void io::WriteBuffer::reset(void) m_vector.clear(); } -void io::WriteBuffer::write_UI8(std::uint8_t value) +void io::WriteBuffer::write(const WriteBuffer& other) +{ + m_vector.insert(m_vector.end(), other.m_vector.begin(), other.m_vector.end()); +} + +void io::WriteBuffer::write(const void* data, std::size_t size) +{ + assert(data); + + auto bytes = reinterpret_cast(data); + m_vector.insert(m_vector.end(), bytes, bytes + size); +} + +template<> +void io::WriteBuffer::write(const std::byte value) +{ + m_vector.push_back(value); +} + +template<> +void io::WriteBuffer::write(const std::uint8_t value) { m_vector.push_back(static_cast(value)); } -void io::WriteBuffer::write_UI16(std::uint16_t value) +template<> +void io::WriteBuffer::write(const std::uint16_t value) { m_vector.push_back(static_cast(UINT16_C(0xFF) & ((value & UINT16_C(0xFF00)) >> 8U))); m_vector.push_back(static_cast(UINT16_C(0xFF) & ((value & UINT16_C(0x00FF)) >> 0U))); } -void io::WriteBuffer::write_UI32(std::uint32_t value) +template<> +void io::WriteBuffer::write(const std::uint32_t value) { m_vector.push_back(static_cast(UINT32_C(0xFF) & ((value & UINT32_C(0xFF000000)) >> 24U))); m_vector.push_back(static_cast(UINT32_C(0xFF) & ((value & UINT32_C(0x00FF0000)) >> 16U))); @@ -169,7 +268,8 @@ void io::WriteBuffer::write_UI32(std::uint32_t value) m_vector.push_back(static_cast(UINT32_C(0xFF) & ((value & UINT32_C(0x000000FF)) >> 0U))); } -void io::WriteBuffer::write_UI64(std::uint64_t value) +template<> +void io::WriteBuffer::write(const std::uint64_t value) { m_vector.push_back(static_cast(UINT64_C(0xFF) & ((value & UINT64_C(0xFF00000000000000)) >> 56U))); m_vector.push_back(static_cast(UINT64_C(0xFF) & ((value & UINT64_C(0x00FF000000000000)) >> 48U))); @@ -181,25 +281,62 @@ void io::WriteBuffer::write_UI64(std::uint64_t value) m_vector.push_back(static_cast(UINT64_C(0xFF) & ((value & UINT64_C(0x00000000000000FF)) >> 0U))); } -void io::WriteBuffer::write_string(const std::string& value) +template<> +void io::WriteBuffer::write(const float value) { - const std::size_t size = math::min(UINT16_MAX, value.size()); + write(std::bit_cast(value)); +} - write_UI16(static_cast(size)); +template<> +void io::WriteBuffer::write(const std::int8_t value) +{ + write(std::bit_cast(value)); +} + +template<> +void io::WriteBuffer::write(const std::int16_t value) +{ + write(std::bit_cast(value)); +} + +template<> +void io::WriteBuffer::write(const std::int32_t value) +{ + write(std::bit_cast(value)); +} + +template<> +void io::WriteBuffer::write(const std::int64_t value) +{ + write(std::bit_cast(value)); +} + +template<> +void io::WriteBuffer::write(const std::string_view value) +{ + write(value.size()); - for(std::size_t i = 0; i < size; m_vector.push_back(static_cast(value[i++]))) { - // empty + for(const auto& character : value) { + m_vector.push_back(static_cast(character)); } } -PHYSFS_File* io::WriteBuffer::to_file(const char* path, bool append) const +PHYSFS_File* io::WriteBuffer::to_file(const std::string& path, bool append) const { - if(auto file = (append ? PHYSFS_openAppend(path) : PHYSFS_openWrite(path))) { + PHYSFS_File* file = nullptr; + + if(append) { + file = PHYSFS_openAppend(path.c_str()); + } + else { + file = PHYSFS_openWrite(path.c_str()); + } + + if(file) { PHYSFS_writeBytes(file, m_vector.data(), m_vector.size()); - return file; } - return nullptr; + return file; } ENetPacket* io::WriteBuffer::to_packet(enet_uint32 flags) const diff --git a/core/io/buffer.hh b/core/io/buffer.hh index 205381f..c301204 100644 --- a/core/io/buffer.hh +++ b/core/io/buffer.hh @@ -1,13 +1,12 @@ #ifndef CORE_IO_BUFFER_HH #define CORE_IO_BUFFER_HH 1 -#include "core/math/floathacks.hh" - namespace io { class ReadBuffer final { public: ReadBuffer(void) = default; + explicit ReadBuffer(const ReadBuffer& other); explicit ReadBuffer(const void* data, std::size_t size); explicit ReadBuffer(const ENetPacket* packet); explicit ReadBuffer(PHYSFS_File* file); @@ -20,28 +19,16 @@ public: void reset(const ENetPacket* packet); void reset(PHYSFS_File* file); - float read_FP32(void); - std::uint8_t read_UI8(void); - std::uint16_t read_UI16(void); - std::uint32_t read_UI32(void); - std::uint64_t read_UI64(void); - std::string read_string(void); + constexpr void rewind(void); + constexpr bool is_ended(void) const; + + void read(void* buffer, std::size_t size); - inline std::int8_t read_I8(void); - inline std::int16_t read_I16(void); - inline std::int32_t read_I32(void); - inline std::int64_t read_I64(void); + template + T read(void); - inline ReadBuffer& operator>>(float& value); - inline ReadBuffer& operator>>(std::int8_t& value); - inline ReadBuffer& operator>>(std::int16_t& value); - inline ReadBuffer& operator>>(std::int32_t& value); - inline ReadBuffer& operator>>(std::int64_t& value); - inline ReadBuffer& operator>>(std::uint8_t& value); - inline ReadBuffer& operator>>(std::uint16_t& value); - inline ReadBuffer& operator>>(std::uint32_t& value); - inline ReadBuffer& operator>>(std::uint64_t& value); - inline ReadBuffer& operator>>(std::string& value); + template + ReadBuffer& operator>>(T& value); private: std::vector m_vector; @@ -54,6 +41,7 @@ namespace io class WriteBuffer final { public: WriteBuffer(void) = default; + explicit WriteBuffer(const WriteBuffer& other); virtual ~WriteBuffer(void) = default; std::size_t size(void) const; @@ -61,30 +49,16 @@ public: void reset(void); - void write_FP32(float value); - void write_UI8(std::uint8_t value); - void write_UI16(std::uint16_t value); - void write_UI32(std::uint32_t value); - void write_UI64(std::uint64_t value); - void write_string(const std::string& value); + void write(const WriteBuffer& other); + void write(const void* data, std::size_t size); - inline void write_I8(std::int8_t value); - inline void write_I16(std::int16_t value); - inline void write_I32(std::int32_t value); - inline void write_I64(std::int64_t value); + template + void write(const T value); - inline WriteBuffer& operator<<(float value); - inline WriteBuffer& operator<<(std::int8_t value); - inline WriteBuffer& operator<<(std::int16_t value); - inline WriteBuffer& operator<<(std::int32_t value); - inline WriteBuffer& operator<<(std::int64_t value); - inline WriteBuffer& operator<<(std::uint8_t value); - inline WriteBuffer& operator<<(std::uint16_t value); - inline WriteBuffer& operator<<(std::uint32_t value); - inline WriteBuffer& operator<<(std::uint64_t value); - inline WriteBuffer& operator<<(const std::string& value); + template + WriteBuffer& operator<<(const T value); - PHYSFS_File* to_file(const char* path, bool append = false) const; + PHYSFS_File* to_file(const std::string& path, bool append = false) const; ENetPacket* to_packet(enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE) const; private: @@ -92,168 +66,27 @@ private: }; } // namespace io -inline std::int8_t io::ReadBuffer::read_I8(void) -{ - return static_cast(read_UI8()); -} - -inline std::int16_t io::ReadBuffer::read_I16(void) -{ - return static_cast(read_UI16()); -} - -inline std::int32_t io::ReadBuffer::read_I32(void) -{ - return static_cast(read_UI32()); -} - -inline std::int64_t io::ReadBuffer::read_I64(void) -{ - return static_cast(read_UI64()); -} - -inline io::ReadBuffer& io::ReadBuffer::operator>>(float& value) -{ - value = read_FP32(); - return *this; -} - -inline io::ReadBuffer& io::ReadBuffer::operator>>(std::int8_t& value) -{ - value = read_I8(); - return *this; -} - -inline io::ReadBuffer& io::ReadBuffer::operator>>(std::int16_t& value) -{ - value = read_I16(); - return *this; -} - -inline io::ReadBuffer& io::ReadBuffer::operator>>(std::int32_t& value) -{ - value = read_I32(); - return *this; -} - -inline io::ReadBuffer& io::ReadBuffer::operator>>(std::int64_t& value) -{ - value = read_I64(); - return *this; -} - -inline io::ReadBuffer& io::ReadBuffer::operator>>(std::uint8_t& value) -{ - value = read_UI8(); - return *this; -} - -inline io::ReadBuffer& io::ReadBuffer::operator>>(std::uint16_t& value) -{ - value = read_UI16(); - return *this; -} - -inline io::ReadBuffer& io::ReadBuffer::operator>>(std::uint32_t& value) +constexpr void io::ReadBuffer::rewind(void) { - value = read_UI32(); - return *this; -} - -inline io::ReadBuffer& io::ReadBuffer::operator>>(std::uint64_t& value) -{ - value = read_UI64(); - return *this; + m_position = 0; } -inline io::ReadBuffer& io::ReadBuffer::operator>>(std::string& value) +constexpr bool io::ReadBuffer::is_ended(void) const { - value = read_string(); - return *this; -} - -inline void io::WriteBuffer::write_FP32(float value) -{ - write_UI32(math::float_to_uint32(value)); -} - -inline void io::WriteBuffer::write_I8(std::int8_t value) -{ - write_UI8(static_cast(value)); -} - -inline void io::WriteBuffer::write_I16(std::int16_t value) -{ - write_UI16(static_cast(value)); -} - -inline void io::WriteBuffer::write_I32(std::int32_t value) -{ - write_UI32(static_cast(value)); -} - -inline void io::WriteBuffer::write_I64(std::int64_t value) -{ - write_UI64(static_cast(value)); -} - -inline io::WriteBuffer& io::WriteBuffer::operator<<(float value) -{ - write_FP32(value); - return *this; -} - -inline io::WriteBuffer& io::WriteBuffer::operator<<(std::int8_t value) -{ - write_I8(value); - return *this; -} - -inline io::WriteBuffer& io::WriteBuffer::operator<<(std::int16_t value) -{ - write_I16(value); - return *this; -} - -inline io::WriteBuffer& io::WriteBuffer::operator<<(std::int32_t value) -{ - write_I32(value); - return *this; -} - -inline io::WriteBuffer& io::WriteBuffer::operator<<(std::int64_t value) -{ - write_I64(value); - return *this; -} - -inline io::WriteBuffer& io::WriteBuffer::operator<<(std::uint8_t value) -{ - write_UI8(value); - return *this; -} - -inline io::WriteBuffer& io::WriteBuffer::operator<<(std::uint16_t value) -{ - write_UI16(value); - return *this; -} - -inline io::WriteBuffer& io::WriteBuffer::operator<<(std::uint32_t value) -{ - write_UI32(value); - return *this; + return m_position >= m_vector.size(); } -inline io::WriteBuffer& io::WriteBuffer::operator<<(std::uint64_t value) +template +io::ReadBuffer& io::ReadBuffer::operator>>(T& value) { - write_UI64(value); + value = read(); return *this; } -inline io::WriteBuffer& io::WriteBuffer::operator<<(const std::string& value) +template +io::WriteBuffer& io::WriteBuffer::operator<<(const T value) { - write_string(value); + write(value); return *this; } diff --git a/core/math/CMakeLists.txt b/core/math/CMakeLists.txt index ab03087..692492e 100644 --- a/core/math/CMakeLists.txt +++ b/core/math/CMakeLists.txt @@ -6,6 +6,5 @@ target_sources(core PRIVATE "${CMAKE_CURRENT_LIST_DIR}/constexpr.hh" "${CMAKE_CURRENT_LIST_DIR}/crc64.cc" "${CMAKE_CURRENT_LIST_DIR}/crc64.hh" - "${CMAKE_CURRENT_LIST_DIR}/floathacks.hh" "${CMAKE_CURRENT_LIST_DIR}/randomizer.hh" "${CMAKE_CURRENT_LIST_DIR}/vectors.hh") diff --git a/core/math/floathacks.hh b/core/math/floathacks.hh deleted file mode 100644 index dc8c235..0000000 --- a/core/math/floathacks.hh +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef CORE_MATH_FLOATHACKS_HH -#define CORE_MATH_FLOATHACKS_HH 1 -#pragma once - -namespace math -{ -static inline float int32_to_float(const std::int32_t value); -static inline float uint32_to_float(const std::uint32_t value); -static inline std::int32_t float_to_int32(const float value); -static inline std::uint32_t float_to_uint32(const float value); -} // namespace math - -static_assert(std::numeric_limits::is_iec559, "Floathacks only works with IEEE 754 compliant floats"); -static_assert(sizeof(std::int32_t) == sizeof(float), "Floathacks requires 32-bit integers to match float size"); - -static inline float math::int32_to_float(const std::int32_t value) -{ - union { - std::int32_t src; - float dst; - } hack; - hack.src = value; - return hack.dst; -} - -static inline float math::uint32_to_float(const std::uint32_t value) -{ - union { - std::uint32_t src; - float dst; - } hack; - hack.src = value; - return hack.dst; -} - -static inline std::int32_t math::float_to_int32(const float value) -{ - union { - float src; - std::int32_t dst; - } hack; - hack.src = value; - return hack.dst; -} - -static inline std::uint32_t math::float_to_uint32(const float value) -{ - union { - float src; - std::uint32_t dst; - } hack; - hack.src = value; - return hack.dst; -} - -#endif // CORE_MATH_FLOATHACKS_HH diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index e5cc4a7..7d94219 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -14,3 +14,11 @@ add_subdirectory(salad) add_subdirectory(spdlog) add_subdirectory(stb) add_subdirectory(thread_pool) + +find_package(Python3 REQUIRED COMPONENTS Interpreter) +add_custom_target(thirdparty_txt ALL + COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR}/thirdparty.py" "${CMAKE_CURRENT_LIST_DIR}" + BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/thirdparty.txt" + DEPENDS "${CMAKE_CURRENT_LIST_DIR}/thirdparty.py" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/thirdparty.txt" DESTINATION ".") diff --git a/deps/glfw/CMakeLists.txt b/deps/glfw/CMakeLists.txt index 24afd53..d982998 100644 --- a/deps/glfw/CMakeLists.txt +++ b/deps/glfw/CMakeLists.txt @@ -8,5 +8,5 @@ if(NOT glfw3_FOUND) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG 3.4) FetchContent_MakeAvailable(glfw) - add_library(glfw3 ALIAS glfw) + #add_library(glfw3 ALIAS glfw) endif() diff --git a/deps/imgui/CMakeLists.txt b/deps/imgui/CMakeLists.txt index 8bb8142..b45e5ba 100644 --- a/deps/imgui/CMakeLists.txt +++ b/deps/imgui/CMakeLists.txt @@ -20,7 +20,7 @@ set_target_properties(imgui PROPERTIES FOLDER Dependencies) add_library(imgui_glfw STATIC "${CMAKE_CURRENT_LIST_DIR}/include/imgui_impl_glfw.h" "${CMAKE_CURRENT_LIST_DIR}/src/imgui_impl_glfw.cpp") -target_link_libraries(imgui_glfw PUBLIC glfw3 imgui) +target_link_libraries(imgui_glfw PUBLIC glfw imgui) set_target_properties(imgui_glfw PROPERTIES FOLDER Dependencies) add_library(imgui_opengl3 STATIC diff --git a/deps/thirdparty.py b/deps/thirdparty.py new file mode 100644 index 0000000..7171bf4 --- /dev/null +++ b/deps/thirdparty.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +import os + +# It is quite annoying to have to write all the dependency notices +# by hand, so this script goes through the dependency list and generates +# a file with all the licenses automatically during the build process + +def read_description_file(subdirectory): + description_filename = "DESCRIPTION" + description_extensions = [ "", ".txt", ".md", ".rst" ] + for extension in description_extensions: + fill_path = os.path.join(subdirectory, description_filename + extension) + if os.path.exists(fill_path): + with open(fill_path, 'r', encoding='utf-8') as file: + return file.read().rstrip().splitlines()[0] + return None + +def read_license_file(subdirectory): + license_filenames = [ "LICENSE", "COPYING", "NOTICE" ] + license_extensions = [ "", ".txt", ".md", ".rst" ] + for filename in license_filenames: + for extension in license_extensions: + fill_path = os.path.join(subdirectory, filename + extension) + if os.path.exists(fill_path): + with open(fill_path, 'r', encoding='utf-8') as file: + return file.read().rstrip() + return None + +def get_dependencies(directory): + dependencies = [] + for subdirectory in os.listdir(directory): + subdirectory_path = os.path.join(directory, subdirectory) + if os.path.isdir(subdirectory_path): + license = read_license_file(subdirectory_path) + description = read_description_file(subdirectory_path) + if description and len(description) > 80: + description = description[:77] + "..." + if license: + dependencies.append((subdirectory, license, description)) + return dependencies + +assert len(os.sys.argv) > 1, "Please provide the path to the dependencies directory." +dependencies_dir = os.sys.argv[1] +dependencies = get_dependencies(dependencies_dir) +assert len(dependencies) > 0, "No licenses found in the dependencies directory." + +with open("thirdparty.txt", 'w', encoding='utf-8') as out_file: + out_file.write("QFengine uses third-party code for certain functions. All the\n") + out_file.write("license texts are included below using an automated script; this generated\n") + out_file.write("file is to be included in binary distributions of the project.\n\n") + + for name, license, description in dependencies: + out_file.write(f"{'=' * 80}\n") + if description and len(description) > 0: + out_file.write(f"{name} - {description}\n") + else: + out_file.write(f"{name}\n") + out_file.write(f"{'=' * 80}\n") + out_file.write(f"{license}\n\n\n") diff --git a/game/client/CMakeLists.txt b/game/client/CMakeLists.txt index b40dbb1..8fbc48d 100644 --- a/game/client/CMakeLists.txt +++ b/game/client/CMakeLists.txt @@ -23,7 +23,7 @@ target_compile_definitions(vclient PUBLIC GLFW_INCLUDE_NONE) target_include_directories(vclient PRIVATE "${PROJECT_SOURCE_DIR}") target_include_directories(vclient PRIVATE "${PROJECT_SOURCE_DIR}/game") target_precompile_headers(vclient PRIVATE "${CMAKE_CURRENT_LIST_DIR}/pch.hh") -target_link_libraries(vclient PUBLIC shared dr_libs glad glfw3 imgui imgui_glfw imgui_opengl3 salad) +target_link_libraries(vclient PUBLIC shared dr_libs glad glfw imgui imgui_glfw imgui_opengl3 salad) add_subdirectory(config) add_subdirectory(entity) diff --git a/game/shared/protocol.cc b/game/shared/protocol.cc index 3af891d..f8a9ba8 100644 --- a/game/shared/protocol.cc +++ b/game/shared/protocol.cc @@ -3,7 +3,6 @@ #include "shared/protocol.hh" #include "core/io/buffer.hh" -#include "core/math/floathacks.hh" #include "shared/entity/head.hh" #include "shared/entity/player.hh" @@ -20,59 +19,59 @@ static io::WriteBuffer write_buffer; ENetPacket* protocol::encode(const protocol::StatusRequest& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::StatusRequest::ID); - write_buffer.write_UI32(packet.version); + write_buffer.write(protocol::StatusRequest::ID); + write_buffer.write(packet.version); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::StatusResponse& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::StatusResponse::ID); - write_buffer.write_UI32(packet.version); - write_buffer.write_UI16(packet.max_players); - write_buffer.write_UI16(packet.num_players); - write_buffer.write_string(packet.motd); + write_buffer.write(protocol::StatusResponse::ID); + write_buffer.write(packet.version); + write_buffer.write(packet.max_players); + write_buffer.write(packet.num_players); + write_buffer.write(packet.motd); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::LoginRequest& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::LoginRequest::ID); - write_buffer.write_UI32(packet.version); - write_buffer.write_UI64(packet.voxel_registry_checksum); - write_buffer.write_UI64(packet.item_registry_checksum); - write_buffer.write_UI64(packet.password_hash); - write_buffer.write_string(packet.username.substr(0, protocol::MAX_USERNAME)); + write_buffer.write(protocol::LoginRequest::ID); + write_buffer.write(packet.version); + write_buffer.write(packet.voxel_registry_checksum); + write_buffer.write(packet.item_registry_checksum); + write_buffer.write(packet.password_hash); + write_buffer.write(packet.username.substr(0, protocol::MAX_USERNAME)); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::LoginResponse& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::LoginResponse::ID); - write_buffer.write_UI16(packet.client_index); - write_buffer.write_UI64(packet.client_identity); - write_buffer.write_UI16(packet.server_tickrate); + write_buffer.write(protocol::LoginResponse::ID); + write_buffer.write(packet.client_index); + write_buffer.write(packet.client_identity); + write_buffer.write(packet.server_tickrate); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::Disconnect& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::Disconnect::ID); - write_buffer.write_string(packet.reason); + write_buffer.write(protocol::Disconnect::ID); + write_buffer.write(packet.reason); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::ChunkVoxels& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::ChunkVoxels::ID); - write_buffer.write_I32(packet.chunk.x); - write_buffer.write_I32(packet.chunk.y); - write_buffer.write_I32(packet.chunk.z); + write_buffer.write(protocol::ChunkVoxels::ID); + write_buffer.write(packet.chunk.x); + write_buffer.write(packet.chunk.y); + write_buffer.write(packet.chunk.z); packet.voxels.serialize(write_buffer); return write_buffer.to_packet(flags); } @@ -80,135 +79,135 @@ ENetPacket* protocol::encode(const protocol::ChunkVoxels& packet, enet_uint32 fl ENetPacket* protocol::encode(const protocol::EntityTransform& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::EntityTransform::ID); - write_buffer.write_UI64(static_cast(packet.entity)); - write_buffer.write_I32(packet.chunk.x); - write_buffer.write_I32(packet.chunk.y); - write_buffer.write_I32(packet.chunk.z); - write_buffer.write_FP32(packet.local.x); - write_buffer.write_FP32(packet.local.y); - write_buffer.write_FP32(packet.local.z); - write_buffer.write_FP32(packet.angles.x); - write_buffer.write_FP32(packet.angles.y); - write_buffer.write_FP32(packet.angles.z); + write_buffer.write(protocol::EntityTransform::ID); + write_buffer.write(static_cast(packet.entity)); + write_buffer.write(packet.chunk.x); + write_buffer.write(packet.chunk.y); + write_buffer.write(packet.chunk.z); + write_buffer.write(packet.local.x); + write_buffer.write(packet.local.y); + write_buffer.write(packet.local.z); + write_buffer.write(packet.angles.x); + write_buffer.write(packet.angles.y); + write_buffer.write(packet.angles.z); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::EntityHead& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::EntityHead::ID); - write_buffer.write_UI64(static_cast(packet.entity)); - write_buffer.write_FP32(packet.angles.x); - write_buffer.write_FP32(packet.angles.y); - write_buffer.write_FP32(packet.angles.z); + write_buffer.write(protocol::EntityHead::ID); + write_buffer.write(static_cast(packet.entity)); + write_buffer.write(packet.angles.x); + write_buffer.write(packet.angles.y); + write_buffer.write(packet.angles.z); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::EntityVelocity& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::EntityVelocity::ID); - write_buffer.write_UI64(static_cast(packet.entity)); - write_buffer.write_FP32(packet.value.x); - write_buffer.write_FP32(packet.value.y); - write_buffer.write_FP32(packet.value.z); + write_buffer.write(protocol::EntityVelocity::ID); + write_buffer.write(static_cast(packet.entity)); + write_buffer.write(packet.value.x); + write_buffer.write(packet.value.y); + write_buffer.write(packet.value.z); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::SpawnPlayer& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::SpawnPlayer::ID); - write_buffer.write_UI64(static_cast(packet.entity)); + write_buffer.write(protocol::SpawnPlayer::ID); + write_buffer.write(static_cast(packet.entity)); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::ChatMessage& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::ChatMessage::ID); - write_buffer.write_UI16(packet.type); - write_buffer.write_string(packet.sender.substr(0, protocol::MAX_USERNAME)); - write_buffer.write_string(packet.message.substr(0, protocol::MAX_CHAT)); + write_buffer.write(protocol::ChatMessage::ID); + write_buffer.write(packet.type); + write_buffer.write(packet.sender.substr(0, protocol::MAX_USERNAME)); + write_buffer.write(packet.message.substr(0, protocol::MAX_CHAT)); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::SetVoxel& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::SetVoxel::ID); - write_buffer.write_I64(packet.vpos.x); - write_buffer.write_I64(packet.vpos.y); - write_buffer.write_I64(packet.vpos.z); - write_buffer.write_UI16(packet.voxel); - write_buffer.write_UI16(packet.flags); + write_buffer.write(protocol::SetVoxel::ID); + write_buffer.write(packet.vpos.x); + write_buffer.write(packet.vpos.y); + write_buffer.write(packet.vpos.z); + write_buffer.write(packet.voxel); + write_buffer.write(packet.flags); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::RemoveEntity& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::RemoveEntity::ID); - write_buffer.write_UI64(static_cast(packet.entity)); + write_buffer.write(protocol::RemoveEntity::ID); + write_buffer.write(static_cast(packet.entity)); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::EntityPlayer& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::EntityPlayer::ID); - write_buffer.write_UI64(static_cast(packet.entity)); + write_buffer.write(protocol::EntityPlayer::ID); + write_buffer.write(static_cast(packet.entity)); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::ScoreboardUpdate& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::ScoreboardUpdate::ID); - write_buffer.write_UI16(static_cast(packet.names.size())); + write_buffer.write(protocol::ScoreboardUpdate::ID); + write_buffer.write(static_cast(packet.names.size())); for(const std::string& username : packet.names) - write_buffer.write_string(username.substr(0, protocol::MAX_USERNAME)); + write_buffer.write(username.substr(0, protocol::MAX_USERNAME)); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::RequestChunk& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::RequestChunk::ID); - write_buffer.write_I32(packet.cpos.x); - write_buffer.write_I32(packet.cpos.y); - write_buffer.write_I32(packet.cpos.z); + write_buffer.write(protocol::RequestChunk::ID); + write_buffer.write(packet.cpos.x); + write_buffer.write(packet.cpos.y); + write_buffer.write(packet.cpos.z); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::GenericSound& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::GenericSound::ID); - write_buffer.write_string(packet.sound.substr(0, protocol::MAX_SOUNDNAME)); - write_buffer.write_UI8(packet.looping); - write_buffer.write_FP32(packet.pitch); + write_buffer.write(protocol::GenericSound::ID); + write_buffer.write(packet.sound.substr(0, protocol::MAX_SOUNDNAME)); + write_buffer.write(packet.looping); + write_buffer.write(packet.pitch); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::EntitySound& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::EntitySound::ID); - write_buffer.write_UI64(static_cast(packet.entity)); - write_buffer.write_string(packet.sound.substr(0, protocol::MAX_SOUNDNAME)); - write_buffer.write_UI8(packet.looping); - write_buffer.write_FP32(packet.pitch); + write_buffer.write(protocol::EntitySound::ID); + write_buffer.write(static_cast(packet.entity)); + write_buffer.write(packet.sound.substr(0, protocol::MAX_SOUNDNAME)); + write_buffer.write(packet.looping); + write_buffer.write(packet.pitch); return write_buffer.to_packet(flags); } ENetPacket* protocol::encode(const protocol::DimensionInfo& packet, enet_uint32 flags) { write_buffer.reset(); - write_buffer.write_UI16(protocol::DimensionInfo::ID); - write_buffer.write_string(packet.name); - write_buffer.write_FP32(packet.gravity); + write_buffer.write(protocol::DimensionInfo::ID); + write_buffer.write(packet.name); + write_buffer.write(packet.gravity); return write_buffer.to_packet(flags); } @@ -263,145 +262,163 @@ void protocol::decode(entt::dispatcher& dispatcher, const ENetPacket* packet, EN protocol::EntitySound entity_sound; protocol::DimensionInfo dimension_info; - auto id = read_buffer.read_UI16(); + auto id = read_buffer.read(); switch(id) { case protocol::StatusRequest::ID: status_request.peer = peer; - status_request.version = read_buffer.read_UI32(); + status_request.version = read_buffer.read(); dispatcher.trigger(status_request); break; + case protocol::StatusResponse::ID: status_response.peer = peer; - status_response.version = read_buffer.read_UI32(); - status_response.max_players = read_buffer.read_UI16(); - status_response.num_players = read_buffer.read_UI16(); - status_response.motd = read_buffer.read_string(); + status_response.version = read_buffer.read(); + status_response.max_players = read_buffer.read(); + status_response.num_players = read_buffer.read(); + status_response.motd = read_buffer.read(); dispatcher.trigger(status_response); break; + case protocol::LoginRequest::ID: login_request.peer = peer; - login_request.version = read_buffer.read_UI32(); - login_request.voxel_registry_checksum = read_buffer.read_UI64(); - login_request.item_registry_checksum = read_buffer.read_UI64(); - login_request.password_hash = read_buffer.read_UI64(); - login_request.username = read_buffer.read_string(); + login_request.version = read_buffer.read(); + login_request.voxel_registry_checksum = read_buffer.read(); + login_request.item_registry_checksum = read_buffer.read(); + login_request.password_hash = read_buffer.read(); + login_request.username = read_buffer.read(); dispatcher.trigger(login_request); break; + case protocol::LoginResponse::ID: login_response.peer = peer; - login_response.client_index = read_buffer.read_UI16(); - login_response.client_identity = read_buffer.read_UI64(); - login_response.server_tickrate = read_buffer.read_UI16(); + login_response.client_index = read_buffer.read(); + login_response.client_identity = read_buffer.read(); + login_response.server_tickrate = read_buffer.read(); dispatcher.trigger(login_response); break; + case protocol::Disconnect::ID: disconnect.peer = peer; - disconnect.reason = read_buffer.read_string(); + disconnect.reason = read_buffer.read(); dispatcher.trigger(disconnect); break; + case protocol::ChunkVoxels::ID: chunk_voxels.peer = peer; - chunk_voxels.chunk.x = read_buffer.read_I32(); - chunk_voxels.chunk.y = read_buffer.read_I32(); - chunk_voxels.chunk.z = read_buffer.read_I32(); + chunk_voxels.chunk.x = read_buffer.read(); + chunk_voxels.chunk.y = read_buffer.read(); + chunk_voxels.chunk.z = read_buffer.read(); chunk_voxels.voxels.deserialize(read_buffer); dispatcher.trigger(chunk_voxels); break; + case protocol::EntityTransform::ID: entity_transform.peer = peer; - entity_transform.entity = static_cast(read_buffer.read_UI64()); - entity_transform.chunk.x = read_buffer.read_I32(); - entity_transform.chunk.y = read_buffer.read_I32(); - entity_transform.chunk.z = read_buffer.read_I32(); - entity_transform.local.x = read_buffer.read_FP32(); - entity_transform.local.y = read_buffer.read_FP32(); - entity_transform.local.z = read_buffer.read_FP32(); - entity_transform.angles.x = read_buffer.read_FP32(); - entity_transform.angles.y = read_buffer.read_FP32(); - entity_transform.angles.z = read_buffer.read_FP32(); + entity_transform.entity = static_cast(read_buffer.read()); + entity_transform.chunk.x = read_buffer.read(); + entity_transform.chunk.y = read_buffer.read(); + entity_transform.chunk.z = read_buffer.read(); + entity_transform.local.x = read_buffer.read(); + entity_transform.local.y = read_buffer.read(); + entity_transform.local.z = read_buffer.read(); + entity_transform.angles.x = read_buffer.read(); + entity_transform.angles.y = read_buffer.read(); + entity_transform.angles.z = read_buffer.read(); dispatcher.trigger(entity_transform); break; + case protocol::EntityHead::ID: entity_head.peer = peer; - entity_head.entity = static_cast(read_buffer.read_UI64()); - entity_head.angles[0] = read_buffer.read_FP32(); - entity_head.angles[1] = read_buffer.read_FP32(); - entity_head.angles[2] = read_buffer.read_FP32(); + entity_head.entity = static_cast(read_buffer.read()); + entity_head.angles[0] = read_buffer.read(); + entity_head.angles[1] = read_buffer.read(); + entity_head.angles[2] = read_buffer.read(); dispatcher.trigger(entity_head); break; + case protocol::EntityVelocity::ID: entity_velocity.peer = peer; - entity_velocity.entity = static_cast(read_buffer.read_UI64()); - entity_velocity.value.x = read_buffer.read_FP32(); - entity_velocity.value.y = read_buffer.read_FP32(); - entity_velocity.value.z = read_buffer.read_FP32(); + entity_velocity.entity = static_cast(read_buffer.read()); + entity_velocity.value.x = read_buffer.read(); + entity_velocity.value.y = read_buffer.read(); + entity_velocity.value.z = read_buffer.read(); dispatcher.trigger(entity_velocity); break; + case protocol::SpawnPlayer::ID: spawn_player.peer = peer; - spawn_player.entity = static_cast(read_buffer.read_UI64()); + spawn_player.entity = static_cast(read_buffer.read()); dispatcher.trigger(spawn_player); break; + case protocol::ChatMessage::ID: chat_message.peer = peer; - chat_message.type = read_buffer.read_UI16(); - chat_message.sender = read_buffer.read_string(); - chat_message.message = read_buffer.read_string(); + chat_message.type = read_buffer.read(); + chat_message.sender = read_buffer.read(); + chat_message.message = read_buffer.read(); dispatcher.trigger(chat_message); break; + case protocol::SetVoxel::ID: set_voxel.peer = peer; - set_voxel.vpos.x = read_buffer.read_I64(); - set_voxel.vpos.y = read_buffer.read_I64(); - set_voxel.vpos.z = read_buffer.read_I64(); - set_voxel.voxel = read_buffer.read_UI16(); - set_voxel.flags = read_buffer.read_UI16(); + set_voxel.vpos.x = read_buffer.read(); + set_voxel.vpos.y = read_buffer.read(); + set_voxel.vpos.z = read_buffer.read(); + set_voxel.voxel = read_buffer.read(); + set_voxel.flags = read_buffer.read(); dispatcher.trigger(set_voxel); break; + case protocol::RemoveEntity::ID: remove_entity.peer = peer; - remove_entity.entity = static_cast(read_buffer.read_UI64()); + remove_entity.entity = static_cast(read_buffer.read()); dispatcher.trigger(remove_entity); break; + case protocol::EntityPlayer::ID: entity_player.peer = peer; - entity_player.entity = static_cast(read_buffer.read_UI64()); + entity_player.entity = static_cast(read_buffer.read()); dispatcher.trigger(entity_player); break; + case protocol::ScoreboardUpdate::ID: scoreboard_update.peer = peer; - scoreboard_update.names.resize(read_buffer.read_UI16()); + scoreboard_update.names.resize(read_buffer.read()); for(std::size_t i = 0; i < scoreboard_update.names.size(); ++i) - scoreboard_update.names[i] = read_buffer.read_string(); + scoreboard_update.names[i] = read_buffer.read(); dispatcher.trigger(scoreboard_update); break; + case protocol::RequestChunk::ID: request_chunk.peer = peer; - request_chunk.cpos.x = read_buffer.read_UI32(); - request_chunk.cpos.y = read_buffer.read_UI32(); - request_chunk.cpos.z = read_buffer.read_UI32(); + request_chunk.cpos.x = read_buffer.read(); + request_chunk.cpos.y = read_buffer.read(); + request_chunk.cpos.z = read_buffer.read(); dispatcher.trigger(request_chunk); break; + case protocol::GenericSound::ID: generic_sound.peer = peer; - generic_sound.sound = read_buffer.read_string(); - generic_sound.looping = read_buffer.read_UI8(); - generic_sound.pitch = read_buffer.read_FP32(); + generic_sound.sound = read_buffer.read(); + generic_sound.looping = read_buffer.read(); + generic_sound.pitch = read_buffer.read(); dispatcher.trigger(generic_sound); break; + case protocol::EntitySound::ID: entity_sound.peer = peer; - entity_sound.entity = static_cast(read_buffer.read_UI64()); - entity_sound.sound = read_buffer.read_string(); - entity_sound.looping = read_buffer.read_UI8(); - entity_sound.pitch = read_buffer.read_FP32(); + entity_sound.entity = static_cast(read_buffer.read()); + entity_sound.sound = read_buffer.read(); + entity_sound.looping = read_buffer.read(); + entity_sound.pitch = read_buffer.read(); dispatcher.trigger(entity_sound); break; + case protocol::DimensionInfo::ID: dimension_info.peer = peer; - dimension_info.name = read_buffer.read_string(); - dimension_info.gravity = read_buffer.read_FP32(); + dimension_info.name = read_buffer.read(); + dimension_info.gravity = read_buffer.read(); dispatcher.trigger(dimension_info); break; } diff --git a/game/shared/world/voxel_storage.cc b/game/shared/world/voxel_storage.cc index e28c34f..68e261c 100644 --- a/game/shared/world/voxel_storage.cc +++ b/game/shared/world/voxel_storage.cc @@ -20,10 +20,10 @@ void world::VoxelStorage::serialize(io::WriteBuffer& buffer) const mz_compress(zdata.data(), &bound, reinterpret_cast(net_storage.data()), sizeof(VoxelStorage)); - buffer.write_UI64(bound); + buffer.write(bound); // Write all the compressed data into the buffer - for(std::size_t i = 0; i < bound; buffer.write_UI8(zdata[i++])) { + for(std::size_t i = 0; i < bound; buffer.write(zdata[i++])) { // empty } } @@ -31,11 +31,11 @@ void world::VoxelStorage::serialize(io::WriteBuffer& buffer) const void world::VoxelStorage::deserialize(io::ReadBuffer& buffer) { auto size = static_cast(sizeof(VoxelStorage)); - auto bound = static_cast(buffer.read_UI64()); + auto bound = static_cast(buffer.read()); auto zdata = std::vector(bound); // Read all the compressed data from the buffer - for(std::size_t i = 0; i < bound; zdata[i++] = buffer.read_UI8()) { + for(std::size_t i = 0; i < bound; zdata[i++] = buffer.read()) { // empty } diff --git a/package.unix.generic.sh b/package.unix.generic.sh deleted file mode 100755 index d051138..0000000 --- a/package.unix.generic.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -${SHELL} build.unix.generic.sh || exit 1 -cpack --config build/CPackConfig.cmake -G ZIP || exit 1 -exit 0 diff --git a/package.windows.x32.sh b/package.windows.x32.sh deleted file mode 100644 index b217c6d..0000000 --- a/package.windows.x32.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -${SHELL} build.windows.x32.sh || exit 1 -cpack --config build32/CPackConfig.cmake -G ZIP || exit 1 -exit 0 diff --git a/package.windows.x64.sh b/package.windows.x64.sh deleted file mode 100644 index d5d056c..0000000 --- a/package.windows.x64.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -${SHELL} build.windows.x64.sh || exit 1 -cpack --config build64/CPackConfig.cmake -G ZIP || exit 1 -exit 0 diff --git a/thirdpartylegalnotices.py b/thirdpartylegalnotices.py deleted file mode 100644 index 64bb03b..0000000 --- a/thirdpartylegalnotices.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python3 - -import os - -# It is quite annoying to have to write all the dependency notices -# by hand, so this script goes through the dependency list and generates -# a file with all the licenses automatically during the build process - -def read_description_file(subdirectory): - description_filename = "DESCRIPTION" - description_extensions = [ "", ".txt", ".md", ".rst" ] - for extension in description_extensions: - fill_path = os.path.join(subdirectory, description_filename + extension) - if os.path.exists(fill_path): - with open(fill_path, 'r', encoding='utf-8') as file: - return file.read().rstrip().splitlines()[0] - return None - -def read_license_file(subdirectory): - license_filenames = [ "LICENSE", "COPYING", "NOTICE" ] - license_extensions = [ "", ".txt", ".md", ".rst" ] - for filename in license_filenames: - for extension in license_extensions: - fill_path = os.path.join(subdirectory, filename + extension) - if os.path.exists(fill_path): - with open(fill_path, 'r', encoding='utf-8') as file: - return file.read().rstrip() - return None - -def get_dependencies(directory): - dependencies = [] - for subdirectory in os.listdir(directory): - subdirectory_path = os.path.join(directory, subdirectory) - if os.path.isdir(subdirectory_path): - license = read_license_file(subdirectory_path) - description = read_description_file(subdirectory_path) - if description and len(description) > 80: - description = description[:77] + "..." - if license: - dependencies.append((subdirectory, license, description)) - return dependencies - -assert len(os.sys.argv) > 1, "Please provide the path to the dependencies directory." -dependencies_dir = os.sys.argv[1] -dependencies = get_dependencies(dependencies_dir) -assert len(dependencies) > 0, "No licenses found in the dependencies directory." - -with open("thirdpartylegalnotices.txt", 'w', encoding='utf-8') as out_file: - out_file.write("Voxelius uses third-party code for certain functions. All the\n") - out_file.write("license texts are included below using an automated script; this generated\n") - out_file.write("file is to be included in binary distributions of the project.\n\n") - - for name, license, description in dependencies: - out_file.write(f"{'=' * 80}\n") - if description and len(description) > 0: - out_file.write(f"{name} - {description}\n") - else: - out_file.write(f"{name}\n") - out_file.write(f"{'=' * 80}\n") - out_file.write(f"{license}\n\n\n") diff --git a/tools/build-unix.sh b/tools/build-unix.sh new file mode 100755 index 0000000..ad1edd2 --- /dev/null +++ b/tools/build-unix.sh @@ -0,0 +1,5 @@ +#!/usr/bin/sh +cd $(dirname $(dirname ${0})) || exit 1 +cmake -B build/unix/${1:-Debug} -DCMAKE_BUILD_TYPE=${1:-Debug} || exit 1 +cmake --build build/unix/${1:-Debug} --config ${1:-Debug} --parallel $(nproc) || exit 1 +exit 0 diff --git a/tools/build-win32.sh b/tools/build-win32.sh new file mode 100644 index 0000000..af152fc --- /dev/null +++ b/tools/build-win32.sh @@ -0,0 +1,5 @@ +#!/usr/bin/sh +cd $(dirname $(dirname ${0})) || exit 1 +cmake -B build/win32 -A Win32 -DCMAKE_BUILD_TYPE=${1:-Debug} || exit 1 +cmake --build build/win32 --config ${1:-Debug} --parallel || exit 1 +exit 0 diff --git a/tools/build-win64.sh b/tools/build-win64.sh new file mode 100644 index 0000000..50ca07a --- /dev/null +++ b/tools/build-win64.sh @@ -0,0 +1,5 @@ +#!/usr/bin/sh +cd $(dirname $(dirname ${0})) || exit 1 +cmake -B build/win64 -A x64 -DCMAKE_BUILD_TYPE=${1:-Debug} || exit 1 +cmake --build build/win64 --config ${1:-Debug} --parallel || exit 1 +exit 0 diff --git a/tools/pack-unix.sh b/tools/pack-unix.sh new file mode 100644 index 0000000..cbadee4 --- /dev/null +++ b/tools/pack-unix.sh @@ -0,0 +1,5 @@ +#!/usr/bin/sh +cd $(dirname $(dirname ${0})) || exit 1 +${SHELL} tools/build-unix.sh Release || exit 1 +cpack --config build/unix/CPackConfig.cmake -G ZIP || exit 1 +exit 0 diff --git a/tools/pack-win32.sh b/tools/pack-win32.sh new file mode 100644 index 0000000..351df9d --- /dev/null +++ b/tools/pack-win32.sh @@ -0,0 +1,5 @@ +#!/usr/bin/sh +cd $(dirname $(dirname ${0})) || exit 1 +${SHELL} tools/build-win32.sh Release || exit 1 +cpack --config build/win32/CPackConfig.cmake -G ZIP || exit 1 +exit 0 diff --git a/tools/pack-win64.sh b/tools/pack-win64.sh new file mode 100644 index 0000000..5cb5404 --- /dev/null +++ b/tools/pack-win64.sh @@ -0,0 +1,5 @@ +#!/usr/bin/sh +cd $(dirname $(dirname ${0})) || exit 1 +${SHELL} tools/build-win64.sh Release || exit 1 +cpack --config build/win64/CPackConfig.cmake -G ZIP || exit 1 +exit 0 -- cgit