mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 22:41:49 +00:00
Merge branch 'main' into animation
This commit is contained in:
commit
ab3c1e1b0c
14 changed files with 56 additions and 15 deletions
|
|
@ -67,9 +67,10 @@ If true - the entity blocks the placement of a block that intersects with the en
|
||||||
|
|
||||||
Default value: *true*.
|
Default value: *true*.
|
||||||
|
|
||||||
### *selectable*
|
### *selectable* (raycast opacity)
|
||||||
|
|
||||||
If set to `false` the cursor will ignore the entity, passing the ray.
|
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*
|
### *sensors*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,11 @@ entity:set_enabled(name: str, enable: bool)
|
||||||
-- At components initialization -1 is also returned,
|
-- At components initialization -1 is also returned,
|
||||||
-- since the binding occurs after initialization.
|
-- since the binding occurs after initialization.
|
||||||
entity:get_player() -> int or nil
|
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
|
## Custom Components
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,10 @@
|
||||||
|
|
||||||
Значение по-умолчанию: *true*.
|
Значение по-умолчанию: *true*.
|
||||||
|
|
||||||
### Выделяемость - *selectable*
|
### Непрозрачность для лучей - *selectable*
|
||||||
|
|
||||||
При значении в `false` курсор будет игнорировать cущность, пропуская луч далее.
|
При значении в `false` курсор будет игнорировать cущность, пропуская луч далее.
|
||||||
|
Распространяется на все использования raycast без флага include_non_selectable.
|
||||||
|
|
||||||
### Список сенсоров - *sensors*
|
### Список сенсоров - *sensors*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,11 @@ body:set_elasticity(elasticity: number)
|
||||||
|
|
||||||
-- Возвращает скорость поверхности, на которой находится тело, либо {0,0,0}
|
-- Возвращает скорость поверхности, на которой находится тело, либо {0,0,0}
|
||||||
body:get_ground_vel() -> vec3
|
body:get_ground_vel() -> vec3
|
||||||
|
|
||||||
|
-- Проверяет свойство 'selectable' у сущности (непрозрачность для лучей)
|
||||||
|
body:is_selectable() -> bool
|
||||||
|
-- Устанавливает значение свойство 'selectable' у сущности
|
||||||
|
body:set_selectable(flag: bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Skeleton
|
### Skeleton
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ local Rigidbody = {__index={
|
||||||
set_mass=function(self, v) return __rigidbody.set_mass(self.eid, v) end,
|
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,
|
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,
|
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)
|
local function new_Rigidbody(eid)
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,14 @@ namespace {
|
||||||
class Parser : BasicParser<char> {
|
class Parser : BasicParser<char> {
|
||||||
std::unique_ptr<Document> document;
|
std::unique_ptr<Document> document;
|
||||||
|
|
||||||
|
void processEscapes(std::string& text) {
|
||||||
|
util::replaceAll(text, """, "\"");
|
||||||
|
util::replaceAll(text, "'", "'");
|
||||||
|
util::replaceAll(text, "<", "<");
|
||||||
|
util::replaceAll(text, ">", ">");
|
||||||
|
util::replaceAll(text, "&", "&");
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<Node> parseOpenTag() {
|
std::unique_ptr<Node> parseOpenTag() {
|
||||||
std::string tag = parseXMLName();
|
std::string tag = parseXMLName();
|
||||||
auto node = std::make_unique<Node>(tag);
|
auto node = std::make_unique<Node>(tag);
|
||||||
|
|
@ -230,6 +238,7 @@ class Parser : BasicParser<char> {
|
||||||
}
|
}
|
||||||
skip(1);
|
skip(1);
|
||||||
attrtext = parseString(quote);
|
attrtext = parseString(quote);
|
||||||
|
processEscapes(attrtext);
|
||||||
}
|
}
|
||||||
node->set(attrname, attrtext);
|
node->set(attrname, attrtext);
|
||||||
}
|
}
|
||||||
|
|
@ -241,11 +250,7 @@ class Parser : BasicParser<char> {
|
||||||
if (peek() != '<') {
|
if (peek() != '<') {
|
||||||
auto element = std::make_unique<Node>("#");
|
auto element = std::make_unique<Node>("#");
|
||||||
auto text = parseText();
|
auto text = parseText();
|
||||||
util::replaceAll(text, """, "\"");
|
processEscapes(text);
|
||||||
util::replaceAll(text, "'", "'");
|
|
||||||
util::replaceAll(text, "<", "<");
|
|
||||||
util::replaceAll(text, ">", ">");
|
|
||||||
util::replaceAll(text, "&", "&");
|
|
||||||
element->set("#", text);
|
element->set("#", text);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ void Texture::resize(uint width, uint height) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture::reload(const ImageData& image) {
|
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) {
|
void Texture::reload(const ubyte* data, uint width, uint height) {
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,20 @@ static int l_get_ground_vel(lua::State* L) {
|
||||||
return 0;
|
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[] = {
|
const luaL_Reg rigidbodylib[] = {
|
||||||
{"is_enabled", lua::wrap<l_is_enabled>},
|
{"is_enabled", lua::wrap<l_is_enabled>},
|
||||||
|
|
@ -226,5 +240,7 @@ const luaL_Reg rigidbodylib[] = {
|
||||||
{"get_elasticity", lua::wrap<l_get_elasticity>},
|
{"get_elasticity", lua::wrap<l_get_elasticity>},
|
||||||
{"set_elasticity", lua::wrap<l_set_elasticity>},
|
{"set_elasticity", lua::wrap<l_set_elasticity>},
|
||||||
{"get_ground_vel", lua::wrap<l_get_ground_vel>},
|
{"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}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -181,9 +181,10 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
|
||||||
glm::ivec3 foundNormal;
|
glm::ivec3 foundNormal;
|
||||||
|
|
||||||
for (auto [entity, eid, transform, body] : view.each()) {
|
for (auto [entity, eid, transform, body] : view.each()) {
|
||||||
|
const auto& hitbox = body.hitbox;
|
||||||
if (eid.uid == settings.ignoredUid || !body.enabled ||
|
if (eid.uid == settings.ignoredUid || !body.enabled ||
|
||||||
(settings.solidEntitiesOnly && !eid.def.solid) ||
|
(settings.solidEntitiesOnly && !eid.def.solid) ||
|
||||||
(!eid.def.selectable && !settings.includeNonSelectable)) {
|
(!hitbox.selectable && !settings.includeNonSelectable)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (settings.entitiesFilter) {
|
if (settings.entitiesFilter) {
|
||||||
|
|
@ -193,7 +194,6 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const auto& hitbox = body.hitbox;
|
|
||||||
glm::ivec3 normal;
|
glm::ivec3 normal;
|
||||||
double distance;
|
double distance;
|
||||||
if (ray.intersectAABB(
|
if (ray.intersectAABB(
|
||||||
|
|
@ -336,6 +336,7 @@ void Entities::preparePhysics(float delta) {
|
||||||
? rigidbody.mass
|
? rigidbody.mass
|
||||||
: std::numeric_limits<float>::infinity();
|
: std::numeric_limits<float>::infinity();
|
||||||
rigidbody.hitbox.elasticity = rigidbody.elasticity;
|
rigidbody.hitbox.elasticity = rigidbody.elasticity;
|
||||||
|
rigidbody.hitbox.selectable = rigidbody.selectable;
|
||||||
hitboxes.emplace_back(&rigidbody.hitbox);
|
hitboxes.emplace_back(&rigidbody.hitbox);
|
||||||
if (!eid.def.solid) {
|
if (!eid.def.solid) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ dv::value Rigidbody::serialize(bool saveVelocity, bool saveBodySettings) const {
|
||||||
}
|
}
|
||||||
bodymap["mass"] = mass;
|
bodymap["mass"] = mass;
|
||||||
bodymap["elasticity"] = elasticity;
|
bodymap["elasticity"] = elasticity;
|
||||||
|
bodymap["selectable"] = selectable;
|
||||||
}
|
}
|
||||||
return bodymap;
|
return bodymap;
|
||||||
}
|
}
|
||||||
|
|
@ -37,6 +38,7 @@ void Rigidbody::deserialize(const dv::value& root) {
|
||||||
root["damping"].asNumber(hitbox.linearDamping);
|
root["damping"].asNumber(hitbox.linearDamping);
|
||||||
root["mass"].asNumber(mass);
|
root["mass"].asNumber(mass);
|
||||||
root["elasticity"].asNumber(elasticity);
|
root["elasticity"].asNumber(elasticity);
|
||||||
|
root["selectable"].asBoolean(selectable);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <void (*callback)(const Entity&, size_t, entityid_t)>
|
template <void (*callback)(const Entity&, size_t, entityid_t)>
|
||||||
|
|
@ -55,6 +57,7 @@ void Rigidbody::initialize(
|
||||||
) {
|
) {
|
||||||
mass = def.mass;
|
mass = def.mass;
|
||||||
elasticity = def.elasticity;
|
elasticity = def.elasticity;
|
||||||
|
selectable = def.selectable;
|
||||||
sensors.resize(def.radialSensors.size() + def.boxSensors.size());
|
sensors.resize(def.radialSensors.size() + def.boxSensors.size());
|
||||||
for (auto& [i, box] : def.boxSensors) {
|
for (auto& [i, box] : def.boxSensors) {
|
||||||
SensorParams params {};
|
SensorParams params {};
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ struct Rigidbody {
|
||||||
std::vector<Sensor> sensors;
|
std::vector<Sensor> sensors;
|
||||||
float mass;
|
float mass;
|
||||||
float elasticity;
|
float elasticity;
|
||||||
|
bool selectable;
|
||||||
|
|
||||||
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
|
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
|
||||||
void deserialize(const dv::value& root);
|
void deserialize(const dv::value& root);
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ struct Hitbox {
|
||||||
float stepHeight = 0.5f;
|
float stepHeight = 0.5f;
|
||||||
float mass = 1.0f;
|
float mass = 1.0f;
|
||||||
float elasticity = 0.0f;
|
float elasticity = 0.0f;
|
||||||
|
bool selectable = true;
|
||||||
std::string material;
|
std::string material;
|
||||||
std::string groundMaterial;
|
std::string groundMaterial;
|
||||||
glm::vec3 groundVelocity {};
|
glm::vec3 groundVelocity {};
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,7 @@ static void calc_collision(
|
||||||
|
|
||||||
auto aabb = AABB(pos - half, pos + half);
|
auto aabb = AABB(pos - half, pos + half);
|
||||||
glm::vec3 scale(1.0f);
|
glm::vec3 scale(1.0f);
|
||||||
scale[nz] = 1.0f - E * 8.0f;
|
scale[nz] = 1.0f - E * 2.0f;
|
||||||
aabb.scale(scale);
|
aabb.scale(scale);
|
||||||
aabb = aabb + offset;
|
aabb = aabb + offset;
|
||||||
aabb.b.y -= stepHeight + E * 2;
|
aabb.b.y -= stepHeight + E * 2;
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ void WorldConverter::createBlockFieldsConvertTasks() {
|
||||||
REGION_LAYER_BLOCKS_DATA,
|
REGION_LAYER_BLOCKS_DATA,
|
||||||
ConvertTaskType::CONVERT_BLOCKS_DATA
|
ConvertTaskType::CONVERT_BLOCKS_DATA
|
||||||
);
|
);
|
||||||
break;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -189,7 +189,7 @@ void WorldConverter::upgradeRegion(
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldConverter::convertVoxels(const io::path& file, int x, int z) const {
|
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,
|
wfile->getRegions().processRegion(x, z, REGION_LAYER_VOXELS,
|
||||||
[=](std::unique_ptr<ubyte[]> data, uint32_t*) {
|
[=](std::unique_ptr<ubyte[]> data, uint32_t*) {
|
||||||
Chunk::convert(data.get(), report.get());
|
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 {
|
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) {
|
wfile->getRegions().processInventories(x, z, [=](Inventory* inventory) {
|
||||||
inventory->convert(report.get());
|
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 {
|
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,
|
wfile->getRegions().processBlocksData(x, z,
|
||||||
[=](BlocksMetadata* heap, std::unique_ptr<ubyte[]> voxelsData) {
|
[=](BlocksMetadata* heap, std::unique_ptr<ubyte[]> voxelsData) {
|
||||||
Chunk chunk(0, 0);
|
Chunk chunk(0, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue