Turned the Transform namespace into TransformSystem so it would be able to subscribe to EntityDeleted and clean up after itself

This commit is contained in:
2016-03-13 00:55:53 +01:00
parent f6113b9d9c
commit a1fda82d3a
31 changed files with 311 additions and 128 deletions
+1 -1
View File
@@ -12,7 +12,7 @@
#include "../Core/AABB.h"
#include "Rendering/RawModelCustom.h"
//#include "Rendering/RawModelAssimp.h"
#include "../Core/Transform.h"
#include "../Core/TransformSystem.h"
#include "../Core/Entity.h"
#include "../Core/EntityWrapper.h"
#include "EntityAABB.h"
-30
View File
@@ -1,30 +0,0 @@
#ifndef Transform_h__
#define Transform_h__
#include "../GLM.h"
#include "World.h"
#include "EntityWrapper.h"
namespace Transform
{
//glm::mat4 AbsoluteTransformation(EntityWrapper entity);
glm::vec3 AbsolutePosition(EntityWrapper entity);
glm::vec3 AbsolutePosition(World* world, EntityID entity);
glm::vec3 AbsoluteOrientationEuler(EntityWrapper entity);
glm::quat AbsoluteOrientation(EntityWrapper entity);
glm::quat AbsoluteOrientation(World* world, EntityID entity);
glm::vec3 AbsoluteScale(EntityWrapper entity);
glm::vec3 AbsoluteScale(World* world, EntityID entity);
glm::mat4 ModelMatrix(EntityWrapper entity);
glm::mat4 ModelMatrix(EntityID entity, World* world);
glm::vec3 TransformPoint(const glm::vec3& point, const glm::mat4& matrix);
extern int RecalculatedPositions;
extern int RecalculatedOrientations;
extern int RecalculatedScales;
}
#endif
+39
View File
@@ -0,0 +1,39 @@
#ifndef Transform_h__
#define Transform_h__
#include "../GLM.h"
#include "System.h"
#include "EEntityDeleted.h"
class TransformSystem : public System
{
public:
TransformSystem(SystemParams params);
//glm::mat4 AbsoluteTransformation(EntityWrapper entity);
static glm::vec3 AbsolutePosition(EntityWrapper entity);
static glm::vec3 AbsolutePosition(World* world, EntityID entity);
static glm::vec3 AbsoluteOrientationEuler(EntityWrapper entity);
static glm::quat AbsoluteOrientation(EntityWrapper entity);
static glm::quat AbsoluteOrientation(World* world, EntityID entity);
static glm::vec3 AbsoluteScale(EntityWrapper entity);
static glm::vec3 AbsoluteScale(World* world, EntityID entity);
static glm::mat4 ModelMatrix(EntityWrapper entity);
static glm::mat4 ModelMatrix(EntityID entity, World* world);
static glm::vec3 TransformPoint(const glm::vec3& point, const glm::mat4& matrix);
static int RecalculatedPositions;
static int RecalculatedOrientations;
static int RecalculatedScales;
private:
static std::unordered_map<EntityWrapper, glm::vec3> PositionCache;
static std::unordered_map<EntityWrapper, glm::quat> OrientationCache;
static std::unordered_map<EntityWrapper, glm::vec3> ScaleCache;
static std::unordered_map<EntityWrapper, glm::mat4> MatrixCache;
EventRelay<TransformSystem, Events::EntityDeleted> m_EEntityDeleted;
bool OnEntityDeleted(const Events::EntityDeleted& e);
};
#endif
@@ -7,7 +7,7 @@
#include "../GLM.h"
#include "../Core/ComponentWrapper.h"
#include "RenderJob.h"
#include "../Core/Transform.h"
#include "../Core/TransformSystem.h"
#include "../Core/World.h"
struct DirectionalLightJob : RenderJob
@@ -16,7 +16,7 @@ struct DirectionalLightJob : RenderJob
: RenderJob()
{
Direction = glm::vec4(0,0,-1,0) * glm::inverse(Transform::AbsoluteOrientation(m_World, transformComponent.EntityID));
Direction = glm::vec4(0,0,-1,0) * glm::inverse(TransformSystem::AbsoluteOrientation(m_World, transformComponent.EntityID));
//Direction = glm::vec4((glm::vec3)directionalLightComponent["Direction"], 0.f);
Color = (glm::vec4)directionalLightComponent["Color"];
Intensity = (double)directionalLightComponent["Intensity"];
+1 -1
View File
@@ -12,7 +12,7 @@
#include "../Core/ResourceManager.h"
#include "Camera.h"
#include "../Core/World.h"
#include "../Core/Transform.h"
#include "../Core/TransformSystem.h"
#include "Skeleton.h"
#include "ShaderProgram.h"
#include "BlendTree.h"
+2 -2
View File
@@ -7,7 +7,7 @@
#include "../GLM.h"
#include "../Core/ComponentWrapper.h"
#include "RenderJob.h"
#include "../Core/Transform.h"
#include "../Core/TransformSystem.h"
#include "../Core/World.h"
struct PointLightJob : RenderJob
@@ -16,7 +16,7 @@ struct PointLightJob : RenderJob
: RenderJob()
{
Position = glm::vec4((glm::vec3)transformComponent["Position"], 1.0f);
Position = glm::vec4(Transform::AbsolutePosition(m_World, transformComponent.EntityID), 1.f);
Position = glm::vec4(TransformSystem::AbsolutePosition(m_World, transformComponent.EntityID), 1.f);
Color = (glm::vec4)pointLightComponent["Color"];
Radius = (double)pointLightComponent["Radius"];
Intensity = (double)pointLightComponent["Intensity"];
+1 -1
View File
@@ -14,7 +14,7 @@
#include "ModelJob.h"
#include "Renderer.h"
#include "PointLightJob.h"
#include "../Core/Transform.h"
#include "../Core/TransformSystem.h"
#include "../Core/EPlayerSpawned.h"
#include "../Core/Octree.h"
#include "../Collision/EntityAABB.h"
+1 -1
View File
@@ -22,7 +22,7 @@
#include "../Core/EventBroker.h"
#include "ImGuiRenderPass.h"
#include "Camera.h"
#include "../Core/Transform.h"
#include "../Core/TransformSystem.h"
#include "imgui/imgui.h"
#include "TextPass.h"
#include "Util/CommonFunctions.h"
+3 -3
View File
@@ -13,7 +13,7 @@
#include "../Core/ResourceManager.h"
#include "Camera.h"
#include "../Core/World.h"
#include "../Core/Transform.h"
#include "../Core/TransformSystem.h"
#include "Skeleton.h"
struct SpriteJob : RenderJob
@@ -37,7 +37,7 @@ struct SpriteJob : RenderJob
BlurBackground = (bool)cSprite["BlurBackground"];
Entity = cSprite.EntityID;
Position = Transform::AbsolutePosition(world, cSprite.EntityID);
Position = TransformSystem::AbsolutePosition(world, cSprite.EntityID);
Depth = 0;
if (depthSorted) {
glm::vec3 viewpos = glm::vec3(camera->ViewMatrix() * glm::vec4(Position, 1));
@@ -50,7 +50,7 @@ struct SpriteJob : RenderJob
FillColor = fillColor;
FillPercentage = fillPercentage;
glm::vec3 scale = Transform::AbsoluteScale(world, cSprite.EntityID);
glm::vec3 scale = TransformSystem::AbsoluteScale(world, cSprite.EntityID);
if((bool)cSprite["KeepRatio"] == true) {
if(scale.y >= scale.x) {
+1 -1
View File
@@ -15,7 +15,7 @@
#include "Core/EventBroker.h"
#include "../Engine/Core/ResourceManager.h"
#include "../Engine/Core/ConfigFile.h"
#include "Core/Transform.h" // Absolute transform
#include "Core/TransformSystem.h"
#include "Sound/Sound.h"
#include "../Engine/Sound/EPlayQueueOnEntity.h"
#include "Sound/EPlaySoundOnEntity.h"