7#include <glm/gtc/quaternion.hpp>
8#define GLM_ENABLE_EXPERIMENTAL
9#include <glm/gtx/quaternion.hpp>
10#include "../Component/SuperComponent.hpp"
85 void CheckIfSceneExists(
const std::string& filename,
bool& error,
const std::string& originScene, Json::Value root);
148 void Serialize(Json::Value& node,
bool load);
178 void Move(
const glm::vec3& translation);
190 void SetScale(
const glm::vec3& scale);
264 void SetEnabled(
bool enabled,
bool recursive =
false);
300 template <
typename T>
void Serialize(Json::Value& node,
bool load,
const std::string&
name);
305 void SetDirty(uint32_t dirtyMask = DirtyFlag::LOCAL_MATRIX | DirtyFlag::WORLD_MATRIX);
309 std::vector<Entity*> children;
311 std::string sceneName;
313 std::map<std::type_index, Component::SuperComponent*> components;
315 glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
316 glm::vec3 scale = glm::vec3(1.0f, 1.0f, 1.0f);
317 glm::quat rotation = glm::angleAxis(0.0f, glm::vec3(0.0f, 1.0f, 0.0f));
321 unsigned int uniqueIdentifier = 0;
324 mutable glm::mat4 localMatrix;
325 mutable glm::mat4 worldMatrix;
326 mutable uint32_t dirtyMask = DirtyFlag::LOCAL_MATRIX | DirtyFlag::WORLD_MATRIX;
330 std::type_index componentType = std::type_index(
typeid(T*));
335 return static_cast<T*
>(
GetComponent(std::type_index(
typeid(T*))));
342template <
typename T>
void Entity::Serialize(Json::Value& node,
bool load,
const std::string& name) {
343 std::type_index componentType = std::type_index(
typeid(T*));
346 if (!node[
name].isNull()) {
353 if (component !=
nullptr) {
Component which all components inherit.
Definition: SuperComponent.hpp:9
virtual void Serialize(Json::Value &node, bool load)=0
Save or load component values to/from JSON.
Entity containing various components.
Definition: Entity.hpp:16
const std::vector< Entity * > & GetChildren() const
Get all of the entity's children.
Definition: Entity.cpp:135
void RotatePitch(float angle)
Rotates around the X axis.
Definition: Entity.cpp:323
const glm::mat4 & GetWorldModelMatrix() const
Get the world model matrix.
Definition: Entity.cpp:355
glm::vec3 GetWorldPosition() const
Get the position in the world.
Definition: Entity.cpp:256
const glm::mat4 & GetLocalMatrix() const
Get the local model matrix.
Definition: Entity.cpp:337
bool vertsLoaded
Definition: Entity.hpp:290
void RotateYaw(float angle)
Rotates around the Y axis.
Definition: Entity.cpp:319
const glm::vec3 & GetPosition() const
Get the local position.
Definition: Entity.cpp:247
void CheckIfSceneExists(const std::string &filename, bool &error, const std::string &originScene, Json::Value root)
Check if scene already exists in any of json files.
Definition: Entity.cpp:117
Entity * GetChild(const std::string &name) const
Get child based on its name.
Definition: Entity.cpp:139
const glm::vec3 & GetScale() const
Get the local scale.
Definition: Entity.cpp:277
void RotateAroundWorldAxis(float angle, const glm::vec3 &axis)
Rotates around an axis given in world space.
Definition: Entity.cpp:331
void RotateRoll(float angle)
Rotates around the Z axis.
Definition: Entity.cpp:327
Entity * InstantiateScene(const std::string &name)
Instantiate a scene as a child to this entity.
Definition: Entity.cpp:76
const glm::quat & GetRotation() const
Get the rotation of this entity.
Definition: Entity.cpp:286
glm::vec3 GetWorldDirection() const
Get direction of the entity.
Definition: Entity.cpp:315
void SetRotation(const glm::quat &localRot)
Set the local rotation of the entity.
Definition: Entity.cpp:290
glm::quat GetWorldRotation() const
Get rotation of the entity.
Definition: Entity.cpp:295
Entity * AddChild(const std::string &name="")
Add child entity.
Definition: Entity.cpp:39
bool sceneChosen
Definition: Entity.hpp:292
Entity * SetParent(Entity *newParent)
Set a new parent.
Definition: Entity.cpp:46
void SetWorldPosition(const glm::vec3 &worldPos)
Set the position of the entity in world space.
Definition: Entity.cpp:265
void SetEnabled(bool enabled, bool recursive=false)
Set whether the entity should be enabled.
Definition: Entity.cpp:368
bool brushActive
Definition: Entity.hpp:289
bool IsKilled() const
Get whether entity has been killed.
Definition: Entity.cpp:182
bool RemoveChild(Entity *child)
Remove child entity.
Definition: Entity.cpp:159
T * AddComponent()
Adds component with type T.
Definition: Entity.hpp:329
std::string name
Name of the entity.
Definition: Entity.hpp:273
unsigned int GetUniqueIdentifier() const
Get the entity's UID.
Definition: Entity.cpp:381
void Move(const glm::vec3 &translation)
Move in local space.
Definition: Entity.cpp:273
void SetPosition(const glm::vec3 &position)
Set the local position.
Definition: Entity.cpp:251
void Kill()
Kill the entity, will be removed at the end of the frame.
Definition: Entity.cpp:174
bool IsScene() const
Get whether the entity is an instantiated scene.
Definition: Entity.cpp:170
bool loadPaintModeClicked
Variables used for enabling and disabling the paint brush tool.
Definition: Entity.hpp:288
Entity(World *world, const std::string &name)
Create new entity.
Definition: Entity.cpp:29
bool IsEnabled() const
Get whether the entity is enabled.
Definition: Entity.cpp:377
void SetWorldRotation(const glm::quat &worldRot)
Set the rotation of the entity in world space.
Definition: Entity.cpp:305
Entity * GetChildFromIndex(int index) const
Get child based on its name.
Definition: Entity.cpp:148
unsigned int GetNumChildren() const
Get the number of children.
Definition: Entity.cpp:155
void SetScale(const glm::vec3 &scale)
Set the local scale.
Definition: Entity.cpp:281
~Entity()
Destructor.
Definition: Entity.cpp:33
void Serialize(Json::Value &node, bool load)
Save or load entity to/from JSON.
Definition: Entity.cpp:186
void KillComponent()
Kill component of type T.
Definition: Entity.hpp:338
Entity * GetParent() const
Get the entity's parent entity.
Definition: Entity.cpp:35
void SetUniqueIdentifier(unsigned int UID)
Set the entity's UID.
Definition: Entity.cpp:385
bool painting
Definition: Entity.hpp:291
bool HasChild(const Entity *child, bool deep=true) const
Check if entity is a child.
Definition: Entity.cpp:65
T * GetComponent() const
Gets component with type T.
Definition: Entity.hpp:334
The game world containing all entities.
Definition: World.hpp:14