Skip to content

Commit

Permalink
Renamed GameObject/GameComponent to Entity/EntityComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
BennyQBD committed Jun 28, 2014
1 parent 732fddf commit c735925
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/3DEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "transform.h"
#include "camera.h"
#include "lighting.h"
#include "gameObject.h"
#include "entity.h"
#include "meshRenderer.h"
#include "window.h"
#include "coreEngine.h"
Expand Down
4 changes: 2 additions & 2 deletions src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ void CameraComponent::AddToEngine(CoreEngine* engine) const
engine->GetRenderingEngine()->SetMainCamera(m_camera);
}

void CameraComponent::SetParent(GameObject* parent)
void CameraComponent::SetParent(Entity* parent)
{
GameComponent::SetParent(parent);
EntityComponent::SetParent(parent);

//The camera's transform is initialized here because this is the first point where
//there is a parent object with a transform.
Expand Down
6 changes: 3 additions & 3 deletions src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define CAMERA_H

#include "math3d.h"
#include "gameComponent.h"
#include "entityComponent.h"

//Cameras represent a location, orientation, and projection from
//which the scene can be rendered.
Expand Down Expand Up @@ -50,7 +50,7 @@ class Camera

//CameraComponents are an easy way to use a camera as a component
//on a game object.
class CameraComponent : public GameComponent
class CameraComponent : public EntityComponent
{
public:
//The camera's transform is initialized to 0 (null) because
Expand All @@ -64,7 +64,7 @@ class CameraComponent : public GameComponent
inline Matrix4f GetViewProjection() const { return m_camera.GetViewProjection(); }

inline void SetProjection(const Matrix4f& projection) { m_camera.SetProjection(projection); }
virtual void SetParent(GameObject* parent);
virtual void SetParent(Entity* parent);
protected:
private:
Camera m_camera; //The camera that's being used like a component.
Expand Down
30 changes: 15 additions & 15 deletions src/gameObject.h → src/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,51 @@
* limitations under the License.
*/

#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H
#ifndef ENTITYOBJECT_H
#define ENTITYOBJECT_H

#include <vector>
#include "transform.h"
#include "input.h"
class Camera;
class CoreEngine;
class GameComponent;
class EntityComponent;
class Shader;
class RenderingEngine;

class GameObject
class Entity
{
public:
GameObject(const Vector3f& pos = Vector3f(0,0,0), const Quaternion& rot = Quaternion(0,0,0,1), float scale = 1.0f) :
Entity(const Vector3f& pos = Vector3f(0,0,0), const Quaternion& rot = Quaternion(0,0,0,1), float scale = 1.0f) :
m_transform(pos, rot, scale),
m_coreEngine(0) {}

virtual ~GameObject();
virtual ~Entity();

GameObject* AddChild(GameObject* child);
GameObject* AddComponent(GameComponent* component);
Entity* AddChild(Entity* child);
Entity* AddComponent(EntityComponent* component);

void ProcessInputAll(const Input& input, float delta);
void UpdateAll(float delta);
void RenderAll(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const;

std::vector<GameObject*> GetAllAttached();
std::vector<Entity*> GetAllAttached();

inline Transform* GetTransform() { return &m_transform; }
void SetEngine(CoreEngine* engine);
protected:
private:
std::vector<GameObject*> m_children;
std::vector<GameComponent*> m_components;
Transform m_transform;
CoreEngine* m_coreEngine;
std::vector<Entity*> m_children;
std::vector<EntityComponent*> m_components;
Transform m_transform;
CoreEngine* m_coreEngine;

void ProcessInput(const Input& input, float delta);
void Update(float delta);
void Render(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const;

GameObject(const GameObject& other) {}
void operator=(const GameObject& other) {}
Entity(const Entity& other) {}
void operator=(const Entity& other) {}
};

#endif // GAMEOBJECT_H
20 changes: 10 additions & 10 deletions src/gameComponent.h → src/entityComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
* limitations under the License.
*/

#ifndef GAMECOMPONENT_H_INCLUDED
#define GAMECOMPONENT_H_INCLUDED
#ifndef ENTITYCOMPONENT_H_INCLUDED
#define ENTITYCOMPONENT_H_INCLUDED

#include "transform.h"
#include "gameObject.h"
#include "entity.h"
#include "input.h"
class RenderingEngine;
class Shader;

class GameComponent
class EntityComponent
{
public:
GameComponent() :
EntityComponent() :
m_parent(0) {}
virtual ~GameComponent() {}
virtual ~EntityComponent() {}

virtual void ProcessInput(const Input& input, float delta) {}
virtual void Update(float delta) {}
Expand All @@ -39,12 +39,12 @@ class GameComponent
inline Transform* GetTransform() { return m_parent->GetTransform(); }
inline const Transform& GetTransform() const { return *m_parent->GetTransform(); }

virtual void SetParent(GameObject* parent) { m_parent = parent; }
virtual void SetParent(Entity* parent) { m_parent = parent; }
private:
GameObject* m_parent;
Entity* m_parent;

GameComponent(const GameComponent& other) {}
void operator=(const GameComponent& other) {}
EntityComponent(const EntityComponent& other) {}
void operator=(const EntityComponent& other) {}
};

#endif // GAMECOMPONENT_H_INCLUDED
4 changes: 2 additions & 2 deletions src/freeLook.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#define FREELOOK_H

#include "math3d.h"
#include "gameComponent.h"
#include "entityComponent.h"

class FreeLook : public GameComponent
class FreeLook : public EntityComponent
{
public:
FreeLook(const Vector2f& windowCenter, float sensitivity = 0.5f, int unlockMouseKey = Input::KEY_ESCAPE) :
Expand Down
4 changes: 2 additions & 2 deletions src/freeMove.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#define FREEMOVE_H

#include "math3d.h"
#include "gameComponent.h"
#include "entityComponent.h"

class FreeMove : public GameComponent
class FreeMove : public EntityComponent
{
public:
FreeMove(float speed = 10.0f, int forwardKey = Input::KEY_W, int backKey = Input::KEY_S, int leftKey = Input::KEY_A, int rightKey = Input::KEY_D) :
Expand Down
6 changes: 3 additions & 3 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef MYGAME_H
#define MYGAME_H

#include "gameObject.h"
#include "entity.h"
#include "coreEngine.h"
#include "profiling.h"

Expand All @@ -37,14 +37,14 @@ class Game

inline void SetEngine(CoreEngine* engine) { m_root.SetEngine(engine); }
protected:
void AddToScene(GameObject* child) { m_root.AddChild(child); }
void AddToScene(Entity* child) { m_root.AddChild(child); }
private:
Game(Game& game) {}
void operator=(Game& game) {}

ProfileTimer m_updateTimer;
ProfileTimer m_inputTimer;
GameObject m_root;
Entity m_root;
};

#endif
30 changes: 15 additions & 15 deletions src/gameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

#include "gameObject.h"
#include "gameComponent.h"
#include "entity.h"
#include "entityComponent.h"
#include "coreEngine.h"

GameObject::~GameObject()
Entity::~Entity()
{
for(unsigned int i = 0; i < m_components.size(); i++)
{
Expand All @@ -37,22 +37,22 @@ GameObject::~GameObject()
}
}

GameObject* GameObject::AddChild(GameObject* child)
Entity* Entity::AddChild(Entity* child)
{
m_children.push_back(child);
child->GetTransform()->SetParent(&m_transform);
child->SetEngine(m_coreEngine);
return this;
}

GameObject* GameObject::AddComponent(GameComponent* component)
Entity* Entity::AddComponent(EntityComponent* component)
{
m_components.push_back(component);
component->SetParent(this);
return this;
}

void GameObject::ProcessInputAll(const Input& input, float delta)
void Entity::ProcessInputAll(const Input& input, float delta)
{
ProcessInput(input, delta);

Expand All @@ -62,7 +62,7 @@ void GameObject::ProcessInputAll(const Input& input, float delta)
}
}

void GameObject::UpdateAll(float delta)
void Entity::UpdateAll(float delta)
{
Update(delta);

Expand All @@ -72,7 +72,7 @@ void GameObject::UpdateAll(float delta)
}
}

void GameObject::RenderAll(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const
void Entity::RenderAll(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const
{
Render(shader, renderingEngine, camera);

Expand All @@ -82,7 +82,7 @@ void GameObject::RenderAll(const Shader& shader, const RenderingEngine& renderin
}
}

void GameObject::ProcessInput(const Input& input, float delta)
void Entity::ProcessInput(const Input& input, float delta)
{
m_transform.Update();

Expand All @@ -92,23 +92,23 @@ void GameObject::ProcessInput(const Input& input, float delta)
}
}

void GameObject::Update(float delta)
void Entity::Update(float delta)
{
for(unsigned int i = 0; i < m_components.size(); i++)
{
m_components[i]->Update(delta);
}
}

void GameObject::Render(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const
void Entity::Render(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const
{
for(unsigned int i = 0; i < m_components.size(); i++)
{
m_components[i]->Render(shader, renderingEngine, camera);
}
}

void GameObject::SetEngine(CoreEngine* engine)
void Entity::SetEngine(CoreEngine* engine)
{
if(m_coreEngine != engine)
{
Expand All @@ -126,13 +126,13 @@ void GameObject::SetEngine(CoreEngine* engine)
}
}

std::vector<GameObject*> GameObject::GetAllAttached()
std::vector<Entity*> Entity::GetAllAttached()
{
std::vector<GameObject*> result;
std::vector<Entity*> result;

for(unsigned int i = 0; i < m_children.size(); i++)
{
std::vector<GameObject*> childObjects = m_children[i]->GetAllAttached();
std::vector<Entity*> childObjects = m_children[i]->GetAllAttached();
result.insert(result.end(), childObjects.begin(), childObjects.end());
}

Expand Down
4 changes: 2 additions & 2 deletions src/lighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define LIGHTING_H

#include "math3d.h"
#include "gameComponent.h"
#include "entityComponent.h"
#include "shader.h"

class CoreEngine;
Expand Down Expand Up @@ -64,7 +64,7 @@ class ShadowInfo
float m_minVariance;
};

class BaseLight : public GameComponent
class BaseLight : public EntityComponent
{
public:
BaseLight(const Vector3f& color, float intensity, const Shader& shader) :
Expand Down
18 changes: 9 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ void TestGame::Init(const Window& window)
}
Mesh customMesh("square", square.Finalize());

AddToScene((new GameObject(Vector3f(0, -1, 5), Quaternion(), 32.0f))
AddToScene((new Entity(Vector3f(0, -1, 5), Quaternion(), 32.0f))
->AddComponent(new MeshRenderer(Mesh("terrain02.obj"), Material("bricks"))));

AddToScene((new GameObject(Vector3f(7,0,7)))
AddToScene((new Entity(Vector3f(7,0,7)))
->AddComponent(new PointLight(Vector3f(0,1,0), 0.4f, Attenuation(0,0,1))));

AddToScene((new GameObject(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f))))
AddToScene((new Entity(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f))))
->AddComponent(new SpotLight(Vector3f(0,1,1), 0.4f, Attenuation(0,0,0.02f), ToRadians(91.1f), 7, 1.0f, 0.5f)));

AddToScene((new GameObject(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45))))
AddToScene((new Entity(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45))))
->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f, 10, 80.0f, 1.0f)));

