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

@ -0,0 +1,43 @@
#include "./transform.hpp"
#include <glm/gtc/matrix_transform.hpp>
#include <tracy/Tracy.hpp>
namespace MM::Systems {
void position3d_from_2d(entt::view<entt::get_t<const Components::DirtyTransformTag, const Components::Position2D, const Components::Position2D_ZOffset, Components::Position3D>> view) {
ZoneScoped;
view.each([](const Components::Position2D& pos2, const Components::Position2D_ZOffset& zoff, Components::Position3D& pos3) {
pos3.pos = glm::vec3(pos2.pos, zoff.z_offset + pos2.pos.y/10.f);
});
}
void transform3d_translate(entt::view<entt::get_t<const Components::DirtyTransformTag, const Components::Position3D, Components::Transform4x4>> view) {
ZoneScoped;
view.each([](const Components::Position3D& pos, Components::Transform4x4& trans) {
trans.trans = glm::translate(glm::mat4x4{1.f}, pos.pos);
});
}
void transform3d_rotate2d(entt::view<entt::get_t<const Components::DirtyTransformTag, const Components::Rotation2D, Components::Transform4x4>> view) {
ZoneScoped;
view.each([](const Components::Rotation2D& rot, Components::Transform4x4& trans) {
trans.trans = glm::rotate(trans.trans, rot.rot, glm::vec3(0.f, 0.f, 1.f));
});
}
void transform3d_scale2d(entt::view<entt::get_t<const Components::DirtyTransformTag, const Components::Scale2D, Components::Transform4x4>> view) {
ZoneScoped;
view.each([](const Components::Scale2D& scale, Components::Transform4x4& trans) {
trans.trans = glm::scale(trans.trans, glm::vec3(scale.scale, 1.f));
});
}
void transform_clear_dirty(entt::registry& scene, entt::view<entt::get_t<Components::DirtyTransformTag>> view) {
ZoneScoped;
scene.remove<Components::DirtyTransformTag>(view.begin(), view.end());
}
} // MM::Systems

View File

@ -0,0 +1,53 @@
#pragma once
#include <mm/components/position2d.hpp>
#include <mm/components/position2d_zoffset.hpp>
#include <mm/components/position3d.hpp>
#include <mm/components/scale2d.hpp>
#include <mm/components/rotation2d.hpp>
#include <mm/components/transform4x4.hpp>
#include <entt/entity/registry.hpp>
namespace MM::Systems {
// 2D usage:
//
// auto create dependencies, eg:
// scene.on_construct<Components::Position2D>().connect<&entt::registry::emplace_or_replace<Components::Position3D>>();
// scene.on_construct<Components::Position2D>().connect<&entt::registry::emplace_or_replace<Components::Transform4x4>>();
// scene.on_construct<Components::Position2D>().connect<&entt::registry::emplace_or_replace<Components::DirtyTransformTag>>();
//
// mark as dirty on change, eg:
// scene.on_update<Components::Position2D>().connect<&entt::registry::emplace_or_replace<Components::DirtyTransformTag>>();
// scene.on_update<Components::Position2D_ZOffset>().connect<&entt::registry::emplace_or_replace<Components::DirtyTransformTag>>();
// scene.on_update<Components::Position3D>().connect<&entt::registry::emplace_or_replace<Components::DirtyTransformTag>>();
// scene.on_update<Components::Scale2D>().connect<&entt::registry::emplace_or_replace<Components::DirtyTransformTag>>();
// scene.on_update<Components::Rotation2D>().connect<&entt::registry::emplace_or_replace<Components::DirtyTransformTag>>();
//
// optinally cleanup on destruction, eg:
// scene.on_destroy<Components::Position2D>().connect<&entt::registry::remove<
// Components::DirtyTransformTag,
// Components::Position2D_ZOffset,
// Components::Position3D,
// Components::Scale2D,
// Components::Rotation2D,
// Components::Transform4x4
// >>();
// TODO: impl for no zoffset comp
void position3d_from_2d(entt::view<entt::get_t<const Components::DirtyTransformTag, const Components::Position2D, const Components::Position2D_ZOffset, Components::Position3D>> view);
void transform3d_translate(entt::view<entt::get_t<const Components::DirtyTransformTag, const Components::Position3D, Components::Transform4x4>> view);
void transform3d_rotate2d(entt::view<entt::get_t<const Components::DirtyTransformTag, const Components::Rotation2D, Components::Transform4x4>> view);
void transform3d_scale2d(entt::view<entt::get_t<const Components::DirtyTransformTag, const Components::Scale2D, Components::Transform4x4>> view);
void transform_clear_dirty(entt::registry& scene, entt::view<entt::get_t<Components::DirtyTransformTag>> view);
} // MM::Systems