Update to sol3, vec3 customization, C++ 17 now required.
parent
c7c2e38c38
commit
d56d6f890a
|
@ -3,6 +3,16 @@ set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
# Set warnings
|
||||||
|
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
|
||||||
|
add_compile_options(
|
||||||
|
-Werror -Wall -Wextra -pedantic -pedantic-errors
|
||||||
|
-Wnon-virtual-dtor -Wmisleading-indentation -Wlogical-op -Wnull-dereference
|
||||||
|
-Wno-unused-parameter -Wno-reorder -Wno-sign-compare)
|
||||||
|
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||||
|
add_compile_options(/permissive /W4 /w14640)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(PROJECT_NAME "Zepha")
|
set(PROJECT_NAME "Zepha")
|
||||||
set(MAIN_EXEC_NAME "Zepha")
|
set(MAIN_EXEC_NAME "Zepha")
|
||||||
set(TEST_EXEC_NAME "ZephaTest")
|
set(TEST_EXEC_NAME "ZephaTest")
|
||||||
|
@ -16,7 +26,7 @@ find_path(LUA_HEADERS lua.hpp
|
||||||
/usr/local/include/lua5.1)
|
/usr/local/include/lua5.1)
|
||||||
find_path(ASSIMP_HEADERS assimp/Importer.hpp)
|
find_path(ASSIMP_HEADERS assimp/Importer.hpp)
|
||||||
find_path(ENET_HEADERS enet/enet.h)
|
find_path(ENET_HEADERS enet/enet.h)
|
||||||
find_path(NOISE_HEADERS libnoise/noise.h)
|
#find_path(NOISE_HEADERS libnoise/noise.h)
|
||||||
find_path(GLM_HEADERS glm/glm.hpp)
|
find_path(GLM_HEADERS glm/glm.hpp)
|
||||||
find_path(PTHREAD_HEADERS pthread.h)
|
find_path(PTHREAD_HEADERS pthread.h)
|
||||||
|
|
||||||
|
@ -34,11 +44,8 @@ else()
|
||||||
find_library(PTHREAD_LIB pthread)
|
find_library(PTHREAD_LIB pthread)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (WIN32)
|
set(SOL_HEADERS lib/header/sol/include)
|
||||||
set(SOL_HEADERS lib/header/sol2/include)
|
set(NOISE_HEADERS lib/static/noise/include)
|
||||||
else()
|
|
||||||
set(SOL_HEADERS lib/header/sol2/include_linux)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${GLM_HEADERS}
|
${GLM_HEADERS}
|
||||||
|
@ -69,9 +76,6 @@ if(WIN32)
|
||||||
target_link_libraries(${MAIN_EXEC_NAME} winmm ws2_32)
|
target_link_libraries(${MAIN_EXEC_NAME} winmm ws2_32)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Enable Safeties
|
|
||||||
target_compile_definitions(${MAIN_EXEC_NAME} PUBLIC SOL_ALL_SAFETIES_ON)
|
|
||||||
|
|
||||||
# Test Build
|
# Test Build
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
add_executable(${TEST_EXEC_NAME} test/Main.cpp)
|
add_executable(${TEST_EXEC_NAME} test/Main.cpp)
|
||||||
|
@ -79,7 +83,6 @@ target_link_libraries(${TEST_EXEC_NAME} Zepha_Core)
|
||||||
target_link_libraries(${TEST_EXEC_NAME} Zepha_Test)
|
target_link_libraries(${TEST_EXEC_NAME} Zepha_Test)
|
||||||
|
|
||||||
target_include_directories(${TEST_EXEC_NAME} PRIVATE ${GLFW_HEADERS})
|
target_include_directories(${TEST_EXEC_NAME} PRIVATE ${GLFW_HEADERS})
|
||||||
target_compile_definitions(${TEST_EXEC_NAME} PUBLIC SOL_ALL_SAFETIES_ON)
|
|
||||||
target_link_libraries(${TEST_EXEC_NAME} ${LUA_LIB})
|
target_link_libraries(${TEST_EXEC_NAME} ${LUA_LIB})
|
||||||
target_link_libraries (${TEST_EXEC_NAME} z)
|
target_link_libraries (${TEST_EXEC_NAME} z)
|
||||||
target_link_libraries(${TEST_EXEC_NAME} ${ENET_LIB})
|
target_link_libraries(${TEST_EXEC_NAME} ${ENET_LIB})
|
|
@ -8,38 +8,57 @@ _G["vector"] = {}
|
||||||
-- x, y, and z must all be numbers.
|
-- x, y, and z must all be numbers.
|
||||||
local function create_vector(x, y, z)
|
local function create_vector(x, y, z)
|
||||||
local v = {x, y, z}
|
local v = {x, y, z}
|
||||||
setmetatable(v, vector._mt)
|
setmetatable(v, vector)
|
||||||
return v
|
return v
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- vector.equal
|
||||||
|
-- Return a boolean indicating if v1 == v2
|
||||||
|
function vector.equal(v1, v2)
|
||||||
|
assert(vector.is_vector(v1) and vector.is_vector(v2))
|
||||||
|
return (rawget(v1, 1) == rawget(v2, 1) and rawget(v1, 2) == rawget(v2, 2) and rawget(v1, 3) == rawget(v2, 3))
|
||||||
|
end
|
||||||
|
|
||||||
|
vector.__eq = vector.equal
|
||||||
|
|
||||||
|
-- vector.copy
|
||||||
|
-- Copies v and returns a new vector
|
||||||
|
function vector.copy(v)
|
||||||
|
assert(vector.is_vector(v))
|
||||||
|
return create_vector(rawget(v, 1), rawget(v, 2), rawget(v, 3))
|
||||||
|
end
|
||||||
|
|
||||||
-- vector.add
|
-- vector.add
|
||||||
-- Add two vectors or a vector and number
|
-- Add two vectors or a vector and number
|
||||||
function vector.add(v1, v2)
|
function vector.add(v1, v2)
|
||||||
if not vector.is_vector(v1) then return end
|
assert(vector.is_vector(v1))
|
||||||
if vector.is_vector(v2) then
|
if vector.is_vector(v2) then return create_vector(rawget(v1, 1) + rawget(v2, 1), rawget(v1, 2) + rawget(v2, 2), rawget(v1, 3) + rawget(v2, 3))
|
||||||
return create_vector(rawget(v1, 1) + rawget(v2, 1), rawget(v1, 2) + rawget(v2, 2), rawget(v1, 3) + rawget(v2, 3))
|
elseif type(v2) == "number" then return create_vector(rawget(v1, 1) + v2, rawget(v1, 2) + v2, rawget(v1, 3) + v2) end
|
||||||
elseif type(v2) == "number" then
|
|
||||||
return create_vector(rawget(v1, 1) + v2, rawget(v1, 2) + v2, rawget(v1, 3) + v2)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vector.__add = vector.add
|
||||||
|
|
||||||
-- vector.negative
|
-- vector.negative
|
||||||
-- Flips a vector's content's signs
|
-- Flips a vector's content's signs
|
||||||
function vector.negative(v)
|
function vector.negative(v)
|
||||||
if not vector.is_vector(v) then return end
|
assert(vector.is_vector(v))
|
||||||
return create_vector(-rawget(v, 1), -rawget(v, 2), -rawget(v, 3))
|
return create_vector(-rawget(v, 1), -rawget(v, 2), -rawget(v, 3))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vector.__unm = vector.negative
|
||||||
|
|
||||||
-- vector.subtract
|
-- vector.subtract
|
||||||
-- Subtract v2 from v1
|
-- Subtract v2 from v1
|
||||||
function vector.subtract(v1, v2)
|
function vector.subtract(v1, v2)
|
||||||
return vector.add(v1, vector.negative(v2))
|
return vector.add(v1, vector.negative(v2))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vector.__sub = vector.subtract
|
||||||
|
|
||||||
-- vector.multiply
|
-- vector.multiply
|
||||||
-- Multiply v1 by a vector or number
|
-- Multiply v1 by a vector or number
|
||||||
function vector.multiply(v1, m)
|
function vector.multiply(v1, m)
|
||||||
if not vector.is_vector(v1) then return end
|
assert(vector.is_vector(v1))
|
||||||
if vector.is_vector(m) then
|
if vector.is_vector(m) then
|
||||||
return create_vector(rawget(v1, 1) * rawget(m, 1), rawget(v1, 2) * rawget(m, 2), rawget(v1, 3) * rawget(m, 3))
|
return create_vector(rawget(v1, 1) * rawget(m, 1), rawget(v1, 2) * rawget(m, 2), rawget(v1, 3) * rawget(m, 3))
|
||||||
elseif type(m) == "number" then
|
elseif type(m) == "number" then
|
||||||
|
@ -47,10 +66,12 @@ function vector.multiply(v1, m)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vector.__mul = vector.multiply
|
||||||
|
|
||||||
-- vector.divide
|
-- vector.divide
|
||||||
-- Divice v1 by a vector or number
|
-- Divice v1 by a vector or number
|
||||||
function vector.divide(v1, m)
|
function vector.divide(v1, m)
|
||||||
if not vector.is_vector(v1) then return end
|
assert(vector.is_vector(v1))
|
||||||
if vector.is_vector(m) then
|
if vector.is_vector(m) then
|
||||||
return create_vector(rawget(v1, 1) / rawget(m, 1), rawget(v1, 2) / rawget(m, 2), rawget(v1, 3) / rawget(m, 3))
|
return create_vector(rawget(v1, 1) / rawget(m, 1), rawget(v1, 2) / rawget(m, 2), rawget(v1, 3) / rawget(m, 3))
|
||||||
elseif type(m) == "number" then
|
elseif type(m) == "number" then
|
||||||
|
@ -58,134 +79,107 @@ function vector.divide(v1, m)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vector.__div = vector.divide
|
||||||
|
|
||||||
-- vector.pow
|
-- vector.pow
|
||||||
-- Return v to the power of p
|
-- Return v to the power of p
|
||||||
function vector.pow(v, m)
|
function vector.pow(v, m)
|
||||||
if not vector.is_vector(v) then return end
|
assert(vector.is_vector(v))
|
||||||
local res = create_vector(rawget(v, 1), rawget(v, 2), rawget(v, 3))
|
local res = create_vector(rawget(v, 1), rawget(v, 2), rawget(v, 3))
|
||||||
for i = 1, power - 1 do res = res * v end
|
for i = 1, power - 1 do res = res * v end
|
||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
-- vector.equal
|
vector.__pow = vector.pow
|
||||||
-- Return a boolean indicating if v1 == v2
|
|
||||||
function vector.equal(v1, v2)
|
|
||||||
if not vector.is_vector(v1) or not vector.is_vector(v2) then return end
|
|
||||||
return (rawget(v1, 1) == rawget(v2, 1) and rawget(v1, 2) == rawget(v2, 2) and rawget(v1, 3) == rawget(v2, 3))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- vector.abs
|
-- vector.abs
|
||||||
-- Return the absolute value of v
|
-- Return the absolute value of v
|
||||||
function vector.abs(v)
|
function vector.abs(v)
|
||||||
if not vector.is_vector(v) then return end
|
assert(vector.is_vector(v))
|
||||||
return create_vector(math.abs(rawget(v, 1)), math.abs(rawget(v, 2)), math.abs(rawget(v, 3)))
|
return create_vector(math.abs(rawget(v, 1)), math.abs(rawget(v, 2)), math.abs(rawget(v, 3)))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- vector.round
|
-- vector.round
|
||||||
-- Round each vector value to the nearest integer
|
-- Round each vector value to the nearest integer
|
||||||
function vector.round(v)
|
function vector.round(v)
|
||||||
if not vector.is_vector(v) then return end
|
assert(vector.is_vector(v))
|
||||||
return create_vector(math.round(rawget(v, 1)), math.round(rawget(v, 2)), math.round(rawget(v, 3)))
|
return create_vector(math.round(rawget(v, 1)), math.round(rawget(v, 2)), math.round(rawget(v, 3)))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- vector.floor
|
-- vector.floor
|
||||||
-- Floor each vector value to the lowest integer
|
-- Floor each vector value to the lowest integer
|
||||||
function vector.floor(v)
|
function vector.floor(v)
|
||||||
if not vector.is_vector(v) then return end
|
assert(vector.is_vector(v))
|
||||||
return create_vector(math.floor(rawget(v, 1)), math.floor(rawget(v, 2)), math.floor(rawget(v, 3)))
|
return create_vector(math.floor(rawget(v, 1)), math.floor(rawget(v, 2)), math.floor(rawget(v, 3)))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- vector.ceil
|
-- vector.ceil
|
||||||
-- Ceil each vector value to the highest integer
|
-- Ceil each vector value to the highest integer
|
||||||
function vector.ceil(v)
|
function vector.ceil(v)
|
||||||
if not vector.is_vector(v) then return end
|
assert(vector.is_vector(v))
|
||||||
return create_vector(math.ceil(rawget(v, 1)), math.ceil(rawget(v, 2)), math.ceil(rawget(v, 3)))
|
return create_vector(math.ceil(rawget(v, 1)), math.ceil(rawget(v, 2)), math.ceil(rawget(v, 3)))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- vector.distance_squared
|
-- vector.length2
|
||||||
|
-- Get the square of the length of a vector
|
||||||
|
function vector.length2(v)
|
||||||
|
assert(vector.is_vector(v))
|
||||||
|
return rawget(v, 1) ^ 2 + rawget(v, 2) ^ 2 + rawget(v, 3) ^ 2
|
||||||
|
end
|
||||||
|
|
||||||
|
-- vector.length
|
||||||
|
-- Get the length of a vector
|
||||||
|
function vector.length(v)
|
||||||
|
assert(vector.is_vector(v))
|
||||||
|
return math.sqrt(vector.length2(v))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- vector.distance2
|
||||||
-- Get the square of the distance between two vectors
|
-- Get the square of the distance between two vectors
|
||||||
-- This function is faster if you only need to compare two distances
|
function vector.distance2(v1, v2)
|
||||||
function vector.distance_squared(v1, v2)
|
assert(vector.is_vector(v1) and vector.is_vector(v2))
|
||||||
if not vector.is_vector(v1) or not vector.is_vector(v2) then return end
|
return vector.length2(vector.abs(vector.subtract(v1, v2)))
|
||||||
local diff = vector.abs(vector.subtract(v1, v2))
|
|
||||||
return diff.x ^ 2 + diff.y ^ 2 + diff.z ^ 2
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- vector.distance
|
-- vector.distance
|
||||||
-- Get the distance between two vectors
|
-- Get the distance between two vectors
|
||||||
function vector.distance(v1, v2)
|
function vector.distance(v1, v2)
|
||||||
if not vector.is_vector(v1) or not vector.is_vector(v2) then return end
|
assert(vector.is_vector(v1) and vector.is_vector(v2))
|
||||||
return math.sqrt(vector.distance_squared(v1, v2))
|
return math.sqrt(vector.distance2(v1, v2))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Vector metatable
|
-- Alias x, y, z to 1, 2, 3
|
||||||
-- A metatable to be assigned to vectors which applies mathematic operators
|
|
||||||
vector._mt = {
|
|
||||||
__is_vector = true,
|
|
||||||
|
|
||||||
-- Value manipulation functions
|
function vector:__index(key)
|
||||||
__index = function(tbl, key)
|
if key == "x" then return rawget(self, 1) end
|
||||||
if key == "x" then return rawget(tbl, 1) end
|
if key == "y" then return rawget(self, 2) end
|
||||||
if key == "y" then return rawget(tbl, 2) end
|
if key == "z" then return rawget(self, 3) end
|
||||||
if key == "z" then return rawget(tbl, 3) end
|
return getmetatable(self)[key]
|
||||||
|
end
|
||||||
|
|
||||||
local val = rawget(tbl, key)
|
function vector:__newindex(key, val)
|
||||||
if val == nil then val = rawget(getmetatable(tbl), key) end
|
if key == "x" then rawset(self, 1, val)
|
||||||
return val
|
elseif key == "y" then rawset(self, 2, val)
|
||||||
end,
|
elseif key == "z" then rawset(self, 3, val) end
|
||||||
__newindex = function(tbl, key, val)
|
end
|
||||||
if key == "x" or key == 0 then rawset(tbl, 1, val)
|
|
||||||
elseif key == "y" or key == 1 then rawset(tbl, 2, val)
|
|
||||||
elseif key == "z" or key == 2 then rawset(tbl, 3, val) end
|
|
||||||
end,
|
|
||||||
__tostring = function(tbl)
|
|
||||||
return table.concat({
|
|
||||||
"{ ",
|
|
||||||
tostring(tbl[1]), ", ",
|
|
||||||
tostring(tbl[2]), ", ",
|
|
||||||
tostring(tbl[3]), " }"
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
__eq = function(tbl, o)
|
|
||||||
return vector.equal(tbl, o)
|
|
||||||
end,
|
|
||||||
|
|
||||||
-- Arithmetic functions
|
function vector:__tostring()
|
||||||
__unm = function(tbl)
|
return table.concat({
|
||||||
return vector.negative(tbl)
|
"{ ",
|
||||||
end,
|
tostring(rawget(self, 1)), ", ",
|
||||||
__add = function(tbl, o)
|
tostring(rawget(self, 2)), ", ",
|
||||||
return vector.add(tbl, o)
|
tostring(rawget(self, 3)), " }"
|
||||||
end,
|
})
|
||||||
__sub = function(tbl, o)
|
end
|
||||||
return vector.subtract(tbl, o)
|
|
||||||
end,
|
|
||||||
__mul = function(tbl, o)
|
|
||||||
return vector.multiply(tbl, o)
|
|
||||||
end,
|
|
||||||
__div = function(tbl, o)
|
|
||||||
return vector.divide(tbl, o)
|
|
||||||
end,
|
|
||||||
__pow = function(tbl, power)
|
|
||||||
return vector.pow(tbl, o)
|
|
||||||
end,
|
|
||||||
|
|
||||||
-- Higher level methods
|
function vector.__concat(a, b)
|
||||||
abs = vector.abs,
|
return tostring(a) .. tostring(b)
|
||||||
round = vector.round,
|
end
|
||||||
floor = vector.floor,
|
|
||||||
ceil = vector.ceil,
|
|
||||||
dist = vector.distance,
|
|
||||||
distance, vector.distance,
|
|
||||||
dist2 = vector.distance_squared,
|
|
||||||
distance_squared = vector.distance_squared
|
|
||||||
}
|
|
||||||
|
|
||||||
-- vector.is_vector
|
-- vector.is_vector
|
||||||
-- Checks if a value is a vector.
|
-- Checks if a value is a vector.
|
||||||
function vector.is_vector(v)
|
function vector.is_vector(v)
|
||||||
if type(v) ~= "table" or not v.__is_vector then return false end
|
return getmetatable(v) == vector
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- vector.new
|
-- vector.new
|
||||||
|
@ -193,7 +187,7 @@ end
|
||||||
-- Table constructor works with 1-3 values
|
-- Table constructor works with 1-3 values
|
||||||
vector.new = function(x, y, z)
|
vector.new = function(x, y, z)
|
||||||
-- Blank new constructor, return empty vector
|
-- Blank new constructor, return empty vector
|
||||||
if x == nil then return create_vector(0, 0, 0)
|
if x == nil or (type(x) == "table" and x[1] == nil) then return create_vector(0, 0, 0)
|
||||||
-- Invalid type passed to function, return nil
|
-- Invalid type passed to function, return nil
|
||||||
elseif type(x) ~= "number" and type(x) ~= "table" then return nil
|
elseif type(x) ~= "number" and type(x) ~= "table" then return nil
|
||||||
-- Passed a table as x with at least x and y parameters, z will be set to table value or 0
|
-- Passed a table as x with at least x and y parameters, z will be set to table value or 0
|
||||||
|
|
|
@ -319,6 +319,6 @@ set(ZEPHA_SRC
|
||||||
def/gen/MapGenProps.cpp
|
def/gen/MapGenProps.cpp
|
||||||
def/gen/MapGenProps.h
|
def/gen/MapGenProps.h
|
||||||
lua/api/class/LuaGuiElement.cpp
|
lua/api/class/LuaGuiElement.cpp
|
||||||
lua/api/class/LuaGuiElement.h world/Dimension.cpp world/Dimension.h world/fs/FileManipulator.cpp world/fs/FileManipulator.h def/item/BlockModel.cpp net/server/world/ServerPacketStream.cpp net/server/world/ServerPacketStream.h lua/register/CreateBlockModel.cpp lua/register/CreateBlockModel.h)
|
lua/api/class/LuaGuiElement.h world/Dimension.cpp world/Dimension.h world/fs/FileManipulator.cpp world/fs/FileManipulator.h def/item/BlockModel.cpp net/server/world/ServerPacketStream.cpp net/server/world/ServerPacketStream.h lua/register/CreateBlockModel.cpp lua/register/CreateBlockModel.h lua/customization/vec3.hpp)
|
||||||
|
|
||||||
add_library (Zepha_Core ${ZEPHA_SRC})
|
add_library (Zepha_Core ${ZEPHA_SRC})
|
12
src/Main.cpp
12
src/Main.cpp
|
@ -20,6 +20,18 @@
|
||||||
#include "StartGame.h"
|
#include "StartGame.h"
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
|
// sol::state lua;
|
||||||
|
// lua.open_libraries(sol::lib::base);
|
||||||
|
//
|
||||||
|
// lua.script(R"(
|
||||||
|
// number = 32
|
||||||
|
// )");
|
||||||
|
//
|
||||||
|
// unsigned short n = lua.get<unsigned short>("number");
|
||||||
|
// std::cout << n << std::endl;
|
||||||
|
|
||||||
|
|
||||||
return StartGame(argc, argv);
|
return StartGame(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sol2/sol.hpp>
|
|
||||||
|
|
||||||
#include "../ItemDef.h"
|
#include "../ItemDef.h"
|
||||||
|
|
||||||
#include "BlockModel.h"
|
#include "BlockModel.h"
|
||||||
#include "SelectionBox.h"
|
#include "SelectionBox.h"
|
||||||
|
#include "../../lua/Lua.h"
|
||||||
#include "../../util/Util.h"
|
#include "../../util/Util.h"
|
||||||
#include "../../lua/Callback.h"
|
#include "../../lua/Callback.h"
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <functional>
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include <glm/mat4x4.hpp>
|
#include <glm/mat4x4.hpp>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
|
|
@ -23,14 +23,14 @@ std::shared_ptr<GuiComponent> GameGuiBuilder::createComponent(LuaGuiElement& ele
|
||||||
|
|
||||||
elem.updateFunction = std::bind(&GameGuiBuilder::elementUpdated, this);
|
elem.updateFunction = std::bind(&GameGuiBuilder::elementUpdated, this);
|
||||||
|
|
||||||
if (elem.callbacks.count("primary")) c->setCallback(GuiComponent::CallbackType::PRIMARY, [=](bool b, glm::vec2 v) {
|
// if (elem.callbacks.count("primary")) c->setCallback(GuiComponent::CallbackType::PRIMARY, [=](bool b, glm::vec2 v) {
|
||||||
elem.callbacks.at("primary")(b, LuaParser::luaVec(elem.callbacks.at("primary").lua_state(), {v.x, v.y, 0})); });
|
// elem.callbacks.at("primary")(b, LuaParser::luaVec(elem.callbacks.at("primary").lua_state(), {v.x, v.y, 0})); });
|
||||||
|
//
|
||||||
if (elem.callbacks.count("secondary")) c->setCallback(GuiComponent::CallbackType::SECONDARY, [=](bool b, glm::vec2 v) {
|
// if (elem.callbacks.count("secondary")) c->setCallback(GuiComponent::CallbackType::SECONDARY, [=](bool b, glm::vec2 v) {
|
||||||
elem.callbacks.at("secondary")(b, LuaParser::luaVec(elem.callbacks.at("secondary").lua_state(), {v.x, v.y, 0})); });
|
// elem.callbacks.at("secondary")(b, LuaParser::luaVec(elem.callbacks.at("secondary").lua_state(), {v.x, v.y, 0})); });
|
||||||
|
//
|
||||||
if (elem.callbacks.count("hover")) c->setCallback(GuiComponent::CallbackType::HOVER, [=](bool b, glm::vec2 v) {
|
// if (elem.callbacks.count("hover")) c->setCallback(GuiComponent::CallbackType::HOVER, [=](bool b, glm::vec2 v) {
|
||||||
elem.callbacks.at("hover")(b, LuaParser::luaVec(elem.callbacks.at("hover").lua_state(), {v.x, v.y, 0})); });
|
// elem.callbacks.at("hover")(b, LuaParser::luaVec(elem.callbacks.at("hover").lua_state(), {v.x, v.y, 0})); });
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,14 +75,14 @@ std::shared_ptr<GuiComponent> GuiBuilder::createComponent(LuaGuiElement& elem, g
|
||||||
|
|
||||||
elem.updateFunction = std::bind(&GuiBuilder::elementUpdated, this);
|
elem.updateFunction = std::bind(&GuiBuilder::elementUpdated, this);
|
||||||
|
|
||||||
if (elem.callbacks.count("primary")) c->setCallback(GuiComponent::CallbackType::PRIMARY, [=](bool b, glm::vec2 v) {
|
// if (elem.callbacks.count("primary")) c->setCallback(GuiComponent::CallbackType::PRIMARY, [=](bool b, glm::vec2 v) {
|
||||||
elem.callbacks.at("primary")(b, LuaParser::luaVec(elem.callbacks.at("primary").lua_state(), {v.x, v.y, 0})); });
|
// elem.callbacks.at("primary")(b, LuaParser::luaVec(elem.callbacks.at("primary").lua_state(), {v.x, v.y, 0})); });
|
||||||
|
//
|
||||||
if (elem.callbacks.count("secondary")) c->setCallback(GuiComponent::CallbackType::SECONDARY, [=](bool b, glm::vec2 v) {
|
// if (elem.callbacks.count("secondary")) c->setCallback(GuiComponent::CallbackType::SECONDARY, [=](bool b, glm::vec2 v) {
|
||||||
elem.callbacks.at("secondary")(b, LuaParser::luaVec(elem.callbacks.at("secondary").lua_state(), {v.x, v.y, 0})); });
|
// elem.callbacks.at("secondary")(b, LuaParser::luaVec(elem.callbacks.at("secondary").lua_state(), {v.x, v.y, 0})); });
|
||||||
|
//
|
||||||
if (elem.callbacks.count("hover")) c->setCallback(GuiComponent::CallbackType::HOVER, [=](bool b, glm::vec2 v) {
|
// if (elem.callbacks.count("hover")) c->setCallback(GuiComponent::CallbackType::HOVER, [=](bool b, glm::vec2 v) {
|
||||||
elem.callbacks.at("hover")(b, LuaParser::luaVec(elem.callbacks.at("hover").lua_state(), {v.x, v.y, 0})); });
|
// elem.callbacks.at("hover")(b, LuaParser::luaVec(elem.callbacks.at("hover").lua_state(), {v.x, v.y, 0})); });
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include <glm/vec4.hpp>
|
#include <glm/vec4.hpp>
|
||||||
#include <sol2/sol.hpp>
|
|
||||||
|
|
||||||
#include "../../util/Any.h"
|
#include "../../util/Any.h"
|
||||||
#include "../../lua/api/class/LuaGuiElement.h"
|
#include "../../lua/api/class/LuaGuiElement.h"
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include "../../entity/Entity.h"
|
#include "../../entity/Entity.h"
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ public:
|
||||||
return std::static_pointer_cast<T>(it);
|
return std::static_pointer_cast<T>(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<GuiComponent> insert(unsigned int index, std::shared_ptr<GuiComponent> component);
|
std::shared_ptr<GuiComponent> insert(unsigned int index, std::shared_ptr<GuiComponent> component);
|
||||||
|
|
|
@ -266,10 +266,10 @@ void InventoryList::setStack(unsigned short i, const ItemStack &stack) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryList::setLuaCallback(InventoryList::Callback type, sol::function cb) {
|
void InventoryList::setLuaCallback(InventoryList::Callback type, sol::safe_function cb) {
|
||||||
luaCallbacks[static_cast<size_t>(type)] = cb;
|
luaCallbacks[static_cast<size_t>(type)] = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::function InventoryList::getLuaCallback(InventoryList::Callback type) {
|
sol::safe_function InventoryList::getLuaCallback(InventoryList::Callback type) {
|
||||||
return luaCallbacks[static_cast<size_t>(type)];
|
return luaCallbacks[static_cast<size_t>(type)];
|
||||||
}
|
}
|
|
@ -5,8 +5,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sol2/sol.hpp>
|
|
||||||
|
|
||||||
|
#include "../../lua/Lua.h"
|
||||||
#include "ItemStack.h"
|
#include "ItemStack.h"
|
||||||
|
|
||||||
class DefinitionAtlas;
|
class DefinitionAtlas;
|
||||||
|
@ -53,7 +53,7 @@ public:
|
||||||
void setStack(unsigned short i, const ItemStack& stack);
|
void setStack(unsigned short i, const ItemStack& stack);
|
||||||
|
|
||||||
sol::function getLuaCallback(Callback type);
|
sol::function getLuaCallback(Callback type);
|
||||||
void setLuaCallback(Callback type, sol::function cb);
|
void setLuaCallback(Callback type, sol::safe_function cb);
|
||||||
|
|
||||||
DefinitionAtlas& defs;
|
DefinitionAtlas& defs;
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ bool ServerInventoryList::addWatcher(unsigned int cid) {
|
||||||
watchers.push_back(cid);
|
watchers.push_back(cid);
|
||||||
|
|
||||||
sendTo(client);
|
sendTo(client);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServerInventoryList::removeWatcher(unsigned int cid) {
|
bool ServerInventoryList::removeWatcher(unsigned int cid) {
|
||||||
|
|
|
@ -62,12 +62,12 @@ void LocalWorld::blockPlace(glm::vec3 pos, unsigned int block) {
|
||||||
if (block == LocalDefinitionAtlas::AIR) {
|
if (block == LocalDefinitionAtlas::AIR) {
|
||||||
auto def = defs.defs.blockFromId(getBlock(pos));
|
auto def = defs.defs.blockFromId(getBlock(pos));
|
||||||
if (def.callbacks.count(Callback::BREAK_CLIENT))
|
if (def.callbacks.count(Callback::BREAK_CLIENT))
|
||||||
defs.parser.safe_function(def.callbacks[Callback::BREAK_CLIENT], defs.parser.luaVec(pos));
|
defs.parser.safe_function(def.callbacks[Callback::BREAK_CLIENT], pos);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto def = defs.defs.blockFromId(block);
|
auto def = defs.defs.blockFromId(block);
|
||||||
if (def.callbacks.count(Callback::PLACE_CLIENT))
|
if (def.callbacks.count(Callback::PLACE_CLIENT))
|
||||||
defs.parser.safe_function(def.callbacks[Callback::PLACE_CLIENT], defs.parser.luaVec(pos));
|
defs.parser.safe_function(def.callbacks[Callback::PLACE_CLIENT], pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
net->blockPlace(pos, block);
|
net->blockPlace(pos, block);
|
||||||
|
@ -82,7 +82,7 @@ void LocalWorld::blockInteract(PointedThing &thing) {
|
||||||
auto def = defs.defs.blockFromId(getBlock(thing.target.block.pos));
|
auto def = defs.defs.blockFromId(getBlock(thing.target.block.pos));
|
||||||
|
|
||||||
if (def.callbacks.count(Callback::INTERACT_CLIENT))
|
if (def.callbacks.count(Callback::INTERACT_CLIENT))
|
||||||
defs.parser.safe_function(def.callbacks[Callback::INTERACT_CLIENT], defs.parser.luaVec(thing.target.block.pos));
|
defs.parser.safe_function(def.callbacks[Callback::INTERACT_CLIENT], thing.target.block.pos);
|
||||||
|
|
||||||
net->blockInteract(thing.target.block.pos);
|
net->blockInteract(thing.target.block.pos);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define SOL_ALL_SAFETIES_ON 1
|
||||||
|
|
||||||
|
#include <sol/sol.hpp>
|
||||||
|
#include "customization/vec3.hpp"
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "Lua.h"
|
||||||
|
|
||||||
class LocalLuaParser;
|
class LocalLuaParser;
|
||||||
|
|
||||||
|
|
|
@ -13,21 +13,10 @@ void LuaParser::update(double delta) {
|
||||||
DelayedFunction& f = *it;
|
DelayedFunction& f = *it;
|
||||||
f.timeout -= delta;
|
f.timeout -= delta;
|
||||||
if (f.timeout <= 0) {
|
if (f.timeout <= 0) {
|
||||||
if (f.function(sol::as_args(f.args))) {
|
sol::optional<bool> res = f.function(sol::as_args(f.args));
|
||||||
f.timeout = f.initial_timeout;
|
if (res && *res) f.timeout = f.initial_timeout;
|
||||||
} else {
|
else { it = delayed_functions.erase(it); continue; }
|
||||||
it = delayed_functions.erase(it);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table LuaParser::luaVec(glm::vec3 vec) {
|
|
||||||
return lua["vector"]["new"](vec.x, vec.y, vec.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
sol::table LuaParser::luaVec(sol::state_view s, glm::vec3 vec) {
|
|
||||||
return s["vector"]["new"](vec.x, vec.y, vec.z);
|
|
||||||
}
|
|
|
@ -8,16 +8,14 @@
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
#include <sol2/sol.hpp>
|
|
||||||
|
#include "Lua.h"
|
||||||
|
|
||||||
class LuaParser {
|
class LuaParser {
|
||||||
public:
|
public:
|
||||||
constexpr static double UPDATE_STEP {1 / 60.0};
|
constexpr static double UPDATE_STEP {1 / 60.0};
|
||||||
virtual void update(double delta);
|
virtual void update(double delta);
|
||||||
|
|
||||||
sol::table luaVec(glm::vec3 vec);
|
|
||||||
static sol::table luaVec(sol::state_view s, glm::vec3 vec);
|
|
||||||
|
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
sol::table core;
|
sol::table core;
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,12 @@
|
||||||
|
|
||||||
#include "LocalLuaAnimationManager.h"
|
#include "LocalLuaAnimationManager.h"
|
||||||
|
|
||||||
|
#include "../../Lua.h"
|
||||||
#include "../../../game/entity/Entity.h"
|
#include "../../../game/entity/Entity.h"
|
||||||
#include "../../../game/entity/AnimationSegment.h"
|
#include "../../../game/entity/AnimationSegment.h"
|
||||||
|
|
||||||
LocalLuaAnimationManager::LocalLuaAnimationManager(Entity &entity) :
|
LocalLuaAnimationManager::LocalLuaAnimationManager(Entity &entity) :
|
||||||
entity(entity) {
|
entity(entity) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocalLuaAnimationManager::define(sol::table anims) {
|
void LocalLuaAnimationManager::define(sol::table anims) {
|
||||||
std::vector<AnimationSegment> animations;
|
std::vector<AnimationSegment> animations;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
class Entity;
|
class Entity;
|
||||||
|
|
||||||
|
|
|
@ -4,35 +4,34 @@
|
||||||
|
|
||||||
#include "LocalLuaEntity.h"
|
#include "LocalLuaEntity.h"
|
||||||
|
|
||||||
|
#include "../../Lua.h"
|
||||||
#include "../../LuaParser.h"
|
#include "../../LuaParser.h"
|
||||||
#include "../../../def/ClientGame.h"
|
#include "../../../def/ClientGame.h"
|
||||||
#include "../../../def/item/BlockDef.h"
|
#include "../../../def/item/BlockDef.h"
|
||||||
#include "../../../def/item/CraftItemDef.h"
|
#include "../../../def/item/CraftItemDef.h"
|
||||||
|
|
||||||
void LocalLuaEntity::snap_pos(const sol::table &pos) {
|
void LocalLuaEntity::snap_pos(glm::vec3 pos) {
|
||||||
entity->setPos({pos[1], pos[2], pos[3]});
|
entity->setPos(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalLuaEntity::set_pos(const sol::table &pos) {
|
void LocalLuaEntity::set_pos(glm::vec3 pos) {
|
||||||
entity->interpPos({pos[1], pos[2], pos[3]});
|
entity->interpPos(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table LocalLuaEntity::get_pos(sol::this_state s) {
|
glm::vec3 LocalLuaEntity::get_pos() {
|
||||||
glm::vec3 pos = entity->getPos();
|
return entity->getPos();
|
||||||
return LuaParser::luaVec(sol::state_view(s), pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalLuaEntity::snap_visual_offset(const sol::table &vs) {
|
void LocalLuaEntity::snap_visual_offset(glm::vec3 vs) {
|
||||||
entity->setVisualOffset({vs["x"], vs["y"], vs["z"]});
|
entity->setVisualOffset(vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalLuaEntity::set_visual_offset(const sol::table &pos) {
|
void LocalLuaEntity::set_visual_offset(glm::vec3 vs) {
|
||||||
entity->interpVisualOffset({pos[1], pos[2], pos[3]});
|
entity->interpVisualOffset(vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table LocalLuaEntity::get_visual_offset(sol::this_state s) {
|
glm::vec3 LocalLuaEntity::get_visual_offset() {
|
||||||
glm::vec3 v = entity->getVisualOffset();
|
return entity->getVisualOffset();
|
||||||
return LuaParser::luaVec(sol::state_view(s), v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalLuaEntity::snap_pitch(float rot) {
|
void LocalLuaEntity::snap_pitch(float rot) {
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "LocalLuaAnimationManager.h"
|
#include "LocalLuaAnimationManager.h"
|
||||||
#include "../../../game/entity/Entity.h"
|
#include "../../../game/entity/Entity.h"
|
||||||
|
|
||||||
|
@ -22,13 +21,13 @@ public:
|
||||||
|
|
||||||
LocalLuaAnimationManager manager;
|
LocalLuaAnimationManager manager;
|
||||||
|
|
||||||
void snap_pos(const sol::table& pos);
|
void snap_pos(glm::vec3 pos);
|
||||||
void set_pos(const sol::table& pos);
|
void set_pos(glm::vec3 pos);
|
||||||
sol::table get_pos(sol::this_state s);
|
glm::vec3 get_pos();
|
||||||
|
|
||||||
void snap_visual_offset(const sol::table& vs);
|
void snap_visual_offset(glm::vec3 vs);
|
||||||
void set_visual_offset(const sol::table& pos);
|
void set_visual_offset(glm::vec3 vs);
|
||||||
sol::table get_visual_offset(sol::this_state s);
|
glm::vec3 get_visual_offset();
|
||||||
|
|
||||||
void snap_pitch(float rot);
|
void snap_pitch(float rot);
|
||||||
void set_pitch(float rot);
|
void set_pitch(float rot);
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "../../../game/inventory/LocalInventory.h"
|
#include "../../../game/inventory/LocalInventory.h"
|
||||||
|
|
||||||
class LocalLuaInventory {
|
class LocalLuaInventory {
|
||||||
|
|
|
@ -10,27 +10,24 @@
|
||||||
#include "LocalLuaInventoryList.h"
|
#include "LocalLuaInventoryList.h"
|
||||||
#include "../../../game/scene/world/Player.h"
|
#include "../../../game/scene/world/Player.h"
|
||||||
|
|
||||||
sol::table LocalLuaPlayer::get_pos(sol::this_state s) {
|
glm::vec3 LocalLuaPlayer::get_pos() {
|
||||||
glm::vec3 pos = player.getPos();
|
return player.getPos();
|
||||||
return LuaParser::luaVec(sol::state_view(s), pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table LocalLuaPlayer::get_block_pos(sol::this_state s) {
|
glm::vec3 LocalLuaPlayer::get_block_pos() {
|
||||||
glm::vec3 pos = glm::floor(player.getPos());
|
return glm::floor(player.getPos());
|
||||||
return LuaParser::luaVec(sol::state_view(s), pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalLuaPlayer::set_pos(const sol::table &pos) {
|
void LocalLuaPlayer::set_pos(glm::vec3 pos) {
|
||||||
player.setPos({pos[1], pos[2], pos[3]}, true);
|
player.setPos(pos, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table LocalLuaPlayer::get_vel(sol::this_state s) {
|
glm::vec3 LocalLuaPlayer::get_vel() {
|
||||||
glm::vec3 vel = player.getVel();
|
return player.getVel();
|
||||||
return LuaParser::luaVec(sol::state_view(s), vel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalLuaPlayer::set_vel(const sol::table &vel) {
|
void LocalLuaPlayer::set_vel(glm::vec3 vel) {
|
||||||
player.setVel({vel[1], vel[2], vel[3]}, true);
|
player.setVel(vel, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
float LocalLuaPlayer::get_look_yaw() {
|
float LocalLuaPlayer::get_look_yaw() {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
//#include <sol/forward.hpp>
|
||||||
|
|
||||||
#include "LocalLuaInventory.h"
|
#include "LocalLuaInventory.h"
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@ public:
|
||||||
|
|
||||||
Player& player;
|
Player& player;
|
||||||
|
|
||||||
sol::table get_pos(sol::this_state s);
|
glm::vec3 get_pos();
|
||||||
sol::table get_block_pos(sol::this_state s);
|
glm::vec3 get_block_pos();
|
||||||
void set_pos(const sol::table& pos);
|
void set_pos(glm::vec3 pos);
|
||||||
|
|
||||||
sol::table get_vel(sol::this_state s);
|
glm::vec3 get_vel();
|
||||||
void set_vel(const sol::table& vel);
|
void set_vel(glm::vec3 vel);
|
||||||
|
|
||||||
float get_look_yaw();
|
float get_look_yaw();
|
||||||
void set_look_yaw(float rot);
|
void set_look_yaw(float rot);
|
||||||
|
|
|
@ -171,5 +171,6 @@ Any LuaGuiElement::getAsAny(const std::string &key) const {
|
||||||
return Any::from<glm::vec4>(values);
|
return Any::from<glm::vec4>(values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else throw std::runtime_error("Invalid type requested in getAsAny");
|
|
||||||
|
throw std::runtime_error("Invalid type requested in getAsAny");
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <sol2/sol.hpp>
|
|
||||||
|
|
||||||
|
#include "../../Lua.h"
|
||||||
#include "../../../util/Any.h"
|
#include "../../../util/Any.h"
|
||||||
|
|
||||||
class LuaGuiElement {
|
class LuaGuiElement {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "LuaItemStack.h"
|
#include "LuaItemStack.h"
|
||||||
|
|
||||||
|
#include "../../Lua.h"
|
||||||
#include "../../../def/ItemDef.h"
|
#include "../../../def/ItemDef.h"
|
||||||
#include "../../../def/DefinitionAtlas.h"
|
#include "../../../def/DefinitionAtlas.h"
|
||||||
#include "../../../game/inventory/ItemStack.h"
|
#include "../../../game/inventory/ItemStack.h"
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include <string>
|
||||||
|
#include <sol/forward.hpp>
|
||||||
|
|
||||||
class DefinitionAtlas;
|
class DefinitionAtlas;
|
||||||
class ItemStack;
|
class ItemStack;
|
||||||
|
|
|
@ -8,30 +8,28 @@
|
||||||
#include "../../../def/ItemDef.h"
|
#include "../../../def/ItemDef.h"
|
||||||
#include "../../../def/ServerGame.h"
|
#include "../../../def/ServerGame.h"
|
||||||
|
|
||||||
void ServerLuaEntity::snap_pos(const sol::table &pos) {
|
void ServerLuaEntity::snap_pos(glm::vec3 pos) {
|
||||||
entity->setPos({pos[1], pos[2], pos[3]});
|
entity->setPos(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLuaEntity::set_pos(const sol::table &pos) {
|
void ServerLuaEntity::set_pos(glm::vec3 pos) {
|
||||||
entity->setPos({pos[1], pos[2], pos[3]});
|
entity->setPos(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table ServerLuaEntity::get_pos(sol::this_state s) {
|
glm::vec3 ServerLuaEntity::get_pos() {
|
||||||
glm::vec3 pos = entity->getPos();
|
return entity->getPos();
|
||||||
return LuaParser::luaVec(sol::state_view(s), pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLuaEntity::snap_visual_offset(const sol::table &vs) {
|
void ServerLuaEntity::snap_visual_offset(glm::vec3 vs) {
|
||||||
entity->setVisualOffset({vs[1], vs[2], vs[3]});
|
entity->setVisualOffset(vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLuaEntity::set_visual_offset(const sol::table &pos) {
|
void ServerLuaEntity::set_visual_offset(glm::vec3 vs) {
|
||||||
entity->setVisualOffset({pos[1], pos[2], pos[3]});
|
entity->setVisualOffset(vs);
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table ServerLuaEntity::get_visual_offset(sol::this_state s) {
|
glm::vec3 ServerLuaEntity::get_visual_offset() {
|
||||||
glm::vec3 v = entity->getVisualOffset();
|
return entity->getVisualOffset();
|
||||||
return LuaParser::luaVec(sol::state_view(s), v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLuaEntity::snap_pitch(float rot) {
|
void ServerLuaEntity::snap_pitch(float rot) {
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sol2/sol.hpp>
|
|
||||||
|
|
||||||
|
#include "../../Lua.h"
|
||||||
#include "../../../net/server/world/ServerEntity.h"
|
#include "../../../net/server/world/ServerEntity.h"
|
||||||
|
|
||||||
class ServerGame;
|
class ServerGame;
|
||||||
|
@ -20,13 +20,13 @@ public:
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
ServerGame& defs;
|
ServerGame& defs;
|
||||||
|
|
||||||
void snap_pos(const sol::table& pos);
|
void snap_pos(glm::vec3 pos);
|
||||||
void set_pos(const sol::table& pos);
|
void set_pos(glm::vec3 pos);
|
||||||
sol::table get_pos(sol::this_state s);
|
glm::vec3 get_pos();
|
||||||
|
|
||||||
void snap_visual_offset(const sol::table& vs);
|
void snap_visual_offset(glm::vec3 vs);
|
||||||
void set_visual_offset(const sol::table& pos);
|
void set_visual_offset(glm::vec3 vs);
|
||||||
sol::table get_visual_offset(sol::this_state s);
|
glm::vec3 get_visual_offset();
|
||||||
|
|
||||||
void snap_pitch(float rot);
|
void snap_pitch(float rot);
|
||||||
void set_pitch(float rot);
|
void set_pitch(float rot);
|
||||||
|
|
|
@ -28,5 +28,5 @@ void ServerLuaInventory::set_default_list(sol::object list) {
|
||||||
|
|
||||||
sol::object ServerLuaInventory::get_default_list(sol::this_state s) {
|
sol::object ServerLuaInventory::get_default_list(sol::this_state s) {
|
||||||
if (inventory.getDefaultList() == "") return sol::nil;
|
if (inventory.getDefaultList() == "") return sol::nil;
|
||||||
else get_list(s, inventory.getDefaultList());
|
else return get_list(s, inventory.getDefaultList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ void ServerLuaInventoryList::set_stack(unsigned short i, LuaItemStack stack) {
|
||||||
|
|
||||||
void ServerLuaInventoryList::set_stack(unsigned short i, sol::table stack) {
|
void ServerLuaInventoryList::set_stack(unsigned short i, sol::table stack) {
|
||||||
if (i < 1 || i > list.getLength()) throw "index is outside of list bounds.";
|
if (i < 1 || i > list.getLength()) throw "index is outside of list bounds.";
|
||||||
list.setStack(i - 1, ItemStack(list.defs.fromStr(stack[1]).index, stack.get<unsigned short>(2)));
|
list.setStack(i - 1, ItemStack(list.defs.fromStr(stack[1]).index, stack[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaItemStack ServerLuaInventoryList::place_stack(unsigned short i, LuaItemStack stack) {
|
LuaItemStack ServerLuaInventoryList::place_stack(unsigned short i, LuaItemStack stack) {
|
||||||
|
@ -54,7 +54,7 @@ LuaItemStack ServerLuaInventoryList::place_stack(unsigned short i, LuaItemStack
|
||||||
|
|
||||||
LuaItemStack ServerLuaInventoryList::place_stack(unsigned short i, sol::table stack) {
|
LuaItemStack ServerLuaInventoryList::place_stack(unsigned short i, sol::table stack) {
|
||||||
if (i < 1 || i > list.getLength()) throw "index is outside of list bounds.";
|
if (i < 1 || i > list.getLength()) throw "index is outside of list bounds.";
|
||||||
return LuaItemStack(list.placeStack(i - 1, ItemStack(list.defs.fromStr(stack[1]).index, stack.get<unsigned short>(2))), list.defs);
|
return LuaItemStack(list.placeStack(i - 1, ItemStack(list.defs.fromStr(stack[1]).index, stack[2])), list.defs);
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaItemStack ServerLuaInventoryList::split_stack(unsigned short i) {
|
LuaItemStack ServerLuaInventoryList::split_stack(unsigned short i) {
|
||||||
|
@ -67,7 +67,7 @@ LuaItemStack ServerLuaInventoryList::add_stack(LuaItemStack stack) {
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaItemStack ServerLuaInventoryList::add_stack(sol::table stack) {
|
LuaItemStack ServerLuaInventoryList::add_stack(sol::table stack) {
|
||||||
return LuaItemStack(list.addStack(ItemStack(list.defs.fromStr(stack[1]).index, stack.get<unsigned short>(2))), list.defs);
|
return LuaItemStack(list.addStack(ItemStack(list.defs.fromStr(stack[1]).index, stack[2])), list.defs);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerLuaInventoryList::stack_fits(LuaItemStack stack) {
|
int ServerLuaInventoryList::stack_fits(LuaItemStack stack) {
|
||||||
|
@ -75,7 +75,7 @@ int ServerLuaInventoryList::stack_fits(LuaItemStack stack) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ServerLuaInventoryList::stack_fits(sol::table stack) {
|
int ServerLuaInventoryList::stack_fits(sol::table stack) {
|
||||||
return list.stackFits(ItemStack(list.defs.fromStr(stack[1]).index, stack.get<unsigned short>(2)));
|
return list.stackFits(ItemStack(list.defs.fromStr(stack[1]).index, stack[2]));
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaItemStack ServerLuaInventoryList::take_stack(LuaItemStack request) {
|
LuaItemStack ServerLuaInventoryList::take_stack(LuaItemStack request) {
|
||||||
|
@ -83,7 +83,7 @@ LuaItemStack ServerLuaInventoryList::take_stack(LuaItemStack request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaItemStack ServerLuaInventoryList::take_stack(sol::table request) {
|
LuaItemStack ServerLuaInventoryList::take_stack(sol::table request) {
|
||||||
return LuaItemStack(list.takeStack(ItemStack(list.defs.fromStr(request[1]).index, request.get<unsigned short>(2))), list.defs);
|
return LuaItemStack(list.takeStack(ItemStack(list.defs.fromStr(request[1]).index, request[2])), list.defs);
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaItemStack ServerLuaInventoryList::remove_stack(unsigned short i, unsigned short count) {
|
LuaItemStack ServerLuaInventoryList::remove_stack(unsigned short i, unsigned short count) {
|
||||||
|
@ -91,10 +91,10 @@ LuaItemStack ServerLuaInventoryList::remove_stack(unsigned short i, unsigned sho
|
||||||
return LuaItemStack(list.removeStack(i - 1, count), list.defs);
|
return LuaItemStack(list.removeStack(i - 1, count), list.defs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLuaInventoryList::set_callback(ServerInventoryList::Callback t, sol::function fun) {
|
void ServerLuaInventoryList::set_callback(ServerInventoryList::Callback t, sol::safe_function fun) {
|
||||||
list.setLuaCallback(t, fun);
|
list.setLuaCallback(t, fun);
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::function ServerLuaInventoryList::get_callback(ServerInventoryList::Callback t) {
|
sol::safe_function ServerLuaInventoryList::get_callback(ServerInventoryList::Callback t) {
|
||||||
return list.getLuaCallback(t);
|
return list.getLuaCallback(t);
|
||||||
}
|
}
|
|
@ -45,6 +45,6 @@ public:
|
||||||
|
|
||||||
LuaItemStack remove_stack(unsigned short ind, unsigned short count);
|
LuaItemStack remove_stack(unsigned short ind, unsigned short count);
|
||||||
|
|
||||||
void set_callback(ServerInventoryList::Callback t, sol::function fun);
|
void set_callback(ServerInventoryList::Callback t, sol::safe_function fun);
|
||||||
sol::function get_callback(ServerInventoryList::Callback t);
|
sol::safe_function get_callback(ServerInventoryList::Callback t);
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,27 +20,24 @@ std::string ServerLuaPlayer::get_address() {
|
||||||
return NetHandler::intToIPString(player.address.host) + ":" + std::to_string(player.address.port);
|
return NetHandler::intToIPString(player.address.host) + ":" + std::to_string(player.address.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table ServerLuaPlayer::get_pos(sol::this_state s) {
|
glm::vec3 ServerLuaPlayer::get_pos() {
|
||||||
glm::vec3 pos = player.getPos();
|
return player.getPos();
|
||||||
return LuaParser::luaVec(sol::state_view(s), pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table ServerLuaPlayer::get_block_pos(sol::this_state s) {
|
glm::vec3 ServerLuaPlayer::get_block_pos() {
|
||||||
glm::vec3 pos = glm::floor(player.getPos());
|
return glm::floor(player.getPos());
|
||||||
return LuaParser::luaVec(sol::state_view(s), pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLuaPlayer::set_pos(const sol::table &pos) {
|
void ServerLuaPlayer::set_pos(glm::vec3 pos) {
|
||||||
player.setPos({pos[1], pos[2], pos[3]}, true);
|
player.setPos(pos, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
sol::table ServerLuaPlayer::get_vel(sol::this_state s) {
|
glm::vec3 ServerLuaPlayer::get_vel() {
|
||||||
glm::vec3 vel = player.getVel();
|
return player.getVel();
|
||||||
return LuaParser::luaVec(sol::state_view(s), vel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLuaPlayer::set_vel(const sol::table &vel) {
|
void ServerLuaPlayer::set_vel(glm::vec3 vel) {
|
||||||
player.setVel({vel[1], vel[2], vel[3]}, true);
|
player.setVel(vel, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
float ServerLuaPlayer::get_look_yaw() {
|
float ServerLuaPlayer::get_look_yaw() {
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "ServerLuaInventory.h"
|
#include "ServerLuaInventory.h"
|
||||||
#include "../../../net/server/conn/ServerClient.h"
|
#include "../../../net/server/conn/ServerClient.h"
|
||||||
|
|
||||||
|
@ -20,12 +19,12 @@ public:
|
||||||
unsigned int get_cid();
|
unsigned int get_cid();
|
||||||
std::string get_address();
|
std::string get_address();
|
||||||
|
|
||||||
sol::table get_pos(sol::this_state s);
|
glm::vec3 get_pos();
|
||||||
sol::table get_block_pos(sol::this_state s);
|
glm::vec3 get_block_pos();
|
||||||
void set_pos(const sol::table& pos);
|
void set_pos(glm::vec3 pos);
|
||||||
|
|
||||||
sol::table get_vel(sol::this_state s);
|
glm::vec3 get_vel();
|
||||||
void set_vel(const sol::table& vel);
|
void set_vel(glm::vec3 vel);
|
||||||
|
|
||||||
float get_look_yaw();
|
float get_look_yaw();
|
||||||
void set_look_yaw(float rot);
|
void set_look_yaw(float rot);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
static void trigger_event(sol::state& lua) {
|
static void trigger_event(sol::state& lua) {
|
||||||
|
@ -19,14 +19,5 @@ namespace Api {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)");
|
)");
|
||||||
|
|
||||||
|
|
||||||
lua.script(R"(
|
|
||||||
zepha.__builtin.add_player = function(player)
|
|
||||||
table.insert(zepha.players, player)
|
|
||||||
zepha.__builtin.trigger_event("new_player", player)
|
|
||||||
zepha.__builtin.trigger_event("player_join", player)
|
|
||||||
end
|
|
||||||
)");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
static void update_entities(sol::state& lua) {
|
static void update_entities(sol::state& lua) {
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <sol2/sol.hpp>
|
|
||||||
|
|
||||||
|
#include "../../Lua.h"
|
||||||
#include "../../LuaParser.h"
|
#include "../../LuaParser.h"
|
||||||
|
|
||||||
namespace MenuApi {
|
namespace MenuApi {
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "../../../game/hud/GuiBuilder.h"
|
#include "../../../game/hud/GuiBuilder.h"
|
||||||
|
|
||||||
class LuaGuiElement;
|
class LuaGuiElement;
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "../../../game/ClientState.h"
|
#include "../../../game/ClientState.h"
|
||||||
|
|
||||||
namespace MenuApi {
|
namespace MenuApi {
|
||||||
|
|
|
@ -17,15 +17,12 @@ namespace Api {
|
||||||
static void add_entity_c(sol::state& lua, sol::table& core, ClientGame& defs, LocalWorld& world) {
|
static void add_entity_c(sol::state& lua, sol::table& core, ClientGame& defs, LocalWorld& world) {
|
||||||
core["entities"] = lua.create_table();
|
core["entities"] = lua.create_table();
|
||||||
|
|
||||||
core.set_function("add_entity", [&](sol::optional<sol::table> pos, sol::optional<std::string> identifier, sol::object staticData) {
|
core.set_function("add_entity", [&](glm::vec3 pos, std::string identifier, sol::object staticData) {
|
||||||
if (!identifier || !identifier->length()) throw std::runtime_error("Expected an identifier as the second argument.");
|
if (core["registered_entities"][identifier] == sol::nil) throw std::runtime_error("identifier '" + identifier + "' is not a valid entity identifier.");
|
||||||
if (!pos) throw std::runtime_error("Expected a position as the first argument.");
|
sol::table entityDef = core["registered_entities"][identifier];
|
||||||
|
|
||||||
if (core["registered_entities"][*identifier] == sol::nil) throw std::runtime_error("identifier '" + *identifier + "' is not a valid entity identifier.");
|
|
||||||
sol::table entityDef = core["registered_entities"][*identifier];
|
|
||||||
|
|
||||||
auto entity = std::make_unique<Entity>();
|
auto entity = std::make_unique<Entity>();
|
||||||
entity->setPos({pos->get<float>("x"), pos->get<float>("y"), pos->get<float>("z")});
|
entity->setPos(pos);
|
||||||
auto entityRef = std::make_shared<LocalLuaEntity>(std::move(entity), entities_ind++, defs);
|
auto entityRef = std::make_shared<LocalLuaEntity>(std::move(entity), entities_ind++, defs);
|
||||||
|
|
||||||
sol::table luaEntity = lua.create_table();
|
sol::table luaEntity = lua.create_table();
|
||||||
|
@ -37,9 +34,9 @@ namespace Api {
|
||||||
auto displayObject = luaEntity.get<sol::optional<std::string>>("display_object");
|
auto displayObject = luaEntity.get<sol::optional<std::string>>("display_object");
|
||||||
auto displayTexture = luaEntity.get<sol::optional<std::string>>("display_texture");
|
auto displayTexture = luaEntity.get<sol::optional<std::string>>("display_texture");
|
||||||
|
|
||||||
if (!displayType) throw std::runtime_error("entity '" + *identifier + "' is missing the display property.");
|
if (!displayType) throw std::runtime_error("entity '" + identifier + "' is missing the display property.");
|
||||||
if (!displayObject) throw std::runtime_error("entity '" + *identifier + "' is missing the display_object property.");
|
if (!displayObject) throw std::runtime_error("entity '" + identifier + "' is missing the display_object property.");
|
||||||
if (strncmp(displayType->data(), "model", 5) == 0 && !displayTexture) throw std::runtime_error("entity '" + *identifier + "' is missing the display_texture property.");
|
if (strncmp(displayType->data(), "model", 5) == 0 && !displayTexture) throw std::runtime_error("entity '" + identifier + "' is missing the display_texture property.");
|
||||||
|
|
||||||
entityRef->set_display_type(*displayType, *displayObject, displayTexture);
|
entityRef->set_display_type(*displayType, *displayObject, displayTexture);
|
||||||
|
|
||||||
|
@ -55,15 +52,12 @@ namespace Api {
|
||||||
static void add_entity_s(sol::state& lua, sol::table& core, ServerGame& defs, ServerWorld& world) {
|
static void add_entity_s(sol::state& lua, sol::table& core, ServerGame& defs, ServerWorld& world) {
|
||||||
core["entities"] = lua.create_table();
|
core["entities"] = lua.create_table();
|
||||||
|
|
||||||
core.set_function("add_entity", [&](sol::optional<sol::table> pos, sol::optional<std::string> identifier, sol::object staticData) {
|
core.set_function("add_entity", [&](glm::vec3 pos, std::string identifier, sol::object staticData) {
|
||||||
if (!identifier || !identifier->length()) throw std::runtime_error("Expected an identifier as the second argument.");
|
if (core["registered_entities"][identifier] == sol::nil) throw std::runtime_error("identifier '" + identifier + "' is not a valid entity identifier.");
|
||||||
if (!pos) throw std::runtime_error("Expected a position as the first argument.");
|
sol::table entityDef = core["registered_entities"][identifier];
|
||||||
|
|
||||||
if (core["registered_entities"][*identifier] == sol::nil) throw std::runtime_error("identifier '" + *identifier + "' is not a valid entity identifier.");
|
|
||||||
sol::table entityDef = core["registered_entities"][*identifier];
|
|
||||||
|
|
||||||
auto entity = std::make_unique<ServerEntity>(entities_ind);
|
auto entity = std::make_unique<ServerEntity>(entities_ind);
|
||||||
entity->setPos({pos->get<float>("x"), pos->get<float>("y"), pos->get<float>("z")});
|
entity->setPos(pos);
|
||||||
auto entityRef = std::make_shared<ServerLuaEntity>(std::move(entity), entities_ind++, defs);
|
auto entityRef = std::make_shared<ServerLuaEntity>(std::move(entity), entities_ind++, defs);
|
||||||
|
|
||||||
sol::table luaEntity = lua.create_table();
|
sol::table luaEntity = lua.create_table();
|
||||||
|
@ -75,9 +69,9 @@ namespace Api {
|
||||||
auto displayObject = luaEntity.get<sol::optional<std::string>>("display_object");
|
auto displayObject = luaEntity.get<sol::optional<std::string>>("display_object");
|
||||||
auto displayTexture = luaEntity.get<sol::optional<std::string>>("display_texture");
|
auto displayTexture = luaEntity.get<sol::optional<std::string>>("display_texture");
|
||||||
|
|
||||||
if (!displayType) throw std::runtime_error("entity '" + *identifier + "' is missing the display property.");
|
if (!displayType) throw std::runtime_error("entity '" + identifier + "' is missing the display property.");
|
||||||
if (!displayObject) throw std::runtime_error("entity '" + *identifier + "' is missing the display_object property.");
|
if (!displayObject) throw std::runtime_error("entity '" + identifier + "' is missing the display_object property.");
|
||||||
if (strncmp(displayType->data(), "model", 5) == 0 && !displayTexture) throw std::runtime_error("entity '" + *identifier + "' is missing the display_texture property.");
|
if (strncmp(displayType->data(), "model", 5) == 0 && !displayTexture) throw std::runtime_error("entity '" + identifier + "' is missing the display_texture property.");
|
||||||
|
|
||||||
entityRef->set_display_type(*displayType, *displayObject, displayTexture);
|
entityRef->set_display_type(*displayType, *displayObject, displayTexture);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace Api {
|
||||||
core.set_function("create_structure", [&](sol::optional<sol::table> data) {
|
core.set_function("create_structure", [&](sol::optional<sol::table> data) {
|
||||||
if (!data) throw "expected a table as the first argument.";
|
if (!data) throw "expected a table as the first argument.";
|
||||||
|
|
||||||
auto origin = data->get<sol::optional<sol::table>>("origin");
|
auto origin = data->get<sol::optional<glm::vec3>>("origin");
|
||||||
auto schematic = data->get<sol::optional<sol::table>>("schematic");
|
auto schematic = data->get<sol::optional<sol::table>>("schematic");
|
||||||
|
|
||||||
if (!origin) throw std::runtime_error("expected a table as the first argument.");
|
if (!origin) throw std::runtime_error("expected a table as the first argument.");
|
||||||
|
@ -26,7 +26,7 @@ namespace Api {
|
||||||
s->dimensions = {xWid, yWid, zWid};
|
s->dimensions = {xWid, yWid, zWid};
|
||||||
s->stringData.resize(xWid * yWid * zWid);
|
s->stringData.resize(xWid * yWid * zWid);
|
||||||
|
|
||||||
s->origin = {origin->get<unsigned int>(1), origin->get<unsigned int>(2), origin->get<unsigned int>(3)};
|
s->origin = origin ? glm::ivec3{*origin} : glm::ivec3 {};
|
||||||
|
|
||||||
for (unsigned int y = 1; y <= yWid; y++) {
|
for (unsigned int y = 1; y <= yWid; y++) {
|
||||||
for (unsigned int z = 1; z <= zWid; z++) {
|
for (unsigned int z = 1; z <= zWid; z++) {
|
||||||
|
|
|
@ -9,11 +9,8 @@
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
static void get_block(sol::table &core, DefinitionAtlas& defs, World& world) {
|
static void get_block(sol::table &core, DefinitionAtlas& defs, World& world) {
|
||||||
core.set_function("get_block", [&](sol::table pos) -> std::string {
|
core.set_function("get_block", [&](glm::ivec3 pos) {
|
||||||
if (!pos.get<sol::optional<float>>("x") || !pos.get<sol::optional<float>>("y") || !pos.get<sol::optional<float>>("z"))
|
return defs.fromId(world.getBlock(pos)).identifier;
|
||||||
throw std::runtime_error("Expected a vector as the first argument.");
|
|
||||||
|
|
||||||
return defs.fromId(world.getBlock({pos.get<float>("x"), pos.get<float>("y"), pos.get<float>("z")})).identifier;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,9 @@
|
||||||
|
|
||||||
namespace Api {
|
namespace Api {
|
||||||
static void set_block(sol::table &core, DefinitionAtlas& defs, World& world) {
|
static void set_block(sol::table &core, DefinitionAtlas& defs, World& world) {
|
||||||
core.set_function("set_block", [&](sol::table pos, std::string identifier) {
|
core.set_function("set_block", [&](glm::vec3 pos, std::string identifier) {
|
||||||
if (!pos["x"] || !pos["y"] || !pos["z"]) throw std::runtime_error("expected a vector as the first argument.");
|
|
||||||
auto& block = defs.fromStr(identifier);
|
auto& block = defs.fromStr(identifier);
|
||||||
world.setBlock({pos.get<float>("x"), pos.get<float>("y"), pos.get<float>("z")}, block.index);
|
world.setBlock(pos, block.index);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "../class/LocalLuaInventory.h"
|
#include "../class/LocalLuaInventory.h"
|
||||||
#include "../class/LocalLuaInventoryList.h"
|
#include "../class/LocalLuaInventoryList.h"
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "../class/LuaItemStack.h"
|
#include "../class/LuaItemStack.h"
|
||||||
|
|
||||||
namespace ClientApi {
|
namespace ClientApi {
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "../class/LocalLuaEntity.h"
|
#include "../class/LocalLuaEntity.h"
|
||||||
#include "../../../game/scene/world/LocalWorld.h"
|
#include "../../../game/scene/world/LocalWorld.h"
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "../class/ServerLuaInventory.h"
|
#include "../class/ServerLuaInventory.h"
|
||||||
#include "../class/ServerLuaInventoryList.h"
|
#include "../class/ServerLuaInventoryList.h"
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../../Lua.h"
|
||||||
|
|
||||||
#include "../class/ServerLuaEntity.h"
|
#include "../class/ServerLuaEntity.h"
|
||||||
|
|
||||||
namespace ServerApi {
|
namespace ServerApi {
|
||||||
|
|
|
@ -0,0 +1,129 @@
|
||||||
|
//
|
||||||
|
// Vec3 to Vector table customization.
|
||||||
|
// Allows sol to transfer glm::vec3 and glm::vec3 to a Lua vector table and back.
|
||||||
|
// This customization was based off of code provided by rubenwardy.
|
||||||
|
// Created by aurailus on 2020-07-22.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma ide diagnostic ignored "OCUnusedStructInspection"
|
||||||
|
#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glm/vec3.hpp>
|
||||||
|
#include "../../util/Util.h"
|
||||||
|
|
||||||
|
namespace sol {
|
||||||
|
|
||||||
|
// Float
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct lua_size<glm::vec3> : std::integral_constant<int, 1> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct lua_type_of<glm::vec3> : std::integral_constant<type, type::table> {};
|
||||||
|
|
||||||
|
template <typename Handler>
|
||||||
|
inline bool sol_lua_check(types<glm::vec3>, lua_State* L, int index, Handler&& handler, stack::record& tracking) {
|
||||||
|
int absoluteIndex = lua_absindex(L, index);
|
||||||
|
if (!stack::check<table>(L, absoluteIndex, handler)) {
|
||||||
|
tracking.use(1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
stack::get_field(L, 1, absoluteIndex);
|
||||||
|
bool x = stack::check<float>(L, -1);
|
||||||
|
|
||||||
|
stack::get_field(L, 2, absoluteIndex);
|
||||||
|
bool y = stack::check<float>(L, -1);
|
||||||
|
|
||||||
|
stack::get_field(L, 3, absoluteIndex);
|
||||||
|
bool z = stack::check<float>(L, -1);
|
||||||
|
|
||||||
|
stack::pop_n(L, 3);
|
||||||
|
tracking.use(1);
|
||||||
|
return x && y && z;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline glm::vec3 sol_lua_get(types<glm::vec3>, lua_State* L, int index, stack::record& tracking) {
|
||||||
|
int absoluteIndex = lua_absindex(L, index);
|
||||||
|
|
||||||
|
sol::table table = stack::get<sol::table>(L, absoluteIndex);
|
||||||
|
float x = table[1];
|
||||||
|
float y = table[2];
|
||||||
|
float z = table[3];
|
||||||
|
|
||||||
|
tracking.use(1);
|
||||||
|
return glm::vec3 { x, y, z };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline int sol_lua_push(sol::types<glm::vec3>, lua_State* L, const glm::vec3& vec) {
|
||||||
|
sol::state_view lua(L);
|
||||||
|
|
||||||
|
lua_createtable(L, 3, 0);
|
||||||
|
sol::stack_table tbl(L, -1);
|
||||||
|
tbl[1] = vec.x; tbl[2] = vec.y; tbl[3] = vec.z;
|
||||||
|
tbl[sol::metatable_key] = lua["vector"];
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct lua_size<glm::ivec3> : std::integral_constant<int, 1> {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct lua_type_of<glm::ivec3> : std::integral_constant<type, type::table> {};
|
||||||
|
|
||||||
|
template <typename Handler>
|
||||||
|
inline bool sol_lua_check(types<glm::ivec3>, lua_State* L, int index, Handler&& handler, stack::record& tracking) {
|
||||||
|
int absoluteIndex = lua_absindex(L, index);
|
||||||
|
if (!stack::check<table>(L, absoluteIndex, handler)) {
|
||||||
|
tracking.use(1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
stack::get_field(L, 1, absoluteIndex);
|
||||||
|
bool x = stack::check<int>(L, -1);
|
||||||
|
|
||||||
|
stack::get_field(L, 2, absoluteIndex);
|
||||||
|
bool y = stack::check<int>(L, -1);
|
||||||
|
|
||||||
|
stack::get_field(L, 3, absoluteIndex);
|
||||||
|
bool z = stack::check<int>(L, -1);
|
||||||
|
|
||||||
|
stack::pop_n(L, 3);
|
||||||
|
tracking.use(1);
|
||||||
|
return x && y && z;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline glm::ivec3 sol_lua_get(types<glm::ivec3>, lua_State* L, int index, stack::record& tracking) {
|
||||||
|
int absoluteIndex = lua_absindex(L, index);
|
||||||
|
|
||||||
|
sol::table table = stack::get<sol::table>(L, absoluteIndex);
|
||||||
|
int x = table[1];
|
||||||
|
int y = table[2];
|
||||||
|
int z = table[3];
|
||||||
|
|
||||||
|
tracking.use(1);
|
||||||
|
return glm::ivec3 { x, y, z };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline int sol_lua_push(sol::types<glm::ivec3>, lua_State* L, const glm::ivec3& vec) {
|
||||||
|
sol::state_view lua(L);
|
||||||
|
|
||||||
|
lua_createtable(L, 3, 0);
|
||||||
|
sol::stack_table tbl(L, -1);
|
||||||
|
tbl[1] = vec.x; tbl[2] = vec.y; tbl[3] = vec.z;
|
||||||
|
tbl[sol::metatable_key] = lua["vector"];
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma clang diagnostic pop
|
|
@ -123,33 +123,36 @@ sol::protected_function_result LocalLuaParser::errorCallback(sol::protected_func
|
||||||
sol::error err = errPfr;
|
sol::error err = errPfr;
|
||||||
std::string errString = err.what();
|
std::string errString = err.what();
|
||||||
|
|
||||||
std::string::size_type slash = errString.find('/');
|
try {
|
||||||
assert(slash != std::string::npos);
|
std::string::size_type slash = errString.find('/');
|
||||||
|
if (slash != std::string::npos) throw "npos";
|
||||||
|
|
||||||
std::string modString = errString.substr(0, slash);
|
std::string modString = errString.substr(0, slash);
|
||||||
|
|
||||||
std::string::size_type lineNumStart = errString.find(':', slash);
|
std::string::size_type lineNumStart = errString.find(':', slash);
|
||||||
assert(lineNumStart != std::string::npos);
|
if (lineNumStart != std::string::npos) throw "lineNumStart";
|
||||||
std::string::size_type lineNumEnd = errString.find(':', lineNumStart + 1);
|
std::string::size_type lineNumEnd = errString.find(':', lineNumStart + 1);
|
||||||
assert(lineNumEnd != std::string::npos);
|
if (lineNumStart != std::string::npos) throw "lineNumEnd";
|
||||||
|
|
||||||
std::string fileName = errString.substr(0, lineNumStart);
|
std::string fileName = errString.substr(0, lineNumStart);
|
||||||
int lineNum = std::stoi(errString.substr(lineNumStart + 1, lineNumEnd - lineNumStart - 1));
|
int lineNum = std::stoi(errString.substr(lineNumStart + 1, lineNumEnd - lineNumStart - 1));
|
||||||
|
|
||||||
for (const auto& mod : handler.cGetMods()) {
|
for (const auto& mod : handler.cGetMods()) {
|
||||||
if (mod.config.name == modString) {
|
if (mod.config.name == modString) {
|
||||||
for (auto& file : mod.files) {
|
for (auto& file : mod.files) {
|
||||||
if (file.path == fileName) {
|
if (file.path == fileName) {
|
||||||
std::cout << std::endl << ErrorFormatter::formatError(fileName, lineNum, errString, file.file) << std::endl;
|
std::cout << std::endl << ErrorFormatter::formatError(fileName, lineNum, errString, file.file) << std::endl;
|
||||||
exit(1);
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (...) {
|
||||||
std::cout << Log::err << "Zepha has encountered an error, and ErrorFormatter failed to format it:"
|
std::cout << Log::err << "Zepha has encountered an error, and ErrorFormatter failed to format it:"
|
||||||
<< std::endl << errString << Log::endl;
|
<< std::endl << std::endl << errString << Log::endl;
|
||||||
|
}
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
return errPfr;
|
return errPfr;
|
||||||
|
|
|
@ -76,7 +76,12 @@ void ServerLuaParser::sendModsPacket(ENetPeer* peer) const {
|
||||||
|
|
||||||
void ServerLuaParser::playerConnected(std::shared_ptr<ServerClient> client) {
|
void ServerLuaParser::playerConnected(std::shared_ptr<ServerClient> client) {
|
||||||
auto players = core.get<sol::table>("players");
|
auto players = core.get<sol::table>("players");
|
||||||
safe_function(core["__builtin"]["add_player"], ServerLuaPlayer(*client));
|
players.add(ServerLuaPlayer(*client));
|
||||||
|
|
||||||
|
sol::object player = players[players.size()];
|
||||||
|
|
||||||
|
safe_function(core["__builtin"]["trigger_event"], "new_player", player);
|
||||||
|
safe_function(core["__builtin"]["trigger_event"], "player_join", player);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerLuaParser::playerDisconnected(std::shared_ptr<ServerClient> client) {
|
void ServerLuaParser::playerDisconnected(std::shared_ptr<ServerClient> client) {
|
||||||
|
@ -148,33 +153,36 @@ sol::protected_function_result ServerLuaParser::errorCallback(sol::protected_fun
|
||||||
sol::error err = errPfr;
|
sol::error err = errPfr;
|
||||||
std::string errString = err.what();
|
std::string errString = err.what();
|
||||||
|
|
||||||
std::string::size_type slash = errString.find_first_of("/");
|
try {
|
||||||
assert(slash != std::string::npos);
|
std::string::size_type slash = errString.find_first_of("/");
|
||||||
|
if (slash != std::string::npos) throw "npos";
|
||||||
|
|
||||||
std::string modString = errString.substr(0, slash);
|
std::string modString = errString.substr(0, slash);
|
||||||
|
|
||||||
std::string::size_type lineNumStart = errString.find(':', slash);
|
std::string::size_type lineNumStart = errString.find(':', slash);
|
||||||
assert(lineNumStart != std::string::npos);
|
if (lineNumStart != std::string::npos) throw "lineNumStart";
|
||||||
std::string::size_type lineNumEnd = errString.find(':', lineNumStart + 1);
|
std::string::size_type lineNumEnd = errString.find(':', lineNumStart + 1);
|
||||||
assert(lineNumEnd != std::string::npos);
|
if (lineNumStart != std::string::npos) throw "lineNumEnd";
|
||||||
|
|
||||||
std::string fileName = errString.substr(0, lineNumStart);
|
std::string fileName = errString.substr(0, lineNumStart);
|
||||||
int lineNum = std::stoi(errString.substr(lineNumStart + 1, lineNumEnd - lineNumStart - 1));
|
int lineNum = std::stoi(errString.substr(lineNumStart + 1, lineNumEnd - lineNumStart - 1));
|
||||||
|
|
||||||
for (auto& mod : handler.cGetMods()) {
|
for (auto& mod : handler.cGetMods()) {
|
||||||
if (mod.config.name == modString) {
|
if (mod.config.name == modString) {
|
||||||
for (auto& file : mod.files) {
|
for (auto& file : mod.files) {
|
||||||
if (file.path == fileName) {
|
if (file.path == fileName) {
|
||||||
std::cout << std::endl << ErrorFormatter::formatError(fileName, lineNum, errString, file.file) << std::endl;
|
std::cout << std::endl << ErrorFormatter::formatError(fileName, lineNum, errString, file.file) << std::endl;
|
||||||
exit(1);
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (...) {
|
||||||
std::cout << Log::err << "Zepha has encountered an error, and ErrorFormatter failed to format it:"
|
std::cout << Log::err << "Zepha has encountered an error, and ErrorFormatter failed to format it:"
|
||||||
<< std::endl << std::endl << errString << Log::endl;
|
<< std::endl << std::endl << errString << Log::endl;
|
||||||
|
}
|
||||||
|
|
||||||
exit(1);
|
exit(1);
|
||||||
return errPfr;
|
return errPfr;
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
|
||||||
#include <noise/module/modulebase.h>
|
#include <noise/module/modulebase.h>
|
||||||
#include <noise/module/add.h>
|
#include <noise/module/add.h>
|
||||||
#include <noise/module/module.h>
|
#include <noise/module/module.h>
|
||||||
|
|
||||||
|
#include "../Lua.h"
|
||||||
#include "../../util/Util.h"
|
#include "../../util/Util.h"
|
||||||
#include "../../def/ClientGame.h"
|
#include "../../def/ClientGame.h"
|
||||||
#include "../../def/ServerGame.h"
|
#include "../../def/ServerGame.h"
|
||||||
|
@ -241,6 +241,7 @@ namespace RegisterBiomes {
|
||||||
modules.push_back(module);
|
modules.push_back(module);
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
throw std::runtime_error("Invalid noise module specified.");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void registerBiomes(sol::table source, DefinitionAtlas& defs, BiomeAtlas& biomes) {
|
static void registerBiomes(sol::table source, DefinitionAtlas& defs, BiomeAtlas& biomes) {
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../Lua.h"
|
||||||
|
|
||||||
#include "../Callback.h"
|
#include "../Callback.h"
|
||||||
#include "../../def/ItemDef.h"
|
#include "../../def/ItemDef.h"
|
||||||
#include "../../def/ClientGame.h"
|
#include "../../def/ClientGame.h"
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../Lua.h"
|
||||||
|
|
||||||
#include "../../def/ClientGame.h"
|
#include "../../def/ClientGame.h"
|
||||||
#include "../../def/ServerGame.h"
|
#include "../../def/ServerGame.h"
|
||||||
#include "../../def/gen/BiomeDef.h"
|
#include "../../def/gen/BiomeDef.h"
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sol2/sol.hpp>
|
#include "../Lua.h"
|
||||||
|
|
||||||
#include "../../def/ClientGame.h"
|
#include "../../def/ClientGame.h"
|
||||||
#include "../../def/ServerGame.h"
|
#include "../../def/ServerGame.h"
|
||||||
#include "../../def/gen/BiomeDef.h"
|
#include "../../def/gen/BiomeDef.h"
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stdexcept>
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ public:
|
||||||
Deserializer(const std::string& data) : data(&data[0]), len(data.length()) {};
|
Deserializer(const std::string& data) : data(&data[0]), len(data.length()) {};
|
||||||
Deserializer(const char* start, size_t len) : data(start), len(len) {};
|
Deserializer(const char* start, size_t len) : data(start), len(len) {};
|
||||||
|
|
||||||
template <typename T> inline T read() { assert(false); };
|
template <typename T> inline T read() { throw std::runtime_error("Tried to append a non-serializable type"); };
|
||||||
template <typename T> inline Deserializer& read(T& ref) {
|
template <typename T> inline Deserializer& read(T& ref) {
|
||||||
ref = read<T>();
|
ref = read<T>();
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <stdexcept>
|
||||||
#include <glm/vec2.hpp>
|
#include <glm/vec2.hpp>
|
||||||
#include <glm/vec3.hpp>
|
#include <glm/vec3.hpp>
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ class Serializer {
|
||||||
public:
|
public:
|
||||||
std::string data {};
|
std::string data {};
|
||||||
|
|
||||||
template <typename T> inline Serializer& append(const T& elem) { assert(false); };
|
template <typename T> inline Serializer& append(const T& elem) { throw std::runtime_error("Tried to append a non-serializable type"); };
|
||||||
|
|
||||||
Packet packet(PacketType p, bool reliable = true) {
|
Packet packet(PacketType p, bool reliable = true) {
|
||||||
Packet packet(p, reliable);
|
Packet packet(p, reliable);
|
||||||
|
|
|
@ -130,52 +130,38 @@ void Server::handlePlayerPacket(ServerClient& client, PacketView& p) {
|
||||||
|
|
||||||
if (block == DefinitionAtlas::AIR) {
|
if (block == DefinitionAtlas::AIR) {
|
||||||
auto def = defs.defs.blockFromId(worldBlock);
|
auto def = defs.defs.blockFromId(worldBlock);
|
||||||
if (def.callbacks.count(Callback::BREAK)) {
|
//TODO: stop casting to float vec3
|
||||||
defs.parser.safe_function(def.callbacks[Callback::BREAK],
|
if (def.callbacks.count(Callback::BREAK)) defs.parser.safe_function(def.callbacks[Callback::BREAK], glm::vec3(pos), ServerLuaPlayer(client));
|
||||||
defs.parser.luaVec(pos), ServerLuaPlayer(client));
|
defs.parser.safe_function(defs.parser.core["__builtin"]["trigger_event"], "break", glm::vec3(pos), ServerLuaPlayer(client));
|
||||||
}
|
|
||||||
defs.parser.safe_function(defs.parser.core["__builtin"]["trigger_event"],
|
|
||||||
"break", defs.parser.luaVec(pos), ServerLuaPlayer(client));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto def = defs.defs.blockFromId(block);
|
auto def = defs.defs.blockFromId(block);
|
||||||
if (def.callbacks.count(Callback::PLACE)) {
|
if (def.callbacks.count(Callback::PLACE))
|
||||||
defs.parser.safe_function(def.callbacks[Callback::PLACE],
|
defs.parser.safe_function(def.callbacks[Callback::PLACE], pos, ServerLuaPlayer(client));
|
||||||
defs.parser.luaVec(pos), ServerLuaPlayer(client));
|
defs.parser.safe_function(defs.parser.core["__builtin"]["trigger_event"], "place", pos, ServerLuaPlayer(client));
|
||||||
}
|
|
||||||
defs.parser.safe_function(defs.parser.core["__builtin"]["trigger_event"],
|
|
||||||
"place", defs.parser.luaVec(pos), ServerLuaPlayer(client));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
world.setBlock(pos, block);
|
world.setBlock(pos, block);
|
||||||
|
|
||||||
if (block == DefinitionAtlas::AIR) {
|
if (block == DefinitionAtlas::AIR) {
|
||||||
auto def = defs.defs.blockFromId(worldBlock);
|
auto def = defs.defs.blockFromId(worldBlock);
|
||||||
if (def.callbacks.count(Callback::AFTER_BREAK)) {
|
if (def.callbacks.count(Callback::AFTER_BREAK))
|
||||||
defs.parser.safe_function(def.callbacks[Callback::AFTER_BREAK],
|
defs.parser.safe_function(def.callbacks[Callback::AFTER_BREAK], pos, ServerLuaPlayer(client));
|
||||||
defs.parser.luaVec(pos), ServerLuaPlayer(client));
|
defs.parser.safe_function(defs.parser.core["__builtin"]["trigger_event"], "after_break", pos, ServerLuaPlayer(client));
|
||||||
}
|
|
||||||
defs.parser.safe_function(defs.parser.core["__builtin"]["trigger_event"],
|
|
||||||
"after_break", defs.parser.luaVec(pos), ServerLuaPlayer(client));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto def = defs.defs.blockFromId(block);
|
auto def = defs.defs.blockFromId(block);
|
||||||
if (def.callbacks.count(Callback::AFTER_PLACE)) {
|
if (def.callbacks.count(Callback::AFTER_PLACE))
|
||||||
defs.parser.safe_function(def.callbacks[Callback::AFTER_PLACE],
|
defs.parser.safe_function(def.callbacks[Callback::AFTER_PLACE], pos, ServerLuaPlayer(client));
|
||||||
defs.parser.luaVec(pos), ServerLuaPlayer(client));
|
defs.parser.safe_function(defs.parser.core["__builtin"]["trigger_event"], "after_place", pos, ServerLuaPlayer(client));
|
||||||
}
|
|
||||||
defs.parser.safe_function(defs.parser.core["__builtin"]["trigger_event"],
|
|
||||||
"after_place", defs.parser.luaVec(pos), ServerLuaPlayer(client));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PacketType::BLOCK_INTERACT: {
|
case PacketType::BLOCK_INTERACT: {
|
||||||
glm::ivec3 pos = p.d.read<glm::ivec3>();
|
glm::ivec3 pos = p.d.read<glm::ivec3>();
|
||||||
auto def = defs.defs.blockFromId(world.getBlock(pos));
|
auto def = defs.defs.blockFromId(world.getBlock(pos));
|
||||||
if (def.callbacks.count(Callback::INTERACT)) {
|
if (def.callbacks.count(Callback::INTERACT))
|
||||||
defs.parser.safe_function(def.callbacks[Callback::INTERACT],
|
defs.parser.safe_function(def.callbacks[Callback::INTERACT], pos, ServerLuaPlayer(client));
|
||||||
defs.parser.luaVec(pos), ServerLuaPlayer(client));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PacketType::INV_WATCH: {
|
case PacketType::INV_WATCH: {
|
||||||
|
|
|
@ -218,15 +218,11 @@ void ServerWorld::setBlock(glm::ivec3 pos, unsigned int block) {
|
||||||
|
|
||||||
if (block == DefinitionAtlas::AIR) {
|
if (block == DefinitionAtlas::AIR) {
|
||||||
auto def = game.defs.blockFromId(oldBlock);
|
auto def = game.defs.blockFromId(oldBlock);
|
||||||
if (def.callbacks.count(Callback::DESTRUCT)) {
|
if (def.callbacks.count(Callback::DESTRUCT)) def.callbacks[Callback::DESTRUCT](pos);
|
||||||
def.callbacks[Callback::DESTRUCT](game.parser.luaVec(pos));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto def = game.defs.blockFromId(block);
|
auto def = game.defs.blockFromId(block);
|
||||||
if (def.callbacks.count(Callback::CONSTRUCT)) {
|
if (def.callbacks.count(Callback::CONSTRUCT)) def.callbacks[Callback::CONSTRUCT](pos);
|
||||||
def.callbacks[Callback::CONSTRUCT](game.parser.luaVec(pos));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dimension.setBlock(pos, block);
|
dimension.setBlock(pos, block);
|
||||||
|
@ -248,13 +244,11 @@ void ServerWorld::setBlock(glm::ivec3 pos, unsigned int block) {
|
||||||
|
|
||||||
if (block == DefinitionAtlas::AIR) {
|
if (block == DefinitionAtlas::AIR) {
|
||||||
auto def = game.defs.blockFromId(oldBlock);
|
auto def = game.defs.blockFromId(oldBlock);
|
||||||
if (def.callbacks.count(Callback::AFTER_DESTRUCT))
|
if (def.callbacks.count(Callback::AFTER_DESTRUCT)) def.callbacks[Callback::AFTER_DESTRUCT](pos);
|
||||||
def.callbacks[Callback::AFTER_DESTRUCT](game.parser.luaVec(pos));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
auto def = game.defs.blockFromId(block);
|
auto def = game.defs.blockFromId(block);
|
||||||
if (def.callbacks.count(Callback::AFTER_CONSTRUCT))
|
if (def.callbacks.count(Callback::AFTER_CONSTRUCT)) def.callbacks[Callback::AFTER_CONSTRUCT](pos);
|
||||||
def.callbacks[Callback::AFTER_CONSTRUCT](game.parser.luaVec(pos));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,11 @@ _G["crafting"] = {}
|
||||||
|
|
||||||
crafting.registered_recipes = {}
|
crafting.registered_recipes = {}
|
||||||
|
|
||||||
crafting.register_recipe = function(tbl)
|
function crafting.register_recipe(tbl)
|
||||||
table.insert(crafting.registered_recipes, tbl)
|
table.insert(crafting.registered_recipes, tbl)
|
||||||
end
|
end
|
||||||
|
|
||||||
crafting.bind = function(craft_input, craft_output)
|
function crafting.bind(craft_input, craft_output)
|
||||||
local width = craft_input.width
|
local width = craft_input.width
|
||||||
local length = craft_input.length
|
local length = craft_input.length
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ zepha.register_entity("@aurailus:item_collection:dropped_item", {
|
||||||
end,
|
end,
|
||||||
check_collect = function(self)
|
check_collect = function(self)
|
||||||
for _,p in pairs(zepha.players) do
|
for _,p in pairs(zepha.players) do
|
||||||
if p.pos:dist(self.object.pos) < 2 then
|
if p.pos:distance(self.object.pos) < 2 then
|
||||||
self.object.pos = p.pos + V{0, 0.90, 0}
|
self.object.pos = p.pos + V{0, 0.90, 0}
|
||||||
self.scooping = true
|
self.scooping = true
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,4 @@ zepha.register_entity("zeus:default:test", {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
if zepha.client then
|
if zepha.client then entity = zepha.add_entity(V(), "zeus:default:test") end
|
||||||
local entity = zepha.add_entity(V{}, "zeus:default:test")
|
|
||||||
end
|
|
|
@ -28,11 +28,4 @@ zepha.register_keybind("zeus:default:double_jump_fly", {
|
||||||
if press - last_press < 0.25 then toggleFlying() end
|
if press - last_press < 0.25 then toggleFlying() end
|
||||||
last_press = press;
|
last_press = press;
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- if (zepha.client) then
|
|
||||||
-- zepha.delay(function()
|
|
||||||
-- zepha.get_hit_impact(zepha.player, "zeus:default:stone")
|
|
||||||
-- return true
|
|
||||||
-- end, 1)
|
|
||||||
-- end
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
|
|
||||||
local shrub = zepha.create_structure({
|
local shrub = zepha.create_structure({
|
||||||
origin = V{},
|
origin = V{1, 2, 3},
|
||||||
schematic = {
|
schematic = {
|
||||||
{{"zeus:default:tallgrass_4"}}
|
{{"zeus:default:tallgrass_4"}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <sol2/sol.hpp>
|
#include <sol/sol.hpp>
|
||||||
|
|
||||||
TEST_CASE("Catch2 Library", "[core]") {
|
TEST_CASE("Catch2 Library", "[core]") {
|
||||||
REQUIRE(true);
|
REQUIRE(true);
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <iostream>
|
|
||||||
#include "../../src/world/chunk/Chunk.h"
|
#include "../../src/world/chunk/Chunk.h"
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../../src/util/net/Serializer.h"
|
#include "../../src/net/Serializer.h"
|
||||||
#include "../../src/util/net/Deserializer.h"
|
#include "../../src/net/Deserializer.h"
|
||||||
|
|
||||||
TEST_CASE("Serialization", "[net]") {
|
TEST_CASE("Serialization", "[net]") {
|
||||||
Serializer s;
|
Serializer s;
|
||||||
|
|
Loading…
Reference in New Issue