Merge branch 'main' into animation

This commit is contained in:
MihailRis 2026-08-23 12:39:46 +03:00
commit ab3c1e1b0c
14 changed files with 56 additions and 15 deletions

View file

@ -67,9 +67,10 @@ If true - the entity blocks the placement of a block that intersects with the en
Default value: *true*.
### *selectable*
### *selectable* (raycast opacity)
If set to `false` the cursor will ignore the entity, passing the ray.
Applies to all uses of raycast without the include_non_selectable flag.
### *sensors*

View file

@ -36,6 +36,11 @@ entity:set_enabled(name: str, enable: bool)
-- At components initialization -1 is also returned,
-- since the binding occurs after initialization.
entity:get_player() -> int or nil
-- Checks the 'selectable' property of an entity (raycast opacity)
body:is_selectable() -> bool
-- Sets the value of the 'selectable' property of an entity
body:set_selectable(flag: bool)
```
## Custom Components

View file

@ -67,9 +67,10 @@
Значение по-умолчанию: *true*.
### Выделяемость - *selectable*
### Непрозрачность для лучей - *selectable*
При значении в `false` курсор будет игнорировать cущность, пропуская луч далее.
Распространяется на все использования raycast без флага include_non_selectable.
### Список сенсоров - *sensors*

View file

@ -134,6 +134,11 @@ body:set_elasticity(elasticity: number)
-- Возвращает скорость поверхности, на которой находится тело, либо {0,0,0}
body:get_ground_vel() -> vec3
-- Проверяет свойство 'selectable' у сущности (непрозрачность для лучей)
body:is_selectable() -> bool
-- Устанавливает значение свойство 'selectable' у сущности
body:set_selectable(flag: bool)
```
### Skeleton

View file

@ -39,6 +39,8 @@ local Rigidbody = {__index={
set_mass=function(self, v) return __rigidbody.set_mass(self.eid, v) end,
set_elasticity=function(self, v) return __rigidbody.set_elasticity(self.eid, v) end,
get_ground_vel=function(self) return __rigidbody.get_ground_vel(self.eid) end,
is_selectable=function (self) return __rigidbody.is_selectable(self.eid) end,
set_selectable=function (self, b) return __rigidbody.set_selectable(self.eid, b) end,
}}
local function new_Rigidbody(eid)

View file

