add rigidbody.get_linear_damping, .set_linear_damping

This commit is contained in:
MihailRis 2024-07-13 00:05:10 +03:00
parent 4aa76e35b7
commit 6214bf4a19
4 changed files with 129 additions and 30 deletions

22
doc/ru/resources.md Normal file
View File

@ -0,0 +1,22 @@
# Ресурсы
К ресурсам относятся:
- камеры
- слоты для эффектов
- фреймбуферы
- и подобные ограниченные по количеству ресурсы
На данный момент реализованы только **камеры**.
Запрашиваемые паком ресурсы указываются через файл resources.json в формате:
```json
{
"тип-ресура": [
"имена",
"ресурсов"
]
}
```
После загрузки пара имена ресурсов получат префикс пака. Например камера
*cinematic* в паке base получает имя *base:cinematic*.

View File

@ -0,0 +1,59 @@
# Компоненты
## Обозначения типов, используемые далее
- vec3 - 3D вектор (массив из трех чисел)
- mat4 - матрица 4x4 (массив из 16 чисел)
Аннотации типов добавлены в целях документации и не являются частью синтаксиса
Lua.
## Встроенные компоненты
### Transform
Компонент отвечает за позицию, масштаб и вращение сущности.
```lua
-- Сокращение
local tsf = entity.transform
-- Возвращает позицию сущности
tsf:get_pos() -> vec3
-- Устанавливает позицию сущности
tsf:set_pos(pos: vec3)
-- Возвращает масштаб сущности
tsf:get_size() -> vec3
-- Устанавливает масштаб сущности
tsf:set_size(size: vec3)
-- Возвращает вращение сущности
tsf:get_rot() -> mat4
-- Устанавливает вращение сущности
tsf:set_rot(size: mat4)
```
### Rigidbody
Компонент отвечает за физическое тело сущности.
```lua
-- Сокращение
local body = entity.rigidbody
-- Проверяет, включен ли рассчет физики тела
body:is_enabled() -> bool
-- Включает/выключает рассчет физики тела
body:set_enabled(enabled: bool)
-- Возвращает линейную скорость
body:get_vel() -> vec3
-- Устанавливает линейную скорость
body:set_vel(vel: vec3)
-- Возвращает размер хитбокса
body:get_size() -> vec3
-- Устанавливает размер хитбокса
body:set_size(size: vec3)
```

View File

