Skip to content

Commit

Permalink
Merge branch 'headless-mode' into base-loot-property
Browse files Browse the repository at this point in the history
  • Loading branch information
MihailRis committed Dec 27, 2024
2 parents ba1d4ab + 5eb739f commit ad12f3a
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 40 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/windows-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ jobs:
cp build/*.dll packaged/
cp -r build/res/* packaged/res/
mv packaged/VoxelEngine.exe packaged/VoxelCore.exe
- env:
MSYS2_LOCATION: ${{ steps.msys2.outputs.msys2-location }}
name: Add lua51.dll to the package
run: |
cp $env:MSYS2_LOCATION/clang64/bin/lua51.dll ${{ github.workspace }}/packaged/
working-directory: ${{ github.workspace }}
- uses: actions/upload-artifact@v4
with:
name: Windows-Build
Expand All @@ -73,4 +67,4 @@ jobs:
shell: msys2 {0}
working-directory: ${{ github.workspace }}
run: |
packaged/vctest.exe -e packaged/VoxelCore.exe -d dev/tests -u build --output-always
packaged/vctest.exe -e packaged/VoxelCore.exe -d dev/tests -u build --output-always
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.26)
project(VoxelEngine)

option(VOXELENGINE_BUILD_APPDIR "" OFF)
Expand Down
2 changes: 1 addition & 1 deletion res/shaders/lib/commons.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ vec3 pick_sky_color(samplerCube cubemap) {
vec3 skyLightColor = texture(cubemap, vec3(0.4f, 0.0f, 0.4f)).rgb;
skyLightColor *= SKY_LIGHT_TINT;
skyLightColor = min(vec3(1.0), skyLightColor*SKY_LIGHT_MUL);
skyLightColor = max(MAX_SKY_LIGHT, skyLightColor);
skyLightColor = max(MIN_SKY_LIGHT, skyLightColor);
return skyLightColor;
}

Expand Down
2 changes: 1 addition & 1 deletion res/shaders/lib/constants.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// lighting
#define SKY_LIGHT_MUL 2.9
#define SKY_LIGHT_TINT vec3(0.9, 0.8, 1.0)
#define MAX_SKY_LIGHT vec3(0.1, 0.11, 0.14)
#define MIN_SKY_LIGHT vec3(0.2, 0.25, 0.33)

// fog
#define FOG_POS_SCALE vec3(1.0, 0.2, 1.0)
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ find_package(GLEW REQUIRED)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
# specific for vcpkg
find_package(OpenAL CONFIG REQUIRED)
set(OPENAL_LIBRARY OpenAL::OpenAL)
else()
find_package(OpenAL REQUIRED)
endif()
Expand Down Expand Up @@ -69,4 +70,4 @@ endif()
include_directories(${LUA_INCLUDE_DIR})
include_directories(${CURL_INCLUDE_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(${PROJECT_NAME} ${LIBS} glfw OpenGL::GL OpenAL::OpenAL GLEW::GLEW ZLIB::ZLIB PNG::PNG CURL::libcurl ${VORBISLIB} ${LUA_LIBRARIES} ${CMAKE_DL_LIBS})
target_link_libraries(${PROJECT_NAME} ${LIBS} glfw OpenGL::GL ${OPENAL_LIBRARY} GLEW::GLEW ZLIB::ZLIB PNG::PNG CURL::libcurl ${VORBISLIB} ${LUA_LIBRARIES} ${CMAKE_DL_LIBS})
50 changes: 32 additions & 18 deletions src/coders/byte_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "util/data_io.hpp"

ByteBuilder::ByteBuilder(size_t size) {
buffer.reserve(size);
}

void ByteBuilder::put(ubyte b) {
buffer.push_back(b);
}
Expand All @@ -31,37 +35,37 @@ void ByteBuilder::put(const ubyte* arr, size_t size) {
}
}

void ByteBuilder::putInt16(int16_t val) {
void ByteBuilder::putInt16(int16_t val, bool bigEndian) {
size_t size = buffer.size();
buffer.resize(buffer.size() + sizeof(int16_t));
val = dataio::h2le(val);
val = bigEndian ? dataio::h2be(val) : dataio::h2le(val);
std::memcpy(buffer.data()+size, &val, sizeof(int16_t));
}

void ByteBuilder::putInt32(int32_t val) {
void ByteBuilder::putInt32(int32_t val, bool bigEndian) {
size_t size = buffer.size();
buffer.resize(buffer.size() + sizeof(int32_t));
val = dataio::h2le(val);
val = bigEndian ? dataio::h2be(val) : dataio::h2le(val);
std::memcpy(buffer.data()+size, &val, sizeof(int32_t));
}

void ByteBuilder::putInt64(int64_t val) {
void ByteBuilder::putInt64(int64_t val, bool bigEndian) {
size_t size = buffer.size();
buffer.resize(buffer.size() + sizeof(int64_t));
val = dataio::h2le(val);
val = bigEndian ? dataio::h2be(val) : dataio::h2le(val);
std::memcpy(buffer.data()+size, &val, sizeof(int64_t));
}

void ByteBuilder::putFloat32(float val) {
void ByteBuilder::putFloat32(float val, bool bigEndian) {
int32_t i32_val;
std::memcpy(&i32_val, &val, sizeof(int32_t));
putInt32(i32_val);
putInt32(i32_val, bigEndian);
}

void ByteBuilder::putFloat64(double val) {
void ByteBuilder::putFloat64(double val, bool bigEndian) {
int64_t i64_val;
std::memcpy(&i64_val, &val, sizeof(int64_t));
putInt64(i64_val);
putInt64(i64_val, bigEndian);
}

void ByteBuilder::set(size_t position, ubyte val) {
Expand Down Expand Up @@ -95,6 +99,10 @@ ByteReader::ByteReader(const ubyte* data) : data(data), size(4), pos(0) {
size = getInt32();
}

ByteReader::ByteReader(const std::vector<ubyte>& data)
: data(data.data()), size(data.size()), pos(0) {
}

void ByteReader::checkMagic(const char* data, size_t size) {
if (pos + size >= this->size) {
throw std::runtime_error("invalid magic number");
Expand Down Expand Up @@ -129,45 +137,51 @@ ubyte ByteReader::peek() {
return data[pos];
}

int16_t ByteReader::getInt16() {
int16_t ByteReader::getInt16(bool bigEndian) {
if (pos + sizeof(int16_t) > size) {
throw std::runtime_error("buffer underflow");
}
int16_t value;
std::memcpy(&value, data + pos, sizeof(int16_t));
pos += sizeof(int16_t);
return dataio::le2h(value);
return bigEndian ? dataio::be2h(value) : dataio::le2h(value);
}

int32_t ByteReader::getInt32() {
int32_t ByteReader::getInt32(bool bigEndian) {
if (pos + sizeof(int32_t) > size) {
throw std::runtime_error("buffer underflow");
}
int32_t value;
std::memcpy(&value, data + pos, sizeof(int32_t));
pos += sizeof(int32_t);
return dataio::le2h(value);
return bigEndian ? dataio::be2h(value) : dataio::le2h(value);
}

int64_t ByteReader::getInt64() {
int64_t ByteReader::getInt64(bool bigEndian) {
if (pos + sizeof(int64_t) > size) {
throw std::runtime_error("buffer underflow");
}
int64_t value;
std::memcpy(&value, data + pos, sizeof(int64_t));
pos += sizeof(int64_t);
return dataio::le2h(value);
return bigEndian ? dataio::be2h(value) : dataio::le2h(value);
}

float ByteReader::getFloat32() {
float ByteReader::getFloat32(bool bigEndian) {
int32_t i32_val = getInt32();
if (bigEndian) {
i32_val = dataio::be2h(i32_val);
}
float val;
std::memcpy(&val, &i32_val, sizeof(float));
return val;
}

double ByteReader::getFloat64() {
double ByteReader::getFloat64(bool bigEndian) {
int64_t i64_val = getInt64();
if (bigEndian) {
i64_val = dataio::be2h(i64_val);
}
double val;
std::memcpy(&val, &i64_val, sizeof(double));
return val;
Expand Down
24 changes: 14 additions & 10 deletions src/coders/byte_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@
class ByteBuilder {
std::vector<ubyte> buffer;
public:
ByteBuilder() = default;
ByteBuilder(size_t size);

/// @brief Write one byte (8 bit unsigned integer)
void put(ubyte b);
/// @brief Write c-string (bytes array terminated with '\00')
void putCStr(const char* str);
/// @brief Write signed 16 bit little-endian integer
void putInt16(int16_t val);
void putInt16(int16_t val, bool bigEndian = false);
/// @brief Write signed 32 bit integer
void putInt32(int32_t val);
void putInt32(int32_t val, bool bigEndian = false);
/// @brief Write signed 64 bit integer
void putInt64(int64_t val);
void putInt64(int64_t val, bool bigEndian = false);
/// @brief Write 32 bit floating-point number
void putFloat32(float val);
void putFloat32(float val, bool bigEndian = false);
/// @brief Write 64 bit floating-point number
void putFloat64(double val);
void putFloat64(double val, bool bigEndian = false);

/// @brief Write string (uint32 length + bytes)
void put(const std::string& s);
Expand Down Expand Up @@ -50,6 +53,7 @@ class ByteReader {
public:
ByteReader(const ubyte* data, size_t size);
ByteReader(const ubyte* data);
ByteReader(const std::vector<ubyte>& data);

void checkMagic(const char* data, size_t size);
/// @brief Get N bytes
Expand All @@ -59,15 +63,15 @@ class ByteReader {
/// @brief Read one byte (unsigned 8 bit integer) without pointer move
ubyte peek();
/// @brief Read signed 16 bit little-endian integer
int16_t getInt16();
int16_t getInt16(bool bigEndian = false);
/// @brief Read signed 32 bit little-endian integer
int32_t getInt32();
int32_t getInt32(bool bigEndian = false);
/// @brief Read signed 64 bit little-endian integer
int64_t getInt64();
int64_t getInt64(bool bigEndian = false);
/// @brief Read 32 bit floating-point number
float getFloat32();
float getFloat32(bool bigEndian = false);
/// @brief Read 64 bit floating-point number
double getFloat64();
double getFloat64(bool bigEndian = false);
/// @brief Read C-String
const char* getCString();
/// @brief Read string with unsigned 32 bit number before (length)
Expand Down
1 change: 0 additions & 1 deletion src/lighting/LightSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void LightSolver::add(int x, int y, int z, int emission) {
}

void LightSolver::add(int x, int y, int z) {
assert (chunks != nullptr);
add(x,y,z, chunks.getLight(x,y,z, channel));
}

Expand Down
1 change: 1 addition & 0 deletions src/logic/scripting/lua/libs/api_lua.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern const luaL_Reg base64lib[];
extern const luaL_Reg bjsonlib[];
extern const luaL_Reg blocklib[];
extern const luaL_Reg blockwrapslib[]; // gfx.blockwraps
extern const luaL_Reg byteutillib[];
extern const luaL_Reg cameralib[];
extern const luaL_Reg consolelib[];
extern const luaL_Reg corelib[];
Expand Down
Loading

0 comments on commit ad12f3a

Please sign in to comment.