2#define GLM_ENABLE_EXPERIMENTAL
3#include <box2cpp/box2cpp.h>
6#include <glm/gtx/matrix_transform_2d.hpp>
52 [[maybe_unused]]
bool bober{};
73 explicit UUID(
const std::string& uuid_str) :
m_UUID(uuid_str) {}
99 entt::entity m_Parent { entt::null };
100 entt::entity m_FirstChild { entt::null };
101 entt::entity m_NextSibling { entt::null };
102 entt::entity m_PreviousSibling { entt::null };
122 if (m_LocalPosition != localPosition) {
123 m_LocalPosition = localPosition;
124 m_DirtyTransform =
true;
126 entt::entity root = m_Owner.GetRawEntity();
127 entt::entity currentParent = m_Owner.GetComponents<
Hierarchy>().m_Parent;
128 while (m_Owner.GetRawHandle().registry()->valid(currentParent)) {
129 root = currentParent;
130 currentParent = m_Owner.GetRawHandle().registry()->get<
Hierarchy>(root).m_Parent;
145 if (m_LocalRotation != localRotation) {
146 m_LocalRotation = localRotation;
147 m_DirtyTransform =
true;
149 entt::entity root = m_Owner.GetRawEntity();
150 entt::entity currentParent = m_Owner.GetComponents<
Hierarchy>().m_Parent;
151 while (m_Owner.GetRawHandle().registry()->valid(currentParent)) {
152 root = currentParent;
153 currentParent = m_Owner.GetRawHandle().registry()->get<
Hierarchy>(root).m_Parent;
168 if (m_LocalScale != localScale) {
169 m_LocalScale = localScale;
170 m_DirtyTransform =
true;
172 entt::entity root = m_Owner.GetRawEntity();
173 entt::entity currentParent = m_Owner.GetComponents<
Hierarchy>().m_Parent;
174 while (m_Owner.GetRawHandle().registry()->valid(currentParent)) {
175 root = currentParent;
176 currentParent = m_Owner.GetRawHandle().registry()->get<
Hierarchy>(root).m_Parent;
191 if (m_LocalDepthOffset != localDepth) {
192 m_LocalDepthOffset = localDepth;
195 entt::entity root = m_Owner.GetRawEntity();
196 entt::entity currentParent = m_Owner.GetComponents<
Hierarchy>().m_Parent;
197 while (m_Owner.GetRawHandle().registry()->valid(currentParent)) {
198 root = currentParent;
199 currentParent = m_Owner.GetRawHandle().registry()->get<
Hierarchy>(root).m_Parent;
213 return m_LocalPosition;
229 return m_LocalRotation;
237 return m_LocalDepthOffset;
262 return glm::translate(glm::mat3(1.0f), m_LocalPosition) *
263 glm::rotate(glm::mat3(1.0f), glm::radians(m_LocalRotation)) *
264 glm::scale(glm::mat3(1.0f), m_LocalScale);
269 glm::vec2 m_LocalPosition{ 0.0f, 0.0f };
270 glm::vec2 m_LocalScale{ 1.0f, 1.0f };
271 float m_LocalRotation{ 0.0f };
272 glm::mat3 m_LastParentTransform{ 1.0f };
273 World::Entity m_Owner;
278 int16_t m_LocalDepthOffset{ 0 };
279 bool m_Detached{
false };
280 bool m_DirtyTransform{
true };
281 bool m_DirtyDepth{
true };
298 struct TransparentHash {
299 using is_transparent = void;
300 size_t operator()(std::string_view sv)
const noexcept {
301 return std::hash<std::string_view>{}(sv);
305 struct TransparentEqual {
306 using is_transparent = void;
307 bool operator()(std::string_view lhs, std::string_view rhs)
const noexcept {
312 std::unordered_map<std::string, entt::entity, TransparentHash, TransparentEqual> m_Children;
323 [[maybe_unused]]
bool pingvin{};
334 [[maybe_unused]]
bool homik{};
344 QuadRenderer(
const glm::vec2 halfSize,
const std::shared_ptr<Graphics::Texture2D>& texture,
const Graphics::UVs& uvs) : m_HalfSize(halfSize), m_UVs(uvs) {
351 QuadRenderer(
const glm::vec2 halfSize,
const std::shared_ptr<Graphics::Texture2D>& texture,
const Graphics::UVs& uvs,
const glm::vec4& tintColor) : m_HalfSize(halfSize), m_UVs(uvs) {
374 std::expected<void, Core::CoriError<>>
SetTexture(
const std::shared_ptr<Graphics::Texture2D>& texture) {
375 if (!m_AnimatorBound) {
376 if (m_HasSemiTransparency && m_Color.a != 1.0f) {
380 m_HasSemiTransparency = texture->HasSemiTransparency();
385 return std::unexpected(
Core::CoriError(
"Can't set Texture2D because Quad Animator is currently bound."));
392 [[nodiscard]]
const std::shared_ptr<Graphics::Texture2D>&
GetTexture()
const {
401 if (m_HasSemiTransparency && (m_Texture ? m_Texture->HasSemiTransparency() :
false)) {
406 if (m_Color.a != 1.0f) {
407 m_HasSemiTransparency =
true;
409 m_HasSemiTransparency =
false;
428 if (!m_AnimatorBound) {
433 return std::unexpected(
Core::CoriError(
"Can't set UVs because Quad Animator is currently bound."));
450 std::expected<void, Core::CoriError<>>
SetHalfSize(
const glm::vec2 halfSize) {
451 if (!m_AnimatorBound) {
452 m_HalfSize = halfSize;
455 return std::unexpected(
Core::CoriError(
"Can't set HalfSize because Quad Animator is currently bound."));
471 return m_HasSemiTransparency;
478 glm::vec2 m_HalfSize{ 0.0f };
480 std::shared_ptr<Graphics::Texture2D> m_Texture{
nullptr };
481 glm::vec4 m_Color{ 1.0f, 1.0f, 1.0f, 1.0f };
488 bool m_HasSemiTransparency{
false };
489 bool m_AnimatorBound{
false };
508 std::shared_ptr<Audio::Track>
AddTrack(
const std::string& name) {
510 m_AudioTracks.insert({name, track});
519 std::shared_ptr<Audio::Track>
AddTrack(
const char* name) {
521 m_AudioTracks.insert({name, track});
531 if (m_AudioTracks.contains(name)) {
532 m_AudioTracks.erase(name);
542 if (m_AudioTracks.contains(name)) {
543 m_AudioTracks.erase(name);
553 if (m_AudioTracks.contains(name)) {
554 return m_AudioTracks.at(name);
557 return std::unexpected(
Core::CoriError(std::format(
"No audio Track is found with the specified name '{}'", name)));
566 if (m_AudioTracks.contains(name)) {
567 return m_AudioTracks.at(name);
570 return std::unexpected(
Core::CoriError(std::format(
"No audio Track is found with the specified name '{}'", name)));
574 struct TransparentHash {
575 using is_transparent = void;
576 size_t operator()(std::string_view sv)
const noexcept {
577 return std::hash<std::string_view>{}(sv);
581 struct TransparentEqual {
582 using is_transparent = void;
583 bool operator()(std::string_view lhs, std::string_view rhs)
const noexcept {
588 std::unordered_map<std::string, std::shared_ptr<Audio::Track>, TransparentHash, TransparentEqual> m_AudioTracks;
603 RigidBody(Physics::WorldRef world,
const std::derived_from<b2BodyDef>
auto& def) :
Physics::BodyRef{world.CreateBody(
Physics::DestroyWithParent, def)} {}
#define CORI_CORE_WARN_TAGGED(...)
static std::shared_ptr< Track > Create(std::string name)
Creates a Track object.
Custom error class mainly used in std::expected.
A 128bit UUID, can be serialized to the string and deserialized from it.
Entities are the essential part of WorldSystem.
System that is responsible for Animations, every Scene has it by default.
Anything connected to physics is in this namespace. Please refer to Box2D docs 'https://box2d....
Components designed to be used with entities.
Components that are used with the WorldSystem (ECS).
static constexpr auto in_place_delete
Cori::World::Entity m_Entity
std::expected< std::shared_ptr< Audio::Track >, Core::CoriError<> > GetTrack(const char *name)
Retries a Track from the AudioSource cache.
AudioSource(const AudioSource &)=delete
AudioSource & operator=(AudioSource &&)=delete
std::shared_ptr< Audio::Track > AddTrack(const char *name)
Adds a Track to the AudioSource cache.
AudioSource & operator=(const AudioSource &)=delete
std::shared_ptr< Audio::Track > AddTrack(const std::string &name)
Adds a Track to the AudioSource cache.
void RemoveTrack(const char *name)
Removes a Track from the AudioSource, and deletes it if it is not referenced anywhere.
std::expected< std::shared_ptr< Audio::Track >, Core::CoriError<> > GetTrack(const std::string &name)
Retries a Track from the AudioSource cache.
void RemoveTrack(const std::string &name)
Removes a Track from the AudioSource, and deletes it if it is not referenced anywhere.
AudioSource(AudioSource &&)=delete
ChildCache(ChildCache &&)=delete
ChildCache(const ChildCache &)=delete
ChildCache & operator=(ChildCache &&)=delete
ChildCache & operator=(const ChildCache &)=delete
Every Entity has a hierarchy component by default, it's essential for entity hierarchy system.
Hierarchy & operator=(Hierarchy &&)=delete
Hierarchy & operator=(const Hierarchy &)=delete
Hierarchy(const Hierarchy &)=delete
Hierarchy(Hierarchy &&)=delete
InactiveGloballyFlag()=default
InactiveLocallyFlag()=default
glm::vec2 GetHalfSize() const
Gets the current quad half size.
void SetColor(const glm::vec4 &color)
Changes the tint color of the quad.
friend class QuadAnimator
QuadRenderer & operator=(QuadRenderer &&)=delete
const std::shared_ptr< Graphics::Texture2D > & GetTexture() const
Returns a const reference to the currently active texture.
std::expected< void, Core::CoriError<> > SetUVs(const Graphics::UVs &uvs)
Changes the current UVs that are used when sampling fom the texture.
const Graphics::UVs & GetUVs() const
Gets a const reference to the current UVs of the quad.
QuadRenderer(const QuadRenderer &)=delete
QuadRenderer(const glm::vec2 halfSize, const std::shared_ptr< Graphics::Texture2D > &texture, const Graphics::UVs &uvs)
std::expected< void, Core::CoriError<> > SetHalfSize(const glm::vec2 halfSize)
Changes the current half size that are used when drawing the quad.
QuadRenderer(const glm::vec2 halfSize, const std::shared_ptr< Graphics::Texture2D > &texture, const Graphics::UVs &uvs, const glm::vec4 &tintColor)
bool GetSemiTransparencyState() const
Checks if a quad needs to be processed with transparency in mind or no.
QuadRenderer(const glm::vec2 halfSize, const glm::vec4 &color)
std::expected< void, Core::CoriError<> > SetTexture(const std::shared_ptr< Graphics::Texture2D > &texture)
Changes the texture that is used to render the quad.
const glm::vec4 & GetColor() const
Gets a const reference to the current tint color of the quad.
QuadRenderer & operator=(const QuadRenderer &)=delete
QuadRenderer(QuadRenderer &&)=delete
RigidBody(const RigidBody &)=delete
RigidBody(Physics::WorldRef world, const std::derived_from< b2BodyDef > auto &def)
Creates a RigidBody.
RigidBody & operator=(RigidBody &&)=delete
RigidBody & operator=(const RigidBody &)=delete
RigidBody(RigidBody &&)=delete
UUID & operator=(const UUID &)=delete
UUID(const UUID &)=delete
UUID(const std::string &uuid_str)
UUID & operator=(UUID &&)=delete