This commit is contained in:
MihailRis
2025-08-09 22:43:06 +03:00
parent 61da6b44a1
commit 5583734bc2
10 changed files with 331 additions and 307 deletions
+5 -28
View File
@@ -19,7 +19,6 @@
#include "EntityDef.hpp"
#include "Entity.hpp"
#include "rigging.hpp"
#include "physics/Hitbox.hpp"
#include "physics/PhysicsSolver.hpp"
#include "world/Level.hpp"
@@ -100,7 +99,8 @@ entityid_t Entities::spawn(
}
body.hitbox.position = tsf.pos;
scripting::on_entity_spawn(
def, id, scripting.components, args, componentsMap);
def, id, scripting.components, args, componentsMap
);
return id;
}
@@ -127,19 +127,10 @@ void Entities::loadEntity(const dv::value& map, Entity entity) {
auto& skeleton = entity.getSkeleton();
if (map.has(COMP_RIGIDBODY)) {
auto& bodymap = map[COMP_RIGIDBODY];
dv::get_vec(bodymap, "vel", body.hitbox.velocity);
std::string bodyTypeName;
map.at("type").get(bodyTypeName);
BodyTypeMeta.getItem(bodyTypeName, body.hitbox.type);
bodymap["crouch"].asBoolean(body.hitbox.crouching);
bodymap["damping"].asNumber(body.hitbox.linearDamping);
body.deserialize(map[COMP_RIGIDBODY]);
}
if (map.has(COMP_TRANSFORM)) {
auto& tsfmap = map[COMP_TRANSFORM];
dv::get_vec(tsfmap, "pos", transform.pos);
dv::get_vec(tsfmap, "size", transform.size);
dv::get_mat(tsfmap, "rot", transform.rot);
transform.deserialize(map[COMP_TRANSFORM]);
}
std::string skeletonName = skeleton.config->getName();
map.at("skeleton").get(skeletonName);
@@ -147,21 +138,7 @@ void Entities::loadEntity(const dv::value& map, Entity entity) {
skeleton.config = level.content.getSkeleton(skeletonName);
}
if (auto foundSkeleton = map.at(COMP_SKELETON)) {
auto& skeletonmap = *foundSkeleton;
if (auto found = skeletonmap.at("textures")) {
auto& texturesmap = *found;
for (auto& [slot, _] : texturesmap.asObject()) {
texturesmap.at(slot).get(skeleton.textures[slot]);
}
}
if (auto found = skeletonmap.at("pose")) {
auto& posearr = *found;
for (size_t i = 0;
i < std::min(skeleton.pose.matrices.size(), posearr.size());
i++) {
dv::get_mat(posearr[i], skeleton.pose.matrices[i]);
}
}
skeleton.deserialize(*foundSkeleton);
}
}
+9
View File
@@ -26,6 +26,15 @@ dv::value Rigidbody::serialize(bool saveVelocity, bool saveBodySettings) const {
return bodymap;
}
void Rigidbody::deserialize(const dv::value& root) {
dv::get_vec(root, "vel", hitbox.velocity);
std::string bodyTypeName;
root.at("type").get(bodyTypeName);
BodyTypeMeta.getItem(bodyTypeName, hitbox.type);
root["crouch"].asBoolean(hitbox.crouching);
root["damping"].asNumber(hitbox.linearDamping);
}
template <void (*callback)(const Entity&, size_t, entityid_t)>
static sensorcallback create_sensor_callback(Entities& entities) {
return [&entities](auto entityid, auto index, auto otherid) {
+1
View File
@@ -15,6 +15,7 @@ struct Rigidbody {
std::vector<Sensor> sensors;
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
void deserialize(const dv::value& root);
void initialize(
const EntityDef& def, entityid_t id, Entities& entities
+6
View File
@@ -23,3 +23,9 @@ dv::value Transform::serialize() const {
}
return tsfmap;
}
void Transform::deserialize(const dv::value& root) {
dv::get_vec(root, "pos", pos);
dv::get_vec(root, "size", size);
dv::get_mat(root, "rot", rot);
}
+2 -1
View File
@@ -8,7 +8,7 @@
#include <data/dv_fwd.hpp>
struct Transform {
static inline constexpr float EPSILON = 0.0000001f;
static inline constexpr float EPSILON = 1e-7f;
glm::vec3 pos;
glm::vec3 size;
glm::mat3 rot;
@@ -19,6 +19,7 @@ struct Transform {
glm::vec3 displaySize;
dv::value serialize() const;
void deserialize(const dv::value& root);
void refresh();
+16
View File
@@ -70,6 +70,22 @@ dv::value Skeleton::serialize(bool saveTextures, bool savePose) const {
return root;
}
void Skeleton::deserialize(const dv::value& root) {
if (auto found = root.at("textures")) {
auto& texturesmap = *found;
for (auto& [slot, _] : texturesmap.asObject()) {
texturesmap.at(slot).get(textures[slot]);
}
}
if (auto found = root.at("pose")) {
auto& posearr = *found;
auto& matrices = pose.matrices;
for (size_t i = 0; i < std::min(matrices.size(), posearr.size()); i++) {
dv::get_mat(posearr[i], pose.matrices[i]);
}
}
}
static void get_all_nodes(std::vector<Bone*>& nodes, Bone* node) {
nodes[node->getIndex()] = node;
for (auto& subnode : node->getSubnodes()) {
+1
View File
@@ -92,6 +92,7 @@ namespace rigging {
Skeleton(const SkeletonConfig* config);
dv::value serialize(bool saveTextures, bool savePose) const;
void deserialize(const dv::value& root);
};
class SkeletonConfig {