This commit is contained in:
sekta 2024-07-31 17:42:28 +04:00
commit bee4421ce9
7 changed files with 58 additions and 30 deletions

View File

@ -34,10 +34,10 @@ block.place(x: int, y: int, z: int, id: int, states: int, [optional] playerid: i
block.destruct(x: int, y: int, z: int, playerid: int) block.destruct(x: int, y: int, z: int, playerid: int)
-- Compose the complete state as an integer -- Compose the complete state as an integer
block.compose_state(rotation: int, segment: int, userbits: int) -> int block.compose_state(state: {rotation: int, segment: int, userbits: int}) -> int
-- Decompose the complete state into: rotation, segment, user bits -- Decompose the complete state into: rotation, segment, user bits
block.decompose_state(state: int) -> int, int, int block.decompose_state(state: int) -> {int, int, int}
``` ```
> [!WARNING] > [!WARNING]

View File

@ -111,7 +111,7 @@ mat4.decompose(m: matrix)
translation=vec3, translation=vec3,
skew=vec3, skew=vec3,
perspective=vec4 perspective=vec4
} } or nil
``` ```
## Look at point - *mat4.look_at(...)* ## Look at point - *mat4.look_at(...)*

View File

@ -33,10 +33,10 @@ block.place(x: int, y: int, z: int, id: int, states: int, [optional] playerid: i
block.destruct(x: int, y: int, z: int, playerid: int) block.destruct(x: int, y: int, z: int, playerid: int)
-- Собирает полное состояние в виде целого числа -- Собирает полное состояние в виде целого числа
block.compose_state(rotation: int, segment: int, userbits: int) -> int block.compose_state(state: {rotation: int, segment: int, userbits: int}) -> int
-- Разбирает полное состояние на: вращение, сегмент, пользовательские биты -- Разбирает полное состояние на: вращение, сегмент, пользовательские биты
block.decompose_state(state: int) -> int, int, int block.decompose_state(state: int) -> {int, int, int}
``` ```
> [!WARNING] > [!WARNING]

View File

@ -111,7 +111,7 @@ mat4.decompose(m: matrix)
translation=vec3, translation=vec3,
skew=vec3, skew=vec3,
perspective=vec4 perspective=vec4
} } или nil
``` ```
## Отслеживание точки *mat4.look_at(...)* ## Отслеживание точки *mat4.look_at(...)*

View File

@ -69,6 +69,21 @@ console.add_command(
end end
) )
local function FormattedTime(seconds, format ) -- from gmod
if not seconds then seconds = 0 end
local hours = math.floor(seconds / 3600)
local minutes = math.floor((seconds / 60) % 60)
local millisecs = (seconds - math.floor(seconds)) * 100
seconds = math.floor(seconds % 60)
if format then
return string.format(format, minutes, seconds, millisecs)
else
return {h = hours, m = minutes, s = seconds, ms = millisecs}
end
end
console.add_command( console.add_command(
"time.uptime", "time.uptime",
"Get time elapsed since the engine started", "Get time elapsed since the engine started",
@ -76,7 +91,7 @@ console.add_command(
local uptime = time.uptime() local uptime = time.uptime()
local formatted_uptime = "" local formatted_uptime = ""
local t = string.formatted_time(uptime) local t = FormattedTime(uptime)
formatted_uptime = t.h .. "h " .. t.m .. "m " .. t.s .. "s" formatted_uptime = t.h .. "h " .. t.m .. "m " .. t.s .. "s"

View File

@ -381,20 +381,32 @@ static int l_raycast(lua::State* L) {
} }
static int l_compose_state(lua::State* L) { static int l_compose_state(lua::State* L) {
if (lua::istable(L, 1) || lua::objlen(L, 1) < 3) {
throw std::runtime_error("expected array of 3 integers");
}
blockstate state {}; blockstate state {};
state.rotation = lua::tointeger(L, 1);
state.segment = lua::tointeger(L, 2); lua::rawgeti(L, 1, 1); state.rotation = lua::tointeger(L, -1); lua::pop(L);
state.userbits = lua::tointeger(L, 3); lua::rawgeti(L, 2, 1); state.segment = lua::tointeger(L, -1); lua::pop(L);
lua::rawgeti(L, 3, 1); state.userbits = lua::tointeger(L, -1); lua::pop(L);
return lua::pushinteger(L, blockstate2int(state)); return lua::pushinteger(L, blockstate2int(state));
} }
static int l_decompose_state(lua::State* L) { static int l_decompose_state(lua::State* L) {
auto stateInt = static_cast<blockstate_t>(lua::tointeger(L, 1)); auto stateInt = static_cast<blockstate_t>(lua::tointeger(L, 1));
auto state = int2blockstate(stateInt); auto state = int2blockstate(stateInt);
lua::createtable(L, 3, 0);
lua::pushinteger(L, state.rotation); lua::pushinteger(L, state.rotation);
lua::rawseti(L, 1);
lua::pushinteger(L, state.segment); lua::pushinteger(L, state.segment);
lua::rawseti(L, 2);
lua::pushinteger(L, state.userbits); lua::pushinteger(L, state.userbits);
return 3; lua::rawseti(L, 3);
return 1;
} }
const luaL_Reg blocklib [] = { const luaL_Reg blocklib [] = {

View File

@ -165,7 +165,7 @@ static int l_transpose(lua::State* L) {
/// translation=float[3], /// translation=float[3],
/// skew=float[3], /// skew=float[3],
/// perspective=float[4] /// perspective=float[4]
/// } /// } or nil
static int l_decompose(lua::State* L) { static int l_decompose(lua::State* L) {
auto matrix = lua::tomat4(L, 1); auto matrix = lua::tomat4(L, 1);
glm::vec3 scale; glm::vec3 scale;
@ -173,35 +173,36 @@ static int l_decompose(lua::State* L) {
glm::vec3 translation; glm::vec3 translation;
glm::vec3 skew; glm::vec3 skew;
glm::vec4 perspective; glm::vec4 perspective;
glm::decompose( if (glm::decompose(
matrix, matrix,
scale, scale,
rotation, rotation,
translation, translation,
skew, skew,
perspective perspective
); )) {
lua::createtable(L, 0, 6);
lua::pushvec3(L, scale);
lua::setfield(L, "scale");
lua::createtable(L, 0, 6); lua::pushmat4(L, glm::toMat4(rotation));
lua::setfield(L, "rotation");
lua::pushvec3(L, scale);
lua::setfield(L, "scale");
lua::pushmat4(L, glm::toMat4(rotation)); lua::pushquat(L, rotation);
lua::setfield(L, "rotation"); lua::setfield(L, "quaternion");
lua::pushquat(L, rotation); lua::pushvec3(L, translation);
lua::setfield(L, "quaternion"); lua::setfield(L, "translation");
lua::pushvec3(L, translation); lua::pushvec3(L, skew);
lua::setfield(L, "translation"); lua::setfield(L, "skew");
lua::pushvec3(L, skew); lua::pushvec4(L, perspective);
lua::setfield(L, "skew"); lua::setfield(L, "perspective");
return 1;
lua::pushvec4(L, perspective); }
lua::setfield(L, "perspective"); return 0;
return 1;
} }
static int l_look_at(lua::State* L) { static int l_look_at(lua::State* L) {