Merge pull request #824 from MihailRis/patch-1

Patch 0.31.1
This commit is contained in:
MihailRis 2026-04-05 20:03:50 +03:00 • committed by GitHub
commit 8ea83ba469
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 74 additions and 45 deletions

View file

@ -104,7 +104,7 @@
Определяет массу сущности. За стандарт приняты килограммы.
В случае `kinematic` тела вместо указанной используется бесконечная масса.
### Эластичность - *elasticity*
### Упругость - *elasticity*
Определяет упругость сущности.

View file

@ -54,7 +54,10 @@ function audio.input.request_open(callback)
_gui_confirm(gui.str(GRANT_PERMISSION_MSG):gsub("%%{0}", caller), function()
audio_input_tokens_store[token] = caller
callback(token)
menu:reset()
if not menu:back() then
menu:reset()
gui.set_active_frame("")
end
end)
end

View file

@ -16,6 +16,13 @@ end
-- remove undefined properties and build tags set
local function process_properties(lib)
for id, props in pairs(lib.properties) do
if props.parent then
for propname, value in pairs(lib.properties[block.index(props.parent)]) do
if not props[propname] then
props[propname] = value
end
end
end
for propname, _ in pairs(props) do
if not table.has(names, propname) then
props[propname] = nil

View file

@ -66,9 +66,7 @@ Decorator::Decorator(
continue;
}
playerTexts[id] = renderer.texts->add(std::make_unique<TextNote>(
util::str2wstr_utf8(player->getName()),
playerNamePreset,
player->getPosition()
player->getName(), playerNamePreset, player->getPosition()
));
}
}
@ -296,9 +294,7 @@ void Decorator::updateTextNotes() {
continue;
}
playerTexts[id] = renderer.texts->add(std::make_unique<TextNote>(
util::str2wstr_utf8(player->getName()),
playerNamePreset,
player->getPosition()
player->getName(), playerNamePreset, player->getPosition()
));
}
@ -315,6 +311,9 @@ void Decorator::updateTextNotes() {
position = entity->getInterpolatedPosition();
}
note->setPosition(position + glm::vec3(0, 1, 0));
if (note->getText() != player->getName()) {
note->setText(player->getName());
}
++textsIter;
}
}

View file

@ -7,9 +7,9 @@ using namespace rigging;
NamedSkeletons::NamedSkeletons() = default;
std::shared_ptr<rigging::Skeleton> NamedSkeletons::createSkeleton(
const std::string& name, const SkeletonConfig* config
const std::string& name, std::shared_ptr<const SkeletonConfig> config
) {
auto skeleton = std::make_shared<Skeleton>(config);
auto skeleton = std::make_shared<Skeleton>(std::move(config));
skeletons[name] = skeleton;
return skeleton;
}

View file

@ -14,7 +14,8 @@ public:
NamedSkeletons();
std::shared_ptr<rigging::Skeleton> createSkeleton(
const std::string& name, const rigging::SkeletonConfig* config
const std::string& name,
std::shared_ptr<const rigging::SkeletonConfig> config
);
rigging::Skeleton* getSkeleton(const std::string& name);

View file

@ -113,7 +113,9 @@ WorldRenderer::WorldRenderer(
content.getDefaults()["hand-skeleton"].asString()
);
hands = std::make_unique<HandsRenderer>(
assets, *modelBatch, skeletons->createSkeleton("hand", &skeletonConfig)
assets,
*modelBatch,
skeletons->createSkeleton("hand", skeletonConfig.shared_from_this())
);
shadowMapping = std::make_unique<Shadows>(level);
debugLines = std::make_unique<DebugLinesRenderer>(level);

View file

@ -108,13 +108,13 @@ static int l_set_skeleton(lua::State* L) {
}
if (auto entity = get_entity(L, 1)) {
std::string skeletonName = lua::require_string(L, 2);
auto rigConfig = assets->get<rigging::SkeletonConfig>(skeletonName);
auto rigConfig = assets->getShared<rigging::SkeletonConfig>(skeletonName);
if (rigConfig == nullptr) {
throw std::runtime_error(
"skeleton not found '" + skeletonName + "'"
);
}
entity->setRig(rigConfig);
entity->setRig(std::move(rigConfig));
}
return 0;
}

View file

