techkaczynski.dev / code

summaryrefslogtreecommitdiff
path: root/save.c
diff options
context:
space:
mode:
Diffstat (limited to 'save.c')
-rw-r--r--save.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/save.c b/save.c
index 9d46fe3..db906a2 100644
--- a/save.c
+++ b/save.c
@@ -772,8 +772,8 @@ read_physics_joint(FILE *fp, PhysicsJoint *joint, u32 body_cnt) {
!read_u32_le(fp, &joint->flags) ||
!read_vec3(fp, &joint->anchor_a) ||
!read_vec3(fp, &joint->anchor_b) ||
- !read_vec3(fp, &joint->axis_a) ||
- !read_vec3(fp, &joint->axis_b) ||
+ !read_quat(fp, &joint->frame_rot_a) ||
+ !read_quat(fp, &joint->frame_rot_b) ||
!read_f32_le(fp, &joint->lower) ||
!read_f32_le(fp, &joint->upper) ||
!read_f32_le(fp, &joint->spring_hz) ||
@@ -800,8 +800,8 @@ write_physics_joint(FILE *fp, PhysicsJoint *joint, u32 body_cnt) {
write_u32_le(fp, joint->flags) &&
write_vec3(fp, joint->anchor_a) &&
write_vec3(fp, joint->anchor_b) &&
- write_vec3(fp, joint->axis_a) &&
- write_vec3(fp, joint->axis_b) &&
+ write_quat(fp, joint->frame_rot_a) &&
+ write_quat(fp, joint->frame_rot_b) &&
write_f32_le(fp, joint->lower) &&
write_f32_le(fp, joint->upper) &&
write_f32_le(fp, joint->spring_hz) &&
@@ -832,6 +832,17 @@ read_physics_chunk(FILE *fp, SaveLoadContext *ctx) {
return false;
}
+ u32 root_body;
+ if (!read_u32_le(fp, &root_body)) {
+ return false;
+ }
+
+ if ((body_cnt && root_body >= body_cnt) ||
+ (!body_cnt && root_body != 0)) {
+ return false;
+ }
+
+ ent->phys.root_body = root_body;
ent->phys.body_cnt = body_cnt;
if (body_cnt) {
@@ -902,9 +913,12 @@ write_physics_chunk(FILE *fp) {
}
if ((phys->body_cnt && !phys->bodies) ||
- (phys->joint_cnt && !phys->joints) ||
- !write_u64_le(fp, ent->pid) ||
- !write_u32_le(fp, phys->body_cnt)) {
+ (phys->joint_cnt && !phys->joints) ||
+ (phys->body_cnt && phys->root_body >= phys->body_cnt) ||
+ (!phys->body_cnt && phys->root_body != 0) ||
+ !write_u64_le(fp, ent->pid) ||
+ !write_u32_le(fp, phys->body_cnt) ||
+ !write_u32_le(fp, phys->root_body)) {
return false;
}