Browse Source

Cleaned up light component code: using a single uniform instead of inheritance of different light types.

Paul A 4 years ago
parent
commit
5f15c8133c
3 changed files with 10 additions and 234 deletions
  1. 5 1
      .gitignore
  2. BIN
      .vs/Praxis3D/v16/.suo
  3. 5 233
      Praxis3D/Source/LightComponent.h

+ 5 - 1
.gitignore

@@ -1,6 +1,6 @@
 Praxis3D/x64/Debug 64bit/Praxis3D.vcxproj.FileListAbsolute.txt
 
-\.vs/
+\.vs/Praxis3D/v16/ipch/
 VC/
 
 *.dae
@@ -21,3 +21,7 @@ VC/
 *.res
 *.recipe
 *.tiff
+*.db
+*.db-shm
+*.db-wal
+*.opendb

BIN
.vs/Praxis3D/v16/.suo


+ 5 - 233
Praxis3D/Source/LightComponent.h

@@ -5,222 +5,7 @@
 #include "ObserverBase.h"
 #include "System.h"
 
-class DirectionalLightComponent : public BaseGraphicsComponent
-{
-	friend class LightComponent;
-public:
-	void load(PropertySet &p_properties) final override
-	{ 
-		// Load property data
-		for(decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
-		{
-			switch(p_properties[i].getPropertyID())
-			{
-			case Properties::Color:
-				m_lightDataSet.m_color = p_properties[i].getVec3f();
-				break;
-
-			case Properties::Direction:
-				// Need to normalize the light direction
-				m_lightDataSet.m_direction = Math::normalize(p_properties[i].getVec3f());
-				break;
-
-			case Properties::Intensity:
-				m_lightDataSet.m_intensity = p_properties[i].getFloat();
-				break;
-				
-			case Properties::WorldRotation:
-				m_lightDataSet.m_direction = p_properties[i].getVec3f();
-				break;
-			}
-		}
-	}
-
-	PropertySet export() final override
-	{ 
-		// Create the root property set
-		PropertySet propertySet(Properties::ArrayEntry);
-		
-		// Add variables
-		propertySet.addProperty(Properties::Type, Properties::DirectionalLight);
-		propertySet.addProperty(Properties::Color, m_lightDataSet.m_color);
-		propertySet.addProperty(Properties::Direction, m_lightDataSet.m_direction);
-		propertySet.addProperty(Properties::Intensity, m_lightDataSet.m_intensity);
-		
-		return propertySet;
-	}
-
-	void update(GraphicsObject &p_parentObject);
-	
-	void changeOccurred(ObservedSubject *p_subject, BitMask p_changeType)
-	{
-		if(p_changeType & Systems::Changes::Graphics::Color)
-		{
-			m_lightDataSet.m_color = p_subject->getVec3(nullptr, Systems::Changes::Graphics::Color);
-		}
-
-		if(p_changeType & Systems::Changes::Graphics::Intensity)
-		{
-			m_lightDataSet.m_intensity = p_subject->getFloat(nullptr, Systems::Changes::Graphics::Intensity);
-		}
-	}
-	
-	BitMask getDesiredSystemChanges() { return Systems::Changes::Graphics::Color | Systems::Changes::Graphics::Intensity; }
-
-private:
-	//DirectionalLightComponent() { }
-	DirectionalLightComponent(DirectionalLightDataSet &p_lightDataSet) : m_lightDataSet(p_lightDataSet) { }
-	~DirectionalLightComponent() { }
-
-	DirectionalLightDataSet m_lightDataSet;
-};
-
-class PointLightComponent : public BaseGraphicsComponent
-{
-	friend class LightComponent;
-public:
-	void load(PropertySet &p_properties) final override
-	{ 
-		// Load property data
-		for(decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
-		{
-			switch(p_properties[i].getPropertyID())
-			{
-			case Properties::Color:
-				m_lightDataSet.m_color = p_properties[i].getVec3f();
-				break;
-
-			case Properties::Intensity:
-				m_lightDataSet.m_intensity = p_properties[i].getFloat();
-				break;
-				
-			case Properties::WorldPosition:
-				m_lightDataSet.m_position = p_properties[i].getVec3f();
-				break;
-			}
-		}
-	}
-
-	PropertySet export() final override
-	{ 		
-		// Create the root property set
-		PropertySet propertySet(Properties::ArrayEntry);
-		
-		// Add variables
-		propertySet.addProperty(Properties::Type, Properties::PointLight);
-		propertySet.addProperty(Properties::Color, m_lightDataSet.m_color);
-		propertySet.addProperty(Properties::Intensity, m_lightDataSet.m_intensity);
-
-		return propertySet;
-	}
-	
-	void update(GraphicsObject &p_parentObject);
-
-	void changeOccurred(ObservedSubject* p_subject, BitMask p_changeType)
-	{
-		if(p_changeType & Systems::Changes::Graphics::Color)
-		{
-			m_lightDataSet.m_color = p_subject->getVec3(nullptr, Systems::Changes::Graphics::Color);
-		}
-
-		if(p_changeType & Systems::Changes::Graphics::Intensity)
-		{
-			m_lightDataSet.m_intensity = p_subject->getFloat(nullptr, Systems::Changes::Graphics::Intensity);
-		}
-	}
-
-	BitMask getDesiredSystemChanges() { return Systems::Changes::Graphics::Color | Systems::Changes::Graphics::Intensity; }
-
-private:
-	//PointLightComponent() { }
-	PointLightComponent(PointLightDataSet &p_lightDataSet) : m_lightDataSet(p_lightDataSet) { }
-	~PointLightComponent() { }
-
-	PointLightDataSet m_lightDataSet;
-};
-
-class SpotLightComponent : public BaseGraphicsComponent
-{
-	friend class LightComponent;
-public:
-	void load(PropertySet &p_properties) final override
-	{ 
-		// Load property data
-		for(decltype(p_properties.getNumProperties()) i = 0, size = p_properties.getNumProperties(); i < size; i++)
-		{
-			switch(p_properties[i].getPropertyID())
-			{
-			case Properties::CutoffAngle:
-				// Convert to radians
-				m_lightDataSet.m_cutoffAngle = cosf(Math::toRadian(p_properties[i].getFloat()));
-				break;
-
-			case Properties::Color:
-				m_lightDataSet.m_color = p_properties[i].getVec3f();
-				break;
-
-			case Properties::Intensity:
-				m_lightDataSet.m_intensity = p_properties[i].getFloat();
-				break;
-				
-			case Properties::WorldPosition:
-				m_lightDataSet.m_position = p_properties[i].getVec3f();
-				break;
-
-			case Properties::WorldRotation:
-				m_lightDataSet.m_direction = p_properties[i].getVec3f();
-				break;
-			}
-		}
-	}
-
-	PropertySet export() final override
-	{ 		
-		// Create the root property set
-		PropertySet propertySet(Properties::ArrayEntry);
-
-		// Add variables
-		propertySet.addProperty(Properties::Type, Properties::SpotLight);
-		// Make sure to revert the cutoff angle back to degrees
-		propertySet.addProperty(Properties::CutoffAngle, Math::toDegree(acosf(m_lightDataSet.m_cutoffAngle)));
-		propertySet.addProperty(Properties::Color, m_lightDataSet.m_color);
-		propertySet.addProperty(Properties::Direction, m_lightDataSet.m_direction);
-		propertySet.addProperty(Properties::Intensity, m_lightDataSet.m_intensity);
-
-		return propertySet;
-	}
-	
-	void update(GraphicsObject &p_parentObject);
-
-	void changeOccurred(ObservedSubject* p_subject, BitMask p_changeType)
-	{
-		if(p_changeType & Systems::Changes::Graphics::Color)
-		{
-			m_lightDataSet.m_color = p_subject->getVec3(nullptr, Systems::Changes::Graphics::Color);
-		}
-
-		if(p_changeType & Systems::Changes::Graphics::Intensity)
-		{
-			m_lightDataSet.m_intensity = p_subject->getFloat(nullptr, Systems::Changes::Graphics::Intensity);
-		}
-
-		if(p_changeType & Systems::Changes::Graphics::CutoffAngle)
-		{
-			m_lightDataSet.m_cutoffAngle = p_subject->getFloat(nullptr, Systems::Changes::Graphics::CutoffAngle);
-		}
-	}
-
-	BitMask getDesiredSystemChanges() { return Systems::Changes::Graphics::Color | Systems::Changes::Graphics::Intensity | Systems::Changes::Graphics::CutoffAngle; }
-
-private:
-	//SpotLightComponent() { }
-	SpotLightComponent(SpotLightDataSet &p_lightDataSet) : m_lightDataSet(p_lightDataSet) { }
-	~SpotLightComponent() { }
-
-	SpotLightDataSet m_lightDataSet;
-};
-
-class LightComponent : public BaseGraphicsComponent
+class LightComponent
 {
 public:
 	enum LightComponentType
@@ -234,43 +19,32 @@ public:
 	{
 		m_lightComponentType = LightComponentType::LightComponentType_directional;
 		m_lightComponent.m_directional = p_lightDataSet;
-		m_currentLightComponent = &m_lightComponent.m_directional;
 	}
 	LightComponent(PointLightDataSet &p_lightDataSet)
 	{
 		m_lightComponentType = LightComponentType::LightComponentType_point;
 		m_lightComponent.m_point = p_lightDataSet;
-		m_currentLightComponent = &m_lightComponent.m_point;
 	}
 	LightComponent(SpotLightDataSet &p_lightDataSet)
 	{
 		m_lightComponentType = LightComponentType::LightComponentType_spot;
 		m_lightComponent.m_spot = p_lightDataSet;
-		m_currentLightComponent = &m_lightComponent.m_spot;
 	}
 
 	~LightComponent() 
 	{
+		// Nothing to delete so far
 		switch(m_lightComponentType)
 		{
 		case LightComponent::LightComponentType_directional:
-			//delete m_lightComponent.m_directional;
 			break;
 		case LightComponent::LightComponentType_point:
-			//delete m_lightComponent.m_point;
 			break;
 		case LightComponent::LightComponentType_spot:
-			//delete m_lightComponent.m_spot;
 			break;
 		}
 	}
 
-	void load(PropertySet& p_properties) final override { m_currentLightComponent->load(p_properties); }
-
-	PropertySet export() final override { return m_currentLightComponent->export(); }
-
-	void update(GraphicsObject &p_parentObject) final override { m_currentLightComponent->update(p_parentObject); }
-
 	void updateSpatialData(SpatialTransformData &p_data)
 	{
 		// Update each type of light individually, as their spatial data is made up of different attributes
@@ -289,14 +63,13 @@ public:
 		}
 	}
 
-	void changeOccurred(ObservedSubject *p_subject, BitMask p_changeType) final override { m_currentLightComponent->changeOccurred(p_subject, p_changeType); }
-
-	BitMask getDesiredSystemChanges() final override { return m_currentLightComponent->getDesiredSystemChanges(); }
-
 	LightComponentType getLightType() { return m_lightComponentType; }
 
+	// Get the directional light data set. If the type of light is not directional, returns a null pointer
 	DirectionalLightDataSet *getDirectionalLight() { return (m_lightComponentType == LightComponentType::LightComponentType_directional) ? &m_lightComponent.m_directional : nullptr; }
+	// Get the point light data set. If the type of light is not point, returns a null pointer
 	PointLightDataSet *getSpotLight() { return (m_lightComponentType == LightComponentType::LightComponentType_point) ? &m_lightComponent.m_point : nullptr; }
+	// Get the spot light data set. If the type of light is not spot, returns a null pointer
 	SpotLightDataSet *getPointLight() { return (m_lightComponentType == LightComponentType::LightComponentType_spot) ? &m_lightComponent.m_spot : nullptr; }
 
 private:
@@ -311,5 +84,4 @@ private:
 	} m_lightComponent;
 
 	LightComponentType m_lightComponentType;
-	BaseGraphicsComponent *m_currentLightComponent;
 };