@ -208,6 +208,14 @@ namespace {
class Parser : BasicParser<char> {
std::unique_ptr<Document> document;
void processEscapes(std::string& text) {
util::replaceAll(text, "&quot;", "\"");
util::replaceAll(text, "&apos;", "'");
util::replaceAll(text, "&lt;", "<");
util::replaceAll(text, "&gt;", ">");
util::replaceAll(text, "&amp;", "&");
}
std::unique_ptr<Node> parseOpenTag() {
std::string tag = parseXMLName();
auto node = std::make_unique<Node>(tag);
@ -230,6 +238,7 @@ class Parser : BasicParser<char> {
}
skip(1);
attrtext = parseString(quote);
processEscapes(attrtext);
}
node->set(attrname, attrtext);
}
@ -241,11 +250,7 @@ class Parser : BasicParser<char> {
if (peek() != '<') {
auto element = std::make_unique<Node>("#");
auto text = parseText();
util::replaceAll(text, "&quot;", "\"");
util::replaceAll(text, "&apos;", "'");
util::replaceAll(text, "&lt;", "<");
util::replaceAll(text, "&gt;", ">");
util::replaceAll(text, "&amp;", "&");
processEscapes(text);
element->set("#", text);
return element;
}

View file

@ -46,7 +46,7 @@ void Texture::resize(uint width, uint height) {
}
void Texture::reload(const ImageData& image) {
reload(image.getData(), width, height);
reload(image.getData(), image.getWidth(), image.getHeight());
}
void Texture::reload(const ubyte* data, uint width, uint height) {

View file

@ -199,6 +199,20 @@ static int l_get_ground_vel(lua::State* L) {
return 0;
}
static int l_is_selectable(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
return lua::pushboolean(L, entity->getRigidbody().hitbox.selectable);
}
return 0;
}
static int l_set_selectable(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
entity->getRigidbody().selectable = lua::toboolean(L, 2);
}
return 0;
}
const luaL_Reg rigidbodylib[] = {
{"is_enabled", lua::wrap<l_is_enabled>},
@ -226,5 +240,7 @@ const luaL_Reg rigidbodylib[] = {
{"get_elasticity", lua::wrap<l_get_elasticity>},
{"set_elasticity", lua::wrap<l_set_elasticity>},
{"get_ground_vel", lua::wrap<l_get_ground_vel>},
{"is_selectable", lua::wrap<l_is_selectable>},
{"set_selectable", lua::wrap<l_set_selectable>},
{nullptr, nullptr}
};

View file

@ -181,9 +181,10 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
glm::ivec3 foundNormal;
for (auto [entity, eid, transform, body] : view.each()) {
const auto& hitbox = body.hitbox;
if (eid.uid == settings.ignoredUid || !body.enabled ||
(settings.solidEntitiesOnly && !eid.def.solid) ||
(!eid.def.selectable && !settings.includeNonSelectable)) {
(!hitbox.selectable && !settings.includeNonSelectable)) {
continue;
}
if (settings.entitiesFilter) {
@ -193,7 +194,6 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
continue;
}
}
const auto& hitbox = body.hitbox;
glm::ivec3 normal;
double distance;
if (ray.intersectAABB(
@ -336,6 +336,7 @@ void Entities::preparePhysics(float delta) {
? rigidbody.mass
: std::numeric_limits<float>::infinity();
rigidbody.hitbox.elasticity = rigidbody.elasticity;
rigidbody.hitbox.selectable = rigidbody.selectable;
hitboxes.emplace_back(&rigidbody.hitbox);
if (!eid.def.solid) {
continue;

View file

@ -24,6 +24,7 @@ dv::value Rigidbody::serialize(bool saveVelocity, bool saveBodySettings) const {
}
bodymap["mass"] = mass;
bodymap["elasticity"] = elasticity;
bodymap["selectable"] = selectable;
}
return bodymap;
}
@ -37,6 +38,7 @@ void Rigidbody::deserialize(const dv::value& root) {
root["damping"].asNumber(hitbox.linearDamping);
root["mass"].asNumber(mass);
root["elasticity"].asNumber(elasticity);
root["selectable"].asBoolean(selectable);
}
template <void (*callback)(const Entity&, size_t, entityid_t)>
@ -55,6 +57,7 @@ void Rigidbody::initialize(
) {
mass = def.mass;
elasticity = def.elasticity;
selectable = def.selectable;
sensors.resize(def.radialSensors.size() + def.boxSensors.size());
for (auto& [i, box] : def.boxSensors) {
SensorParams params {};

View file

@ -15,6 +15,7 @@ struct Rigidbody {
std::vector<Sensor> sensors;
float mass;
float elasticity;
bool selectable;
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
void deserialize(const dv::value& root);

View file

@ -65,6 +65,7 @@ struct Hitbox {
float stepHeight = 0.5f;
float mass = 1.0f;
float elasticity = 0.0f;
bool selectable = true;
std::string material;
std::string groundMaterial;
glm::vec3 groundVelocity {};

View file

@ -122,7 +122,7 @@ static void calc_collision(
auto aabb = AABB(pos - half, pos + half);
glm::vec3 scale(1.0f);
scale[nz] = 1.0f - E * 8.0f;
scale[nz] = 1.0f - E * 2.0f;
aabb.scale(scale);
aabb = aabb + offset;
aabb.b.y -= stepHeight + E * 2;

View file

@ -109,7 +109,7 @@ void WorldConverter::createBlockFieldsConvertTasks() {
REGION_LAYER_BLOCKS_DATA,
ConvertTaskType::CONVERT_BLOCKS_DATA
);
break;
return;
default:
break;
}
@ -189,7 +189,7 @@ void WorldConverter::upgradeRegion(
}
void WorldConverter::convertVoxels(const io::path& file, int x, int z) const {
logger.info() << "converting voxels region " << x << "_" << z;
logger.info() << "converting voxels in region " << x << "_" << z;
wfile->getRegions().processRegion(x, z, REGION_LAYER_VOXELS,
[=](std::unique_ptr<ubyte[]> data, uint32_t*) {
Chunk::convert(data.get(), report.get());
@ -198,7 +198,7 @@ void WorldConverter::convertVoxels(const io::path& file, int x, int z) const {
}
void WorldConverter::convertInventories(const io::path& file, int x, int z) const {
logger.info() << "converting inventories region " << x << "_" << z;
logger.info() << "converting inventories in region " << x << "_" << z;
wfile->getRegions().processInventories(x, z, [=](Inventory* inventory) {
inventory->convert(report.get());
});
@ -212,7 +212,7 @@ void WorldConverter::convertPlayer(const io::path& file) const {
}
void WorldConverter::convertBlocksData(int x, int z, const ContentReport& report) const {
logger.info() << "converting blocks data";
logger.info() << "converting blocks data in region " << x << "_" << z;
wfile->getRegions().processBlocksData(x, z,
[=](BlocksMetadata* heap, std::unique_ptr<ubyte[]> voxelsData) {
Chunk chunk(0, 0);