From 5148ea7217120468e78740b50509ea31ed664d1e Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 26 Nov 2022 13:48:52 +0100 Subject: [PATCH] componets json with defaults, minor formatting --- framework/common_components/src/mm/components/name.hpp | 2 +- .../src/mm/components/position2d_zoffset.hpp | 2 +- .../src/mm/components/serialize/json_color.hpp | 2 +- .../src/mm/components/serialize/json_glm.hpp | 10 +++++----- .../src/mm/components/serialize/json_name.hpp | 1 + .../src/mm/components/serialize/json_position2d.hpp | 2 +- .../components/serialize/json_position2d_zoffset.hpp | 2 +- .../src/mm/components/serialize/json_position3d.hpp | 2 +- .../src/mm/components/serialize/json_rotation2d.hpp | 2 +- .../src/mm/components/serialize/json_scale2d.hpp | 2 +- .../src/mm/components/serialize/json_transform4x4.hpp | 2 +- .../components/serialize/json_velocity2d_position.hpp | 2 +- .../serialize/json_velocity2d_position_intent.hpp | 2 +- .../components/serialize/json_velocity2d_rotation.hpp | 2 +- .../src/mm/components/serialize/json_view_dir2d.hpp | 2 +- .../src/mm/components/serialize/json_view_dir3d.hpp | 2 +- .../common_components/src/mm/components/view_dir2d.hpp | 2 +- .../common_components/src/mm/components/view_dir3d.hpp | 6 +++--- 18 files changed, 24 insertions(+), 23 deletions(-) diff --git a/framework/common_components/src/mm/components/name.hpp b/framework/common_components/src/mm/components/name.hpp index 8df0cfb..a884c04 100644 --- a/framework/common_components/src/mm/components/name.hpp +++ b/framework/common_components/src/mm/components/name.hpp @@ -4,7 +4,7 @@ namespace MM::Components { struct Name { - static const size_t max_str_len = 64; + static const size_t max_str_len {64u}; std::string str; }; } diff --git a/framework/common_components/src/mm/components/position2d_zoffset.hpp b/framework/common_components/src/mm/components/position2d_zoffset.hpp index 7aad861..c27a67c 100644 --- a/framework/common_components/src/mm/components/position2d_zoffset.hpp +++ b/framework/common_components/src/mm/components/position2d_zoffset.hpp @@ -4,7 +4,7 @@ namespace MM::Components { // used to lift 2D into 3D space. like a z-index in css/svg struct Position2D_ZOffset { - float z_offset = 500.f; // default camera allows values to be between 0 and 1000 + float z_offset {500.f}; // default camera allows values to be between 0 and 1000 }; } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_color.hpp b/framework/common_components/src/mm/components/serialize/json_color.hpp index b71ca81..e7b7809 100644 --- a/framework/common_components/src/mm/components/serialize/json_color.hpp +++ b/framework/common_components/src/mm/components/serialize/json_color.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Color, color) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Color, color) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_glm.hpp b/framework/common_components/src/mm/components/serialize/json_glm.hpp index 0f5c05a..976f396 100644 --- a/framework/common_components/src/mm/components/serialize/json_glm.hpp +++ b/framework/common_components/src/mm/components/serialize/json_glm.hpp @@ -9,12 +9,12 @@ namespace glm { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec2, x, y) - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec3, x, y, z) - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec4, x, y, z, w) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec2, x, y) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec3, x, y, z) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec4, x, y, z, w) //NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(mat4x4, [0], y, z, w) - inline void to_json(nlohmann::json& nlohmann_json_j, const mat4x4& nlohmann_json_t) { + inline void to_json(nlohmann::json& nlohmann_json_j, const mat4x4& nlohmann_json_t) { // TODO: make 2d array? nlohmann_json_j = nlohmann::json::array_t{}; nlohmann_json_j[0] = nlohmann_json_t[0]; @@ -22,7 +22,7 @@ namespace glm { nlohmann_json_j[2] = nlohmann_json_t[2]; nlohmann_json_j[3] = nlohmann_json_t[3]; } - inline void from_json(const nlohmann::json& nlohmann_json_j, mat4x4& nlohmann_json_t) { + inline void from_json(const nlohmann::json& nlohmann_json_j, mat4x4& nlohmann_json_t) { if (!nlohmann_json_j.is_array()) { //throw nlohmann::json::type_error::create(0, "", nlohmann_json_j); assert(false && "expected array"); diff --git a/framework/common_components/src/mm/components/serialize/json_name.hpp b/framework/common_components/src/mm/components/serialize/json_name.hpp index ca5c0f5..f994893 100644 --- a/framework/common_components/src/mm/components/serialize/json_name.hpp +++ b/framework/common_components/src/mm/components/serialize/json_name.hpp @@ -5,6 +5,7 @@ #include namespace MM::Components { + // TODO: manual with str len limit NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Name, str) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_position2d.hpp b/framework/common_components/src/mm/components/serialize/json_position2d.hpp index 7e7998f..4decada 100644 --- a/framework/common_components/src/mm/components/serialize/json_position2d.hpp +++ b/framework/common_components/src/mm/components/serialize/json_position2d.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D, pos) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D, pos) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_position2d_zoffset.hpp b/framework/common_components/src/mm/components/serialize/json_position2d_zoffset.hpp index e22c1c0..e570995 100644 --- a/framework/common_components/src/mm/components/serialize/json_position2d_zoffset.hpp +++ b/framework/common_components/src/mm/components/serialize/json_position2d_zoffset.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D_ZOffset, z_offset) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D_ZOffset, z_offset) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_position3d.hpp b/framework/common_components/src/mm/components/serialize/json_position3d.hpp index ce0eb78..ab6e5cf 100644 --- a/framework/common_components/src/mm/components/serialize/json_position3d.hpp +++ b/framework/common_components/src/mm/components/serialize/json_position3d.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position3D, pos) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position3D, pos) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_rotation2d.hpp b/framework/common_components/src/mm/components/serialize/json_rotation2d.hpp index 8f3a4cb..209b5b9 100644 --- a/framework/common_components/src/mm/components/serialize/json_rotation2d.hpp +++ b/framework/common_components/src/mm/components/serialize/json_rotation2d.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Rotation2D, rot) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Rotation2D, rot) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_scale2d.hpp b/framework/common_components/src/mm/components/serialize/json_scale2d.hpp index 32a3662..0c785e5 100644 --- a/framework/common_components/src/mm/components/serialize/json_scale2d.hpp +++ b/framework/common_components/src/mm/components/serialize/json_scale2d.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Scale2D, scale) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Scale2D, scale) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_transform4x4.hpp b/framework/common_components/src/mm/components/serialize/json_transform4x4.hpp index 513836d..daca6f0 100644 --- a/framework/common_components/src/mm/components/serialize/json_transform4x4.hpp +++ b/framework/common_components/src/mm/components/serialize/json_transform4x4.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform4x4, trans) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Transform4x4, trans) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_velocity2d_position.hpp b/framework/common_components/src/mm/components/serialize/json_velocity2d_position.hpp index cd75b41..58819dc 100644 --- a/framework/common_components/src/mm/components/serialize/json_velocity2d_position.hpp +++ b/framework/common_components/src/mm/components/serialize/json_velocity2d_position.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPosition, pos_vel) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPosition, pos_vel) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_velocity2d_position_intent.hpp b/framework/common_components/src/mm/components/serialize/json_velocity2d_position_intent.hpp index 356347b..1d36ed7 100644 --- a/framework/common_components/src/mm/components/serialize/json_velocity2d_position_intent.hpp +++ b/framework/common_components/src/mm/components/serialize/json_velocity2d_position_intent.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPositionIntent, intent) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPositionIntent, intent) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_velocity2d_rotation.hpp b/framework/common_components/src/mm/components/serialize/json_velocity2d_rotation.hpp index 9a313e3..c380486 100644 --- a/framework/common_components/src/mm/components/serialize/json_velocity2d_rotation.hpp +++ b/framework/common_components/src/mm/components/serialize/json_velocity2d_rotation.hpp @@ -7,6 +7,6 @@ #include "./json_glm.hpp" namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DRotation, rot_vel) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DRotation, rot_vel) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_view_dir2d.hpp b/framework/common_components/src/mm/components/serialize/json_view_dir2d.hpp index f611b9b..0c3f564 100644 --- a/framework/common_components/src/mm/components/serialize/json_view_dir2d.hpp +++ b/framework/common_components/src/mm/components/serialize/json_view_dir2d.hpp @@ -5,6 +5,6 @@ #include namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ViewDir2D, dir) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir2D, dir) } // MM::Components diff --git a/framework/common_components/src/mm/components/serialize/json_view_dir3d.hpp b/framework/common_components/src/mm/components/serialize/json_view_dir3d.hpp index b7b86ea..ec780b7 100644 --- a/framework/common_components/src/mm/components/serialize/json_view_dir3d.hpp +++ b/framework/common_components/src/mm/components/serialize/json_view_dir3d.hpp @@ -5,6 +5,6 @@ #include namespace MM::Components { - NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ViewDir3D, yaw, pitch, roll) + NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir3D, yaw, pitch, roll) } // MM::Components diff --git a/framework/common_components/src/mm/components/view_dir2d.hpp b/framework/common_components/src/mm/components/view_dir2d.hpp index fd7025b..899dd64 100644 --- a/framework/common_components/src/mm/components/view_dir2d.hpp +++ b/framework/common_components/src/mm/components/view_dir2d.hpp @@ -3,7 +3,7 @@ namespace MM::Components { struct ViewDir2D { - float dir = 0.f; // rad + float dir {0.f}; // rad }; } // MM::Components diff --git a/framework/common_components/src/mm/components/view_dir3d.hpp b/framework/common_components/src/mm/components/view_dir3d.hpp index 4fa2ff9..78e742b 100644 --- a/framework/common_components/src/mm/components/view_dir3d.hpp +++ b/framework/common_components/src/mm/components/view_dir3d.hpp @@ -3,9 +3,9 @@ namespace MM::Components { struct ViewDir3D { - float yaw = 0.f; // rad - float pitch = 0.f; // rad - float roll = 0.f; // rad + float yaw {0.f}; // rad + float pitch {0.f}; // rad + float roll {0.f}; // rad }; } // MM::Components