forked from TheCherno/Hazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "hzpch.h" | ||
#include "Entity.h" | ||
|
||
namespace Hazel { | ||
|
||
Entity::Entity(entt::entity handle, Scene* scene) | ||
: m_EntityHandle(handle), m_Scene(scene) | ||
{ | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "Scene.h" | ||
|
||
#include "entt.hpp" | ||
|
||
namespace Hazel { | ||
|
||
class Entity | ||
{ | ||
public: | ||
Entity() = default; | ||
Entity(entt::entity handle, Scene* scene); | ||
Entity(const Entity& other) = default; | ||
|
||
template<typename T, typename... Args> | ||
T& AddComponent(Args&&... args) | ||
{ | ||
HZ_CORE_ASSERT(!HasComponent<T>(), "Entity already has component!"); | ||
return m_Scene->m_Registry.emplace<T>(m_EntityHandle, std::forward<Args>(args)...); | ||
} | ||
|
||
template<typename T> | ||
T& GetComponent() | ||
{ | ||
HZ_CORE_ASSERT(HasComponent<T>(), "Entity does not have component!"); | ||
return m_Scene->m_Registry.get<T>(m_EntityHandle); | ||
} | ||
|
||
template<typename T> | ||
bool HasComponent() | ||
{ | ||
return m_Scene->m_Registry.has<T>(m_EntityHandle); | ||
} | ||
|
||
template<typename T> | ||
void RemoveComponent() | ||
{ | ||
HZ_CORE_ASSERT(HasComponent<T>(), "Entity does not have component!"); | ||
m_Scene->m_Registry.remove<T>(m_EntityHandle); | ||
} | ||
|
||
operator bool() const { return m_EntityHandle != 0; } | ||
private: | ||
entt::entity m_EntityHandle{ 0 }; | ||
Scene* m_Scene = nullptr; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters