Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
entity.h
1 #pragma once
2 
3 #include "util/shared_ptr.h"
4 #include "util/weak_ptr.h"
5 #include "util/vector.h"
6 #include "util/queue.h"
7 #include "util/string.h"
8 #include "renderer/mesh.h"
9 #include "renderer/buffers/upload_buffer.h"
10 #include <DirectXMath.h>
11 
12 namespace blowbox
13 {
26  class Entity
27  {
28  friend class SceneManager;
29  friend class EntityFactory;
30  public:
35  Entity(const String& name);
36 
38  ~Entity();
39 
44  void SetName(const String& name);
45 
50  const String& GetName() const;
51 
56  void SetLocalPosition(const DirectX::XMFLOAT3& position);
57 
62  void SetLocalRotation(const DirectX::XMFLOAT3& rotation);
63 
68  void SetLocalScaling(const DirectX::XMFLOAT3& scaling);
69 
74  void SetMesh(SharedPtr<Mesh> mesh);
75 
77  const DirectX::XMFLOAT3& GetLocalPosition() const;
78 
80  const DirectX::XMFLOAT3& GetLocalRotation() const;
81 
83  const DirectX::XMFLOAT3& GetLocalScaling() const;
84 
86  SharedPtr<Mesh> GetMesh() const;
87 
93  const DirectX::XMMATRIX& GetWorldTransform();
94 
96  const Vector<SharedPtr<Entity>>& GetChildren() const;
97 
100 
101  protected:
103  void Init();
104 
106  void Update();
107 
109  void Shutdown();
110 
116  bool AddChild(SharedPtr<Entity> entity);
117 
123  bool RemoveChild(SharedPtr<Entity> entity);
124 
129  void SetInScene(bool in_scene);
130 
135  bool GetInScene() const;
136 
137  protected:
142  bool IsTransformDirty();
143 
145  void UpdateWorldTransform();
146 
147  private:
151 
152  // Transform stuff
153  DirectX::XMFLOAT3 position_;
154  DirectX::XMFLOAT3 rotation_;
155  DirectX::XMFLOAT3 scaling_;
156  DirectX::XMMATRIX world_transform_;
158 
159  bool in_scene_;
160 
163  };
164 }
DirectX::XMFLOAT3 position_
The local position of this Entity.
Definition: entity.h:153
The Blowbox equivalent of a game object.
Definition: entity.h:26
void Shutdown()
Shuts down the Entity.
Definition: entity.cc:124
void SetLocalRotation(const DirectX::XMFLOAT3 &rotation)
Sets the local rotation of this Entity.
Definition: entity.cc:48
SharedPtr< Mesh > GetMesh() const
Definition: entity.cc:86
bool GetInScene() const
Returns whether the Entity is present in the SceneManager.
Definition: entity.cc:173
eastl::vector< T > Vector
Typedef for wrapping the EASTL vector.
Definition: vector.h:14
void SetMesh(SharedPtr< Mesh > mesh)
Sets the Mesh of this Entity.
Definition: entity.cc:62
void SetInScene(bool in_scene)
Sets whether the Entity is present in the SceneManager.
Definition: entity.cc:162
Manages the entire scene.
Definition: scene_manager.h:19
SharedPtr< Mesh > mesh_
The Mesh object that is attached to this Entity.
Definition: entity.h:161
const DirectX::XMFLOAT3 & GetLocalPosition() const
Definition: entity.cc:68
void UpdateWorldTransform()
Updates the world transform based on current position, rotation and scaling.
Definition: entity.cc:185
Factory for creating Entity instances and managing Entity children.
Definition: entity_factory.h:16
Entity(const String &name)
Constructs an Entity.
Definition: entity.cc:10
UploadBuffer constant_buffer_
This Entity&#39;s constant buffer.
Definition: entity.h:162
const DirectX::XMFLOAT3 & GetLocalRotation() const
Definition: entity.cc:74
void SetLocalScaling(const DirectX::XMFLOAT3 &scaling)
Sets the local scaling of this Entity.
Definition: entity.cc:55
const DirectX::XMMATRIX & GetWorldTransform()
Returns the world transform of this Entity.
Definition: entity.cc:92
eastl::weak_ptr< T > WeakPtr
Typedef for wrapping the EASTL weak_ptr.
Definition: weak_ptr.h:14
const Vector< SharedPtr< Entity > > & GetChildren() const
Definition: entity.cc:103
DirectX::XMFLOAT3 scaling_
The local scaling of this Entity.
Definition: entity.h:155
void Init()
Initialises the Entity.
Definition: entity.cc:109
bool IsTransformDirty()
Returns whether the transform is dirty.
Definition: entity.cc:179
DirectX::XMMATRIX world_transform_
The world transform of this Entity.
Definition: entity.h:156
const String & GetName() const
Returns the name of this Entity.
Definition: entity.cc:35
eastl::string String
Typedef for wrapping the EASTL string.
Definition: string.h:13
void SetName(const String &name)
Sets the name of this Entity.
Definition: entity.cc:29
const DirectX::XMFLOAT3 & GetLocalScaling() const
Definition: entity.cc:80
void Update()
Updates the Entity.
Definition: entity.cc:115
The main Blowbox namespace.
Definition: image.cc:8
bool transform_dirty_
Whether the current world_transform_ is dirty (i.e. position/rotation/scaling changed).
Definition: entity.h:157
bool RemoveChild(SharedPtr< Entity > entity)
Removes a child Entity from this Entity.
Definition: entity.cc:147
bool in_scene_
Flag that determines whether this Entity exists in the SceneManager.
Definition: entity.h:159
String name_
The name of this Entity.
Definition: entity.h:148
DirectX::XMFLOAT3 rotation_
The local rotation of this Entity.
Definition: entity.h:154
bool AddChild(SharedPtr< Entity > entity)
Adds a child Entity to this Entity.
Definition: entity.cc:130
Wraps upload buffer types, which allow you to upload data to the GPU.
Definition: upload_buffer.h:19
eastl::shared_ptr< T > SharedPtr
Typedef for wrapping the EASTL shared_ptr.
Definition: shared_ptr.h:14
Vector< SharedPtr< Entity > > children_
All the children of this Entity.
Definition: entity.h:150
void SetLocalPosition(const DirectX::XMFLOAT3 &position)
Sets the local position of this Entity.
Definition: entity.cc:41
~Entity()
Destructs the Entity.
Definition: entity.cc:23
UploadBuffer & GetConstantBuffer()
Definition: entity.h:99
WeakPtr< Entity > parent_
The parent of this Entity.
Definition: entity.h:149