From dae9c6d0ef3430618335db5a9efa9d0c82d1d82c Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Mon, 23 Apr 2018 22:29:53 +1000 Subject: [PATCH] Began work on serializing entity physics data to file --- README.md | 3 +++ src/common/common.h | 2 ++ src/game/physics.c | 1 + src/libsymmetry/entity.c | 52 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/README.md b/README.md index 0117f69..0f2e3be 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,8 @@ - ## TODO + - Work on (yet another)entity refactor before moving on to serialization + - Implement collision/physics data serialization, read and write. - Physics forces/torque etc - Implement physics debug visualizations for other primitives and tri mesh shapes - Replace all renderer_check_gl calls with GL_CHECK macro @@ -173,6 +175,7 @@ - Re-order lib folder for linux by putting all libraries in one folder - Figure out a better way for handling libs on linux, current method DOES NOT work on other computers - Fix 30fps bug on windows + - Change compilation so that that external libraries are compiled along with the project code(like Urho3d) - Add fallback shader - Implement Game States - Store Materials in new format supported by parser diff --git a/src/common/common.h b/src/common/common.h index 9e673e5..b29da09 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -58,6 +58,8 @@ enum Collision_Shape_Type CST_BOX = 0, CST_SPHERE, CST_CYLINDER, + CST_CAPSULE, + CST_PLANE, CST_TRIMESH, CST_UNKNOWN }; diff --git a/src/game/physics.c b/src/game/physics.c index a73935d..190c03d 100644 --- a/src/game/physics.c +++ b/src/game/physics.c @@ -238,6 +238,7 @@ int physics_cs_type_get(Collision_Shape shape) case dSphereClass: return CST_SPHERE; case dCylinderClass: return CST_CYLINDER; case dTriMeshClass: return CST_TRIMESH; + case dPlaneClass: return CST_PLANE; default: return CST_UNKNOWN; } } diff --git a/src/libsymmetry/entity.c b/src/libsymmetry/entity.c index 4c50bae..b0b0996 100644 --- a/src/libsymmetry/entity.c +++ b/src/libsymmetry/entity.c @@ -238,6 +238,58 @@ bool entity_write(struct Entity* entity, struct Parser_Object* object) hashmap_int_set(entity_data, "type", entity->type); hashmap_bool_set(entity_data, "is_listener", entity->is_listener); hashmap_bool_set(entity_data, "renderable", entity->renderable); + hashmap_bool_set(entity_data, "has_collision", entity->has_collision); + + if(entity->has_collision) + { + if(entity->collision.rigidbody) + hashmap_bool_set(entity_data, "has_rigidbody", true); + else + hashmap_bool_set(entity_data, "has_rigidbody", false); + + int shape_type = platform->physics.cs_type_get(entity->collision.collision_shape); + hashmap_int_set(entity_data, "collision_shape_type", shape_type); + switch(shape_type) + { + case CST_BOX: + { + float x, y, z; + x = y = z = 0.f; + platform->physics.cs_box_params_get(entity->collision.collision_shape, &x, &y, &z); + hashmap_float_set(entity_data, "collision_shape_x", x); + hashmap_float_set(entity_data, "collision_shape_y", y); + hashmap_float_set(entity_data, "collision_shape_z", z); + } + break; + case CST_SPHERE: + { + float radius = 0.f; + platform->physics.cs_sphere_radius_get(entity->collision.collision_shape); + hashmap_float_set(entity_data, "collision_shape_radius", radius); + } + break; + case CST_CAPSULE: + { + float length = 0.f, radius = 0.f; + platform->physics.cs_capsule_params_get(entity->collision.collision_shape, &radius, &length); + hashmap_float_set(entity_data, "collision_shape_length", length); + hashmap_float_set(entity_data, "collision_shape_radius", radius); + } + break; + case CST_PLANE: + { + float a, b, c, d; + platform->physics.cs_plane_params_get(entity->collision.collision_shape, &a, &b, &c, &d); + hashmap_float_set(entity_data, "collision_shape_a", a); + hashmap_float_set(entity_data, "collision_shape_b", b); + hashmap_float_set(entity_data, "collision_shape_c", c); + hashmap_float_set(entity_data, "collision_shape_d", d); + } + break; + default: break; + } + + } struct Entity* parent = entity_get_parent(entity->id); hashmap_str_set(entity_data, "parent", parent ? parent->name : "NONE");