AddToScene((new GameObject(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f))
AddToScene((new Entity(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f))
->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2")))
->AddChild((new GameObject(Vector3f(0, 0, 25)))
->AddChild((new Entity(Vector3f(0, 0, 25)))
->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2")))
->AddChild((new GameObject())
->AddChild((new Entity())
->AddComponent(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70.0f), window.GetAspect(), 0.1f, 1000.0f)))
->AddComponent(new FreeLook(window.GetCenter()))
->AddComponent(new FreeMove(10.0f)))));

AddToScene((new GameObject(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f))))
AddToScene((new Entity(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f))))
->AddComponent(new MeshRenderer(Mesh("cube.obj"), Material("bricks2"))));

AddToScene((new GameObject(Vector3f(0,0,7), Quaternion(), 1.0f))
AddToScene((new Entity(Vector3f(0,0,7), Quaternion(), 1.0f))
->AddComponent(new MeshRenderer(Mesh("square"), Material("bricks2"))));
}

Expand Down
4 changes: 2 additions & 2 deletions src/meshRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#ifndef MESHRENDERER_H_INCLUDED
#define MESHRENDERER_H_INCLUDED

#include "gameComponent.h"
#include "entityComponent.h"
#include "mesh.h"

class MeshRenderer : public GameComponent
class MeshRenderer : public EntityComponent
{
public:
MeshRenderer(const Mesh& mesh, const Material& material) :
Expand Down
Loading

0 comments on commit c735925

Please sign in to comment.