@ -22,6 +22,8 @@ local Rigidbody = {__index={
set_size=function(self, v) return __rigidbody.set_size(self.eid, v) end, set_size=function(self, v) return __rigidbody.set_size(self.eid, v) end,
get_gravity_scale=function(self) return __rigidbody.get_gravity_scale(self.eid) end, get_gravity_scale=function(self) return __rigidbody.get_gravity_scale(self.eid) end,
set_gravity_scale=function(self, s) return __rigidbody.set_gravity_scale(self.eid, s) end, set_gravity_scale=function(self, s) return __rigidbody.set_gravity_scale(self.eid, s) end,
get_linear_damping=function(self) return __rigidbody.get_linear_damping(self.eid) end,
set_linear_damping=function(self, f) return __rigidbody.set_linear_damping(self.eid, f) end,
is_vdamping=function(self) return __rigidbody.is_vdamping(self.eid) end, is_vdamping=function(self) return __rigidbody.is_vdamping(self.eid) end,
set_vdamping=function(self, b) return __rigidbody.set_vdamping(self.eid, b) end, set_vdamping=function(self, b) return __rigidbody.set_vdamping(self.eid, b) end,
is_grounded=function(self) return __rigidbody.is_grounded(self.eid) end, is_grounded=function(self) return __rigidbody.is_grounded(self.eid) end,

View File

@ -2,105 +2,105 @@
#include "../../../util/stringutil.hpp" #include "../../../util/stringutil.hpp"
static int l_rigidbody_get_vel(lua::State* L) { static int l_get_vel(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
return lua::pushvec3_arr(L, entity->getRigidbody().hitbox.velocity); return lua::pushvec3_arr(L, entity->getRigidbody().hitbox.velocity);
} }
return 0; return 0;
} }
static int l_rigidbody_set_vel(lua::State* L) { static int l_set_vel(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
entity->getRigidbody().hitbox.velocity = lua::tovec3(L, 2); entity->getRigidbody().hitbox.velocity = lua::tovec3(L, 2);
} }
return 0; return 0;
} }
static int l_rigidbody_is_enabled(lua::State* L) { static int l_is_enabled(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
lua::pushboolean(L, entity->getRigidbody().enabled); lua::pushboolean(L, entity->getRigidbody().enabled);
} }
return 0; return 0;
} }
static int l_rigidbody_set_enabled(lua::State* L) { static int l_set_enabled(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
entity->getRigidbody().enabled = lua::toboolean(L, 2); entity->getRigidbody().enabled = lua::toboolean(L, 2);
} }
return 0; return 0;
} }
static int l_rigidbody_get_size(lua::State* L) { static int l_get_size(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
return lua::pushvec3_arr(L, entity->getRigidbody().hitbox.halfsize * 2.0f); return lua::pushvec3_arr(L, entity->getRigidbody().hitbox.halfsize * 2.0f);
} }
return 0; return 0;
} }
static int l_rigidbody_set_size(lua::State* L) { static int l_set_size(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
entity->getRigidbody().hitbox.halfsize = lua::tovec3(L, 2) * 0.5f; entity->getRigidbody().hitbox.halfsize = lua::tovec3(L, 2) * 0.5f;
} }
return 0; return 0;
} }
static int l_rigidbody_get_gravity_scale(lua::State* L) { static int l_get_gravity_scale(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
return lua::pushnumber(L, entity->getRigidbody().hitbox.gravityScale); return lua::pushnumber(L, entity->getRigidbody().hitbox.gravityScale);
} }
return 0; return 0;
} }
static int l_rigidbody_set_gravity_scale(lua::State* L) { static int l_set_gravity_scale(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
entity->getRigidbody().hitbox.gravityScale = lua::tonumber(L, 2); entity->getRigidbody().hitbox.gravityScale = lua::tonumber(L, 2);
} }
return 0; return 0;
} }
static int l_rigidbody_is_vdamping(lua::State* L) { static int l_is_vdamping(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
return lua::pushboolean(L, entity->getRigidbody().hitbox.verticalDamping); return lua::pushboolean(L, entity->getRigidbody().hitbox.verticalDamping);
} }
return 0; return 0;
} }
static int l_rigidbody_set_vdamping(lua::State* L) { static int l_set_vdamping(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
entity->getRigidbody().hitbox.verticalDamping = lua::toboolean(L, 2); entity->getRigidbody().hitbox.verticalDamping = lua::toboolean(L, 2);
} }
return 0; return 0;
} }
static int l_rigidbody_is_grounded(lua::State* L) { static int l_is_grounded(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
return lua::pushboolean(L, entity->getRigidbody().hitbox.grounded); return lua::pushboolean(L, entity->getRigidbody().hitbox.grounded);
} }
return 0; return 0;
} }
static int l_rigidbody_is_crouching(lua::State* L) { static int l_is_crouching(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
return lua::pushboolean(L, entity->getRigidbody().hitbox.crouching); return lua::pushboolean(L, entity->getRigidbody().hitbox.crouching);
} }
return 0; return 0;
} }
static int l_rigidbody_set_crouching(lua::State* L) { static int l_set_crouching(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
entity->getRigidbody().hitbox.crouching = lua::toboolean(L, 2); entity->getRigidbody().hitbox.crouching = lua::toboolean(L, 2);
} }
return 0; return 0;
} }
static int l_rigidbody_get_body_type(lua::State* L) { static int l_get_body_type(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
return lua::pushstring(L, to_string(entity->getRigidbody().hitbox.type)); return lua::pushstring(L, to_string(entity->getRigidbody().hitbox.type));
} }
return 0; return 0;
} }
static int l_rigidbody_set_body_type(lua::State* L) { static int l_set_body_type(lua::State* L) {
if (auto entity = get_entity(L, 1)) { if (auto entity = get_entity(L, 1)) {
if (auto type = BodyType_from(lua::tostring(L, 2))) { if (auto type = BodyType_from(lua::tostring(L, 2))) {
entity->getRigidbody().hitbox.type = *type; entity->getRigidbody().hitbox.type = *type;
@ -112,21 +112,37 @@ static int l_rigidbody_set_body_type(lua::State* L) {
return 0; return 0;
} }
static int l_get_linear_damping(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
return lua::pushnumber(L, entity->getRigidbody().hitbox.linearDamping);
}
return 0;
}
static int l_set_linear_damping(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
entity->getRigidbody().hitbox.linearDamping = lua::tonumber(L, 2);
}
return 0;
}
const luaL_Reg rigidbodylib [] = { const luaL_Reg rigidbodylib [] = {
{"is_enabled", lua::wrap<l_rigidbody_is_enabled>}, {"is_enabled", lua::wrap<l_is_enabled>},
{"set_enabled", lua::wrap<l_rigidbody_set_enabled>}, {"set_enabled", lua::wrap<l_set_enabled>},
{"get_vel", lua::wrap<l_rigidbody_get_vel>}, {"get_vel", lua::wrap<l_get_vel>},
{"set_vel", lua::wrap<l_rigidbody_set_vel>}, {"set_vel", lua::wrap<l_set_vel>},
{"get_size", lua::wrap<l_rigidbody_get_size>}, {"get_size", lua::wrap<l_get_size>},
{"set_size", lua::wrap<l_rigidbody_set_size>}, {"set_size", lua::wrap<l_set_size>},
{"get_gravity_scale", lua::wrap<l_rigidbody_get_gravity_scale>}, {"get_gravity_scale", lua::wrap<l_get_gravity_scale>},
{"set_gravity_scale", lua::wrap<l_rigidbody_set_gravity_scale>}, {"set_gravity_scale", lua::wrap<l_set_gravity_scale>},
{"is_vdamping", lua::wrap<l_rigidbody_is_vdamping>}, {"get_linear_damping", lua::wrap<l_get_linear_damping>},
{"set_vdamping", lua::wrap<l_rigidbody_set_vdamping>}, {"set_linear_damping", lua::wrap<l_set_linear_damping>},
{"is_grounded", lua::wrap<l_rigidbody_is_grounded>}, {"is_vdamping", lua::wrap<l_is_vdamping>},
{"is_crouching", lua::wrap<l_rigidbody_is_crouching>}, {"set_vdamping", lua::wrap<l_set_vdamping>},
{"set_crouching", lua::wrap<l_rigidbody_set_crouching>}, {"is_grounded", lua::wrap<l_is_grounded>},
{"get_body_type", lua::wrap<l_rigidbody_get_body_type>}, {"is_crouching", lua::wrap<l_is_crouching>},
{"set_body_type", lua::wrap<l_rigidbody_set_body_type>}, {"set_crouching", lua::wrap<l_set_crouching>},
{"get_body_type", lua::wrap<l_get_body_type>},
{"set_body_type", lua::wrap<l_set_body_type>},
{NULL, NULL} {NULL, NULL}
}; };