@ -294,14 +294,14 @@ static int l_set_camera(lua::State* L) {
static int l_get_name(lua::State* L) {
if (auto player = get_player(L, 1)) {
return lua::pushstring(L, player->getName());
return lua::pushwstring(L, player->getName());
}
return 0;
}
static int l_set_name(lua::State* L) {
if (auto player = get_player(L, 1)) {
player->setName(lua::require_string(L, 2));
player->setName(lua::require_wstring(L, 2));
}
return 0;
}
@ -313,7 +313,7 @@ static int l_create(lua::State* L) {
}
auto& level = require_level();
auto player = level.players->create(playerId);
player->setName(lua::require_string(L, 1));
player->setName(lua::require_wstring(L, 1));
return lua::pushinteger(L, player->getId());
}

View file

@ -155,7 +155,7 @@ void Entities::loadEntity(const dv::value& map, Entity entity) {
std::string skeletonName = skeleton->config->getName();
map.at("skeleton-name").get(skeletonName);
if (skeletonName != skeleton->config->getName()) {
skeleton->config = assets->get<rigging::SkeletonConfig>(skeletonName);
skeleton->config = assets->getShared<rigging::SkeletonConfig>(skeletonName);
}
if (auto foundSkeleton = map.at(COMP_SKELETON)) {
skeleton->deserialize(*foundSkeleton);
@ -470,7 +470,7 @@ void Entities::render(
continue;
}
const auto* rigConfig = skeleton.config;
const auto& rigConfig = skeleton.config;
if (rigConfig) {
rigConfig->render(
assets, batch, skeleton, transform.rot, pos, size
@ -482,7 +482,9 @@ void Entities::render(
bool Entities::hasBlockingInside(AABB aabb) {
auto view = registry->view<EntityId, Rigidbody>();
for (auto [entity, eid, body] : view.each()) {
if (eid.def.blocking && aabb.intersects(body.hitbox.getAABB(), -0.05f)) {
AABB bodyAABB(body.hitbox.getAABB());
bodyAABB.scale({1, 0.95f, 1});
if (eid.def.blocking && aabb.intersects(bodyAABB)) {
return true;
}
}

View file

@ -37,15 +37,9 @@ rigging::Skeleton* Entity::getSkeleton() const {
return registry.try_get<rigging::Skeleton>(entity);
}
void Entity::setRig(const rigging::SkeletonConfig* rigConfig) {
void Entity::setRig(std::shared_ptr<const rigging::SkeletonConfig> rigConfig) {
auto& skeleton = registry.get<rigging::Skeleton>(entity);
skeleton.config = rigConfig;
skeleton.pose.matrices.resize(
rigConfig->getBones().size(), glm::mat4(1.0f)
);
skeleton.calculated.matrices.resize(
rigConfig->getBones().size(), glm::mat4(1.0f)
);
skeleton.setConfig(std::move(rigConfig));
}
dv::value Entity::serialize() const {

View file

@ -60,7 +60,7 @@ public:
rigging::Skeleton* getSkeleton() const;
void setRig(const rigging::SkeletonConfig* rigConfig);
void setRig(std::shared_ptr<const rigging::SkeletonConfig> rigConfig);
entityid_t getUID() const;

View file

@ -20,6 +20,7 @@
#include "world/generator/GeneratorDef.hpp"
#include "data/dv_util.hpp"
#include "debug/Logger.hpp"
#include "util/stringutil.hpp"
static debug::Logger logger("player");
@ -28,7 +29,7 @@ constexpr int SPAWN_ATTEMPTS_PER_UPDATE = 64;
Player::Player(
Level& level,
int64_t id,
const std::string& name,
const std::wstring& name,
glm::vec3 position,
float speed,
std::shared_ptr<Inventory> inv,
@ -230,11 +231,11 @@ entityid_t Player::getSelectedEntity() const {
return selectedEid;
}
void Player::setName(const std::string& name) {
void Player::setName(const std::wstring& name) {
this->name = name;
}
const std::string& Player::getName() const {
const std::wstring& Player::getName() const {
return name;
}
@ -266,7 +267,7 @@ dv::value Player::serialize() const {
auto root = dv::object();
root["id"] = id;
root["name"] = name;
root["name"] = util::wstr2str_utf8(name);
root["position"] = dv::to_value(position);
root["rotation"] = dv::to_value(rotation);
@ -293,7 +294,10 @@ dv::value Player::serialize() const {
void Player::deserialize(const dv::value& src) {
src.at("id").get(id);
src.at("name").get(name);
std::string utf8name;
src.at("name").get(utf8name);
name = util::str2wstr_utf8(utf8name);
const auto& posarr = src["position"];

View file

@ -45,7 +45,7 @@ struct CursorSelection {
class Player : public Serializable {
Level& level;
int64_t id;
std::string name;
std::wstring name;
float speed;
int chosenSlot;
@ -79,7 +79,7 @@ public:
Player(
Level& level,
int64_t id,
const std::string& name,
const std::wstring& name,
glm::vec3 position,
float speed,
std::shared_ptr<Inventory> inv,
@ -124,8 +124,8 @@ public:
entityid_t getSelectedEntity() const;
void setName(const std::string& name);
const std::string& getName() const;
void setName(const std::wstring& name);
const std::wstring& getName() const;
const std::shared_ptr<Inventory>& getInventory() const;

View file

@ -79,7 +79,7 @@ Player* Players::create(int64_t id) {
auto playerPtr = std::make_unique<Player>(
level,
id,
"",
L"",
glm::vec3(0, DEF_PLAYER_Y, 0),
DEF_PLAYER_SPEED,
level.inventories->create(DEF_PLAYER_INVENTORY_SIZE),
@ -134,7 +134,7 @@ void Players::deserialize(const dv::value& src) {
auto playerPtr = std::make_unique<Player>(
level,
0,
"",
L"",
glm::vec3(0, DEF_PLAYER_Y, 0),
DEF_PLAYER_SPEED,
level.inventories->create(DEF_PLAYER_INVENTORY_SIZE),

View file

@ -39,7 +39,7 @@ void Bone::setModel(const std::string& name) {
model = {name, nullptr, true};
}
Skeleton::Skeleton(const SkeletonConfig* config)
Skeleton::Skeleton(std::shared_ptr<const SkeletonConfig> config)
: config(config),
pose(config->getBones().size()),
calculated(config->getBones().size()),
@ -86,6 +86,16 @@ void Skeleton::deserialize(const dv::value& root) {
}
}
void Skeleton::setConfig(std::shared_ptr<const SkeletonConfig> rigConfig) {
config = std::move(rigConfig);
pose.matrices.resize(
config->getBones().size(), glm::mat4(1.0f)
);
calculated.matrices.resize(
config->getBones().size(), glm::mat4(1.0f)
);
}
static void get_all_nodes(std::vector<Bone*>& nodes, Bone* node) {
nodes[node->getIndex()] = node;
for (auto& subnode : node->getBones()) {
@ -97,6 +107,7 @@ SkeletonConfig::SkeletonConfig(
const std::string& name, std::unique_ptr<Bone> root, size_t nodesCount
)
: name(name), root(std::move(root)), nodes(nodesCount) {
assert(this->root.get() != nullptr);
get_all_nodes(nodes, this->root.get());
}
@ -159,6 +170,9 @@ void SkeletonConfig::render(
const glm::vec3& position,
const glm::vec3& scale
) const {
if (skeleton.config->root == nullptr) {
return;
}
update(skeleton, rotation, position, scale);
if (!skeleton.visible) {

View file

@ -78,7 +78,7 @@ namespace rigging {
};
struct Skeleton {
const SkeletonConfig* config;
std::shared_ptr<const SkeletonConfig> config;
Pose pose;
Pose calculated;
std::vector<BoneFlags> flags;
@ -89,13 +89,15 @@ namespace rigging {
util::VecInterpolation<3, float> interpolation {false};
Skeleton(const SkeletonConfig* config);
Skeleton(std::shared_ptr<const SkeletonConfig> config);
dv::value serialize(bool saveTextures, bool savePose) const;
void deserialize(const dv::value& root);
void setConfig(std::shared_ptr<const SkeletonConfig> config);
};
class SkeletonConfig {
class SkeletonConfig : public std::enable_shared_from_this<SkeletonConfig> {
std::string name;
std::unique_ptr<Bone> root;
std::unordered_map<std::string, size_t> indices;
@ -135,7 +137,7 @@ namespace rigging {
) const;
Skeleton instance() const {
return Skeleton(this);
return Skeleton(shared_from_this());
}
const Bone* find(std::string_view str) const;

View file

@ -294,6 +294,7 @@ public:
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
} else {
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwSetCursor(window, nullptr);
}
cursorLocked = !cursorLocked;
}