remove old transform and velocity components and replace with new decomposed components

focus on 2D for now
This commit is contained in:
2022-01-04 22:33:59 +01:00
parent c36fa30cbc
commit 12b0a90ad0
71 changed files with 1114 additions and 528 deletions

View File

@@ -3,6 +3,7 @@
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <nlohmann/json.hpp>
@@ -12,5 +13,26 @@ namespace glm {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec3, x, y, z)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(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) {
// TODO: make 2d array?
nlohmann_json_j = nlohmann::json::array_t{};
nlohmann_json_j[0] = nlohmann_json_t[0];
nlohmann_json_j[1] = nlohmann_json_t[1];
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) {
if (!nlohmann_json_j.is_array()) {
//throw nlohmann::json::type_error::create(0, "", nlohmann_json_j);
assert(false && "expected array");
return; // TODO: dont fail silently
}
nlohmann_json_j.at(0).get_to(nlohmann_json_t[0]);
nlohmann_json_j.at(1).get_to(nlohmann_json_t[1]);
nlohmann_json_j.at(2).get_to(nlohmann_json_t[2]);
nlohmann_json_j.at(3).get_to(nlohmann_json_t[3]);
}
}

View File

@@ -2,11 +2,11 @@
#include <nlohmann/json.hpp>
#include <mm/components/velocity2d.hpp>
#include <mm/components/position2d.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2D, velocity, rotation)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D, pos)
} // MM::Components

View File

@@ -2,11 +2,11 @@
#include <nlohmann/json.hpp>
#include <mm/components/transform2d.hpp>
#include <mm/components/position2d_zoffset.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform2D, position, scale, rotation)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D_ZOffset, z_offset)
} // MM::Components

View File

@@ -2,11 +2,11 @@
#include <nlohmann/json.hpp>
#include <mm/components/velocity3d.hpp>
#include <mm/components/position3d.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity3D, velocity, rotation)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position3D, pos)
} // MM::Components

View File

@@ -2,11 +2,11 @@
#include <nlohmann/json.hpp>
#include <mm/components/transform3d.hpp>
#include <mm/components/rotation2d.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform3D, position, scale, rotation)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Rotation2D, rot)
} // MM::Components

View File

@@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/scale2d.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Scale2D, scale)
} // MM::Components

View File

@@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/transform4x4.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform4x4, trans)
} // MM::Components

View File

@@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/velocity2d_position.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPosition, pos_vel)
} // MM::Components

View File

@@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/velocity2d_position_intent.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPositionIntent, intent)
} // MM::Components

View File

@@ -0,0 +1,12 @@
#pragma once
#include <nlohmann/json.hpp>
#include <mm/components/velocity2d_rotation.hpp>
#include "./json_glm.hpp"
namespace MM::Components {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DRotation, rot_vel)
} // MM::Components